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 <mabain/db.h>
21 using namespace mabain;
23 const char *db_name = "my-memory-only-test";
25 // memory-only mode test
26 // No db directory is required. Need an unique name instead.
27 // Note MEMORY_ONLY_MODE does not support multi-process accessing the DB.
28 int main(int argc, char *argv[])
30 DB db(db_name, CONSTS::WriterOptions() | CONSTS::MEMORY_ONLY_MODE);
32 std::cerr << "failed to open mabain db: " << db.StatusStr() << "\n";
36 std::string key[3], value[3];
46 for(int i = 0; i < 3; i++) {
47 rval = db.Add(key[i], value[i]);
48 if(rval == MBError::SUCCESS) {
49 std::cout << "Add " << key[i] << ": " << value[i] << std::endl;
54 for(int i = 0; i < 3; i++) {
55 rval = db.Find(key[i], mbd);
56 if(rval == MBError::SUCCESS) {
57 std::cout << "Lookup " << key[i] << ": " << std::string((char *)mbd.buff, mbd.data_len) << std::endl;