Author: kpvdr
Date: 2007-09-23 13:37:01 -0400 (Sun, 23 Sep 2007)
New Revision: 941
Removed:
store/trunk/cpp/tests/jrnl/jrnl_scope_test.cpp
Modified:
store/trunk/cpp/tests/jrnl/JournalTest.cpp
store/trunk/cpp/tests/jrnl/Makefile.rtest
store/trunk/cpp/tests/jrnl/rtest
Log:
Changed tests in jrnl_scope_test.cpp into CppUnit format and added them to
JournalTest.cpp.
Modified: store/trunk/cpp/tests/jrnl/JournalTest.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/JournalTest.cpp 2007-09-22 15:09:17 UTC (rev 940)
+++ store/trunk/cpp/tests/jrnl/JournalTest.cpp 2007-09-23 17:37:01 UTC (rev 941)
@@ -34,216 +34,816 @@
#include "msg_consumer.hpp"
#include "jtest.hpp"
+#define MAX_MSG_SIZE 127
+#define NUM_MSGS 5
+#define MAX_AIO_SLEEPS 500
+#define AIO_SLEEP_TIME 1000
+
class JournalTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(JournalTest);
- CPPUNIT_TEST(Test_000);
- CPPUNIT_TEST(Test_001);
- CPPUNIT_TEST(Test_002);
- CPPUNIT_TEST(Test_003);
- CPPUNIT_TEST(Test_004);
- CPPUNIT_TEST(Test_005);
- CPPUNIT_TEST(Test_006);
- CPPUNIT_TEST(Test_007);
- CPPUNIT_TEST(Test_008);
- CPPUNIT_TEST(Test_009);
- CPPUNIT_TEST(Test_010);
- CPPUNIT_TEST(Test_011);
- CPPUNIT_TEST(Test_012);
- CPPUNIT_TEST(Test_013);
- CPPUNIT_TEST(Test_014);
- CPPUNIT_TEST(Test_015);
- CPPUNIT_TEST(Test_016);
- CPPUNIT_TEST(Test_017);
- CPPUNIT_TEST(Test_018);
- CPPUNIT_TEST(Test_019);
- CPPUNIT_TEST(Test_020);
- CPPUNIT_TEST(Test_021);
- CPPUNIT_TEST(Test_022);
- CPPUNIT_TEST(Test_023);
- CPPUNIT_TEST(Test_024);
- CPPUNIT_TEST(Test_025);
- CPPUNIT_TEST(Test_026);
- CPPUNIT_TEST(Test_027);
-// CPPUNIT_TEST(Test_028); // Until race condition fixed
+ CPPUNIT_TEST(InstantiationTest_Stack);
+ CPPUNIT_TEST(InstantiationTest_Heap);
+ CPPUNIT_TEST(InitializationTest_Stack);
+ CPPUNIT_TEST(InitializationTest_Heap);
+ CPPUNIT_TEST(EmptyRecoverTest_Stack);
+ CPPUNIT_TEST(EmptyRecoverTest_Heap);
+ CPPUNIT_TEST(EnqueueTest_Stack);
+ CPPUNIT_TEST(EnqueueTest_Heap);
+ CPPUNIT_TEST(RecoverReadTest_Stack);
+ CPPUNIT_TEST(RecoverReadTest_Heap);
+ CPPUNIT_TEST(RecoveredReadTest_Stack);
+ CPPUNIT_TEST(RecoveredReadTest_Heap);
+ CPPUNIT_TEST(RecoveredDequeueTest_Stack);
+ CPPUNIT_TEST(RecoveredDequeueTest_Heap);
+ CPPUNIT_TEST(ComplexRecoveryTest1_Stack);
+ CPPUNIT_TEST(ComplexRecoveryTest1_Heap);
+ CPPUNIT_TEST(EncodeTest_000);
+ CPPUNIT_TEST(EncodeTest_001);
+ CPPUNIT_TEST(EncodeTest_002);
+ CPPUNIT_TEST(EncodeTest_003);
+ CPPUNIT_TEST(EncodeTest_004);
+ CPPUNIT_TEST(EncodeTest_005);
+ CPPUNIT_TEST(EncodeTest_006);
+ CPPUNIT_TEST(EncodeTest_007);
+ CPPUNIT_TEST(EncodeTest_008);
+ CPPUNIT_TEST(EncodeTest_009);
+ CPPUNIT_TEST(EncodeTest_010);
+ CPPUNIT_TEST(EncodeTest_011);
+ CPPUNIT_TEST(EncodeTest_012);
+ CPPUNIT_TEST(EncodeTest_013);
+ CPPUNIT_TEST(EncodeTest_014);
+ CPPUNIT_TEST(EncodeTest_015);
+ CPPUNIT_TEST(EncodeTest_016);
+ CPPUNIT_TEST(EncodeTest_017);
+ CPPUNIT_TEST(EncodeTest_018);
+ CPPUNIT_TEST(EncodeTest_019);
+ CPPUNIT_TEST(EncodeTest_020);
+ CPPUNIT_TEST(EncodeTest_021);
+ CPPUNIT_TEST(EncodeTest_022);
+ CPPUNIT_TEST(EncodeTest_023);
+ CPPUNIT_TEST(EncodeTest_024);
+ CPPUNIT_TEST(EncodeTest_025);
+ CPPUNIT_TEST(EncodeTest_026);
+ CPPUNIT_TEST(EncodeTest_027);
+// CPPUNIT_TEST(EncodeTest_028); // Until race condition fixed
CPPUNIT_TEST_SUITE_END();
jtest t;
+ std::string msg;
+ char buff[MAX_MSG_SIZE + 1];
- void runJournalTest(const unsigned num_msgs, const unsigned min_msg_size,
- const unsigned max_msg_szie, const bool auto_deq, const unsigned iterations,
- const char* test_descr)
+public:
+
+ void InstantiationTest_Stack()
{
- std::cout << " [" << test_descr << "] "
<< std::flush;
- jtest::targs ta(num_msgs, min_msg_size, max_msg_szie, auto_deq, test_descr);
- for (unsigned i=0; i<iterations; i++)
+ const char* test_name = "InstantiationTest_Stack";
+ try
{
- std::cout << "." << std::flush;
- try
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
+ }
+
+ void InstantiationTest_Heap()
+ {
+ const char* test_name = "InstantiationTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.", jcp !=
NULL);
+ delete jcp;
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
+ }
+
+ void InitializationTest_Stack()
+ {
+ const char* test_name = "InitializationTest_Stack";
+ try
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
+ }
+
+ void InitializationTest_Heap()
+ {
+ const char* test_name = "InitializationTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.", jcp !=
NULL);
+ jcp->initialize();
+ delete jcp;
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
+ }
+
+ void EmptyRecoverTest_Stack()
+ {
+ const char* test_name = "EmptyRecoverTest_Stack";
+ try
+ {
{
- t.initialize(ta);
- t.run();
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
}
- catch (rhm::journal::jexception e)
{
- t.finalize();
- std::string s;
- CPPUNIT_FAIL(e.to_string(s));
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.recover();
}
- t.finalize();
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.recover();
+ jc.recovered();
+ }
}
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
-public:
- void Test_000()
+ void EmptyRecoverTest_Heap()
{
- runJournalTest(0, 0, 0, false, 2, "Empty journal");
+ const char* test_name = "EmptyRecoverTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->initialize();
+ delete jcp;
+ jcp = NULL;
+ }
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->recover();
+ delete jcp;
+ jcp = NULL;
+ }
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->recover();
+ jcp->recovered();
+ delete jcp;
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_001()
+ void EnqueueTest_Stack()
{
- runJournalTest(1, 10, 10, false, 2, "1*(10 bytes)");
+ const char* test_name = "EnqueueTest_Stack";
+ try
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(&jc, create_msg(msg, m));
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_002()
+ void EnqueueTest_Heap()
{
- runJournalTest(1, 10, 10, true, 2, "1*(10 bytes), auto-deq");
+ const char* test_name = "EnqueueTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.", jcp !=
NULL);
+ jcp->initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(jcp, create_msg(msg, m));
+ delete jcp;
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_003()
+ void RecoverReadTest_Stack()
{
- runJournalTest(10, 10, 10, false, 2, "10*(10 bytes)");
+ const char* test_name = "RecoverReadTest_Stack";
+ try
+ {
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(&jc, create_msg(msg, m));
+ }
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.recover();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_004()
+ void RecoverReadTest_Heap()
{
- runJournalTest(10, 10, 10, true, 2, "10*(10 bytes), auto-deq");
+ const char* test_name = "RecoverReadTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(jcp, create_msg(msg, m));
+ delete jcp;
+ jcp = NULL;
+ }
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->recover();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ delete jcp;
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_005()
+ void RecoveredReadTest_Stack()
{
- runJournalTest(10, 92, 92, false, 2, "10*(1 dblk exact fit)");
+ const char* test_name = "RecoveredReadTest_Stack";
+ try
+ {
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(&jc, create_msg(msg, m));
+ }
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.recover();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ jc.recovered();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt after recovery.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_006()
+ void RecoveredReadTest_Heap()
{
- runJournalTest(10, 92, 92, true, 2, "10*(1 dblk exact fit),
auto-deq");
+ const char* test_name = "RecoveredReadTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(jcp, create_msg(msg, m));
+ delete jcp;
+ jcp = NULL;
+ }
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->recover();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ jcp->recovered();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt after recovery.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ delete jcp;
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_007()
+ void RecoveredDequeueTest_Stack()
{
- runJournalTest(10, 93, 93, false, 2, "10*(1 dblk + 1 byte)");
+ const char* test_name = "RecoveredDequeueTest_Stack";
+ try
+ {
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(&jc, create_msg(msg, m));
+ }
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.recover();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ jc.recovered();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt after recovery.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ for (int m=0; m<NUM_MSGS; m++)
+ deq_msg(&jc, m);
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_008()
+ void RecoveredDequeueTest_Heap()
{
- runJournalTest(10, 93, 93, true, 2, "10*(1 dblk + 1 byte), auto-deq");
+ const char* test_name = "RecoveredDequeueTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->initialize();
+ for (int m=0; m<NUM_MSGS; m++)
+ enq_msg(jcp, create_msg(msg, m));
+ delete jcp;
+ jcp = NULL;
+ }
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->recover();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ jcp->recovered();
+ for (int m=0; m<NUM_MSGS; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt after recovery.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ for (int m=0; m<NUM_MSGS; m++)
+ deq_msg(jcp, m);
+ delete jcp;
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_009()
+ void ComplexRecoveryTest1_Stack()
{
- runJournalTest(10, 476, 476, false, 2, "10*(1 sblk exact fit)");
+ const char* test_name = "ComplexRecoveryTest1_Stack";
+ try
+ {
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.initialize();
+ // rids: 0 to NUM_MSGS*2 - 1
+ for (int m=0; m<NUM_MSGS*2; m++)
+ enq_msg(&jc, create_msg(msg, m));
+ // rids: NUM_MSGS*2 to NUM_MSGS*3 - 1
+ for (int m=0; m<NUM_MSGS; m++)
+ deq_msg(&jc, m);
+ jc.flush();
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ }
+ {
+ rhm::journal::jcntl jc(test_name, "jdata", test_name);
+ jc.recover();
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ jc.recovered();
+ // rids: NUM_MSGS*3 to NUM_MSGS*4 - 1
+ for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
+ enq_msg(&jc, create_msg(msg, m));
+ jc.flush();
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(&jc)) == 0);
+ // rids: NUM_MSGS*4 to NUM_MSGS*6 - 1
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ deq_msg(&jc, m);
+ for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
+ deq_msg(&jc, m);
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_010()
+ void ComplexRecoveryTest1_Heap()
{
- runJournalTest(10, 476, 476, true, 2, "10*(1 sblk exact fit),
auto-deq");
+ const char* test_name = "RecoveredDequeueTest_Heap";
+ rhm::journal::jcntl* jcp = NULL;
+ try
+ {
+ {
+ jcp = new rhm::journal::jcntl(test_name, "jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->initialize();
+ // rids: 0 to NUM_MSGS*2 - 1
+ for (int m=0; m<NUM_MSGS*2; m++)
+ enq_msg(jcp, create_msg(msg, m));
+ // rids: NUM_MSGS*2 to NUM_MSGS*3 - 1
+ for (int m=0; m<NUM_MSGS; m++)
+ deq_msg(jcp, m);
+ jcp->flush();
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ delete jcp;
+ jcp = NULL;
+ }
+ {
+ rhm::journal::jcntl* jcp = new rhm::journal::jcntl(test_name,
"jdata", test_name);
+ CPPUNIT_ASSERT_MESSAGE("Journal heap instantiation failed.",
jcp != NULL);
+ jcp->recover();
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt during recover.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ jcp->recovered();
+ // rids: NUM_MSGS*3 to NUM_MSGS*4 - 1
+ for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
+ enq_msg(jcp, create_msg(msg, m));
+ jcp->flush();
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt after recovery.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
+ CPPUNIT_ASSERT_MESSAGE("Message corrupt after recovery.",
+ create_msg(msg, m).compare(read_msg(jcp)) == 0);
+ // rids: NUM_MSGS*4 to NUM_MSGS*6 - 1
+ for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
+ deq_msg(jcp, m);
+ for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
+ deq_msg(jcp, m);
+ delete jcp;
+ }
+ }
+ catch (rhm::journal::jexception& e)
+ {
+ if (jcp)
+ delete jcp;
+ std::stringstream ss;
+ ss << e;
+ CPPUNIT_FAIL(ss.str());
+ }
}
- void Test_011()
+ void EncodeTest_000()
{
- runJournalTest(10, 477, 477, false, 2, "10*(1 sblk + 1 byte)");
+ runEncodeTest(0, 0, 0, false, 2, "Empty journal");
}
- void Test_012()
+ void EncodeTest_001()
{
- runJournalTest(10, 477, 477, true, 2, "10*(1 sblk + 1 byte),
auto-deq");
+ runEncodeTest(1, 10, 10, false, 2, "1*(10 bytes)");
}
- void Test_013()
+ void EncodeTest_002()
{
- runJournalTest(8, 4060, 4060, false, 2, "8*(1/8 page)");
+ runEncodeTest(1, 10, 10, true, 2, "1*(10 bytes), auto-deq");
}
- void Test_014()
+ void EncodeTest_003()
{
- runJournalTest(9, 4060, 4060, false, 2, "9*(1/8 page)");
+ runEncodeTest(10, 10, 10, false, 2, "10*(10 bytes)");
}
- void Test_015()
+ void EncodeTest_004()
{
- runJournalTest(8, 4061, 4061, false, 2, "8*(1/8 page + 1 byte)");
+ runEncodeTest(10, 10, 10, true, 2, "10*(10 bytes), auto-deq");
}
- void Test_016()
+ void EncodeTest_005()
{
- runJournalTest(8, 3932, 3932, true, 2, "8*(1/8 page - 1 dblk for deq
record), auto-deq");
+ runEncodeTest(10, 92, 92, false, 2, "10*(1 dblk exact fit)");
}
- void Test_017()
+ void EncodeTest_006()
{
- runJournalTest(9, 3932, 3932, true, 2, "9*(1/8 page - 1 dblk for deq
record), auto-deq");
+ runEncodeTest(10, 92, 92, true, 2, "10*(1 dblk exact fit), auto-deq");
}
- void Test_018()
+ void EncodeTest_007()
{
- runJournalTest(8, 3933, 3933, true, 2,
+ runEncodeTest(10, 93, 93, false, 2, "10*(1 dblk + 1 byte)");
+ }
+
+ void EncodeTest_008()
+ {
+ runEncodeTest(10, 93, 93, true, 2, "10*(1 dblk + 1 byte), auto-deq");
+ }
+
+ void EncodeTest_009()
+ {
+ runEncodeTest(10, 476, 476, false, 2, "10*(1 sblk exact fit)");
+ }
+
+ void EncodeTest_010()
+ {
+ runEncodeTest(10, 476, 476, true, 2, "10*(1 sblk exact fit),
auto-deq");
+ }
+
+ void EncodeTest_011()
+ {
+ runEncodeTest(10, 477, 477, false, 2, "10*(1 sblk + 1 byte)");
+ }
+
+ void EncodeTest_012()
+ {
+ runEncodeTest(10, 477, 477, true, 2, "10*(1 sblk + 1 byte),
auto-deq");
+ }
+
+ void EncodeTest_013()
+ {
+ runEncodeTest(8, 4060, 4060, false, 2, "8*(1/8 page)");
+ }
+
+ void EncodeTest_014()
+ {
+ runEncodeTest(9, 4060, 4060, false, 2, "9*(1/8 page)");
+ }
+
+ void EncodeTest_015()
+ {
+ runEncodeTest(8, 4061, 4061, false, 2, "8*(1/8 page + 1 byte)");
+ }
+
+ void EncodeTest_016()
+ {
+ runEncodeTest(8, 3932, 3932, true, 2, "8*(1/8 page - 1 dblk for deq record),
auto-deq");
+ }
+
+ void EncodeTest_017()
+ {
+ runEncodeTest(9, 3932, 3932, true, 2, "9*(1/8 page - 1 dblk for deq record),
auto-deq");
+ }
+
+ void EncodeTest_018()
+ {
+ runEncodeTest(8, 3933, 3933, true, 2,
"8*(1/8 page - 1 dblk for deq record + 1 byte), auto-deq");
}
- void Test_019()
+ void EncodeTest_019()
{
- runJournalTest(32, 32732, 32732, false, 2, "32*(1 page exact fit)");
+ runEncodeTest(32, 32732, 32732, false, 2, "32*(1 page exact fit)");
}
- void Test_020()
+ void EncodeTest_020()
{
- runJournalTest(33, 32732, 32732, false, 2, "33*(1 page exact fit)");
+ runEncodeTest(33, 32732, 32732, false, 2, "33*(1 page exact fit)");
}
- void Test_021()
+ void EncodeTest_021()
{
- runJournalTest(22, 49116, 49116, false, 2, "22*(1.5 pages)");
+ runEncodeTest(22, 49116, 49116, false, 2, "22*(1.5 pages)");
}
- void Test_022()
+ void EncodeTest_022()
{
- runJournalTest(22, 48988, 48988, true, 2,
+ runEncodeTest(22, 48988, 48988, true, 2,
"22*(1.5 pages - 1 dblk for deq record), auto-deq");
}
- void Test_023()
+ void EncodeTest_023()
{
- runJournalTest(48, 32732, 32732, false, 2, "48*(1 page exact fit)");
+ runEncodeTest(48, 32732, 32732, false, 2, "48*(1 page exact fit)");
}
- void Test_024()
+ void EncodeTest_024()
{
- runJournalTest(49, 32732, 32732, false, 2, "49*(1 page exact fit)");
+ runEncodeTest(49, 32732, 32732, false, 2, "49*(1 page exact fit)");
}
- void Test_025()
+ void EncodeTest_025()
{
- runJournalTest(20, 81884, 81884, false, 2, "20*(2.5 pages)");
+ runEncodeTest(20, 81884, 81884, false, 2, "20*(2.5 pages)");
}
- void Test_026()
+ void EncodeTest_026()
{
- runJournalTest(20, 81756, 81756, true, 2,
+ runEncodeTest(20, 81756, 81756, true, 2,
"20*(2.5 pages - 1 dblk for deq record), auto-deq");
}
- void Test_027()
+ void EncodeTest_027()
{
- runJournalTest(16, 786268, 786268, true, 2,
+ runEncodeTest(16, 786268, 786268, true, 2,
"16*(24 pages = 1/2 file); Total = 8 files exactly (full journal
filespace)");
}
- void Test_028()
+ void EncodeTest_028()
{
- runJournalTest(17, 786268, 786268, true, 2,
+ runEncodeTest(17, 786268, 786268, true, 2,
"17*(24 pages = 1/2 file); Total = 8 files + file 0 overwritten by
1/2 file");
}
+
+private:
+
+ void enq_msg(rhm::journal::jcntl* jc, const std::string msg)
+ {
+ rhm::journal::data_tok* dtp = new rhm::journal::data_tok;
+ CPPUNIT_ASSERT_MESSAGE("Data Token heap intantiation failed.", dtp !=
NULL);
+
+ unsigned aio_sleep_cnt = 0;
+ while (handle_jcntl_response(jc->enqueue_data(msg.c_str(), msg.size(), dtp),
jc,
+ aio_sleep_cnt, dtp));
+ }
+
+ void deq_msg(rhm::journal::jcntl* jc, u_int64_t rid)
+ {
+ rhm::journal::data_tok* dtp = new rhm::journal::data_tok;
+ CPPUNIT_ASSERT_MESSAGE("Data Token heap intantiation failed.", dtp !=
NULL);
+ dtp->set_wstate(rhm::journal::data_tok::ENQ);
+ dtp->set_rid(rid);
+
+ unsigned aio_sleep_cnt = 0;
+ while (handle_jcntl_response(jc->dequeue_data(dtp), jc, aio_sleep_cnt, dtp));
+ }
+
+ char* read_msg(rhm::journal::jcntl* jc)
+ {
+ memset(buff, '*', MAX_MSG_SIZE);
+ buff[MAX_MSG_SIZE] = '\0';
+
+ rhm::journal::data_tok* dtp = new rhm::journal::data_tok;
+ CPPUNIT_ASSERT_MESSAGE("Data Token heap intantiation failed.", dtp !=
NULL);
+ dtp->set_wstate(rhm::journal::data_tok::ENQ);
+
+ unsigned aio_sleep_cnt = 0;
+ while (handle_jcntl_response(jc->read_data(buff, MAX_MSG_SIZE, dtp), jc,
aio_sleep_cnt, dtp));
+ buff[dtp->dsize()] = '\0';
+ return buff;
+ }
+
+ bool handle_jcntl_response(rhm::journal::iores res, rhm::journal::jcntl* jc,
+ unsigned& aio_sleep_cnt, rhm::journal::data_tok* dtp)
+ {
+ switch (res)
+ {
+ case rhm::journal::RHM_IORES_SUCCESS:
+ buff[dtp->dsize()] = '\0';
+ return false;
+ case rhm::journal::RHM_IORES_AIO_WAIT:
+ if (++aio_sleep_cnt <= MAX_AIO_SLEEPS)
+ {
+ jc->get_wr_events();
+ usleep(AIO_SLEEP_TIME);
+ }
+ else
+ {
+ delete dtp;
+ CPPUNIT_FAIL("dequeue_data(): timeout on
RHM_IORES_AIO_WAIT.");
+ }
+ break;
+ case rhm::journal::RHM_IORES_EMPTY:
+ delete dtp;
+ CPPUNIT_FAIL("dequeue_data(): RHM_IORES_EMPTY.");
+ case rhm::journal::RHM_IORES_FULL:
+ delete dtp;
+ CPPUNIT_FAIL("dequeue_data(): RHM_IORES_FULL.");
+ case rhm::journal::RHM_IORES_BUSY:
+ delete dtp;
+ CPPUNIT_FAIL("dequeue_data(): RHM_IORES_BUSY.");
+ default:
+ delete dtp;
+ CPPUNIT_FAIL("dequeue_data(): unknown return value.");
+ }
+ return true;
+ }
+
+ static std::string& create_msg(std::string& s, int msg_num)
+ {
+ std::stringstream ss;
+ ss << "Message_" << std::setfill('0') <<
std::setw(4) << msg_num;
+ ss << "_4567890123456789012345678901234567890";
+ ss << "12345678901234567890123456789012345678901234567890"; //
100 chars long (2 dblks)
+ s.assign(ss.str());
+ return s;
+ }
+
+ void runEncodeTest(const unsigned num_msgs, const unsigned min_msg_size,
+ const unsigned max_msg_szie, const bool auto_deq, const unsigned iterations,
+ const char* test_descr)
+ {
+ std::cout << " [" << test_descr << "] "
<< std::flush;
+ jtest::targs ta(num_msgs, min_msg_size, max_msg_szie, auto_deq, test_descr);
+ for (unsigned i=0; i<iterations; i++)
+ {
+ std::cout << "." << std::flush;
+ try
+ {
+ t.initialize(ta);
+ t.run();
+ }
+ catch (rhm::journal::jexception e)
+ {
+ t.finalize();
+ std::string s;
+ CPPUNIT_FAIL(e.to_string(s));
+ }
+ t.finalize();
+ }
+ }
};
// Make this test suite a plugin.
Modified: store/trunk/cpp/tests/jrnl/Makefile.rtest
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.rtest 2007-09-22 15:09:17 UTC (rev 940)
+++ store/trunk/cpp/tests/jrnl/Makefile.rtest 2007-09-23 17:37:01 UTC (rev 941)
@@ -68,7 +68,7 @@
msg_producer.o \
msg_consumer.o \
-JTEST_FILES = jtest jrnl_scope_test
+JTEST_FILES = jtest
CXX = g++
CXXINCLUDES = -I. -I../../lib -I../../../../qpid/cpp/src -I../../../../qpid/cpp/src/gen
@@ -104,9 +104,6 @@
jtest: $(JRNL_OBJ_FILES) $(JTEST_OBJ_FILES)
-jrnl_scope_test: RHM_DEFINES = -DRHM_CLEAN
-jrnl_scope_test: $(JRNL_OBJ_FILES) jrnl_scope_test.cpp
-
jrtest: RHM_DEFINES = -DRHM_JOWRITE -DRHM_RDONLY -DRHM_TESTVALS
jrtest: $(JTEST_FILES)
@@ -122,7 +119,6 @@
clean:
@rm -f *.o
@rm -f jtest
- @rm -f jrnl_scope_test
clean-data:
@rm -rf jdata
Deleted: store/trunk/cpp/tests/jrnl/jrnl_scope_test.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jrnl_scope_test.cpp 2007-09-22 15:09:17 UTC (rev 940)
+++ store/trunk/cpp/tests/jrnl/jrnl_scope_test.cpp 2007-09-23 17:37:01 UTC (rev 941)
@@ -1,751 +0,0 @@
-#include <iostream>
-#include <jrnl/data_tok.hpp>
-#include <jrnl/jcntl.hpp>
-#include <sstream>
-
-using namespace std;
-
-#define TEST_ITERATIONS 5
-#define NUM_TESTS 16
-#define NUM_MSGS 5
-#define MAX_MSG_SIZE 127
-#define MAX_AIO_SLEEPS 500
-#define AIO_SLEEP_TIME 1000
-
-class jrnl_scope_test
-{
- static const char* iores_str[];
- std::string _msg;
-public:
- jrnl_scope_test() {_msg.reserve(MAX_MSG_SIZE+1);}
- ~jrnl_scope_test() {}
-
- int run()
- {
- int res;
- for (int t=1; t<=NUM_TESTS; t++)
- if ((res = run(t, TEST_ITERATIONS)))
- break;
- return res;
- }
-
- int run(int test_num, int num_iter)
- {
- try
- {
- switch(test_num)
- {
- case 1:
- return test_1(num_iter);
- case 2:
- return test_2(num_iter);
- case 3:
- return test_3(num_iter);
- case 4:
- return test_4(num_iter);
- case 5:
- return test_5(num_iter);
- case 6:
- return test_6(num_iter);
- case 7:
- return test_7(num_iter);
- case 8:
- return test_8(num_iter);
- case 9:
- return test_9(num_iter);
- case 10:
- return test_10(num_iter);
- case 11:
- return test_11(num_iter);
- case 12:
- return test_12(num_iter);
- case 13:
- return test_13(num_iter);
- case 14:
- return test_14(num_iter);
- case 15:
- return test_15(num_iter);
- case 16:
- return test_16(num_iter);
- default:
- cout << " unknown test: " << test_num <<
endl;
- return 1;
- }
- }
- catch (rhm::journal::jexception& e)
- {
- cout << e << endl;
- return 2;
- }
- }
-
-protected:
- int test_1(int num_iter)
- {
- cout << " 1. instance: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- rhm::journal::jcntl jc("scope_test_01", "jdata",
"t01");
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_2(int num_iter)
- {
- cout << " 2. instance_ptr: ";
- {
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_02", "jdata", "t02");
- if (!jc)
- {
- cout << " failed, jc==NULL" << endl;
- return 1;
- }
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_3(int num_iter)
- {
- cout << " 3. init: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- rhm::journal::jcntl jc("scope_test_03", "jdata",
"t03");
- jc.initialize();
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_4(int num_iter)
- {
- cout << " 4. init_ptr: ";
- {
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_04", "jdata", "t04");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_5(int num_iter)
- {
- cout << " 5. init_recover: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl jc("scope_test_05", "jdata",
"t05");
- jc.initialize();
- }
- {
- rhm::journal::jcntl jc("scope_test_05", "jdata",
"t05");
- jc.recover();
- }
- {
- rhm::journal::jcntl jc("scope_test_05", "jdata",
"t05");
- jc.recover();
- jc.recovered();
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_6(int num_iter)
- {
- cout << " 6. init_recover_ptr: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_06", "jdata", "t06");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- delete jc;
- }
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_06", "jdata", "t06");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->recover();
- delete jc;
- }
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_06", "jdata", "t06");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->recover();
- jc->recovered();
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_7(int num_iter)
- {
- cout << " 7. enq: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl jc("scope_test_07", "jdata",
"t07");
- jc.initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(&jc, create_msg(_msg, m)))
- return 1;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_8(int num_iter)
- {
- cout << " 8. enq_ptr: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_08", "jdata", "t08");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(jc, create_msg(_msg, m)))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_9(int num_iter)
- {
- cout << " 9. recover_read: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl jc("scope_test_09", "jdata",
"t09");
- jc.initialize();
- for (int m=0; m<NUM_MSGS; m++) // 12288 - fills 1 file
- if (enq_msg(&jc, create_msg(_msg, m)))
- return 1;
- }
- {
- rhm::journal::jcntl jc("scope_test_09", "jdata",
"t09");
- jc.recover();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, &jc))
- return 1;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_10(int num_iter)
- {
- cout << " 10. recover_read_ptr: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_10", "jdata", "t10");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(jc, create_msg(_msg, m)))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_10", "jdata", "t10");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->recover();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_11(int num_iter)
- {
- cout << " 11. recover_read_read: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl jc("scope_test_11", "jdata",
"t11");
- jc.initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(&jc, create_msg(_msg, m)))
- return 1;
- }
- {
- rhm::journal::jcntl jc("scope_test_11", "jdata",
"t11");
- jc.recover();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, &jc))
- return 1;
- jc.recovered();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, &jc))
- return 1;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_12(int num_iter)
- {
- cout << " 12. recover_read_read_ptr: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_12", "jdata", "t12");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(jc, create_msg(_msg, m)))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_12", "jdata", "t12");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->recover();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- jc->recovered();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_13(int num_iter)
- {
- cout << " 13. recover_read_read_deq: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl jc("scope_test_13", "jdata",
"t13");
- jc.initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(&jc, create_msg(_msg, m)))
- return 1;
- }
- {
- rhm::journal::jcntl jc("scope_test_13", "jdata",
"t13");
- jc.recover();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, &jc))
- return 1;
- jc.recovered();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, &jc))
- return 1;
- for (int m=0; m<NUM_MSGS; m++)
- if (deq_msg(&jc, m))
- return 1;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_14(int num_iter)
- {
- cout << " 14. recover_read_read_deq_ptr: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_14", "jdata", "t14");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- for (int m=0; m<NUM_MSGS; m++)
- if (enq_msg(jc, create_msg(_msg, m)))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_14", "jdata", "t14");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->recover();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- jc->recovered();
- for (int m=0; m<NUM_MSGS; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- for (int m=0; m<NUM_MSGS; m++)
- if (deq_msg(jc, m))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_15(int num_iter)
- {
- cout << " 15. complex recover: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl jc("scope_test_15", "jdata",
"t15");
- jc.initialize();
- // enqueue msgs, read then dequeue half
- // rids 0-9
- for (int m=0; m<NUM_MSGS*2; m++)
- if (enq_msg(&jc, create_msg(_msg, m)))
- return 1;
- // rids 10-14 dequeueing rids 0-4
- for (int m=0; m<NUM_MSGS; m++)
- if (deq_msg(&jc, m))
- return 1;
- jc.flush();
- for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
- if (read_msg(m, &jc))
- return 1;
- }
- {
- rhm::journal::jcntl jc("scope_test_15", "jdata",
"t15");
- jc.recover();
- // recover other half of messages
- for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
- if (read_msg(m, &jc))
- return 1;
- jc.recovered();
- // write more messages, read and dequeue all
- // rids 15-19
- for (int m=NUM_MSGS*2; m<NUM_MSGS*3; m++)
- if (enq_msg(&jc, create_msg(_msg, m)))
- return 1;
- jc.flush();
- for (int m=NUM_MSGS; m<NUM_MSGS*3; m++)
- if (read_msg(m, &jc))
- return 1;
- // rids 20-29 dequeueing rids 5-9, 15-19
- for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
- if (deq_msg(&jc, m))
- return 1;
- for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
- if (deq_msg(&jc, m))
- return 1;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int test_16(int num_iter)
- {
- cout << " 16. complex recover ptr: ";
- for (int i=0; i<num_iter; i++)
- {
- cout << "." << flush;
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_16", "jdata", "t16");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->initialize();
- // enqueue msgs, read then dequeue half
- for (int m=0; m<NUM_MSGS*2; m++)
- if (enq_msg(jc, create_msg(_msg, m)))
- {
- delete jc;
- return 1;
- }
- for (int m=0; m<NUM_MSGS; m++)
- if (deq_msg(jc, m))
- {
- delete jc;
- return 1;
- }
- jc->flush();
- for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- {
- rhm::journal::jcntl* jc = new
rhm::journal::jcntl("scope_test_16", "jdata", "t16");
- if (!jc)
- {
- cout << "failed" << endl;
- return 1;
- }
- jc->recover();
- // recover other half of messages
- for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- jc->recovered();
- // write more messages, read and dequeue all
- for (int m=NUM_MSGS*2; m<NUM_MSGS*3; m++)
- if (enq_msg(jc, create_msg(_msg, m)))
- {
- delete jc;
- return 1;
- }
- jc->flush();
- for (int m=NUM_MSGS; m<NUM_MSGS*3; m++)
- if (read_msg(m, jc))
- {
- delete jc;
- return 1;
- }
- for (int m=NUM_MSGS; m<NUM_MSGS*2; m++)
- if (deq_msg(jc, m))
- {
- delete jc;
- return 1;
- }
- for (int m=NUM_MSGS*3; m<NUM_MSGS*4; m++)
- if (deq_msg(jc, m))
- {
- delete jc;
- return 1;
- }
- delete jc;
- }
- }
- cout << " ok" << endl;
- return 0;
- }
-
- int enq_msg(rhm::journal::jcntl* jc, const std::string msg)
- {
- rhm::journal::data_tok* dtp = new rhm::journal::data_tok;
- rhm::journal::iores res = jc->enqueue_data(msg.c_str(), msg.size(), dtp);
- if (res != rhm::journal::RHM_IORES_SUCCESS)
- {
- cout << "jcntl::enqueue_data() returned " <<
iores_str[res] << ". failed" << endl;
- delete dtp;
- return 1;
- }
- return 0;
- }
-
- int deq_msg(rhm::journal::jcntl* jc, u_int64_t drid)
- {
- rhm::journal::data_tok* dtp = new rhm::journal::data_tok;
- dtp->set_wstate(rhm::journal::data_tok::ENQ);
- dtp->set_rid(drid);
- rhm::journal::iores res = jc->dequeue_data(dtp);
- if (res != rhm::journal::RHM_IORES_SUCCESS)
- {
- cout << "jcntl::dequeue_data() returned " <<
iores_str[res] << ". failed" << endl;
- delete dtp;
- return 1;
- }
- return 0;
- }
-
- int read_msg(int msg_num, rhm::journal::jcntl* jc)
- {
- char buff[MAX_MSG_SIZE + 1];
- memset(buff, '?', MAX_MSG_SIZE);
- buff[MAX_MSG_SIZE] = '\0';
- rhm::journal::data_tok* dtp = new rhm::journal::data_tok;
- dtp->set_wstate(rhm::journal::data_tok::ENQ);
- unsigned aio_sleep_cnt = 0;
- bool read = false;
- while (!read)
- {
- rhm::journal::iores res = jc->read_data(buff, 127, dtp);
- switch (res)
- {
- case rhm::journal::RHM_IORES_SUCCESS:
- buff[dtp->dsize()] = '\0';
- read = true;
- break;
- case rhm::journal::RHM_IORES_AIO_WAIT:
- if (++aio_sleep_cnt > MAX_AIO_SLEEPS)
- {
- cout << "Exceeded max count for RHM_IORES_AIO_WAIT.
failed" << endl;
- delete dtp;
- return 1;
- }
- jc->get_wr_events();
- ::usleep(AIO_SLEEP_TIME);
- break;
- default:
- cout << "jcntl::read_data() returned " <<
iores_str[res] << ". failed" << endl;
- delete dtp;
- return 1;
- }
- }
- std::string s;
- create_msg(s, msg_num);
- if (s.compare(buff) != 0)
- {
- cout << "Message comparison failure: read \"" <<
buff << "\", expected \"" << s <<
- "\"." << endl;
- return 1;
- }
- return 0;
- }
-
- static std::string& create_msg(std::string& s, int msg_num)
- {
- std::stringstream ss;
- ss << "Message_" << std::setfill('0') <<
std::setw(4) << msg_num;
- ss << "_4567890123456789012345678901234567890";
- ss << "12345678901234567890123456789012345678901234567890"; //
100 chars long (2 dblks)
- s.assign(ss.str());
- return s;
- }
-};
-
-int main(int argc, char** argv)
-{
- int test_num = 0;
- int num_iter = TEST_ITERATIONS;
- if (argc > 1)
- test_num = atoi(argv[1]);
- if (argc > 2)
- num_iter = atoi(argv[2]);
- if (num_iter < 1)
- {
- cout << "num_iter=" << num_iter << endl;
- return 1;
- }
- cout << "jrnl_scope_test";
- if (test_num)
- cout << " test=" << test_num;
- cout << ":" << endl;
- jrnl_scope_test jst;
- int res = test_num ? jst.run(test_num, num_iter) : jst.run();
- if (res)
- {
- cout << "failed res=" << res << endl;
- return res;
- }
- cout << "ok" << endl;
- return 0;
-}
-
-const char* jrnl_scope_test::iores_str[] = {
- "RHM_IORES_SUCCESS",
- "RHM_IORES_AIO_WAIT",
- "RHM_IORES_EMPTY",
- "RHM_IORES_FULL",
- "RHM_IORES_BUSY"
- };
Modified: store/trunk/cpp/tests/jrnl/rtest
===================================================================
--- store/trunk/cpp/tests/jrnl/rtest 2007-09-22 15:09:17 UTC (rev 940)
+++ store/trunk/cpp/tests/jrnl/rtest 2007-09-23 17:37:01 UTC (rev 941)
@@ -56,7 +56,8 @@
RM_DIR="${RM} -rf"
TEST_PROG="./jtest"
CHK_PROG="./ftest.py"
-VALGRIND="valgrind -q --track-fds=yes --leak-check=full --leak-resolution=high
--show-reachable=yes --suppressions=/usr/lib/valgrind/glibc-2.5.supp"
+VALGRIND="valgrind -q --track-fds=yes --leak-check=full --leak-resolution=high
--show-reachable=yes"
+#VALGRIND="valgrind -q --track-fds=yes --leak-check=full --leak-resolution=high
--show-reachable=yes --suppressions=/usr/lib/valgrind/glibc-2.5.supp"
MAKE="make -f Makefile.rtest"