Commit 1f076e75 authored by Matthieu Dorier's avatar Matthieu Dorier

added test for restart

parent f1e3831a
# Move the configuration file used for the configuration test
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run-test.sh ${CMAKE_CURRENT_BINARY_DIR}/run-test.sh COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run-two-tests.sh ${CMAKE_CURRENT_BINARY_DIR}/run-two-tests.sh COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-util.sh ${CMAKE_CURRENT_BINARY_DIR}/test-util.sh COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test-util.sh ${CMAKE_CURRENT_BINARY_DIR}/test-util.sh COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.yaml ${CMAKE_CURRENT_BINARY_DIR}/config.yaml COPYONLY)
......@@ -9,25 +11,31 @@ target_link_libraries(example hepnos ${Boost_LIBRARIES})
set(CTEST_ENVIRONMENT "MKTEMP=mktemp" "TIMEOUT=timeout")
add_executable(DataStoreTest DataStoreTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(DataStoreTest cppunit hepnos hepnos-service)
target_link_libraries(DataStoreTest cppunit hepnos)
add_executable(DataSetTest DataSetTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(DataSetTest cppunit hepnos hepnos-service)
target_link_libraries(DataSetTest cppunit hepnos)
add_executable(RunSetTest RunSetTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(RunSetTest cppunit hepnos hepnos-service)
target_link_libraries(RunSetTest cppunit hepnos)
add_executable(RunTest RunTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(RunTest cppunit hepnos hepnos-service)
target_link_libraries(RunTest cppunit hepnos)
add_executable(SubRunTest SubRunTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(SubRunTest cppunit hepnos hepnos-service)
target_link_libraries(SubRunTest cppunit hepnos)
add_executable(EventTest EventTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(EventTest cppunit hepnos hepnos-service)
target_link_libraries(EventTest cppunit hepnos)
add_executable(LoadStoreTest LoadStoreTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(LoadStoreTest cppunit hepnos hepnos-service boost_serialization)
target_link_libraries(LoadStoreTest cppunit hepnos boost_serialization)
add_executable(WriteAndRestartTest WriteAndRestartTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(WriteAndRestartTest cppunit hepnos boost_serialization)
add_executable(RestartAndReadTest RestartAndReadTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(RestartAndReadTest cppunit hepnos boost_serialization)
add_test(NAME DataStoreTest COMMAND run-test.sh ./DataStoreTest)
add_test(NAME DataSetTest COMMAND run-test.sh ./DataSetTest)
......@@ -36,3 +44,4 @@ add_test(NAME RunTest COMMAND run-test.sh ./RunTest)
add_test(NAME SubRunTest COMMAND run-test.sh ./SubRunTest)
add_test(NAME EventTest COMMAND run-test.sh ./EventTest)
add_test(NAME LoadStoreTest COMMAND run-test.sh ./LoadStoreTest)
add_test(NAME RestartTest COMMAND run-two-tests.sh ./WriteAndRestartTest ./RestartAndReadTest)
#include "LoadStoreTest.hpp"
#include "CppUnitAdditionalMacros.hpp"
#include "TestObjects.hpp"
CPPUNIT_TEST_SUITE_REGISTRATION( LoadStoreTest );
......
#ifndef __HEPNOS_TEST_LOADSTORE_H
#define __HEPNOS_TEST_LOADSTORE_H
#include <boost/serialization/access.hpp>
#include <boost/serialization/string.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <hepnos.hpp>
class TestObjectA {
friend class boost::serialization::access;
public:
int& x() { return _x; }
double& y() { return _y; }
bool operator==(const TestObjectA& other) const {
return _x == other._x && _y == other._y;
}
private:
int _x;
double _y;
template<typename Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & _x;
ar & _y;
}
};
class TestObjectB {
friend class boost::serialization::access;
public:
int& a() { return _a; }
std::string& b() { return _b; }
bool operator==(const TestObjectB& other) const {
return _a == other._a && _b == other._b;
}
private:
int _a;
std::string _b;
template<typename Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & _a;
ar & _b;
}
};
extern hepnos::DataStore* datastore;
class LoadStoreTest : public CppUnit::TestFixture
......
#include "RestartAndReadTest.hpp"
#include "CppUnitAdditionalMacros.hpp"
#include "TestObjects.hpp"
CPPUNIT_TEST_SUITE_REGISTRATION( RestartAndReadTest );
using namespace hepnos;
void RestartAndReadTest::setUp() {}
void RestartAndReadTest::tearDown() {}
void RestartAndReadTest::testLoadDataSet() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
// initialized for comparison
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
TestObjectA in_obj_a;
TestObjectB in_obj_b;
// we can reload obj_a from key1
CPPUNIT_ASSERT(mds.load(key1, in_obj_a));
// and they are the same
CPPUNIT_ASSERT(in_obj_a == out_obj_a);
// we can reload obj_b from key1
CPPUNIT_ASSERT(mds.load(key1, in_obj_b));
// and they are the same
CPPUNIT_ASSERT(in_obj_b == out_obj_b);
}
void RestartAndReadTest::testLoadRun() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
// For comparison
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
TestObjectA in_obj_a;
TestObjectB in_obj_b;
// we can reload obj_a from key1
CPPUNIT_ASSERT(run.load(key1, in_obj_a));
// and they are the same
CPPUNIT_ASSERT(in_obj_a == out_obj_a);
// we can reload obj_b from key1
CPPUNIT_ASSERT(run.load(key1, in_obj_b));
// and they are the same
CPPUNIT_ASSERT(in_obj_b == out_obj_b);
}
void RestartAndReadTest::testLoadSubRun() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
// For comparison
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
TestObjectA in_obj_a;
TestObjectB in_obj_b;
// we can reload obj_a from key1
CPPUNIT_ASSERT(subrun.load(key1, in_obj_a));
// and they are the same
CPPUNIT_ASSERT(in_obj_a == out_obj_a);
// we can reload obj_b from key1
CPPUNIT_ASSERT(subrun.load(key1, in_obj_b));
// and they are the same
CPPUNIT_ASSERT(in_obj_b == out_obj_b);
}
void RestartAndReadTest::testLoadEvent() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
// For comparison
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
TestObjectA in_obj_a;
TestObjectB in_obj_b;
// we can reload obj_a from key1
CPPUNIT_ASSERT(event.load(key1, in_obj_a));
// and they are the same
CPPUNIT_ASSERT(in_obj_a == out_obj_a);
// we can reload obj_b from key1
CPPUNIT_ASSERT(event.load(key1, in_obj_b));
// and they are the same
CPPUNIT_ASSERT(in_obj_b == out_obj_b);
}
#ifndef __HEPNOS_TEST_RESTARTANDREAD_H
#define __HEPNOS_TEST_RESTARTANDREAD_H
#include <cppunit/extensions/HelperMacros.h>
#include <hepnos.hpp>
extern hepnos::DataStore* datastore;
class RestartAndReadTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( RestartAndReadTest );
CPPUNIT_TEST( testLoadDataSet );
CPPUNIT_TEST( testLoadRun );
CPPUNIT_TEST( testLoadSubRun );
CPPUNIT_TEST( testLoadEvent );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testLoadDataSet();
void testLoadRun();
void testLoadSubRun();
void testLoadEvent();
};
#endif
#ifndef __HEPNOS_TEST_OBJECTS_H
#define __HEPNOS_TEST_OBJECTS_H
#include <boost/serialization/access.hpp>
#include <boost/serialization/string.hpp>
class TestObjectA {
friend class boost::serialization::access;
public:
int& x() { return _x; }
double& y() { return _y; }
bool operator==(const TestObjectA& other) const {
return _x == other._x && _y == other._y;
}
private:
int _x;
double _y;
template<typename Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & _x;
ar & _y;
}
};
class TestObjectB {
friend class boost::serialization::access;
public:
int& a() { return _a; }
std::string& b() { return _b; }
bool operator==(const TestObjectB& other) const {
return _a == other._a && _b == other._b;
}
private:
int _a;
std::string _b;
template<typename Archive>
void serialize(Archive& ar, const unsigned int version) {
ar & _a;
ar & _b;
}
};
#endif
#include "WriteAndRestartTest.hpp"
#include "CppUnitAdditionalMacros.hpp"
#include "TestObjects.hpp"
CPPUNIT_TEST_SUITE_REGISTRATION( WriteAndRestartTest );
using namespace hepnos;
void WriteAndRestartTest::setUp() {}
void WriteAndRestartTest::tearDown() {}
void WriteAndRestartTest::testFillDataStore() {
auto mds = datastore->createDataSet("matthieu");
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds.createRun(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1.createSubRun(3);
CPPUNIT_ASSERT(sr1.valid());
Event ev1 = sr1.createEvent(22);
CPPUNIT_ASSERT(ev1.valid());
}
void WriteAndRestartTest::testStoreDataSet() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
// we can store obj_a
CPPUNIT_ASSERT(mds.store(key1, out_obj_a));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT(mds.store(key1, out_obj_b));
}
void WriteAndRestartTest::testStoreRun() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
// we can store obj_a
CPPUNIT_ASSERT(run.store(key1, out_obj_a));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT(run.store(key1, out_obj_b));
}
void WriteAndRestartTest::testStoreSubRun() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
// we can store obj_a
CPPUNIT_ASSERT(subrun.store(key1, out_obj_a));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT(subrun.store(key1, out_obj_b));
}
void WriteAndRestartTest::testStoreEvent() {
auto mds = (*datastore)["matthieu"];
auto run = mds[42];
auto subrun = run[3];
auto event = subrun[22];
CPPUNIT_ASSERT(mds.valid());
CPPUNIT_ASSERT(run.valid());
CPPUNIT_ASSERT(subrun.valid());
CPPUNIT_ASSERT(event.valid());
TestObjectA out_obj_a;
out_obj_a.x() = 44;
out_obj_a.y() = 1.2;
TestObjectB out_obj_b;
out_obj_b.a() = 33;
out_obj_b.b() = "you";
std::string key1 = "mykey";
// we can store obj_a
CPPUNIT_ASSERT(event.store(key1, out_obj_a));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT(event.store(key1, out_obj_b));
}
#ifndef __HEPNOS_TEST_WRITEANDRESTART_H
#define __HEPNOS_TEST_WRITEANDRESTART_H
#include <cppunit/extensions/HelperMacros.h>
#include <hepnos.hpp>
extern hepnos::DataStore* datastore;
class WriteAndRestartTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( WriteAndRestartTest );
CPPUNIT_TEST( testFillDataStore );
CPPUNIT_TEST( testStoreDataSet );
CPPUNIT_TEST( testStoreRun );
CPPUNIT_TEST( testStoreSubRun );
CPPUNIT_TEST( testStoreEvent );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testFillDataStore();
void testStoreDataSet();
void testStoreRun();
void testStoreSubRun();
void testStoreEvent();
};
#endif
#!/bin/bash -x
if [ -z "$MKTEMP" ] ; then
echo expected MKTEMP variable defined to its respective command
exit 1
fi
source test-util.sh
TEST_DIR=`$MKTEMP -d /tmp/hepnos-XXXXXX`
CON_FILE=$TEST_DIR/connection.yaml
cp config.yaml $TEST_DIR/config.yaml
CFG_FILE=$TEST_DIR/config.yaml
sed -i -e "s|XXX|${TEST_DIR}/database|g" $CFG_FILE
export HEPNOS_CONFIG_FILE=$CON_FILE
# Run HEPnOS
hepnos_test_start_servers 2 1 20 $CFG_FILE $CON_FILE
# Run a test client
run_to 10 $1 $CON_FILE
if [ $? -ne 0 ]; then
wait
exit 1
fi
# Wait on both HEPnOS and test client to close
wait
# Run HEPnOS again
hepnos_test_start_servers 2 1 20 $CFG_FILE $CON_FILE
# Run the second test client
run_to 10 $2 $CON_FILE
if [ $? -ne 0 ]; then
wait
exit 1
fi
# Wait on both HEPnOS and test client to close
wait
##############
# cleanup
rm -rf $TEST_DIR
rm -rf /dev/shm/hepnos.dat
exit 0
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