[rhmessaging-commits] rhmessaging commits: r1348 - in store/trunk/cpp: tests/jrnl and 1 other directory.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Tue Nov 20 23:11:54 EST 2007
Author: kpvdr
Date: 2007-11-20 23:11:54 -0500 (Tue, 20 Nov 2007)
New Revision: 1348
Added:
store/trunk/cpp/tests/jrnl/unit_test_txn_map.cpp
Modified:
store/trunk/cpp/lib/jrnl/txn_map.cpp
store/trunk/cpp/lib/jrnl/txn_map.hpp
store/trunk/cpp/tests/jrnl/Makefile.am
Log:
Added another unit test, still needs work to complete, but works.
Modified: store/trunk/cpp/lib/jrnl/txn_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_map.cpp 2007-11-20 21:34:39 UTC (rev 1347)
+++ store/trunk/cpp/lib/jrnl/txn_map.cpp 2007-11-21 04:11:54 UTC (rev 1348)
@@ -117,6 +117,17 @@
return list;
}
+const bool
+txn_map::in_map(const std::string& xid)
+{
+ pthread_mutex_lock(&_mutex);
+ xmap_itr itr = _map.find(xid);
+ pthread_mutex_unlock(&_mutex);
+ if (itr == _map.end()) // not found in map
+ return false;
+ return true;
+}
+
const u_int32_t
txn_map::get_rid_count(const std::string& xid) throw (jexception)
{
Modified: store/trunk/cpp/lib/jrnl/txn_map.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_map.hpp 2007-11-20 21:34:39 UTC (rev 1347)
+++ store/trunk/cpp/lib/jrnl/txn_map.hpp 2007-11-21 04:11:54 UTC (rev 1348)
@@ -82,6 +82,7 @@
const bool insert_txn_data(const std::string& xid, const txn_data& td) throw (jexception);
const txn_data_list get_tdata_list(const std::string& xid) throw (jexception);
const txn_data_list get_remove_tdata_list(const std::string& xid) throw (jexception);
+ const bool in_map(const std::string& xid);
const u_int32_t get_rid_count(const std::string& xid) throw (jexception);
const bool is_txn_synced(const std::string& xid) throw (jexception);
const bool set_aio_compl(const std::string& xid, const u_int64_t rid) throw (jexception);
Modified: store/trunk/cpp/tests/jrnl/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.am 2007-11-20 21:34:39 UTC (rev 1347)
+++ store/trunk/cpp/tests/jrnl/Makefile.am 2007-11-21 04:11:54 UTC (rev 1348)
@@ -32,6 +32,7 @@
unit_test_jdir \
unit_test_file_hdr \
unit_test_enq_map \
+ unit_test_txn_map \
run-journal-tests
check_LTLIBRARIES = \
@@ -44,6 +45,7 @@
unit_test_jinf \
unit_test_jdir \
unit_test_enq_map \
+ unit_test_txn_map \
unit_test_file_hdr
unit_test_jexception_SOURCES = unit_test_jexception.cpp
@@ -64,6 +66,9 @@
unit_test_enq_map_SOURCES = unit_test_enq_map.cpp
unit_test_enq_map_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
+unit_test_txn_map_SOURCES = unit_test_txn_map.cpp
+unit_test_txn_map_LDFLAGS = -lboost_unit_test_framework -lbdbstore -lrt -L../../lib/.libs
+
JournalSystemTests_la_SOURCES = \
JournalSystemTests.cpp \
JournalSystemTests.hpp
Added: store/trunk/cpp/tests/jrnl/unit_test_txn_map.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/unit_test_txn_map.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/unit_test_txn_map.cpp 2007-11-21 04:11:54 UTC (rev 1348)
@@ -0,0 +1,126 @@
+/**
+* \file unit_test_txn_map.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* This file contains the unit tests for the journal.
+*
+* \author Kim van der Riet
+*
+* Copyright 2007 Red Hat, Inc.
+*
+* This file is part of Red Hat Messaging.
+*
+* Red Hat Messaging is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation; either
+* version 2.1 of the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+* USA
+*
+* The GNU Lesser General Public License is available in the file COPYING.
+*/
+
+#include <boost/test/results_reporter.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <iostream>
+#include <iomanip>
+#include <jrnl/txn_map.hpp>
+#include <sstream>
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+
+// Helper function declarations
+const std::string make_xid(u_int64_t rid);
+void check_td_equal(txn_data& td1, txn_data& td2);
+
+// Test functions of the form
+// void fn() {...}
+
+void test_constructor()
+{
+ const u_int64_t rid = 0x123456789abcdef0ULL;
+ const u_int64_t drid = 0xfedcba9876543210ULL;
+ const u_int16_t fid = 0xfedcU;
+ const bool enq_flag = true;
+ txn_data td(rid, drid, fid, enq_flag);
+ BOOST_CHECK_EQUAL(td._rid, rid);
+ BOOST_CHECK_EQUAL(td._drid, drid);
+ BOOST_CHECK_EQUAL(td._fid, fid);
+ BOOST_CHECK_EQUAL(td._enq_flag, enq_flag);
+ BOOST_CHECK_EQUAL(td._aio_compl, false);
+
+ txn_map t1;
+ BOOST_CHECK(t1.empty());
+ BOOST_CHECK_EQUAL(t1.size(), 0);
+}
+
+void test_insert_get()
+{
+ u_int16_t fid;
+ u_int64_t rid;
+ u_int16_t fid_start = 0x2000U;
+ u_int64_t rid_begin = 0xffffffff00000000ULL;
+ u_int64_t rid_end = 0xffffffff00000200ULL;
+
+ // insert with no dups
+ u_int64_t rid_incr_1 = 4ULL;
+ txn_map t2;
+ for (rid = rid_begin, fid = fid_start; rid < rid_end; rid += rid_incr_1, fid++)
+ t2.insert_txn_data(make_xid(rid), txn_data(rid, ~rid, fid, false));
+ BOOST_CHECK(!t2.empty());
+ BOOST_CHECK_EQUAL(t2.size(), 128);
+
+ // get
+ u_int64_t rid_incr_2 = 6ULL;
+ for (u_int64_t rid = rid_begin; rid < rid_end; rid += rid_incr_2)
+ {
+ std::string xid = make_xid(rid);
+ BOOST_CHECK_EQUAL(t2.in_map(xid), (rid%rid_incr_1 ? false : true));
+ }
+}
+
+// Helper functions
+
+const std::string make_xid(u_int64_t rid)
+{
+ std::stringstream ss;
+ ss << "XID-" << std::setfill('0') << std::setw(16) << std::hex << rid;
+ ss << "-0123456789abcdef";
+ return ss.str();
+}
+
+void check_td_equal(txn_data& td1, txn_data& td2)
+{
+ BOOST_CHECK_EQUAL(td1._rid, td2._rid);
+ BOOST_CHECK_EQUAL(td1._drid, td2._drid);
+ BOOST_CHECK_EQUAL(td1._fid, td2._fid);
+ BOOST_CHECK_EQUAL(td1._enq_flag, td2._enq_flag);
+ BOOST_CHECK_EQUAL(td1._aio_compl, td2._aio_compl);
+}
+
+// Initialize test suite and include test functions
+
+test_suite* init_unit_test_suite(int, char**)
+{
+ std::cout << "--------" << std::endl << "unit_test_txn_map: ";
+ test_suite* ts = BOOST_TEST_SUITE("unit_test_txn_map");
+
+ results_reporter::set_level(SHORT_REPORT);
+ unit_test_log_t::instance().set_threshold_level(log_messages);
+
+ ts->add(BOOST_TEST_CASE(&test_constructor));
+ ts->add(BOOST_TEST_CASE(&test_insert_get));
+
+ return ts;
+}
More information about the rhmessaging-commits
mailing list