[rhmessaging-commits] rhmessaging commits: r1585 - in store/trunk/cpp: tests/jrnl/jtt and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Sun Jan 20 12:02:11 EST 2008


Author: kpvdr
Date: 2008-01-20 12:02:11 -0500 (Sun, 20 Jan 2008)
New Revision: 1585

Modified:
   store/trunk/cpp/lib/jrnl/wmgr.cpp
   store/trunk/cpp/tests/jrnl/jtt/Makefile.am
   store/trunk/cpp/tests/jrnl/jtt/_ut_data_src.cpp
   store/trunk/cpp/tests/jrnl/jtt/_ut_jrnl_instance.cpp
   store/trunk/cpp/tests/jrnl/jtt/_ut_test_case_result.cpp
   store/trunk/cpp/tests/jrnl/jtt/data_src.cpp
   store/trunk/cpp/tests/jrnl/jtt/data_src.hpp
   store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.cpp
   store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.hpp
   store/trunk/cpp/tests/jrnl/jtt/main.cpp
   store/trunk/cpp/tests/jrnl/jtt/test_case_result.cpp
   store/trunk/cpp/tests/jrnl/jtt/test_case_result.hpp
   store/trunk/cpp/tests/jrnl/jtt/test_mgr.cpp
Log:
Bugfixes to journal and journal test tool

Modified: store/trunk/cpp/lib/jrnl/wmgr.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/wmgr.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/lib/jrnl/wmgr.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -37,8 +37,6 @@
 #include <jrnl/jcntl.hpp>
 #include <jrnl/jerrno.hpp>
 
-#include <iostream> // debug
-
 namespace rhm
 {
 namespace journal
@@ -144,8 +142,7 @@
     else
         _enq_busy = true;
 
-    u_int64_t rid = dtokp->external_rid() ? dtokp->rid() :
-            (cont ? _wrfc.rid() - 1 : _wrfc.get_incr_rid());
+    u_int64_t rid = (dtokp->external_rid() | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
     _enq_rec.reset(rid, data_buff, tot_data_len, xid_ptr, xid_len, _wrfc.owi(), transient,
             external);
     if (!cont)
@@ -286,16 +283,16 @@
     }
 
     const bool ext_rid = dtokp->external_rid();
-    u_int64_t rid = ext_rid ? dtokp->rid() : (cont ? _wrfc.rid() - 1 : _wrfc.get_incr_rid());
-    u_int64_t dequeue_rid = ext_rid ? dtokp->dequeue_rid() : dtokp->rid();
-	if (!ext_rid)
-	{
-		dtokp->set_rid(rid);
-		dtokp->set_dequeue_rid(dequeue_rid);
-	}
+    u_int64_t rid = (ext_rid | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
+    u_int64_t dequeue_rid = (ext_rid | cont) ? dtokp->dequeue_rid() : dtokp->rid();
     _deq_rec.reset(rid, dequeue_rid, xid_ptr, xid_len, _wrfc.owi());
     if (!cont)
     {
+	    if (!ext_rid)
+	    {
+		    dtokp->set_rid(rid);
+		    dtokp->set_dequeue_rid(dequeue_rid);
+	    }
         if (xid_len)
             dtokp->set_xid(xid_ptr, xid_len);
         else
@@ -433,8 +430,7 @@
         dtokp->set_dblocks_written(0); // Reset dblks_written from previous op
     }
 
-    u_int64_t rid = dtokp->external_rid() ? dtokp->rid() :
-            (cont ? _wrfc.rid() - 1 : _wrfc.get_incr_rid());
+    u_int64_t rid = (dtokp->external_rid() | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
     _txn_rec.reset(RHM_JDAT_TXA_MAGIC, rid, xid_ptr, xid_len, _wrfc.owi());
     if (!cont)
     {
@@ -581,8 +577,7 @@
         dtokp->set_dblocks_written(0); // Reset dblks_written from previous op
     }
 
-    u_int64_t rid = dtokp->external_rid() ? dtokp->rid() :
-            (cont ? _wrfc.rid() - 1 : _wrfc.get_incr_rid());
+    u_int64_t rid = (dtokp->external_rid() | cont) ? dtokp->rid() : _wrfc.get_incr_rid();
     _txn_rec.reset(RHM_JDAT_TXC_MAGIC, rid, xid_ptr, xid_len, _wrfc.owi());
     if (!cont)
     {

Modified: store/trunk/cpp/tests/jrnl/jtt/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/Makefile.am	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/Makefile.am	2008-01-20 17:02:11 UTC (rev 1585)
@@ -80,7 +80,9 @@
 
 _ut_data_src_SOURCES = _ut_data_src.cpp ../../unit_test.cpp
 _ut_data_src_LDFLAGS = -lboost_unit_test_framework -lrt
-_ut_data_src_LDADD = data_src.o
+_ut_data_src_LDADD = data_src.o \
+    ${LIBOBJDIR}/jerrno.o \
+    ${LIBOBJDIR}/jexception.o
 
 _ut_jrnl_init_params_SOURCES = _ut_jrnl_init_params.cpp ../../unit_test.cpp
 _ut_jrnl_init_params_LDFLAGS =  -lboost_unit_test_framework -lrt

Modified: store/trunk/cpp/tests/jrnl/jtt/_ut_data_src.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/_ut_data_src.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/_ut_data_src.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -23,6 +23,7 @@
 
 #include "../../unit_test.h"
 #include "data_src.hpp"
+#include <iomanip>
 #include <iostream>
 
 using namespace boost::unit_test;
@@ -49,21 +50,46 @@
     BOOST_CHECK_EQUAL(dp2, (char*)0);
 }
 
-BOOST_AUTO_TEST_CASE(data_src_xid_data)
+BOOST_AUTO_TEST_CASE(data_src_xid_data_xid)
 {
-    BOOST_CHECK(data_src::max_xsize > 0);
-    for (size_t i=0; i<1024; i++)
+    BOOST_CHECK_EQUAL(data_src::get_xid(1),  "0");
+    BOOST_CHECK_EQUAL(data_src::get_xid(2),  "01");
+    BOOST_CHECK_EQUAL(data_src::get_xid(3),  "002");
+    BOOST_CHECK_EQUAL(data_src::get_xid(4),  "0003");
+    BOOST_CHECK_EQUAL(data_src::get_xid(5),  "00004");
+    BOOST_CHECK_EQUAL(data_src::get_xid(6),  "000005");
+    BOOST_CHECK_EQUAL(data_src::get_xid(7),  "0000006");
+    BOOST_CHECK_EQUAL(data_src::get_xid(8),  "00000007");
+    BOOST_CHECK_EQUAL(data_src::get_xid(9),  "xid:00008");
+    BOOST_CHECK_EQUAL(data_src::get_xid(10), "xid:000009");
+    BOOST_CHECK_EQUAL(data_src::get_xid(11), "xid:0000010");
+    BOOST_CHECK_EQUAL(data_src::get_xid(12), "xid:00000011");
+    BOOST_CHECK_EQUAL(data_src::get_xid(13), "xid:00000012:");
+    BOOST_CHECK_EQUAL(data_src::get_xid(14), "xid:00000013:n");
+    BOOST_CHECK_EQUAL(data_src::get_xid(15), "xid:00000014:no");
+    size_t i = 15;
+    for (; i<1024; i++)
     {
-        const char* dp = data_src::get_xid(i);
-        BOOST_CHECK_EQUAL(*dp, static_cast<char>('a' + (i % 26)));
+        std::string xid(data_src::get_xid(i));
+
+        std::ostringstream oss;
+        oss << std::setfill('0') << "xid:" << std::setw(8) << i << ":";
+
+        BOOST_CHECK_EQUAL(xid.size(), i);
+        BOOST_CHECK_EQUAL(xid.substr(0, 13), oss.str());
+        BOOST_CHECK_EQUAL(xid[13], 'n');
+        BOOST_CHECK_EQUAL(xid[i-1], (char)('a' + ((i-1)%26)));
     }
-    for (size_t i=data_src::max_xsize-1024; i<data_src::max_xsize; i++)
+    for (size_t j=data_src::max_xsize-1024; j<data_src::max_xsize; j++,i++)
     {
-        const char* dp = data_src::get_xid(i);
-        BOOST_CHECK_EQUAL(*dp, static_cast<char>('a' + (i % 26)));
+        std::string xid(data_src::get_xid(j));
+
+        std::ostringstream oss;
+        oss << std::setfill('0') << "xid:" << std::setw(8) << i << ":";
+
+        BOOST_CHECK_EQUAL(xid.size(), j);
+        BOOST_CHECK_EQUAL(xid.substr(0, 13), oss.str());
+        BOOST_CHECK_EQUAL(xid[13], 'n');
+        BOOST_CHECK_EQUAL(xid[j-1], (char)('a' + ((j-1)%26)));
     }
-    const char* dp1 = data_src::get_xid(data_src::max_xsize);
-    BOOST_CHECK_EQUAL(dp1, (char*)0);
-    const char* dp2 = data_src::get_xid(data_src::max_xsize + 0x1000);
-    BOOST_CHECK_EQUAL(dp2, (char*)0);
 }

Modified: store/trunk/cpp/tests/jrnl/jtt/_ut_jrnl_instance.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/_ut_jrnl_instance.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/_ut_jrnl_instance.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -45,7 +45,7 @@
     test_case::shared_ptr p(new test_case(1, 0, 0, 0, false, 0, 0, test_case::JTT_PERSISTNET,
             test_case::JDL_INTERNAL, "t1"));
     jrnl_instance ji(jid, jdir, bfn, num_jfiles, jfsize_sblks);
-    ji.init_tc(p, false, false, true);
+    ji.init_tc(p, false, true);
     ji.run_tc();
     ji.tc_wait_compl();
     try { jdir::verify_dir(jdir, bfn); }
@@ -67,7 +67,7 @@
     jrnl_init_params::shared_ptr jpp(new jrnl_init_params(jid, jdir, bfn, num_jfiles,
             jfsize_sblks));
     jrnl_instance ji(jpp);
-    ji.init_tc(p, false, false, true);
+    ji.init_tc(p, false, true);
     ji.run_tc();
     ji.tc_wait_compl();
     try { jdir::verify_dir(jdir, bfn); }
@@ -89,7 +89,7 @@
     jrnl_init_params::shared_ptr jpp(new jrnl_init_params(jid, jdir, bfn, num_jfiles,
             jfsize_sblks));
     jrnl_instance ji(jpp);
-    ji.init_tc(p, false, false, true);
+    ji.init_tc(p, false, true);
     ji.run_tc();
     ji.tc_wait_compl();
     try { jdir::verify_dir(jdir, bfn); }
@@ -97,33 +97,6 @@
     jdir::delete_dir(jdir);
 }
 
-BOOST_AUTO_TEST_CASE(jrnl_instance_reuse)
-{
-    const std::string jid = "jid4";
-    const std::string jdir = "/tmp/test4";
-    const std::string bfn = "test";
-    const u_int16_t num_jfiles = 20;
-    const u_int32_t jfsize_sblks = 128;
-
-    using rhm::jtt::test_case;
-    test_case::shared_ptr p(new test_case(4, 0, 0, 0, false, 0, 0, test_case::JTT_PERSISTNET,
-            test_case::JDL_INTERNAL, "t4"));
-    jrnl_init_params::shared_ptr jpp(new jrnl_init_params(jid, jdir, bfn, num_jfiles,
-            jfsize_sblks));
-    jrnl_instance ji(jpp);
-    ji.init_tc(p, true, false, true);
-    ji.run_tc();
-    ji.tc_wait_compl();
-    try { jdir::verify_dir(jdir, bfn); }
-    catch (const jexception& e) { BOOST_ERROR(e.what()); }
-    ji.init_tc(p, true, true, true);
-    ji.run_tc();
-    ji.tc_wait_compl();
-    try { jdir::verify_dir(jdir, bfn); }
-    catch (const jexception& e) { BOOST_ERROR(e.what()); }
-    jdir::delete_dir(jdir);
-}
-
 BOOST_AUTO_TEST_CASE(jrnl_instance_recover)
 {
     const std::string jid = "jid5";
@@ -138,12 +111,12 @@
     jrnl_init_params::shared_ptr jpp(new jrnl_init_params(jid, jdir, bfn, num_jfiles,
             jfsize_sblks));
     jrnl_instance ji(jpp);
-    ji.init_tc(p, false, false, true);
+    ji.init_tc(p, false, true);
     ji.run_tc();
     ji.tc_wait_compl();
     try { jdir::verify_dir(jdir, bfn); }
     catch (const jexception& e) { BOOST_ERROR(e.what()); }
-    ji.init_tc(p, false, true, true);
+    ji.init_tc(p, true, true);
     ji.run_tc();
     ji.tc_wait_compl();
     try { jdir::verify_dir(jdir, bfn); }
@@ -165,7 +138,7 @@
     jrnl_init_params::shared_ptr jpp(new jrnl_init_params(jid, jdir, bfn, num_jfiles,
             jfsize_sblks));
     jrnl_instance ji(jpp);
-    ji.init_tc(p, false, true, true);
+    ji.init_tc(p, true, true);
     ji.run_tc();
     ji.tc_wait_compl();
     try { jdir::verify_dir(jdir, bfn); }
@@ -185,7 +158,7 @@
     test_case::shared_ptr p(new test_case(7, 0, 0, 0, false, 0, 0, test_case::JTT_PERSISTNET,
             test_case::JDL_INTERNAL, "t7"));
     jrnl_instance ji(jid, jdir, bfn, num_jfiles, jfsize_sblks);
-    ji.init_tc(p, false, false, false);
+    ji.init_tc(p, false, false);
     ji.run_tc();
     ji.tc_wait_compl();
     try

Modified: store/trunk/cpp/tests/jrnl/jtt/_ut_test_case_result.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/_ut_test_case_result.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/_ut_test_case_result.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -95,7 +95,7 @@
     BOOST_CHECK(ts8.tv_nsec < 200000000); // 0.2 sec in nanoseconds
 }
 
-BOOST_AUTO_TEST_CASE(test_case_result_start_exception_stop)
+BOOST_AUTO_TEST_CASE(test_case_result_start_exception_stop_1)
 {
     const std::string jid("journal id 3");
     test_case_result tcr(jid);
@@ -117,10 +117,50 @@
     BOOST_CHECK(ts2.tv_nsec < 200000000); // 0.2 sec in nanoseconds
 }
 
-BOOST_AUTO_TEST_CASE(test_case_result_start_exception)
+BOOST_AUTO_TEST_CASE(test_case_result_start_exception_stop_2)
 {
     const std::string jid("journal id 4");
     test_case_result tcr(jid);
+    const std::string err_msg = "exception message";
+    tcr.set_start_time();
+    ::usleep(1100000); // 1.1 sec in microseconds
+    tcr.set_exception(err_msg);
+    BOOST_CHECK_EQUAL(tcr.exception(), true);
+    BOOST_CHECK_EQUAL(tcr.err_code(), u_int32_t(0));
+    BOOST_CHECK_EQUAL(tcr.what(), err_msg);
+    const timespec& ts1 = tcr.stop_time();
+    BOOST_CHECK(ts1.tv_sec > 0);
+    BOOST_CHECK(ts1.tv_nsec > 0);
+    const timespec& ts2 = tcr.test_time();
+    BOOST_CHECK(ts2.tv_sec == 1);
+    BOOST_CHECK(ts2.tv_nsec > 100000000); // 0.1 sec in nanoseconds
+    BOOST_CHECK(ts2.tv_nsec < 200000000); // 0.2 sec in nanoseconds
+}
+
+BOOST_AUTO_TEST_CASE(test_case_result_start_exception_stop_3)
+{
+    const std::string jid("journal id 5");
+    test_case_result tcr(jid);
+    const char* err_msg = "exception message";
+    tcr.set_start_time();
+    ::usleep(1100000); // 1.1 sec in microseconds
+    tcr.set_exception(err_msg);
+    BOOST_CHECK_EQUAL(tcr.exception(), true);
+    BOOST_CHECK_EQUAL(tcr.err_code(), u_int32_t(0));
+    BOOST_CHECK_EQUAL(tcr.what(), err_msg);
+    const timespec& ts1 = tcr.stop_time();
+    BOOST_CHECK(ts1.tv_sec > 0);
+    BOOST_CHECK(ts1.tv_nsec > 0);
+    const timespec& ts2 = tcr.test_time();
+    BOOST_CHECK(ts2.tv_sec == 1);
+    BOOST_CHECK(ts2.tv_nsec > 100000000); // 0.1 sec in nanoseconds
+    BOOST_CHECK(ts2.tv_nsec < 200000000); // 0.2 sec in nanoseconds
+}
+
+BOOST_AUTO_TEST_CASE(test_case_result_start_exception)
+{
+    const std::string jid("journal id 6");
+    test_case_result tcr(jid);
     u_int32_t err_code = 0x654;
     const std::string err_msg = "exception message";
     const jexception e(err_code, err_msg);
@@ -143,7 +183,7 @@
     const u_int32_t num_enq = 125;
     const u_int32_t num_deq = 64;
     const u_int32_t num_read = 22;
-    const std::string jid("journal id 5");
+    const std::string jid("journal id 7");
     test_case_result tcr(jid);
     BOOST_CHECK_EQUAL(tcr.num_enq(), u_int32_t(0));
     BOOST_CHECK_EQUAL(tcr.num_deq(), u_int32_t(0));

Modified: store/trunk/cpp/tests/jrnl/jtt/data_src.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/data_src.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/data_src.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -23,6 +23,9 @@
 
 #include "data_src.hpp"
 
+#include <iomanip>
+#include <sstream>
+
 namespace rhm
 {
 namespace jtt
@@ -31,6 +34,8 @@
 char data_src::_data_src[data_src::max_dsize];
 char data_src::_xid_src[data_src::max_xsize];
 bool data_src::_initialized = data_src::__init();
+u_int64_t data_src::_xid_cnt = 0ULL;
+data_src::mutex data_src::_m;
 
 data_src::data_src()
 {}
@@ -52,8 +57,27 @@
     return _data_src + offs;
 }
 
+std::string
+data_src::get_xid(const size_t xid_size)
+{
+    if (xid_size == 0)
+        return "";
+    std::ostringstream oss;
+    oss << std::setfill('0');
+    if (xid_size < 9)
+        oss << std::setw(xid_size) << get_xid_cnt();
+    else if (xid_size < 13)
+        oss << "xid:" << std::setw(xid_size - 4) << get_xid_cnt();
+    else
+    {
+        oss << "xid:" << std::setw(8) << get_xid_cnt() << ":";
+        oss.write(get_xid_content(13), xid_size - 13);
+    }
+    return oss.str();
+}
+
 const char* const
-data_src::get_xid(const size_t offs)
+data_src::get_xid_content(const size_t offs)
 {
     if (offs >= max_xsize) return 0;
     return _xid_src + offs;

Modified: store/trunk/cpp/tests/jrnl/jtt/data_src.hpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/data_src.hpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/data_src.hpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -24,8 +24,14 @@
 #ifndef rhm_jtt_data_src_hpp
 #define rhm_jtt_data_src_hpp
 
+#include <jrnl/slock.hpp>
+#include <pthread.h>
+#include <string>
 #include <sys/types.h>
 
+#define DATA_SIZE 1024 * 1024
+#define XID_SIZE  1024 * 1024
+
 namespace rhm
 {
 namespace jtt
@@ -33,19 +39,34 @@
     class data_src
     {
     public:
-        static const size_t max_dsize = 1024 * 1024;
-        static const size_t max_xsize = 1024 * 1024;
+        static const size_t max_dsize = DATA_SIZE;
+        static const size_t max_xsize = XID_SIZE;
 
     private:
         static char _data_src[];
         static char _xid_src[];
+        static u_int64_t _xid_cnt;
         static bool _initialized;
-        static bool __init();
-        data_src();
+        class mutex
+        {
+        private:
+            pthread_mutex_t _mutex;
+        public:
+            inline mutex() { pthread_mutex_init(&_mutex, 0); }
+            inline ~mutex() { pthread_mutex_destroy(&_mutex); }
+            inline pthread_mutex_t* m() { return &_mutex; }
+        };
+        static mutex _m;
 
     public:
         static const char* const get_data(const size_t offs);
-        static const char* const get_xid(const size_t offs);
+        static std::string get_xid(const size_t xid_size);
+    
+    private:
+        data_src();
+        static const u_int64_t get_xid_cnt() { rhm::journal::slock s(_m.m()); return _xid_cnt++; }
+        static const char* const get_xid_content(const size_t offs);
+        static bool __init();
     };
     
 } // namespace jtt

Modified: store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -28,8 +28,6 @@
 #include <jrnl/data_tok.hpp>
 #include <jrnl/jerrno.hpp>
 
-#include <iostream> // debug
-
 #define SLEEP_US        1000 // 1 ms
 #define MAX_SLEEP_CNT   2000 // 2 sec max
 
@@ -70,39 +68,45 @@
 }
 
 void
-jrnl_instance::init_tc(test_case::shared_ptr& tcp, const bool /* reuse_instance */,
-        const bool recover_mode, const bool keep_jrnls)
+jrnl_instance::init_tc(test_case::shared_ptr& tcp, const bool recover_mode, const bool keep_jrnls)
+        throw ()
 {
-    _tcp = tcp;
-    _recover_mode = recover_mode;
-    _keep_jrnls = keep_jrnls;
-    
-    if (_recover_mode)
+    try
     {
-        try
+        _tcp = tcp;
+        _recover_mode = recover_mode;
+        _keep_jrnls = keep_jrnls;
+
+        if (_recover_mode)
         {
-        std::vector<std::string> prep_txn_list;
-        u_int64_t highest_rid;
-        recover(0, 0, prep_txn_list, highest_rid);
-        recover_complete();
+            try
+            {
+            std::vector<std::string> prep_txn_list;
+            u_int64_t highest_rid;
+            recover(0, 0, prep_txn_list, highest_rid);
+            recover_complete();
+            }
+            catch (const rhm::journal::jexception& e)
+            {
+                if (e.err_code() == rhm::journal::jerrno::JERR_JDIR_STAT)
+                    initialize(0, 0);
+                else
+                    throw;
+            }
         }
-        catch (const rhm::journal::jexception& e)
-        {
-            if (e.err_code() == rhm::journal::jerrno::JERR_JDIR_STAT)
-                initialize(0, 0);
-            else
-                throw;
-        }
+        else
+            initialize(aio_rd_callback, aio_wr_callback);
+
+        test_case_result::shared_ptr p(new test_case_result(_jpp->jid()));
+        _tcrp = p;
     }
-    else
-        initialize(aio_rd_callback, aio_wr_callback);
-
-    test_case_result::shared_ptr p(new test_case_result(_jpp->jid()));
-    _tcrp = p;
+    catch (const rhm::journal::jexception& e) { _tcrp->set_exception(e); }
+    catch (const std::exception& e) { _tcrp->set_exception(e.what()); }
+    catch (...) { _tcrp->set_exception("Unknown exception"); }
 }
 
 void
-jrnl_instance::run_tc()
+jrnl_instance::run_tc() throw ()
 {
     _tcrp->set_start_time();
     ::pthread_create(&_enq_thread, 0, run_enq, this);
@@ -111,36 +115,43 @@
 }
 
 void
-jrnl_instance::tc_wait_compl()
+jrnl_instance::tc_wait_compl() throw ()
 {
-    ::pthread_join(_read_thread, 0);
-    ::pthread_join(_deq_thread, 0);
-    ::pthread_join(_enq_thread, 0);
-    stop(true);
+    try
+    {
+        ::pthread_join(_read_thread, 0);
+        ::pthread_join(_deq_thread, 0);
+        ::pthread_join(_enq_thread, 0);
+        stop(true);
+        _tcrp->set_stop_time();
+    }
+    catch (const rhm::journal::jexception& e) { _tcrp->set_exception(e); }
+    catch (const std::exception& e) { _tcrp->set_exception(e.what()); }
+    catch (...) { _tcrp->set_exception("Unknown exception"); }
     _tcrp->set_stop_time();
     _tcp->add_result(_tcrp);
     
     if (!_recover_mode && !_keep_jrnls)
-        rhm::journal::jdir::delete_dir(_jpp->jdir());
+        try { rhm::journal::jdir::delete_dir(_jpp->jdir()); }
+        catch (...) {} // TODO - work out exception strategy for failure here...
 }
 
 void
 jrnl_instance::run_enq() throw ()
 {
-    unsigned sleep_cnt = 0U;
-    while(_tcrp->num_enq() < _tcp->num_msgs() && !_tcrp->exception())
+    try
     {
-        dtok_ptr p(new rhm::journal::data_tok);
-        _dtok_master_list.push_back(p);
-        const char* msgp = data_src::get_data(_tcrp->num_enq() % 10);
-        const size_t msg_size = _tcp->this_data_size();
-        const char* xidp = data_src::get_xid(_tcrp->num_enq() % 26);
-        const size_t xid_size = _tcp->this_xid_size();
-        const std::string xid(xidp, xid_size);
-        const bool external = _tcp->this_external();
-        const bool transient = _tcp->this_transience();
-        try
+        unsigned sleep_cnt = 0U;
+        while(_tcrp->num_enq() < _tcp->num_msgs() && !_tcrp->exception())
         {
+            dtok_ptr p(new rhm::journal::data_tok);
+            _dtok_master_list.push_back(p);
+            const char* msgp = data_src::get_data(_tcrp->num_enq() % 10);
+            const size_t msg_size = _tcp->this_data_size();
+            const size_t xid_size = _tcp->this_xid_size();
+            const std::string xid(data_src::get_xid(xid_size));
+            const bool external = _tcp->this_external();
+            const bool transient = _tcp->this_transience();
             rhm::journal::iores res;
             if (xid_size)
             {
@@ -183,79 +194,72 @@
             }
             
         }
-        catch (const rhm::journal::jexception& e) { _tcrp->set_exception(e); }
+        flush();
     }
-    flush();
+    catch (const rhm::journal::jexception& e) { _tcrp->set_exception(e); }
+    catch (const std::exception& e) { _tcrp->set_exception(e.what()); }
+    catch (...) { _tcrp->set_exception("Unknown exception"); }
 }
 
 void
 jrnl_instance::run_deq() throw ()
 {
-    if (_tcp->auto_deq())
+    try
     {
-        unsigned sleep_cnt = 0U;
-        while(_tcrp->num_deq() < _tcp->num_msgs() && !_tcrp->exception())
+        if (_tcp->auto_deq())
         {
-            if (_dtok_deq_list.empty())
+            unsigned sleep_cnt = 0U;
+            while(_tcrp->num_deq() < _tcp->num_msgs() && !_tcrp->exception())
             {
-                if (sleep_cnt++ > MAX_SLEEP_CNT)
+                if (_dtok_deq_list.empty())
                 {
-                    std::ostringstream oss;
-                    oss << "ERROR: Timeout waiting for AIO in journal \"" << _jid;
-                    oss << "\": num_enq=" << _tcp->num_msgs() << " num_deq=" << _tcrp->num_deq();
-                    _tcrp->set_exception(oss.str());
+                    if (sleep_cnt++ > MAX_SLEEP_CNT)
+                    {
+                        std::ostringstream oss;
+                        oss << "ERROR: Timeout waiting for AIO in journal \"" << _jid;
+                        oss << "\": num_enq=" << _tcp->num_msgs();
+                        oss << " num_deq=" << _tcrp->num_deq();
+                        _tcrp->set_exception(oss.str());
+                    }
+                    get_wr_events();
+                    ::usleep(SLEEP_US); // 1ms
                 }
-                get_wr_events();
-                ::usleep(SLEEP_US); // 1ms
-            }
-            else
-            {
-                journal::data_tok* dtokp;
+                else
                 {
-                    rhm::journal::slock sl(&_dm);
-                    dtokp = _dtok_deq_list.back();
-                    _dtok_deq_list.pop_back();
-                }
+                    journal::data_tok* dtokp;
+                    {
+                        rhm::journal::slock sl(&_dm);
+                        dtokp = _dtok_deq_list.back();
+                        _dtok_deq_list.pop_back();
+                    }
 
-                switch (dtokp->wstate())
-                {
-                case rhm::journal::data_tok::ENQ: // dequeue these, enqueue complete
-                    try
+                    rhm::journal::iores res;
+                    if (dtokp->has_xid())
+                        res = dequeue_txn_data_record(dtokp, dtokp->xid());
+                    else
+                        res = dequeue_data_record(dtokp);
+                    if (res == rhm::journal::RHM_IORES_SUCCESS)
                     {
-                        rhm::journal::iores res;
-                        if (dtokp->has_xid())
-                            res = dequeue_txn_data_record(dtokp, dtokp->xid());
-                        else
-                            res = dequeue_data_record(dtokp);
-                        if (res == rhm::journal::RHM_IORES_SUCCESS)
-                        {
-                            sleep_cnt = 0U;
-                            _tcrp->incr_num_deq();
-                            commit(dtokp);
-                        }
-                        else
-                        {
-                            std::ostringstream oss;
-                            oss << "ERROR: dequeue operation in journal \"" << _jid;
-                            oss << "\" returned " << rhm::journal::iores_str(res) << ".";
-                            _tcrp->set_exception(oss.str());
-                        }
+                        sleep_cnt = 0U;
+                        _tcrp->incr_num_deq();
+                        commit(dtokp);
                     }
-                    catch (const rhm::journal::jexception& e) { _tcrp->set_exception(e); }
-                    break;
-                case rhm::journal::data_tok::DEQ: // ignore these, dequeue complete
-                    break;
-                default: // these should not happen in regular tests
-                    std::ostringstream oss;
-                    oss << "Unexpected dtok wstate in journal \"" << _jid << "\": id=0x";
-                    oss << std::hex << dtokp->id() << std::dec << " wstate=" << dtokp->wstate_str();
-                    _tcrp->set_exception(oss.str());
+                    else
+                    {
+                        std::ostringstream oss;
+                        oss << "ERROR: dequeue operation in journal \"" << _jid;
+                        oss << "\" returned " << rhm::journal::iores_str(res) << ".";
+                        _tcrp->set_exception(oss.str());
+                    }
+                    sleep_cnt = 0U;
                 }
-                sleep_cnt = 0U;
             }
+            flush();
         }
-        flush();
     }
+    catch (const rhm::journal::jexception& e) { _tcrp->set_exception(e); }
+    catch (const std::exception& e) { _tcrp->set_exception(e.what()); }
+    catch (...) { _tcrp->set_exception("Unknown exception"); }
 }
 
 void

Modified: store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.hpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.hpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/jrnl_instance.hpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -68,10 +68,10 @@
         inline const jrnl_init_params::shared_ptr& params() const { return _jpp; }
         inline const std::string& jid() const { return _jpp->jid(); }
 
-        void init_tc(test_case::shared_ptr& tcp, const bool reuse_instance, const bool recover_mode,
-                const bool keep_jrnls);
-        void run_tc();
-        void tc_wait_compl();
+        void init_tc(test_case::shared_ptr& tcp, const bool recover_mode, const bool keep_jrnls)
+                throw ();
+        void run_tc() throw ();
+        void tc_wait_compl() throw ();
 
     private:
         inline void push_dtokp(rhm::journal::data_tok* dtokp)

Modified: store/trunk/cpp/tests/jrnl/jtt/main.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/main.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/main.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -120,6 +120,10 @@
         tm.run(test_case_csv_file_name, jrnl_format_chk, reuse_instance, recover_mode,
                 random_test_order, repeat_flag, keep_jrnls);
     }
-    catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 1; }
+    catch (const std::exception& e)
+    {
+        std::cerr << e.what() << std::endl;
+        return 1;
+    }
     return 0;
 }

Modified: store/trunk/cpp/tests/jrnl/jtt/test_case_result.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/test_case_result.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/test_case_result.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -81,6 +81,15 @@
 }
 
 void
+test_case_result::set_exception(const char* err_str, const bool set_stop_time_flag)
+{
+    if (set_stop_time_flag)
+        set_stop_time();
+    _exception_flag = true;
+    _exception_str = err_str;
+}
+
+void
 test_case_result::clear()
 {
     _num_enq = 0;

Modified: store/trunk/cpp/tests/jrnl/jtt/test_case_result.hpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/test_case_result.hpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/test_case_result.hpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -78,6 +78,7 @@
         inline const std::string& what() const { return _exception_str; }
         void set_exception(const journal::jexception& e, const bool set_stop_time_flag = true);
         void set_exception(const std::string& err_str, const bool set_stop_time_flag = true);
+        void set_exception(const char* err_str, const bool set_stop_time_flag = true);
         
         void clear();
         const std::string str(const bool summary) const;

Modified: store/trunk/cpp/tests/jrnl/jtt/test_mgr.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/test_mgr.cpp	2008-01-18 23:18:37 UTC (rev 1584)
+++ store/trunk/cpp/tests/jrnl/jtt/test_mgr.cpp	2008-01-20 17:02:11 UTC (rev 1585)
@@ -93,7 +93,7 @@
             if (!reuse_instance || _ji_list.empty())
                 initialize_jrnls();
             for (ji_list_citr jii=_ji_list.begin(); jii!=_ji_list.end(); jii++)
-                (*jii)->init_tc(*tci, reuse_instance, recover_mode, keep_jrnls);
+                (*jii)->init_tc(*tci, recover_mode, keep_jrnls);
             for (ji_list_citr jii=_ji_list.begin(); jii!=_ji_list.end(); jii++)
                 (*jii)->run_tc();
             for (ji_list_citr jii=_ji_list.begin(); jii!=_ji_list.end(); jii++)




More information about the rhmessaging-commits mailing list