TEST_F (Simple, SetSystemGetAppend2) { using namespace kdb; KDB kdb; KeySet ks; Key parentKey (testRoot, KEY_END); ks.append (Key ("system" + testRoot + "key", KEY_VALUE, "value1", KEY_END)); kdb.get (ks, parentKey); ASSERT_EQ (ks.size (), 1) << "got keys from freshly mounted backends"; ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "value1") << "string of element in keyset wrong"; kdb.set (ks, parentKey); kdb.close (parentKey); KeySet ks2; ks2.append (Key ("system" + testRoot + "key2", KEY_VALUE, "value2", KEY_END)); kdb.open (parentKey); kdb.get (ks2, parentKey); ks2.rewind (); ks2.next (); ASSERT_EQ (ks2.size (), 1) << "wrong size"; EXPECT_EQ (ks2.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks2.current ().getString (), "value1") << "string of element in keyset wrong"; }
int main(int argc, char**argv) { using namespace kdb; KDB kdb; KeySet ks; kdb.get(ks, "/test/lift"); kdb.get(ks, "/test/material_lift"); kdb.get(ks, "/test/heavy_material_lift"); kdb.get(ks, "/test/person_lift"); Parameters par(ks); std::cout << std::boolalpha; std::cout << "delay: " << par.getTestLiftEmergencyDelay() << std::endl; std::cout << "stops: " << par.getTestLiftEmergencyActionStops() << std::endl; // std::cout << "algorithm: " << par.getTestLiftAlgorithm() << std::endl; std::cout << "height #3: " << par.getTestLiftFloor3Height() << std::endl; std::cout << "limit: " << par.getTestLiftLimit() << std::endl; bool write = par.getTestLiftWrite(); par.setTestLiftWrite(false); // write back to user/test/lift, see comments in lift.c if (write) { kdb.set(ks, "user/test/lift"); } return 0; }
TEST_F (Simple, GetSystem) { using namespace kdb; KDB kdb; KeySet ks; Key parentKey ("system" + testRoot, KEY_END); ks.append (Key (parentKey.getName () + "/key", KEY_END)); EXPECT_NE (kdb.get (ks, parentKey), -1); ASSERT_EQ (ks.size (), 1) << "no key stayed" << ks; ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; ASSERT_NE (kdb.set (ks, parentKey), -1); ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; kdb.close (parentKey); KeySet ks2; kdb.open (parentKey); kdb.get (ks2, parentKey); ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "system/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; }
TEST_F (Simple, RemoveFile) { using namespace kdb; KDB kdb; KeySet ks; kdb.get (ks, testRoot); ks.append (Key ("system" + testRoot + "remove", KEY_END)); ASSERT_EQ (ks.size (), 1) << "could not append key\n" << ks; kdb.set (ks, testRoot); ASSERT_EQ (ks.size (), 1) << "key gone after kdb.set?\n" << ks; struct stat buf; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), 0) << "found no file"; Key parentKey; kdb.close (parentKey); kdb.open (parentKey); kdb.get (ks, testRoot); ks.clear (); ASSERT_EQ (ks.size (), 0) << "keyset should be empty after clearing it\n" << ks; kdb.set (ks, testRoot); ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "found wrong file"; }
int main() { using namespace kdb; KDB kdb; KeySet ks; Context c; kdb.get(ks, "/test/lift"); kdb.get(ks, "/test/material_lift"); kdb.get(ks, "/test/heavy_material_lift"); kdb.get(ks, "/test/person_lift"); Parameters par(ks,c); std::cout << std::boolalpha; std::cout << "delay: " << par.test.lift.emergency.delay << std::endl; std::cout << "stops: " << par.test.lift.emergency.action.stops << std::endl; kdb::test::Lift const & lift = par.test.lift; std::cout << "height #3: " << lift.floor.n3.height << std::endl; std::cout << "limit: " << par.test.lift.limit << std::endl; bool write = lift.write; par.test.lift.write = false; // write back to user/test/lift, see comments in lift.c if(write) { kdb.set(ks, "user/test/lift"); } return 0; }
void TestCommand::doBasicTest () { { KDB kdb; Key t = root.dup (); t.addBaseName ("basic"); t.setString ("BasicString"); KeySet basic; basic.append (t); KeySet test; kdb.get (test, root); kdb.set (basic, root); } { KDB kdb; Key t = root.dup (); t.addBaseName ("basic"); t.setString ("BasicString"); KeySet test; kdb.get (test, root); nrTest++; if (!test.lookup (t)) { nrError++; cerr << "Basic test failed" << endl; } } }
TEST_F (Simple, GetAppendMeta) { using namespace kdb; KDB kdb; KeySet ks; ks.append (Key ("meta/key", KEY_META_NAME, KEY_END)); Key parentKey (testRoot, KEY_END); kdb.get (ks, parentKey); ASSERT_EQ (ks.size (), 1) << "no key stayed"; ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "meta/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; kdb.set (ks, parentKey); ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "meta/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; kdb.close (parentKey); KeySet ks2; kdb.open (parentKey); kdb.get (ks2, parentKey); ASSERT_EQ (ks2.size (), 0) << "got keys from freshly mounted backends"; }
int main() { using namespace kdb; KDB kdb; KeySet ks; kdb.get(ks, "/test/lift"); kdb.get(ks, "/test/material_lift"); kdb.get(ks, "/test/heavy_material_lift"); kdb.get(ks, "/test/person_lift"); Parameters par(ks); std::cout << std::boolalpha; std::cout << "delay: " << par.test().lift().emergency().getDelay() << std::endl; std::cout << "stops: " << par.test().lift().emergency().action().getStops() << std::endl; // std::cout << "algorithm: " << par.getTestLiftAlgorithm() << std::endl; kdb::test::Lift const & lift = par.test().lift(); std::cout << "height #3: " << lift.floor().n3().getHeight() << std::endl; std::cout << "limit: " << par.test().lift().getLimit() << std::endl; bool write = lift.getWrite(); par.test().lift().setWrite(false); // write back to user/test/lift, see comments in lift.c if(write) { kdb.set(ks, "user/test/lift"); } return 0; }
void TestCommand::doStringTest () { vector<string> teststrings; teststrings.push_back (""); teststrings.push_back ("value"); teststrings.push_back ("value with spaces"); teststrings.push_back (" a very long value with many spaces and basically very very long, but only text ... "); for (int i = 1; i < 256; ++i) teststrings.back () += " very very long, but only text ... "; for (auto & teststring : teststrings) { { KDB kdb; Key t = root.dup (); t.addBaseName ("string"); t.setString (teststring); KeySet basic; basic.append (t); KeySet test; kdb.get (test, root); kdb.set (basic, root); } { KDB kdb; KeySet test; kdb.get (test, root); Key t = root.dup (); t.addBaseName ("string"); Key res = test.lookup (t); nrTest++; if (!res) { nrError++; cerr << "String test failed (key not found)" << t.getName () << endl; continue; } nrTest++; if (res.getString () != teststring) { nrError++; cerr << "String test failed (value is not equal)" << endl; cerr << "We got: \"" << res.getString () << "\"" << endl; cerr << "We wanted: \"" << teststring << "\"" << endl; } } } }
kdb::Key mountBackend (int iteration) { using namespace kdb; using namespace kdb::tools; Key mp = getMountpointForIteration<VARIANT> (iteration); std::string cf = "benchmark_" + plugin_variant_names[VARIANT] + "_" + std::to_string (iteration) + ".ecf"; unlink (cf.c_str ()); KDB kdb; KeySet mountConfig; kdb.get (mountConfig, "system/elektra/mountpoints"); MountBackendBuilder b; b.setMountpoint (mp, KeySet (0, KS_END)); b.addPlugin (PluginSpec ("resolver")); b.useConfigFile (cf); b.addPlugin (PluginSpec ("dump")); if (VARIANT != NO_CRYPTO) { KeySet pluginConfig; pluginConfig.append (Key ("user/encrypt/key", KEY_VALUE, GPG_TEST_KEY_ID, KEY_END)); pluginConfig.append (Key ("user/gpg/unit_test", KEY_VALUE, "1", KEY_END)); b.addPlugin (PluginSpec (plugin_variant_names[VARIANT], pluginConfig)); } b.validated (); b.serialize (mountConfig); kdb.set (mountConfig, "system/elektra/mountpoints"); kdb.close (); return mp; }
QString GUIBackend::mountPoints () const { Key parentKey (Backends::mountpointsPath, KEY_END); KeySet mountConf; KDB kdb (parentKey); try { kdb.get (mountConf, parentKey); } catch (KDBException const & ex) { emit showMessage (tr ("Error"), tr ("Could not read from configuration."), QString (ex.what ())); return ""; } Backends::BackendInfoVector vec = Backends::getBackendInfo (mountConf); QStringList mPoints; mPoints.append ("system/elektra"); foreach (BackendInfo info, vec) { QString backend = QString::fromStdString (info.name); if (backend.startsWith ("/")) { mPoints.append ("dir" + backend); mPoints.append ("user" + backend); mPoints.append ("system" + backend); } else { mPoints.append (backend); } }
void test_kdbGetSet() { cout << "testing kdbSet() and kdbGet()" << endl; { KeySet ks_set (5, *Key ("user/tests/key3", KEY_DIR, KEY_END), *Key ("user/tests/key3/1", KEY_END), *Key ("user/tests/key3/2", KEY_END), *Key ("user/tests/key3/3", KEY_VALUE, "value", KEY_END), KS_END); KeySet ks; KDB kdb; kdb.get (ks, "user/tests/key3"); ks.append(ks_set); kdb.set (ks, "user/tests/key3"); } // check if they were written { KDB kdb; KeySet ks; kdb.get (ks, "user/tests/key3"); exit_if_fail(ks.lookup("user/tests/key3/3"), "could not find previously written key"); succeed_if(ks.lookup("user/tests/key3/3").get<std::string>() == "value", "could not get value"); succeed_if(!ks.lookup("user/tests/key3/3").needSync(), "should not need sync"); } // now remove keys (cleanup) { KeySet ks; KDB kdb; kdb.get (ks, "user/tests/key3"); ks.cut(Key("user/tests/key3", KEY_END)); kdb.set (ks, "user/tests/key3"); } // check if its gone now { KDB kdb; KeySet ks; kdb.get (ks, "user/tests/key3"); succeed_if(!ks.lookup("user/tests/key3/3"), "key was not removed"); } }
int main () { using namespace kdb; KDB kdb; KeySet conf; kdb.get (conf, "/"); std::cout << conf; kdb.set (conf, "/"); }
TEST_F (Simple, GetNothing) { using namespace kdb; KDB kdb; KeySet ks; kdb.get (ks, testRoot); ASSERT_EQ (ks.size (), 0) << "got keys from freshly mounted backends" << ks; struct stat buf; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "found wrong file"; }
TEST_F (Simple, GetAppendCascading) { using namespace kdb; KDB kdb; KeySet ks; ks.append (Key (testRoot + "key", KEY_END)); Key parentKey (testRoot, KEY_END); std::string myRoot = testRoot.substr (0, testRoot.length () - 1); EXPECT_EQ (parentKey.getName (), myRoot); EXPECT_EQ (parentKey.getString (), ""); kdb.get (ks, parentKey); EXPECT_EQ (parentKey.getName (), myRoot); std::string fn = parentKey.getString (); EXPECT_EQ (fn.substr (fn.find_last_of ('/') + 1), "kdbFile.dump"); parentKey.setString (""); ASSERT_EQ (ks.size (), 1) << "no key stayed" << ks; ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; kdb.set (ks, parentKey); EXPECT_EQ (parentKey.getName (), myRoot); EXPECT_EQ (parentKey.getString (), ""); ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), "/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; kdb.close (parentKey); EXPECT_EQ (parentKey.getName (), myRoot); EXPECT_EQ (parentKey.getString (), ""); KeySet ks2; kdb.open (parentKey); EXPECT_EQ (parentKey.getName (), myRoot); EXPECT_EQ (parentKey.getString (), ""); kdb.get (ks2, parentKey); EXPECT_EQ (parentKey.getName (), myRoot); fn = parentKey.getString (); EXPECT_EQ (fn.substr (fn.find_last_of ('/') + 1), "kdbFile.dump"); ASSERT_EQ (ks2.size (), 0) << "got keys from freshly mounted backends"; }
TEST_F (Simple, GetCascading) { using namespace kdb; KDB kdb; KeySet ks; Key parentKey (testRoot, KEY_END); kdb.get (ks, parentKey); ASSERT_EQ (ks.size (), 0) << "got keys from freshly mounted backends" << ks; Key setParentKey ("system" + testRoot, KEY_END); kdb.set (ks, setParentKey); kdb.close (parentKey); }
/** * @brief Allows for updating of a database entry. * * Will renew the entry and all its subkeys (configuration). * * @param entry A custom Entry object holding current information. * @return true if the entry was updated, false if not * @throw kdbrest::exception::EntryNotFoundException in case the entry * to update does not exist. */ bool StorageEngine::updateEntry (model::Entry & entry) { using namespace kdb; // register exclusive access boost::unique_lock<boost::shared_mutex> lock (m_mutex_entryCache); bool found = false; std::vector<model::Entry> & entries = this->m_entryCache; unsigned int i = 0; while (i < entries.size ()) { if (entries[i].getName ().compare (entry.getName ()) == 0) { found = true; break; } i++; } if (!found) { throw exception::EntryNotFoundException (); } KDB kdb; KeySet ks; kdb.get (ks, entry.getName ()); Key k = ks.lookup (entry.getName ()); if (!k) { throw kdbrest::exception::EntryNotFoundException (); } ks.cut (entry); ks.append (entry); ks.append (entry.getSubkeys ()); if (kdb.set (ks, entry.getName ()) >= 1) { entries.erase (entries.begin () + i); entries.push_back (entry); return true; } else { return false; } }
int main() { using namespace kdb; KDB kdb; KeySet ks; Coordinator c; ThreadContext tc(c); kdb.get(ks, "/test/lift"); kdb.get(ks, "/test/material_lift"); kdb.get(ks, "/test/heavy_material_lift"); kdb.get(ks, "/test/person_lift"); Environment <ContextPolicyIs<ThreadContext>> env(ks,tc); // Environment <ContextPolicyIs<ThreadContext>, WritePolicyIs<ReadOnlyPolicy>> env(ks,tc); std::cout << std::boolalpha; std::cout << "delay: " << env.test.lift.emergency.delay << std::endl; std::cout << "stops: " << env.test.lift.emergency.action.stops << std::endl; // kdb::test::Lift <ContextPolicyIs<ThreadContext>, WritePolicyIs<ReadOnlyPolicy>> const & lift = env.test.lift; kdb::test::Lift <ContextPolicyIs<ThreadContext>> const & lift = env.test.lift; std::cout << "height #3: " << lift.floor.n3.height << std::endl; std::cout << "limit: " << env.test.lift.limit << std::endl; // kdb::test::lift::emergency::Delay <ContextPolicyIs<ThreadContext>, WritePolicyIs<ReadOnlyPolicy>> delay(ks, tc); // delay = 20; // read only value! bool write = lift.write; env.test.lift.write = false; // write back to user/test/lift, see comments in lift.c if (write) { kdb.set(ks, "user/test/lift"); } return 0; }
TEST_F (Simple, TriggerError) { using namespace kdb; KDB kdb; KeySet ks; EXPECT_EQ (kdb.get (ks, testRoot), 0) << "nothing to do in get"; ks.append (Key ("system" + testRoot + "a", KEY_END)); ks.append (Key ("system" + testRoot + "k", KEY_META, "trigger/error", "10", KEY_END)); ks.append (Key ("system" + testRoot + "z", KEY_END)); struct stat buf; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "found wrong file"; EXPECT_THROW (kdb.set (ks, testRoot), kdb::KDBException) << "could not trigger error"; ASSERT_EQ (ks.size (), 3) << "key suddenly missing"; EXPECT_EQ (ks.current ().getName (), "system" + testRoot + "k") << "ks should point to error key"; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "created file even though error triggered"; }
TEST_F (Simple, GetAppendNamespaces) { using namespace kdb; for (size_t i = 0; i < namespaces.size (); ++i) { KDB kdb; KeySet ks; ks.append (Key (namespaces[i].name + testRoot + "key", KEY_END)); kdb.get (ks, testRoot); ASSERT_EQ (ks.size (), 1) << "did not got key appended first with namespace " << namespaces[i].name; ks.rewind (); ks.next (); EXPECT_EQ (ks.current ().getName (), namespaces[i].name + "/tests/kdb/key") << "name of element in keyset wrong"; EXPECT_EQ (ks.current ().getString (), "") << "string of element in keyset wrong"; } }
/** * @brief Allows for deleting of an user entry. * * Will delete the entry iteself as well as all subkeys (additional user information). * * @param user A custom User object that should be deleted. * @return true if the user was deleted successfully, false otherwise * @throw kdbrest::exception::UserNotFoundException in case the user * to delete does not exist. */ bool StorageEngine::deleteUser (model::User & user) { using namespace kdb; // register exclusive access boost::unique_lock<boost::shared_mutex> lock (m_mutex_userCache); bool found = false; std::vector<model::User> & users = this->m_userCache; unsigned int i = 0; while (i < users.size ()) { if (users[i].getName ().compare (user.getName ()) == 0) { found = true; break; } i++; } if (!found) { throw exception::UserNotFoundException (); } KDB kdb; KeySet ks; kdb.get (ks, user.getName ()); Key k = ks.lookup (user.getName ()); if (!k) { throw kdbrest::exception::UserNotFoundException (); } ks.cut (user); if (kdb.set (ks, user.getName ()) >= 1) { users.erase (users.begin () + i); return true; } else { return false; } }
TEST_F (Simple, DISABLED_GetNothingEmpty) { using namespace kdb; KDB kdb; KeySet ks; Key k; try { ASSERT_EQ (kdb.get (ks, k), 1); } catch (std::exception const & e) { std::cout << "Could not get everything from keydatabase: " << e.what () << std::endl; } ASSERT_EQ (k.getMeta<int> ("warnings/#00/number"), 105) << "did not get warning for empty key"; // got everything, so make no assumption of size }
int TestCommand::execute(Cmdline const& cl) { if (cl.arguments.size() < 1) { throw invalid_argument ("need at least one argument"); } // do a basic check on every argument for (size_t i=1; i<cl.arguments.size(); ++i) { string name = " "; name += cl.arguments[i]; name += " "; if (testNames.find(name) == std::string::npos) { throw invalid_argument ("test name " + cl.arguments[i] + " does not exist in:" + testNames); } } printWarnings(cerr, root); root = cl.createKey(0); KDB kdb; KeySet original; kdb.get(original, root); original.rewind(); doTests(cl.arguments); cerr << "We got " << nrError << " errors in " << nrTest << " testcases." << endl; cout << "Test suite is now finished." << endl; cout << "Now restoring the original keyset." << endl; kdb.set(original, root); printWarnings(cerr, root); return nrError; }
TEST_F (Simple, MetaInSet) { using namespace kdb; KDB kdb; KeySet ks; Key parent (testRoot, KEY_END); kdb.get (ks, parent); ASSERT_EQ (ks.size (), 0) << "got keys from freshly mounted backend" << ks; ks.append (Key ("meta" + testRoot + "wrong_meta_key", KEY_META_NAME, KEY_END)); ASSERT_EQ (ks.size (), 1) << "key not inserted:\n" << ks; kdb.set (ks, parent); printError (std::cout, parent); printWarnings (std::cout, parent); ASSERT_EQ (ks.size (), 1) << "got wrong keys:\n" << ks; struct stat buf; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "did find config file"; }
TEST_F (Simple, EverythingInGetSet) { using namespace kdb; KDB kdb; KeySet ks = getAll (); Key parent (testRoot, KEY_END); kdb.get (ks, parent); ASSERT_EQ (ks.size (), 714) << "did not keep" << ks; kdb.set (ks, parent); printError (std::cout, parent); printWarnings (std::cout, parent); ASSERT_EQ (ks.size (), 714) << "got wrong keys:\n" << ks; // KeySet cmp = getAll(); // ASSERT_EQ(ks, cmp); // ASSERT_THAT(ks, ContainerEq(cmp)); compareKeySet (ks, getAll ()); struct stat buf; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), -1) << "did find config file"; }
TEST_F (Simple, TryChangeAfterSet) { using namespace kdb; KDB kdb; KeySet ks; std::string name = "system" + testRoot + "try_change"; Key k (name, KEY_END); EXPECT_EQ (k.getName (), name); ks.append (k); EXPECT_THROW (k.setName ("user/x"), kdb::KeyInvalidName); EXPECT_EQ (k.getName (), name); kdb.get (ks, testRoot); ASSERT_EQ (ks.size (), 1) << "lost keys in get\n" << ks; kdb.set (ks, testRoot); EXPECT_THROW (k.setName ("user/x"), kdb::KeyInvalidName); EXPECT_EQ (k.getName (), name); ASSERT_EQ (ks.size (), 1) << "got no keys\n" << ks; struct stat buf; ASSERT_EQ (stat (mp->systemConfigFile.c_str (), &buf), 0) << "did not find config file"; }
int main () { KeySet config; KDB kdb; kdb.get (config, "/sw/MyApp"); Key k = config.lookup ("/sw/MyApp/mykey"); if (k) { k.set<int> (k.get<int> () + 1); } else { Key n; n.setName ("user/sw/MyApp/mykey"); n.set<int> (0); config.append (n); } kdb.set (config, "/sw/MyApp"); }
/** * @brief Can be used to create an entry in the database. * * Will add the entry and all subkeys to the database (configuration). * * @param entry A custom Entry object holding information to store. * @return true if the entry was stored, false if something went wrong * @throws kdbrest::exception::EntryAlreadyExistsException in case an * entry with the given name does already exist in the key database. */ bool StorageEngine::createEntry (model::Entry & entry) { using namespace kdb; // register exclusive access boost::unique_lock<boost::shared_mutex> lock (m_mutex_entryCache); std::vector<model::Entry> & entries = this->m_entryCache; for (auto & elem : entries) { if (elem.getName ().compare (entry.getName ()) == 0) { throw exception::EntryAlreadyExistsException (); } } KDB kdb; KeySet ks; kdb.get (ks, entry.getName ()); Key k = ks.lookup (entry.getName ()); if (k) { throw kdbrest::exception::EntryAlreadyExistsException (); } ks.append (entry); ks.append (entry.getSubkeys ()); if (kdb.set (ks, entry.getName ()) >= 1) { entries.push_back (entry); return true; } else { return false; } }
/** * @brief Can be used to create an user entry in the database. * * Will add the user and all subkeys to the database (additional information). * * @param user A custom User object holding information to store. * @return true if the user was stored, false if something went wrong * @throws kdbrest::exception::UserAlreadyExistsException in case an * user with the given name does already exist in the key database. */ bool StorageEngine::createUser (model::User & user) { using namespace kdb; // register exclusive access boost::unique_lock<boost::shared_mutex> lock (m_mutex_userCache); std::vector<model::User> & users = this->m_userCache; for (auto & elem : users) { if (elem.getName ().compare (user.getName ()) == 0) { throw exception::UserAlreadyExistsException (); } } KDB kdb; KeySet ks; kdb.get (ks, user.getName ()); Key k = ks.lookup (user.getName ()); if (k) { throw exception::UserAlreadyExistsException (); } ks.append (user); ks.append (user.getSubkeys ()); if (kdb.set (ks, user.getName ()) >= 1) { users.push_back (user); return true; } else { return false; } }
__attribute__ ((noinline)) void benchmark_crypto_set (int iteration) { using namespace kdb; using namespace kdb::tools; static Timer t (plugin_variant_names[VARIANT]); Key mp = mountBackend<VARIANT> (iteration); { KDB kdb; KeySet ks; kdb.get (ks, mp); for (int i = 0; i < nr_keys; ++i) { // clang-format off ks.append (Key (mp.getName () + "/k" + std::to_string (i), KEY_VALUE, "value", KEY_META, "crypto/encrypt", "1", KEY_END)); // clang-format on } /*************************************************************************** * start of measurement **************************************************************************/ t.start (); kdb.set (ks, mp); t.stop (); /*************************************************************************** * end of measurement **************************************************************************/ kdb.close (); } std::cout << t; }