Author: kpvdr
Date: 2008-04-16 11:38:14 -0400 (Wed, 16 Apr 2008)
New Revision: 1922
Added:
store/trunk/cpp/lib/jrnl/arr_cnt.cpp
store/trunk/cpp/lib/jrnl/arr_cnt.hpp
store/trunk/cpp/tests/jrnl/_ut_arr_cnt.cpp
Modified:
store/trunk/cpp/lib/Makefile.am
store/trunk/cpp/lib/jrnl/enq_map.cpp
store/trunk/cpp/lib/jrnl/enq_map.hpp
store/trunk/cpp/lib/jrnl/jcntl.cpp
store/trunk/cpp/lib/jrnl/txn_map.cpp
store/trunk/cpp/lib/jrnl/txn_map.hpp
store/trunk/cpp/tests/jrnl/
store/trunk/cpp/tests/jrnl/Makefile.am
store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp
store/trunk/cpp/tests/jrnl/jtt/Makefile.am
Log:
Added per-fid enq counter for enq_map and per-fid txn counter for txn_map. Updated unit
tests.
Modified: store/trunk/cpp/lib/Makefile.am
===================================================================
--- store/trunk/cpp/lib/Makefile.am 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/lib/Makefile.am 2008-04-16 15:38:14 UTC (rev 1922)
@@ -39,6 +39,7 @@
StoreException.h \
StringDbt.h \
TxnCtxt.h \
+ jrnl/arr_cnt.cpp \
jrnl/cvar.cpp \
jrnl/data_tok.cpp \
jrnl/deq_rec.cpp \
@@ -62,6 +63,7 @@
jrnl/wmgr.cpp \
jrnl/wrfc.cpp \
jrnl/aio_cb.hpp \
+ jrnl/arr_cnt.hpp \
jrnl/cvar.hpp \
jrnl/data_tok.hpp \
jrnl/deq_hdr.hpp \
Added: store/trunk/cpp/lib/jrnl/arr_cnt.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/arr_cnt.cpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/arr_cnt.cpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -0,0 +1,169 @@
+/**
+* \file arr_cnt.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::arr_cnt (enqueue map). See
+* comments in file arr_cnt.hpp for details.
+*
+* Copyright (C) 2007, 2008 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 "jrnl/arr_cnt.hpp"
+
+#include <cassert>
+
+namespace rhm
+{
+namespace journal
+{
+
+arr_cnt::arr_cnt(): _size(0), _cnt_arr_ptr(0)
+{}
+
+arr_cnt::~arr_cnt()
+{
+ clean(_cnt_arr_ptr, _size);
+}
+
+void
+arr_cnt::set_size(const u_int16_t size)
+{
+ u_int16_t old_size = _size;
+ u_int32_t** old_cnt_arr_ptr = _cnt_arr_ptr;
+ _size = size;
+ if (_size)
+ {
+ _cnt_arr_ptr = new u_int32_t*[_size];
+ for (u_int16_t i=0; i<_size; i++)
+ {
+ _cnt_arr_ptr[i] = new u_int32_t;
+ // transfer counts from old file array
+ *_cnt_arr_ptr[i] = i < old_size ? *(old_cnt_arr_ptr[i]) : u_int32_t(0);
+ }
+ }
+ else
+ _cnt_arr_ptr = 0;
+ clean(old_cnt_arr_ptr, old_size);
+}
+
+u_int32_t
+arr_cnt::cnt(const u_int16_t index) const
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ return *(_cnt_arr_ptr[index]);
+ return 0;
+}
+
+u_int32_t
+arr_cnt::incr(const u_int16_t index)
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ return ++(*(_cnt_arr_ptr[index]));
+ return 0;
+}
+
+u_int32_t
+arr_cnt::decr(const u_int16_t index)
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ {
+ assert(*(_cnt_arr_ptr[index]) > 0);
+ return --(*(_cnt_arr_ptr[index]));
+ }
+ return 0;
+}
+
+u_int32_t
+arr_cnt::add(const u_int16_t index, u_int32_t amt)
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ {
+ *(_cnt_arr_ptr[index]) += amt;
+ return *(_cnt_arr_ptr[index]);
+ }
+ return 0;
+}
+
+u_int32_t
+arr_cnt::sub(const u_int16_t index, u_int32_t amt)
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ {
+ assert(*(_cnt_arr_ptr[index]) >= amt);
+ *(_cnt_arr_ptr[index]) -= amt;
+ return *(_cnt_arr_ptr[index]);
+ }
+ return 0;
+}
+
+void
+arr_cnt::set_cnt(const u_int16_t index, u_int32_t val)
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ *(_cnt_arr_ptr[index]) = val;
+}
+
+void
+arr_cnt::clear_cnt(const u_int16_t index)
+{
+ assert(_size == 0 || index < _size);
+ if (_cnt_arr_ptr)
+ *(_cnt_arr_ptr[index]) = 0;
+}
+
+void
+arr_cnt::clear_all()
+{
+ if (_cnt_arr_ptr)
+ {
+ for (u_int16_t i=0; i<_size; i++)
+ *(_cnt_arr_ptr[i]) = 0;
+ }
+}
+
+void
+arr_cnt::clean(u_int32_t** cnt_arr_ptr, const u_int16_t size)
+{
+ if (cnt_arr_ptr)
+ {
+ for (u_int16_t i=0; i<size; i++)
+ {
+ if (cnt_arr_ptr[i])
+ {
+ delete cnt_arr_ptr[i];
+ cnt_arr_ptr[i] = 0;
+ }
+ }
+ delete[] cnt_arr_ptr;
+ cnt_arr_ptr = 0;
+ }
+}
+
+} // namespace journal
+} // namespace rhm
Added: store/trunk/cpp/lib/jrnl/arr_cnt.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/arr_cnt.hpp (rev 0)
+++ store/trunk/cpp/lib/jrnl/arr_cnt.hpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -0,0 +1,77 @@
+/**
+* \file arr_cnt.hpp
+*
+* Red Hat Messaging - Message Journal
+*
+* File containing code for class rhm::journal::arr_cnt (array counter).
+* See class documentation for details.
+*
+* \author Kim van der Riet
+*
+* Copyright (C) 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.
+*/
+
+#ifndef rhm_journal_arr_cnt_hpp
+#define rhm_journal_arr_cnt_hpp
+
+#include <sys/types.h>
+
+namespace rhm
+{
+namespace journal
+{
+
+ /**
+ * \class arr_cnt
+ * \brief Class which implements a dynamically allocated array of u_int32_t counters.
+ * This is ideal where it is necessary to increment and decrement counts for an
entuty
+ * for which the number of elements is unknown, but for which the efficiency of a
static
+ * array is required. None of the counts may go below zero.
+ */
+ class arr_cnt
+ {
+ private:
+ u_int16_t _size;
+ u_int32_t** _cnt_arr_ptr;
+
+ public:
+ arr_cnt();
+ virtual ~arr_cnt();
+
+ inline u_int16_t size() const { return _size; }
+ void set_size(const u_int16_t size);
+ u_int32_t cnt(const u_int16_t index) const;
+ u_int32_t incr(const u_int16_t index);
+ u_int32_t decr(const u_int16_t index);
+ u_int32_t add(const u_int16_t index, u_int32_t amt);
+ u_int32_t sub(const u_int16_t index, u_int32_t amt);
+ void set_cnt(const u_int16_t index, u_int32_t val);
+ void clear_cnt(const u_int16_t index);
+ void clear_all();
+ private:
+ void clean(u_int32_t** cnt_arr_ptr, const u_int16_t size);
+ };
+
+} // namespace journal
+} // namespace rhm
+
+#endif // ifndef rhm_journal_arr_cnt_hpp
Modified: store/trunk/cpp/lib/jrnl/enq_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_map.cpp 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/lib/jrnl/enq_map.cpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -42,7 +42,8 @@
{
enq_map::enq_map():
- _map()
+ _map(),
+ _fid_enq_cnt()
{
pthread_mutex_init(&_mutex, 0);
}
@@ -53,6 +54,12 @@
}
void
+enq_map::set_num_jfiles(const u_int16_t num_jfiles)
+{
+ _fid_enq_cnt.set_size(num_jfiles);
+}
+
+void
enq_map::insert_fid(const u_int64_t rid, const u_int16_t fid)
{
insert_fid(rid, fid, false);
@@ -73,6 +80,7 @@
oss << std::hex << "rid=0x" << rid << "
fid=0x" << fid;
throw jexception(jerrno::JERR_MAP_DUPLICATE, oss.str(), "enq_map",
"insert");
}
+ _fid_enq_cnt.incr(fid);
}
u_int16_t
@@ -117,6 +125,7 @@
}
u_int16_t fid = itr->second.first;
_map.erase(itr);
+ _fid_enq_cnt.decr(fid);
return fid;
}
Modified: store/trunk/cpp/lib/jrnl/enq_map.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/enq_map.hpp 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/lib/jrnl/enq_map.hpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -41,6 +41,7 @@
}
}
+#include "jrnl/arr_cnt.hpp"
#include "jrnl/jexception.hpp"
#include <map>
#include <pthread.h>
@@ -81,11 +82,15 @@
emap _map;
pthread_mutex_t _mutex;
+ arr_cnt _fid_enq_cnt;
public:
enq_map();
virtual ~enq_map();
+ void set_num_jfiles(const u_int16_t num_jfiles);
+ inline u_int32_t get_enq_cnt(const u_int16_t fid) const { return
_fid_enq_cnt.cnt(fid); };
+
void insert_fid(const u_int64_t rid, const u_int16_t fid);
void insert_fid(const u_int64_t rid, const u_int16_t fid, const bool locked);
u_int16_t get_fid(const u_int64_t rid);
Modified: store/trunk/cpp/lib/jrnl/jcntl.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/jcntl.cpp 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/lib/jrnl/jcntl.cpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -113,6 +113,8 @@
assert(num_jfiles >= JRNL_MIN_NUM_FILES);
assert(num_jfiles <= JRNL_MAX_NUM_FILES);
_num_jfiles = num_jfiles;
+ _emap.set_num_jfiles(_num_jfiles);
+ _tmap.set_num_jfiles(_num_jfiles);
assert(jfsize_sblks >= JRNL_MIN_FILE_SIZE);
assert(jfsize_sblks <= JRNL_MAX_FILE_SIZE);
@@ -169,6 +171,8 @@
assert(num_jfiles >= JRNL_MIN_NUM_FILES);
assert(num_jfiles <= JRNL_MAX_NUM_FILES);
_num_jfiles = num_jfiles;
+ _emap.set_num_jfiles(_num_jfiles);
+ _tmap.set_num_jfiles(_num_jfiles);
assert(jfsize_sblks >= JRNL_MIN_FILE_SIZE);
assert(jfsize_sblks <= JRNL_MAX_FILE_SIZE);
Modified: store/trunk/cpp/lib/jrnl/txn_map.cpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_map.cpp 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/lib/jrnl/txn_map.cpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -51,7 +51,8 @@
{}
txn_map::txn_map():
- _map()
+ _map(),
+ _fid_txn_cnt()
{
pthread_mutex_init(&_mutex, 0);
}
@@ -61,6 +62,12 @@
pthread_mutex_destroy(&_mutex);
}
+void
+txn_map::set_num_jfiles(const u_int16_t num_jfiles)
+{
+ _fid_txn_cnt.set_size(num_jfiles);
+}
+
bool
txn_map::insert_txn_data(const std::string& xid, const txn_data& td)
{
@@ -77,6 +84,7 @@
}
else
itr->second.push_back(td);
+ _fid_txn_cnt.incr(td._fid);
return ok;
}
@@ -111,6 +119,8 @@
}
txn_data_list list = itr->second;
_map.erase(itr);
+ for (tdl_itr i=list.begin(); i!=list.end(); i++)
+ _fid_txn_cnt.decr(i->_fid);
return list;
}
Modified: store/trunk/cpp/lib/jrnl/txn_map.hpp
===================================================================
--- store/trunk/cpp/lib/jrnl/txn_map.hpp 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/lib/jrnl/txn_map.hpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -41,6 +41,7 @@
}
}
+#include "jrnl/arr_cnt.hpp"
#include <map>
#include <pthread.h>
#include <string>
@@ -115,11 +116,16 @@
xmap _map;
pthread_mutex_t _mutex;
+ arr_cnt _fid_txn_cnt;
public:
txn_map();
virtual ~txn_map();
+ void set_num_jfiles(const u_int16_t num_jfiles);
+ inline u_int32_t get_txn_fid_cnt(const u_int16_t fid) const
+ { return _fid_txn_cnt.cnt(fid); };
+
bool insert_txn_data(const std::string& xid, const txn_data& td);
const txn_data_list get_tdata_list(const std::string& xid);
const txn_data_list get_remove_tdata_list(const std::string& xid);
Property changes on: store/trunk/cpp/tests/jrnl
___________________________________________________________________
Name: svn:ignore
- .deps
.libs
Makefile
Makefile.in
jtest
_ut_enq_map
_ut_jdir
_ut_jerrno
_ut_jexception
_ut_jinf
_ut_rec_hdr
_ut_time_ns
_ut_txn_map
_st_basic
_st_basic_txn
_st_read
_st_read_txn
+ .deps
.libs
Makefile
Makefile.in
jtest
_ut_enq_map
_ut_arr_cnt
_ut_jdir
_ut_jerrno
_ut_jexception
_ut_jinf
_ut_rec_hdr
_ut_time_ns
_ut_txn_map
_st_basic
_st_basic_txn
_st_read
_st_read_txn
Modified: store/trunk/cpp/tests/jrnl/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/Makefile.am 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/tests/jrnl/Makefile.am 2008-04-16 15:38:14 UTC (rev 1922)
@@ -29,6 +29,7 @@
TESTS = \
_ut_time_ns \
+ _ut_arr_cnt \
_ut_jexception \
_ut_jerrno \
_ut_rec_hdr \
@@ -44,6 +45,7 @@
check_PROGRAMS = \
_ut_time_ns \
+ _ut_arr_cnt \
_ut_jexception \
_ut_jerrno \
_ut_rec_hdr \
@@ -62,6 +64,9 @@
_ut_time_ns_SOURCES = _ut_time_ns.cpp $(UNIT_TEST_SRCS)
_ut_time_ns_LDFLAGS = $(UNIT_TEST_LDADD)
+_ut_arr_cnt_SOURCES = _ut_arr_cnt.cpp $(UNIT_TEST_SRCS)
+_ut_arr_cnt_LDFLAGS = $(UNIT_TEST_LDADD)
+
_ut_jexception_SOURCES = _ut_jexception.cpp $(UNIT_TEST_SRCS)
_ut_jexception_LDFLAGS = $(UNIT_TEST_LDADD)
Added: store/trunk/cpp/tests/jrnl/_ut_arr_cnt.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_ut_arr_cnt.cpp (rev 0)
+++ store/trunk/cpp/tests/jrnl/_ut_arr_cnt.cpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -0,0 +1,153 @@
+/**
+* \file _ut_enq_map.cpp
+*
+* Red Hat Messaging - Message Journal
+*
+* This file contains the unit tests for the journal.
+*
+* Copyright 2007, 2008 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 "../unit_test.h"
+
+#include <iostream>
+#include "jrnl/arr_cnt.hpp"
+
+using namespace boost::unit_test;
+using namespace rhm::journal;
+using namespace std;
+
+QPID_AUTO_TEST_SUITE(eng_map_suite)
+
+const string test_filename("_ut_arr_cnt");
+
+QPID_AUTO_TEST_CASE(default_constructor)
+{
+ cout << test_filename << ".default_constructor: " <<
flush;
+ arr_cnt a1;
+ BOOST_CHECK_EQUAL(a1.size(), u_int16_t(0));
+ BOOST_CHECK_EQUAL(a1.cnt(0), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a1.incr(0), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a1.decr(0), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a1.add(0, 100), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a1.sub(0, 100), u_int32_t(0));
+ a1.set_cnt(0, 100);
+ a1.clear_cnt(0);
+ a1.clear_all();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(basic_fns)
+{
+ cout << test_filename << ".basic_fns: " << flush;
+ const u_int16_t num_elts = 8;
+ arr_cnt a2;
+ BOOST_CHECK_EQUAL(a2.size(), u_int16_t(0));
+ a2.set_size(num_elts);
+ BOOST_CHECK_EQUAL(a2.size(), num_elts);
+ for (u_int16_t i=0; i<num_elts; i++)
+ {
+ BOOST_CHECK_EQUAL(a2.cnt(i), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a2.incr(i), u_int32_t(1));
+ BOOST_CHECK_EQUAL(a2.decr(i), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a2.add(i, 100), u_int32_t(100));
+ BOOST_CHECK_EQUAL(a2.sub(i, 100), u_int32_t(0));
+ a2.set_cnt(i, 100);
+ a2.set_cnt(i, 100);
+ BOOST_CHECK_EQUAL(a2.cnt(i), u_int32_t(100));
+ a2.clear_cnt(i);
+ BOOST_CHECK_EQUAL(a2.cnt(i), u_int32_t(0));
+ a2.set_cnt(i, i);
+ }
+ a2.clear_all();
+ for (u_int16_t i=0; i<num_elts; i++)
+ BOOST_CHECK_EQUAL(a2.cnt(i), u_int32_t(0));
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(resize)
+{
+ cout << test_filename << ".resize: " << flush;
+ arr_cnt a3;
+ BOOST_CHECK_EQUAL(a3.size(), u_int16_t(0));
+ a3.set_size(8);
+ BOOST_CHECK_EQUAL(a3.size(), u_int16_t(8));
+ a3.set_size(1000);
+ BOOST_CHECK_EQUAL(a3.size(), u_int16_t(1000));
+ a3.set_size(4);
+ BOOST_CHECK_EQUAL(a3.size(), u_int16_t(4));
+ a3.set_size(0);
+ BOOST_CHECK_EQUAL(a3.size(), u_int16_t(0));
+ a3.set_size(10);
+ BOOST_CHECK_EQUAL(a3.size(), u_int16_t(10));
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(resize_up_transfer_cnt)
+{
+ cout << test_filename << ".transfer_up: " << flush;
+ const u_int16_t num_elts = 8;
+ arr_cnt a4;
+ a4.set_size(num_elts);
+ for (u_int16_t i=0; i<num_elts; i++)
+ a4.set_cnt(i, i*i);
+ a4.set_size(2*num_elts);
+ for (u_int16_t i=0; i<num_elts; i++)
+ BOOST_CHECK_EQUAL(a4.cnt(i), u_int32_t(i*i));
+ for (u_int16_t i=num_elts; i<2*num_elts; i++)
+ BOOST_CHECK_EQUAL(a4.cnt(i), u_int32_t(0));
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(resize_down_transfer_cnt)
+{
+ cout << test_filename << ".transfer_up: " << flush;
+ const u_int16_t num_elts = 16;
+ arr_cnt a5;
+ a5.set_size(num_elts);
+ for (u_int16_t i=0; i<num_elts; i++)
+ a5.set_cnt(i, i*i);
+ a5.set_size(num_elts/2);
+ for (u_int16_t i=0; i<num_elts/2; i++)
+ BOOST_CHECK_EQUAL(a5.cnt(i), u_int32_t(i*i));
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_CASE(null_immunity_after_resize_to_zero)
+{
+ cout << test_filename << ".null_immunity_after_resize_to_zero:
" << flush;
+ arr_cnt a6;
+ a6.set_size(8);
+ a6.set_size(0);
+ BOOST_CHECK_EQUAL(a6.size(), u_int16_t(0));
+ BOOST_CHECK_EQUAL(a6.cnt(8), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a6.incr(8), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a6.decr(8), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a6.add(8, 100), u_int32_t(0));
+ BOOST_CHECK_EQUAL(a6.sub(8, 100), u_int32_t(0));
+ a6.set_cnt(8, 100);
+ a6.clear_cnt(8);
+ a6.clear_all();
+ cout << "ok" << endl;
+}
+
+QPID_AUTO_TEST_SUITE_END()
Modified: store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp
===================================================================
--- store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/tests/jrnl/_ut_enq_map.cpp 2008-04-16 15:38:14 UTC (rev 1922)
@@ -250,6 +250,55 @@
cout << "ok" << endl;
}
+QPID_AUTO_TEST_CASE(enq_count)
+{
+ cout << test_filename << ".enq_count: " << flush;
+
+ enq_map e6;
+
+ // Check the allocation and cleanup as the file size is set both up and down
+ e6.set_num_jfiles(24);
+ e6.set_num_jfiles(0);
+ e6.set_num_jfiles(100);
+ e6.set_num_jfiles(4);
+
+ // Add 100 enqueues to file 1, check that the counts match
+ for (u_int16_t fid=0; fid<4; fid++)
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(0));
+ for (u_int64_t rid=0; rid<100; rid++)
+ e6.insert_fid(rid, 1);
+ for (u_int16_t fid=0; fid<4; fid++)
+ {
+ if (fid == 1)
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(100));
+ else
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(0));
+ }
+
+ // Now remove 10 from file 1, check that the counts match
+ for (u_int64_t rid=0; rid<100; rid+=10)
+ e6.get_remove_fid(rid);
+ for (u_int16_t fid=0; fid<4; fid++)
+ {
+ if (fid == 1)
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(90));
+ else
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(0));
+ }
+
+ // Now resize the file up and make sure the count in file 1 still exists
+ e6.set_num_jfiles(8);
+ for (u_int16_t fid=0; fid<8; fid++)
+ {
+ if (fid == 1)
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(90));
+ else
+ BOOST_CHECK_EQUAL(e6.get_enq_cnt(fid), u_int32_t(0));
+ }
+
+ cout << "ok" << endl;
+}
+
QPID_AUTO_TEST_CASE(stress)
{
cout << test_filename << ".stress: " << flush;
@@ -258,23 +307,24 @@
u_int64_t rid_begin = 0xffffffff00000000ULL;
u_int64_t num_rid = 0x800000ULL;
- enq_map e6;
+ enq_map e7;
// insert even rids with no dups
for (rid = rid_begin, rid_cnt = u_int64_t(0); rid_cnt < num_rid; rid += 2ULL,
rid_cnt++)
- e6.insert_fid(rid, u_int16_t(0));
- BOOST_CHECK_EQUAL(e6.size(), num_rid);
+ e7.insert_fid(rid, u_int16_t(0));
+ BOOST_CHECK_EQUAL(e7.size(), num_rid);
// insert odd rids with no dups
for (rid = rid_begin + 1, rid_cnt = u_int64_t(0); rid_cnt < num_rid; rid += 2ULL,
rid_cnt++)
- e6.insert_fid(rid, u_int16_t(0));
- BOOST_CHECK_EQUAL(e6.size(), num_rid * 2);
- cout << "ok" << endl;
+ e7.insert_fid(rid, u_int16_t(0));
+ BOOST_CHECK_EQUAL(e7.size(), num_rid * 2);
// remove even rids
for (rid = rid_begin, rid_cnt = u_int64_t(0); rid_cnt < num_rid; rid += 2ULL,
rid_cnt++)
- e6.get_remove_fid(rid);
- BOOST_CHECK_EQUAL(e6.size(), num_rid);
+ e7.get_remove_fid(rid);
+ BOOST_CHECK_EQUAL(e7.size(), num_rid);
+
+ cout << "ok" << endl;
}
QPID_AUTO_TEST_SUITE_END()
Modified: store/trunk/cpp/tests/jrnl/jtt/Makefile.am
===================================================================
--- store/trunk/cpp/tests/jrnl/jtt/Makefile.am 2008-04-16 15:31:34 UTC (rev 1921)
+++ store/trunk/cpp/tests/jrnl/jtt/Makefile.am 2008-04-16 15:38:14 UTC (rev 1922)
@@ -69,6 +69,7 @@
test_case_set.hpp \
test_mgr.hpp
jtt_LDADD = \
+ ${LIBOBJDIR}/arr_cnt.o \
${LIBOBJDIR}/data_tok.o \
${LIBOBJDIR}/deq_rec.o \
${LIBOBJDIR}/enq_map.o \
@@ -116,6 +117,7 @@
test_case.o \
test_case_result.o \
test_case_result_agregation.o \
+ ${LIBOBJDIR}/arr_cnt.o \
${LIBOBJDIR}/data_tok.o \
${LIBOBJDIR}/deq_rec.o \
${LIBOBJDIR}/enq_map.o \