2 Copyright (c) 2018-2019 Nokia.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #include <gtest/gtest.h>
23 #include "private/error.hpp"
24 #include "private/redis/asyncredisstorage.hpp"
25 #include "private/syncstorageimpl.hpp"
26 #include "private/tst/asyncstoragemock.hpp"
27 #include "private/tst/systemmock.hpp"
28 #include <sdl/backenderror.hpp>
29 #include <sdl/invalidnamespace.hpp>
30 #include <sdl/notconnected.hpp>
31 #include <sdl/operationinterrupted.hpp>
32 #include <sdl/rejectedbybackend.hpp>
34 using namespace shareddatalayer;
35 using namespace shareddatalayer::redis;
36 using namespace shareddatalayer::tst;
37 using namespace testing;
41 class SyncStorageImplTest: public testing::Test
44 std::unique_ptr<SyncStorageImpl> syncStorage;
45 /* AsyncStorageMock ownership will be passed to implementation. To be able to do verification
46 * with the mock object also here after its ownership is passed we take raw pointer to
47 * AsyncStorageMock before passing it to implementation. Works fine, as implementation will
48 * not release injected mock object before test case execution finishes
50 std::unique_ptr<StrictMock<AsyncStorageMock>> asyncStorageMockPassedToImplementation;
51 StrictMock<AsyncStorageMock>* asyncStorageMockRawPtr;
52 StrictMock<SystemMock> systemMock;
53 AsyncStorage::ModifyAck savedModifyAck;
54 AsyncStorage::ModifyIfAck savedModifyIfAck;
55 AsyncStorage::GetAck savedGetAck;
56 AsyncStorage::FindKeysAck savedFindKeysAck;
57 AsyncStorage::ReadyAck savedReadyAck;
59 SyncStorage::DataMap dataMap;
60 SyncStorage::Keys keys;
61 const SyncStorage::Namespace ns;
62 std::chrono::steady_clock::duration TEST_OPERATION_WAIT_TIMEOUT;
63 int TEST_OPERATION_POLL_WAIT_TIMEOUT;
64 SyncStorageImplTest():
65 asyncStorageMockPassedToImplementation(new StrictMock<AsyncStorageMock>()),
66 asyncStorageMockRawPtr(asyncStorageMockPassedToImplementation.get()),
68 dataMap({{ "key1", { 0x0a, 0x0b, 0x0c } }, { "key2", { 0x0d, 0x0e, 0x0f, 0xff } }}),
69 keys({ "key1", "key2" }),
70 ns("someKnownNamespace"),
71 TEST_OPERATION_WAIT_TIMEOUT(std::chrono::seconds(1)),
72 TEST_OPERATION_POLL_WAIT_TIMEOUT(std::chrono::duration_cast<std::chrono::milliseconds>(TEST_OPERATION_WAIT_TIMEOUT).count() / 10)
74 expectConstructorCalls();
75 syncStorage.reset(new SyncStorageImpl(std::move(asyncStorageMockPassedToImplementation), systemMock));
78 ~SyncStorageImplTest()
80 syncStorage->setOperationTimeout(std::chrono::steady_clock::duration::zero());
83 void expectConstructorCalls()
86 EXPECT_CALL(*asyncStorageMockRawPtr, fd())
88 .WillOnce(Return(pFd));
91 void expectSdlReadinessCheck(int timeout)
94 expectPollForPendingEvents_ReturnNoEvents();
95 expectWaitReadyAsync();
96 expectPollWait(timeout);
97 expectHandleEvents_callWaitReadyAck();
100 void expectPollForPendingEvents_ReturnNoEvents()
102 EXPECT_CALL(systemMock, poll( _, 1, 0))
104 .WillOnce(Invoke([](struct pollfd *, nfds_t, int)
110 void expectPollWait(int timeout)
112 EXPECT_CALL(systemMock, poll( _, 1, timeout))
114 .WillOnce(Invoke([](struct pollfd *fds, nfds_t, int)
116 fds->revents = POLLIN;
121 void expectPollError()
123 EXPECT_CALL(systemMock, poll( _, 1, -1))
125 .WillOnce(Invoke([](struct pollfd *fds, nfds_t, int)
127 fds->revents = POLLIN;
132 void expectPollExceptionalCondition()
134 EXPECT_CALL(systemMock, poll( _, 1, -1))
136 .WillOnce(Invoke([](struct pollfd *fds, nfds_t, int)
138 fds->revents = POLLPRI;
143 void expectHandleEvents()
145 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
149 void expectHandleEvents_callWaitReadyAck()
151 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
153 .WillOnce(Invoke([this]()
155 savedReadyAck(std::error_code());
159 void expectHandleEvents_callModifyAck()
161 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
163 .WillOnce(Invoke([this]()
165 savedModifyAck(std::error_code());
169 void expectWaitReadyAsync()
171 EXPECT_CALL(*asyncStorageMockRawPtr, waitReadyAsync(ns,_))
173 .WillOnce(SaveArg<1>(&savedReadyAck));
177 void expectModifyAckWithError()
179 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
181 .WillOnce(Invoke([this]()
183 savedModifyAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY);
187 void expectModifyIfAck(const std::error_code& error, bool status)
189 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
191 .WillOnce(Invoke([this, error, status]()
193 savedModifyIfAck(error, status);
197 void expectGetAckWithError()
199 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
201 .WillOnce(Invoke([this]()
203 savedGetAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, dataMap);
209 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
211 .WillOnce(Invoke([this]()
213 savedGetAck(std::error_code(), dataMap);
217 void expectFindKeysAck()
219 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
221 .WillOnce(Invoke([this]()
223 savedFindKeysAck(std::error_code(), keys);
227 void expectFindKeysAckWithError()
229 EXPECT_CALL(*asyncStorageMockRawPtr, handleEvents())
231 .WillOnce(Invoke([this]()
233 savedFindKeysAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, keys);
237 void expectSetAsync(const SyncStorage::DataMap& dataMap)
239 EXPECT_CALL(*asyncStorageMockRawPtr, setAsync(ns, dataMap, _))
241 .WillOnce(SaveArg<2>(&savedModifyAck));
244 void expectSetIfAsync(const SyncStorage::Key& key, const SyncStorage::Data& oldData, const SyncStorage::Data& newData)
246 EXPECT_CALL(*asyncStorageMockRawPtr, setIfAsync(ns, key, oldData, newData, _))
248 .WillOnce(SaveArg<4>(&savedModifyIfAck));
251 void expectGetAsync(const SyncStorage::Keys& keys)
253 EXPECT_CALL(*asyncStorageMockRawPtr, getAsync(ns, keys, _))
255 .WillOnce(SaveArg<2>(&savedGetAck));
258 void expectFindKeysAsync()
260 EXPECT_CALL(*asyncStorageMockRawPtr, findKeysAsync(ns, _, _))
262 .WillOnce(SaveArg<2>(&savedFindKeysAck));
265 void expectRemoveAsync(const SyncStorage::Keys& keys)
267 EXPECT_CALL(*asyncStorageMockRawPtr, removeAsync(ns, keys, _))
269 .WillOnce(SaveArg<2>(&savedModifyAck));
272 void expectRemoveIfAsync(const SyncStorage::Key& key, const SyncStorage::Data& data)
274 EXPECT_CALL(*asyncStorageMockRawPtr, removeIfAsync(ns, key, data, _))
276 .WillOnce(SaveArg<3>(&savedModifyIfAck));
279 void expectRemoveAllAsync()
281 EXPECT_CALL(*asyncStorageMockRawPtr, removeAllAsync(ns, _))
283 .WillOnce(SaveArg<1>(&savedModifyAck));
286 void expectSetIfNotExistsAsync(const SyncStorage::Key& key, const SyncStorage::Data& data)
288 EXPECT_CALL(*asyncStorageMockRawPtr, setIfNotExistsAsync(ns, key, data, _))
290 .WillOnce(SaveArg<3>(&savedModifyIfAck));
295 TEST_F(SyncStorageImplTest, IsNotCopyable)
298 EXPECT_FALSE(std::is_copy_constructible<SyncStorageImpl>::value);
299 EXPECT_FALSE(std::is_copy_assignable<SyncStorageImpl>::value);
302 TEST_F(SyncStorageImplTest, ImplementssyncStorage)
305 EXPECT_TRUE((std::is_base_of<SyncStorage, SyncStorageImpl>::value));
308 TEST_F(SyncStorageImplTest, EventsAreNotHandledWhenPollReturnsError)
311 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
312 expectSetAsync(dataMap);
314 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
315 expectHandleEvents_callModifyAck();
316 syncStorage->set(ns, dataMap);
319 TEST_F(SyncStorageImplTest, EventsAreNotHandledWhenThereIsAnExceptionalConditionOnTheFd)
322 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
323 expectSetAsync(dataMap);
324 expectPollExceptionalCondition();
325 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
326 expectHandleEvents_callModifyAck();
327 syncStorage->set(ns, dataMap);
330 TEST_F(SyncStorageImplTest, SetSuccessfully)
333 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
334 expectSetAsync(dataMap);
335 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
336 expectHandleEvents_callModifyAck();
337 syncStorage->set(ns, dataMap);
340 TEST_F(SyncStorageImplTest, SetWithReadinessTimeoutSuccessfully)
343 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
344 expectSetAsync(dataMap);
345 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
346 expectHandleEvents_callModifyAck();
347 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
348 syncStorage->set(ns, dataMap);
351 TEST_F(SyncStorageImplTest, SetCanThrowBackendError)
354 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
355 expectSetAsync(dataMap);
356 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
357 expectModifyAckWithError();
358 EXPECT_THROW(syncStorage->set(ns, dataMap), BackendError);
361 TEST_F(SyncStorageImplTest, SetIfSuccessfully)
364 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
365 expectSetAsync(dataMap);
366 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
367 expectHandleEvents_callModifyAck();
368 syncStorage->set(ns, dataMap);
369 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
370 expectSetIfAsync("key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
371 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
372 expectHandleEvents_callModifyAck();
373 syncStorage->setIf(ns, "key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
376 TEST_F(SyncStorageImplTest, SetIfWithReadinessTimeoutSuccessfully)
379 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
380 expectSetAsync(dataMap);
381 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
382 expectHandleEvents_callModifyAck();
383 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
384 syncStorage->set(ns, dataMap);
385 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
386 expectSetIfAsync("key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
387 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
388 expectHandleEvents_callModifyAck();
389 syncStorage->setIf(ns, "key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
392 TEST_F(SyncStorageImplTest, SetIfCanThrowBackendError)
395 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
396 expectSetAsync(dataMap);
397 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
398 expectHandleEvents_callModifyAck();
399 syncStorage->set(ns, dataMap);
400 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
401 expectSetIfAsync("key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f });
402 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
403 expectModifyIfAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, false);
404 EXPECT_THROW(syncStorage->setIf(ns, "key1", { 0x0a, 0x0b, 0x0c }, { 0x0d, 0x0e, 0x0f }), BackendError);
407 TEST_F(SyncStorageImplTest, SetIfNotExistsSuccessfully)
410 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
411 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
412 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
413 expectModifyIfAck(std::error_code(), true);
414 EXPECT_TRUE(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }));
417 TEST_F(SyncStorageImplTest, SetIfNotExistsIfWithReadinessTimeoutSuccessfully)
420 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
421 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
422 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
423 expectModifyIfAck(std::error_code(), true);
424 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
425 EXPECT_TRUE(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }));
428 TEST_F(SyncStorageImplTest, SetIfNotExistsReturnsFalseIfKeyAlreadyExists)
431 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
432 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
433 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
434 expectModifyIfAck(std::error_code(), false);
435 EXPECT_FALSE(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }));
438 TEST_F(SyncStorageImplTest, SetIfNotExistsCanThrowBackendError)
441 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
442 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
443 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
444 expectModifyIfAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, false);
445 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
448 TEST_F(SyncStorageImplTest, GetSuccessfully)
451 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
452 expectGetAsync(keys);
453 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
455 auto map(syncStorage->get(ns, keys));
456 EXPECT_EQ(map, dataMap);
459 TEST_F(SyncStorageImplTest, GetWithReadinessTimeoutSuccessfully)
462 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
463 expectGetAsync(keys);
464 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
466 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
467 auto map(syncStorage->get(ns, keys));
468 EXPECT_EQ(map, dataMap);
471 TEST_F(SyncStorageImplTest, GetCanThrowBackendError)
474 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
475 expectGetAsync(keys);
476 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
477 expectGetAckWithError();
478 EXPECT_THROW(syncStorage->get(ns, keys), BackendError);
481 TEST_F(SyncStorageImplTest, RemoveSuccessfully)
484 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
485 expectRemoveAsync(keys);
486 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
487 expectHandleEvents_callModifyAck();
488 syncStorage->remove(ns, keys);
491 TEST_F(SyncStorageImplTest, RemoveWithReadinessTimeoutSuccessfully)
494 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
495 expectRemoveAsync(keys);
496 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
497 expectHandleEvents_callModifyAck();
498 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
499 syncStorage->remove(ns, keys);
502 TEST_F(SyncStorageImplTest, RemoveCanThrowBackendError)
505 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
506 expectRemoveAsync(keys);
507 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
508 expectModifyAckWithError();
509 EXPECT_THROW(syncStorage->remove(ns, keys), BackendError);
512 TEST_F(SyncStorageImplTest, RemoveIfSuccessfully)
515 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
516 expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
517 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
518 expectModifyIfAck(std::error_code(), true);
519 EXPECT_TRUE(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }));
522 TEST_F(SyncStorageImplTest, RemoveIfWithReadinessTimeoutSuccessfully)
525 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
526 expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
527 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
528 expectModifyIfAck(std::error_code(), true);
529 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
530 EXPECT_TRUE(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }));
533 TEST_F(SyncStorageImplTest, RemoveIfReturnsFalseIfKeyDoesnotMatch)
536 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
537 expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
538 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
539 expectModifyIfAck(std::error_code(), false);
540 EXPECT_FALSE(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }));
543 TEST_F(SyncStorageImplTest, RemoveIfCanThrowBackendError)
546 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
547 expectRemoveIfAsync("key1", { 0x0a, 0x0b, 0x0c });
548 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
549 expectModifyIfAck(AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY, false);
550 EXPECT_THROW(syncStorage->removeIf(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
553 TEST_F(SyncStorageImplTest, FindKeysSuccessfully)
556 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
557 expectFindKeysAsync();
558 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
560 auto ids(syncStorage->findKeys(ns, "*"));
561 EXPECT_EQ(ids, keys);
564 TEST_F(SyncStorageImplTest, FindKeysWithReadinessTimeoutSuccessfully)
567 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
568 expectFindKeysAsync();
569 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
571 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
572 auto ids(syncStorage->findKeys(ns, "*"));
573 EXPECT_EQ(ids, keys);
576 TEST_F(SyncStorageImplTest, FindKeysAckCanThrowBackendError)
579 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
580 expectFindKeysAsync();
581 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
582 expectFindKeysAckWithError();
583 EXPECT_THROW(syncStorage->findKeys(ns, "*"), BackendError);
586 TEST_F(SyncStorageImplTest, RemoveAllSuccessfully)
589 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
590 expectRemoveAllAsync();
591 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
592 expectHandleEvents_callModifyAck();
593 syncStorage->removeAll(ns);
596 TEST_F(SyncStorageImplTest, RemoveAllWithReadinessTimeoutSuccessfully)
599 expectSdlReadinessCheck(TEST_OPERATION_POLL_WAIT_TIMEOUT);
600 expectRemoveAllAsync();
601 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
602 expectHandleEvents_callModifyAck();
603 syncStorage->setOperationTimeout(TEST_OPERATION_WAIT_TIMEOUT);
604 syncStorage->removeAll(ns);
607 TEST_F(SyncStorageImplTest, RemoveAllCanThrowBackendError)
610 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
611 expectRemoveAllAsync();
612 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
613 expectModifyAckWithError();
614 EXPECT_THROW(syncStorage->removeAll(ns), BackendError);
617 TEST_F(SyncStorageImplTest, AllAsyncRedisStorageErrorCodesThrowCorrectException)
622 for (AsyncRedisStorage::ErrorCode arsec = AsyncRedisStorage::ErrorCode::SUCCESS; arsec < AsyncRedisStorage::ErrorCode::END_MARKER; ++arsec)
624 if (arsec != AsyncRedisStorage::ErrorCode::SUCCESS)
626 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
627 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
628 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
633 case AsyncRedisStorage::ErrorCode::SUCCESS:
635 case AsyncRedisStorage::ErrorCode::INVALID_NAMESPACE:
636 expectModifyIfAck(arsec, false);
637 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), InvalidNamespace);
639 case AsyncRedisStorage::ErrorCode::REDIS_NOT_YET_DISCOVERED:
640 expectModifyIfAck(arsec, false);
641 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), NotConnected);
644 FAIL() << "No mapping for AsyncRedisStorage::ErrorCode value: " << arsec;
650 TEST_F(SyncStorageImplTest, AllDispatcherErrorCodesThrowCorrectException)
655 for (AsyncRedisCommandDispatcherErrorCode aec = AsyncRedisCommandDispatcherErrorCode::SUCCESS; aec < AsyncRedisCommandDispatcherErrorCode::END_MARKER; ++aec)
657 if (aec != AsyncRedisCommandDispatcherErrorCode::SUCCESS)
659 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
660 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
661 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
666 case AsyncRedisCommandDispatcherErrorCode::SUCCESS:
668 case AsyncRedisCommandDispatcherErrorCode::UNKNOWN_ERROR:
669 expectModifyIfAck(aec, false);
670 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
672 case AsyncRedisCommandDispatcherErrorCode::CONNECTION_LOST:
673 expectModifyIfAck(aec, false);
674 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), OperationInterrupted);
676 case AsyncRedisCommandDispatcherErrorCode::PROTOCOL_ERROR:
677 expectModifyIfAck(aec, false);
678 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), RejectedByBackend);
680 case AsyncRedisCommandDispatcherErrorCode::OUT_OF_MEMORY:
681 expectModifyIfAck(aec, false);
682 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
684 case AsyncRedisCommandDispatcherErrorCode::DATASET_LOADING:
685 expectModifyIfAck(aec, false);
686 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), NotConnected);
688 case AsyncRedisCommandDispatcherErrorCode::NOT_CONNECTED:
689 expectModifyIfAck(aec, false);
690 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), NotConnected);
692 case AsyncRedisCommandDispatcherErrorCode::IO_ERROR:
693 expectModifyIfAck(aec, false);
694 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
696 case AsyncRedisCommandDispatcherErrorCode::WRITING_TO_SLAVE:
697 expectModifyIfAck(aec, false);
698 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), BackendError);
701 FAIL() << "No mapping for AsyncRedisCommandDispatcherErrorCode value: " << aec;
707 TEST_F(SyncStorageImplTest, CanThrowStdExceptionIfDispatcherErrorCodeCannotBeMappedToSdlException)
710 expectSdlReadinessCheck(SyncStorageImpl::NO_TIMEOUT);
711 expectSetIfNotExistsAsync("key1", { 0x0a, 0x0b, 0x0c });
712 expectPollWait(SyncStorageImpl::NO_TIMEOUT);
713 expectModifyIfAck(std::error_code(1, std::system_category()), false);
714 EXPECT_THROW(syncStorage->setIfNotExists(ns, "key1", { 0x0a, 0x0b, 0x0c }), std::range_error);