2 * Copyright (C) 2018 Cisco Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // @author Changxue Deng <chadeng@cisco.com>
19 #include <gtest/gtest.h>
22 #include "../resource_pool.h"
24 using namespace mabain;
28 class MemoryOnlyTest : public ::testing::Test
33 virtual ~MemoryOnlyTest() {
36 virtual void SetUp() {
39 virtual void TearDown() {
44 ResourcePool::getInstance().RemoveAll();
51 TEST_F(MemoryOnlyTest, MemoryOnlyTest_test_constructor_1)
53 int options = CONSTS::WriterOptions() | CONSTS::MEMORY_ONLY_MODE;
54 db = new DB("test_constructor_1", options);
55 EXPECT_EQ(MBError::SUCCESS, db->Status());
58 TEST_F(MemoryOnlyTest, MemoryOnlyTest_test_constructor_2)
60 int options = CONSTS::ReaderOptions() | CONSTS::MEMORY_ONLY_MODE;
61 db = new DB("test_constructor_2", options);
62 EXPECT_EQ(MBError::NO_DB, db->Status());
65 TEST_F(MemoryOnlyTest, MemoryOnlyTest_test_add)
67 int options = CONSTS::WriterOptions() | CONSTS::MEMORY_ONLY_MODE;
68 db = new DB("test_add", options);
72 for(int i = 0; i < num; i++) {
73 key = std::string("test_add_") + std::to_string(i);
80 for(int i = 0; i < num; i++) {
81 key = std::string("test_add_") + std::to_string(i);
82 rval = db->Find(key, mbd);
83 EXPECT_EQ(MBError::SUCCESS, rval);
84 value = std::string((char *)mbd.buff, mbd.data_len);
85 EXPECT_EQ(key, value);
89 TEST_F(MemoryOnlyTest, MemoryOnlyTest_test_async)
91 int options = CONSTS::WriterOptions() | CONSTS::MEMORY_ONLY_MODE;
92 options |= CONSTS::ASYNC_WRITER_MODE;
93 db = new DB("test_async", options);
95 options = CONSTS::ReaderOptions() | CONSTS::MEMORY_ONLY_MODE;
96 DB db_r = DB("test_async", options);