Commit 70c35581 authored by Matthieu Dorier's avatar Matthieu Dorier

improved tests for async engine

parent 24dc1b19
......@@ -320,55 +320,7 @@ class DataStoreImpl {
}
return key;
}
#if 0
void storeMultiple(unsigned long db_index,
const std::vector<std::string>& keys,
const std::vector<std::string>& values) {
// Create the product id
const auto& db = m_databases.dbs[db_index];
try {
db.put_multi(keys, values);
} catch(sdskv::exception& ex) {
throw Exception("Error occured when calling sdskv::database::put (SDSKV error=" +std::to_string(ex.error()) + ")");
}
}
size_t nextKeys(uint8_t level, const std::string& containerName,
const std::string& lower,
std::vector<std::string>& keys, size_t maxKeys) const {
int ret;
if(level == 0) return 0; // cannot iterate at object level
// hash the name to get the provider id
long unsigned db_idx = 0;
uint64_t h = hashString(containerName);
ch_placement_find_closest(m_databases.chi, h, 1, &db_idx);
// make an entry for the lower bound
auto lb_entry = buildKey(level, containerName, lower);
// get provider and database
const auto& db = m_databases.dbs[db_idx];
// ignore keys that don't have the same level or the same prefix
std::string prefix(2+containerName.size(), '\0');
prefix[0] = level;
if(containerName.size() != 0) {
std::memcpy(&prefix[1], containerName.data(), containerName.size());
prefix[prefix.size()-1] = '/';
} else {
prefix.resize(1);
}
// issue an sdskv_list_keys
std::vector<std::string> entries(maxKeys, std::string(1024,'\0'));
try {
db.list_keys(lb_entry, prefix, entries);
} catch(sdskv::exception& ex) {
throw Exception("Error occured when calling sdskv::database::list_keys (SDSKV error="+std::string(ex.what()) + ")");
}
keys.resize(0);
for(const auto& entry : entries) {
keys.emplace_back(&entry[1], entry.size()-1);
}
return keys.size();
}
#endif
///////////////////////////////////////////////////////////////////////////
// DataSet access functions
///////////////////////////////////////////////////////////////////////////
......
......@@ -167,3 +167,21 @@ void RunSetTest::testCreateSubRuns() {
CPPUNIT_ASSERT(73 == sr.number());
}
}
void RunSetTest::testAsync() {
auto root = datastore->root();
DataSet mds = root.createDataSet("matthieu_async");
CPPUNIT_ASSERT(mds.valid());
hepnos::AsyncEngine async(*datastore, 1);
for(unsigned i=0; i < 10; i++) {
Run r = mds.createRun(async, i);
CPPUNIT_ASSERT(r.valid());
}
async.wait();
for(unsigned i=0; i < 10; i++) {
CPPUNIT_ASSERT(mds[i].valid());
}
}
......@@ -15,6 +15,7 @@ class RunSetTest : public CppUnit::TestFixture
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST( testLowerUpperBounds );
CPPUNIT_TEST( testCreateSubRuns );
CPPUNIT_TEST( testAsync );
CPPUNIT_TEST_SUITE_END();
public:
......@@ -28,6 +29,7 @@ class RunSetTest : public CppUnit::TestFixture
void testBeginEnd();
void testLowerUpperBounds();
void testCreateSubRuns();
void testAsync();
};
#endif
......@@ -160,3 +160,22 @@ void RunTest::testLowerUpperBounds() {
}
}
void RunTest::testAsync() {
auto root = datastore->root();
DataSet mds = root.createDataSet("matthieu_async");
Run r = mds.createRun(1);
hepnos::AsyncEngine async(*datastore, 1);
for(unsigned i=0; i < 10; i++) {
SubRun sr = r.createSubRun(async, i);
CPPUNIT_ASSERT(sr.valid());
}
async.wait();
for(unsigned i=0; i < 10; i++) {
SubRun sr = r[i];
CPPUNIT_ASSERT(sr.valid());
}
}
......@@ -15,6 +15,7 @@ class RunTest : public CppUnit::TestFixture
CPPUNIT_TEST( testFind );
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST( testLowerUpperBounds );
CPPUNIT_TEST( testAsync );
CPPUNIT_TEST_SUITE_END();
public:
......@@ -28,6 +29,7 @@ class RunTest : public CppUnit::TestFixture
void testFind();
void testBeginEnd();
void testLowerUpperBounds();
void testAsync();
};
#endif
......@@ -157,3 +157,22 @@ void SubRunTest::testLowerUpperBounds() {
}
}
void SubRunTest::testAsync() {
auto root = datastore->root();
DataSet mds = root.createDataSet("matthieu_async");
Run r = mds.createRun(1);
SubRun sr = r.createSubRun(3);
hepnos::AsyncEngine async(*datastore, 1);
for(unsigned i=0; i < 10; i++) {
Event e = sr.createEvent(async, i);
CPPUNIT_ASSERT(e.valid());
}
async.wait();
for(unsigned i=0; i < 10; i++) {
Event e = sr[i];
CPPUNIT_ASSERT(e.valid());
}
}
......@@ -15,6 +15,7 @@ class SubRunTest : public CppUnit::TestFixture
CPPUNIT_TEST( testFind );
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST( testLowerUpperBounds );
CPPUNIT_TEST( testAsync );
CPPUNIT_TEST_SUITE_END();
public:
......@@ -28,6 +29,7 @@ class SubRunTest : public CppUnit::TestFixture
void testFind();
void testBeginEnd();
void testLowerUpperBounds();
void testAsync();
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment