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 <type_traits>
25 #include <sys/eventfd.h>
26 #include "private/asyncdummystorage.hpp"
27 #include "private/tst/enginemock.hpp"
29 using namespace shareddatalayer;
30 using namespace shareddatalayer::tst;
31 using namespace testing;
35 class AsyncDummyStorageTest: public testing::Test
38 std::shared_ptr<StrictMock<EngineMock>> engineMock;
40 AsyncStorage::Namespace ns;
41 Engine::Callback storedCallback;
42 std::unique_ptr<AsyncDummyStorage> dummyStorage;
44 AsyncDummyStorageTest():
45 engineMock(std::make_shared<StrictMock<EngineMock>>()),
47 ns("someKnownNamespace")
49 dummyStorage.reset(new AsyncDummyStorage(engineMock));
52 MOCK_METHOD1(ack1, void(const std::error_code&));
54 MOCK_METHOD2(ack2, void(const std::error_code&, bool));
56 MOCK_METHOD2(ack3, void(const std::error_code&, const AsyncStorage::DataMap&));
58 MOCK_METHOD2(ack4, void(const std::error_code&, const AsyncStorage::Keys&));
62 EXPECT_CALL(*this, ack1(std::error_code()))
68 EXPECT_CALL(*this, ack2(std::error_code(), true))
74 EXPECT_CALL(*this, ack3(std::error_code(), IsEmpty()))
80 EXPECT_CALL(*this, ack4(std::error_code(), IsEmpty()))
84 void expectPostCallback()
86 EXPECT_CALL(*engineMock, postCallback(_))
88 .WillOnce(SaveArg<0>(&storedCallback));
93 TEST_F(AsyncDummyStorageTest, IsNotCopyableAndIsNotMovable)
95 EXPECT_FALSE(std::is_copy_assignable<AsyncDummyStorage>::value);
96 EXPECT_FALSE(std::is_move_assignable<AsyncDummyStorage>::value);
97 EXPECT_FALSE(std::is_copy_constructible<AsyncDummyStorage>::value);
98 EXPECT_FALSE(std::is_move_constructible<AsyncDummyStorage>::value);
101 TEST_F(AsyncDummyStorageTest, ImplementsAsyncStorage)
103 EXPECT_TRUE((std::is_base_of<AsyncStorage, AsyncDummyStorage>::value));
106 TEST_F(AsyncDummyStorageTest, CanGetFd)
108 EXPECT_CALL(*engineMock, fd())
110 .WillOnce(Return(fd));
111 EXPECT_EQ(fd, dummyStorage->fd());
114 TEST_F(AsyncDummyStorageTest, CanHandleEvents)
116 EXPECT_CALL(*engineMock, handleEvents())
118 dummyStorage->handleEvents();
121 TEST_F(AsyncDummyStorageTest, AcksAreImmediatelyScheduled)
125 expectPostCallback();
126 dummyStorage->waitReadyAsync(ns, std::bind(&AsyncDummyStorageTest::ack1,
128 std::placeholders::_1));
132 expectPostCallback();
133 dummyStorage->setAsync(ns, { }, std::bind(&AsyncDummyStorageTest::ack1,
135 std::placeholders::_1));
139 expectPostCallback();
140 dummyStorage->setIfAsync(ns, { }, { }, { }, std::bind(&AsyncDummyStorageTest::ack2,
142 std::placeholders::_1,
143 std::placeholders::_2));
147 expectPostCallback();
148 dummyStorage->setIfNotExistsAsync(ns, { }, { }, std::bind(&AsyncDummyStorageTest::ack2,
150 std::placeholders::_1,
151 std::placeholders::_2));
155 expectPostCallback();
156 dummyStorage->getAsync(ns, { }, std::bind(&AsyncDummyStorageTest::ack3,
158 std::placeholders::_1,
159 std::placeholders::_2));
163 expectPostCallback();
164 dummyStorage->removeAsync(ns, { }, std::bind(&AsyncDummyStorageTest::ack1,
166 std::placeholders::_1));
170 expectPostCallback();
171 dummyStorage->removeIfAsync(ns, { }, { }, std::bind(&AsyncDummyStorageTest::ack2,
173 std::placeholders::_1,
174 std::placeholders::_2));
178 expectPostCallback();
179 dummyStorage->findKeysAsync(ns,
181 std::bind(&AsyncDummyStorageTest::ack4,
183 std::placeholders::_1,
184 std::placeholders::_2));
188 expectPostCallback();
189 dummyStorage->removeAllAsync(ns, std::bind(&AsyncDummyStorageTest::ack1,
191 std::placeholders::_1));