* platform project (RICP).
*/
+#include <chrono>
#include <sstream>
-#include <sys/poll.h>
#include <sdl/asyncstorage.hpp>
#include <sdl/backenderror.hpp>
#include <sdl/errorqueries.hpp>
}
}
+/* TODO: This synchronous API implementation could probably be refactored to be boost::asio based
+ * instead of current (bit error prone) poll based implementation.
+ */
+
SyncStorageImpl::SyncStorageImpl(std::unique_ptr<AsyncStorage> asyncStorage):
SyncStorageImpl(std::move(asyncStorage), System::getSystem())
{
System& system):
asyncStorage(std::move(pAsyncStorage)),
system(system),
- pFd(asyncStorage->fd()),
localStatus(false),
- synced(false)
+ synced(false),
+ isReady(false),
+ events{ asyncStorage->fd(), POLLIN, 0 },
+ operationTimeout(std::chrono::steady_clock::duration::zero())
+{
+}
+
+void SyncStorageImpl::waitReadyAck(const std::error_code&)
{
+ isReady = true;
}
void SyncStorageImpl::modifyAck(const std::error_code& error)
throwExceptionForErrorCode(localError);
}
-void SyncStorageImpl::waitForCallback()
+void SyncStorageImpl::waitForOperationCallback()
{
- struct pollfd events { pFd, POLLIN, 0 };
while(!synced)
- if (system.poll(&events, 1, -1) > 0 && (events.revents & POLLIN))
- asyncStorage->handleEvents();
+ pollAndHandleEvents(NO_TIMEOUT);
+}
+
+void SyncStorageImpl::pollAndHandleEvents(int timeout_ms)
+{
+ if (system.poll(&events, 1, timeout_ms) > 0 && (events.revents & POLLIN))
+ asyncStorage->handleEvents();
+}
+
+void SyncStorageImpl::waitForReadinessCheckCallback()
+{
+ if (operationTimeout == std::chrono::steady_clock::duration::zero())
+ {
+ while (!isReady)
+ pollAndHandleEvents(NO_TIMEOUT);
+ }
+ else
+ {
+ int pollTimeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(operationTimeout).count() / 10;
+ std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
+ while(!isReady && (std::chrono::steady_clock::now() - start < operationTimeout))
+ pollAndHandleEvents(pollTimeout_ms);
+ }
}
void SyncStorageImpl::waitSdlToBeReady(const Namespace& ns)
{
- synced = false;
+ isReady = false;
asyncStorage->waitReadyAsync(ns,
- std::bind(&shareddatalayer::SyncStorageImpl::modifyAck,
+ std::bind(&shareddatalayer::SyncStorageImpl::waitReadyAck,
this,
std::error_code()));
- waitForCallback();
- verifyBackendResponse();
+ waitForReadinessCheckCallback();
}
void SyncStorageImpl::set(const Namespace& ns, const DataMap& dataMap)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
+
asyncStorage->setAsync(ns,
dataMap,
std::bind(&shareddatalayer::SyncStorageImpl::modifyAck,
this,
std::placeholders::_1));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
}
bool SyncStorageImpl::setIf(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->setIfAsync(ns,
this,
std::placeholders::_1,
std::placeholders::_2));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
return localStatus;
}
bool SyncStorageImpl::setIfNotExists(const Namespace& ns, const Key& key, const Data& data)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->setIfNotExistsAsync(ns,
this,
std::placeholders::_1,
std::placeholders::_2));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
return localStatus;
}
SyncStorageImpl::DataMap SyncStorageImpl::get(const Namespace& ns, const Keys& keys)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->getAsync(ns,
this,
std::placeholders::_1,
std::placeholders::_2));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
return localMap;
}
void SyncStorageImpl::remove(const Namespace& ns, const Keys& keys)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->removeAsync(ns,
std::bind(&shareddatalayer::SyncStorageImpl::modifyAck,
this,
std::placeholders::_1));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
}
bool SyncStorageImpl::removeIf(const Namespace& ns, const Key& key, const Data& data)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->removeIfAsync(ns,
this,
std::placeholders::_1,
std::placeholders::_2));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
return localStatus;
}
SyncStorageImpl::Keys SyncStorageImpl::findKeys(const Namespace& ns, const std::string& keyPrefix)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->findKeysAsync(ns,
this,
std::placeholders::_1,
std::placeholders::_2));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
return localKeys;
}
void SyncStorageImpl::removeAll(const Namespace& ns)
{
+ handlePendingEvents();
waitSdlToBeReady(ns);
synced = false;
asyncStorage->removeAllAsync(ns,
std::bind(&shareddatalayer::SyncStorageImpl::modifyAck,
this,
std::placeholders::_1));
- waitForCallback();
+ waitForOperationCallback();
verifyBackendResponse();
}
+
+void SyncStorageImpl::handlePendingEvents()
+{
+ int pollRetVal = system.poll(&events, 1, 0);
+
+ while (pollRetVal > 0 && events.revents & POLLIN)
+ {
+ asyncStorage->handleEvents();
+ pollRetVal = system.poll(&events, 1, 0);
+ }
+}
+
+void SyncStorageImpl::setOperationTimeout(const std::chrono::steady_clock::duration& timeout)
+{
+ operationTimeout = timeout;
+}
SyncStorage::DataMap dataMap;
SyncStorage::Keys keys;
const SyncStorage::Namespace ns;
+ std::chrono::steady_clock::duration TEST_OPERATION_WAIT_TIMEOUT;
+ int TEST_OPERATION_POLL_WAIT_TIMEOUT;
SyncStorageImplTest():
asyncStorageMockPassedToImplementation(new StrictMock<AsyncStorageMock>()),
asyncStorageMockRawPtr(asyncStorageMockPassedToImplementation.get()),
pFd(10),
dataMap({{ "key1", { 0x0a, 0x0b, 0x0c } }, { "key2", { 0x0d, 0x0e, 0x0f, 0xff } }}),
keys({ "key1", "key2" }),
- ns("someKnownNamespace")
+ ns("someKnownNamespace"),
+ TEST_OPERATION_WAIT_TIMEOUT(std::chrono::seconds(1)),
+ TEST_OPERATION_POLL_WAIT_TIMEOUT(std::chrono::duration_cast<std::chrono::milliseconds>(TEST_OPERATION_WAIT_TIMEOUT).count() / 10)
{
expectConstructorCalls();
syncStorage.reset(new SyncStorageImpl(std::move(asyncStorageMockPassedToImplementation), systemMock));
}
+ ~SyncStorageImplTest()
+ {
+ syncStorage->setOperationTimeout(std::chrono::steady_clock::duration::zero());
+ }
+
void expectConstructorCalls()
{
InSequence dummy;
.WillOnce(Return(pFd));
}
- void expectSdlReadinessCheck()
+ void expectSdlReadinessCheck(int timeout)
{
InSequence dummy;
+ expectPollForPendingEvents_ReturnNoEvents();
expectWaitReadyAsync();
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(timeout);
+ expectHandleEvents_callWaitReadyAck();
}
- void expectPollWait()
+ void expectPollForPendingEvents_ReturnNoEvents()
{
- EXPECT_CALL(systemMock, poll( _, 1, -1))
+ EXPECT_CALL(systemMock, poll( _, 1, 0))
+ .Times(1)
+ .WillOnce(Invoke([](struct pollfd *, nfds_t, int)
+ {
+ return 0;
+ }));
+ }
+
+ void expectPollWait(int timeout)
+ {
+ EXPECT_CALL(systemMock, poll( _, 1, timeout))
.Times(1)
.WillOnce(Invoke([](struct pollfd *fds, nfds_t, int)
{
}
void expectHandleEvents()
+ {
+ EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
+ .Times(1);
+ }
+
+ void expectHandleEvents_callWaitReadyAck()
{
EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
.Times(1)
}));
}
+ void expectHandleEvents_callModifyAck()
+ {
+ EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
+ .Times(1)
+ .WillOnce(Invoke([this]()
+ {
+ savedModifyAck(std::error_code());
+ }));
+ }
+
void expectWaitReadyAsync()
{
EXPECT_CALL(*asyncStorageMockRawPtr, waitReadyAsync(ns,_))
TEST_F(SyncStorageImplTest, EventsAreNotHandledWhenPollReturnsError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetAsync(dataMap);
expectPollError();
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
syncStorage->set(ns, dataMap);
}
TEST_F(SyncStorageImplTest, EventsAreNotHandledWhenThereIsAnExceptionalConditionOnTheFd)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetAsync(dataMap);
expectPollExceptionalCondition();
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
syncStorage->set(ns, dataMap);
}
TEST_F(SyncStorageImplTest, SetSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
+ expectSetAsync(dataMap);
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->set(ns, dataMap);
+}
+
+TEST_F(SyncStorageImplTest, SetWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
expectSetAsync(dataMap);
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
syncStorage->set(ns, dataMap);
}
TEST_F(SyncStorageImplTest, SetCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetAsync(dataMap);
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyAckWithError();
EXPECT_THROW(syncStorage->set(ns, dataMap), BackendError);
}
TEST_F(SyncStorageImplTest, SetIfSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetAsync(dataMap);
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
syncStorage->set(ns, dataMap);
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfAsync("key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->setIf(ns, "key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
+}
+
+TEST_F(SyncStorageImplTest, SetIfWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
+ expectSetAsync(dataMap);
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
+ syncStorage->set(ns, dataMap);
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
+ expectSetIfAsync("key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
syncStorage->setIf(ns, "key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
}
TEST_F(SyncStorageImplTest, SetIfCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetAsync(dataMap);
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
syncStorage->set(ns, dataMap);
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfAsync("key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, false);
EXPECT_THROW(syncStorage->setIf(ns, "key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f }), BackendError);
}
TEST_F(SyncStorageImplTest, SetIfNotExistsSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
+ expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectModifyIfAck(std::error_code(), true);
+ EXPECT_TRUE(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }));
+}
+
+TEST_F(SyncStorageImplTest, SetIfNotExistsIfWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(std::error_code(), true);
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
EXPECT_TRUE(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }));
}
TEST_F(SyncStorageImplTest, SetIfNotExistsReturnsFalseIfKeyAlreadyExists)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(std::error_code(), false);
EXPECT_FALSE(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }));
}
TEST_F(SyncStorageImplTest, SetIfNotExistsCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, false);
EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
}
TEST_F(SyncStorageImplTest, GetSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
+ expectGetAsync(keys);
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectGetAck();
+ auto map(syncStorage->get(ns, keys));
+ EXPECT_EQ(map, dataMap);
+}
+
+TEST_F(SyncStorageImplTest, GetWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
expectGetAsync(keys);
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectGetAck();
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
auto map(syncStorage->get(ns, keys));
EXPECT_EQ(map, dataMap);
}
TEST_F(SyncStorageImplTest, GetCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectGetAsync(keys);
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectGetAckWithError();
EXPECT_THROW(syncStorage->get(ns, keys), BackendError);
}
TEST_F(SyncStorageImplTest, RemoveSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
+ expectRemoveAsync(keys);
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->remove(ns, keys);
+}
+
+TEST_F(SyncStorageImplTest, RemoveWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
expectRemoveAsync(keys);
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
syncStorage->remove(ns, keys);
}
TEST_F(SyncStorageImplTest, RemoveCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectRemoveAsync(keys);
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyAckWithError();
EXPECT_THROW(syncStorage->remove(ns, keys), BackendError);
}
TEST_F(SyncStorageImplTest, RemoveIfSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(std::error_code(), true);
EXPECT_TRUE(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }));
}
+TEST_F(SyncStorageImplTest, RemoveIfWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
+ expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectModifyIfAck(std::error_code(), true);
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
+ EXPECT_TRUE(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }));
+}
+
TEST_F(SyncStorageImplTest, RemoveIfReturnsFalseIfKeyDoesnotMatch)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(std::error_code(), false);
EXPECT_FALSE(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }));
}
TEST_F(SyncStorageImplTest, RemoveIfCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, false);
EXPECT_THROW(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
}
TEST_F(SyncStorageImplTest, FindKeysSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectFindKeysAsync();
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectFindKeysAck();
auto ids(syncStorage->findKeys(ns, "*"));
EXPECT_EQ(ids, keys);
}
+TEST_F(SyncStorageImplTest, FindKeysWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
+ expectFindKeysAsync();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectFindKeysAck();
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
+ auto ids(syncStorage->findKeys(ns, "*"));
+ EXPECT_EQ(ids, keys);
+}
+
TEST_F(SyncStorageImplTest, FindKeysAckCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectFindKeysAsync();
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectFindKeysAckWithError();
EXPECT_THROW(syncStorage->findKeys(ns, "*"), BackendError);
}
TEST_F(SyncStorageImplTest, RemoveAllSuccessfully)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
+ expectRemoveAllAsync();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->removeAll(ns);
+}
+
+TEST_F(SyncStorageImplTest, RemoveAllWithReadinessTimeoutSuccessfully)
+{
+ InSequence dummy;
+ expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
expectRemoveAllAsync();
- expectPollWait();
- expectHandleEvents();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
+ expectHandleEvents_callModifyAck();
+ syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
syncStorage->removeAll(ns);
}
TEST_F(SyncStorageImplTest, RemoveAllCanThrowBackendError)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectRemoveAllAsync();
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyAckWithError();
EXPECT_THROW(syncStorage->removeAll(ns), BackendError);
}
{
if (arsec != AsyncRedisStorage::ErrorCode::SUCCESS)
{
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
}
switch (arsec)
{
if (aec != AsyncRedisCommandDispatcherErrorCode::SUCCESS)
{
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
}
switch (aec)
TEST_F(SyncStorageImplTest, CanThrowStdExceptionIfDispatcherErrorCodeCannotBeMappedToSdlException)
{
InSequence dummy;
- expectSdlReadinessCheck();
+ expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
- expectPollWait();
+ expectPollWait(SyncStorageImpl::NO_TIMEOUT);
expectModifyIfAck(std::error_code(1, std::system_category()), false);
EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), std::range_error);
}