summaryrefslogtreecommitdiff
path: root/cpp/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/tests')
-rw-r--r--cpp/src/tests/StoreStatus.cpp10
-rw-r--r--cpp/src/tests/Uuid.cpp24
-rwxr-xr-xcpp/src/tests/cluster_tests.py39
-rw-r--r--cpp/src/tests/testagent.mk2
4 files changed, 45 insertions, 30 deletions
diff --git a/cpp/src/tests/StoreStatus.cpp b/cpp/src/tests/StoreStatus.cpp
index 87b3531236..43d4cfd920 100644
--- a/cpp/src/tests/StoreStatus.cpp
+++ b/cpp/src/tests/StoreStatus.cpp
@@ -65,7 +65,8 @@ QPID_AUTO_TEST_CASE(testSaveLoadDirty) {
Uuid clusterId = Uuid(true);
StoreStatus ss(TEST_DIR);
ss.load();
- ss.dirty(clusterId);
+ ss.setClusterId(clusterId);
+ ss.dirty();
BOOST_CHECK_EQUAL(ss.getState(), STORE_STATE_DIRTY_STORE);
StoreStatus ss2(TEST_DIR);
@@ -81,7 +82,7 @@ QPID_AUTO_TEST_CASE(testSaveLoadClean) {
Uuid shutdownId = Uuid(true);
StoreStatus ss(TEST_DIR);
ss.load();
- ss.dirty(clusterId);
+ ss.setClusterId(clusterId);
ss.clean(shutdownId);
BOOST_CHECK_EQUAL(ss.getState(), STORE_STATE_CLEAN_STORE);
@@ -99,9 +100,10 @@ QPID_AUTO_TEST_CASE(testMarkDirty) {
Uuid shutdownId = Uuid(true);
StoreStatus ss(TEST_DIR);
ss.load();
- ss.dirty(clusterId);
+ ss.setClusterId(clusterId);
+ ss.dirty();
ss.clean(shutdownId);
- ss.dirty(clusterId);
+ ss.dirty();
StoreStatus ss2(TEST_DIR);
ss2.load();
diff --git a/cpp/src/tests/Uuid.cpp b/cpp/src/tests/Uuid.cpp
index 4c6505b139..0195455ca3 100644
--- a/cpp/src/tests/Uuid.cpp
+++ b/cpp/src/tests/Uuid.cpp
@@ -50,6 +50,7 @@ QPID_AUTO_TEST_CASE(testUuidCtor) {
boost::array<uint8_t, 16> sample = {{'\x1b', '\x4e', '\x28', '\xba', '\x2f', '\xa1', '\x11', '\xd2', '\x88', '\x3f', '\xb9', '\xa7', '\x61', '\xbd', '\xe3', '\xfb'}};
const string sampleStr("1b4e28ba-2fa1-11d2-883f-b9a761bde3fb");
+const string zeroStr("00000000-0000-0000-0000-000000000000");
QPID_AUTO_TEST_CASE(testUuidIstream) {
Uuid uuid;
@@ -57,6 +58,12 @@ QPID_AUTO_TEST_CASE(testUuidIstream) {
in >> uuid;
BOOST_CHECK(!in.fail());
BOOST_CHECK(uuid == sample);
+
+ istringstream is(zeroStr);
+ Uuid zero;
+ is >> zero;
+ BOOST_CHECK(!in.fail());
+ BOOST_CHECK_EQUAL(zero, Uuid());
}
QPID_AUTO_TEST_CASE(testUuidOstream) {
@@ -65,6 +72,23 @@ QPID_AUTO_TEST_CASE(testUuidOstream) {
out << uuid;
BOOST_CHECK(out.good());
BOOST_CHECK_EQUAL(out.str(), sampleStr);
+
+ ostringstream os;
+ os << Uuid();
+ BOOST_CHECK(out.good());
+ BOOST_CHECK_EQUAL(os.str(), zeroStr);
+}
+
+QPID_AUTO_TEST_CASE(testUuidIOstream) {
+ Uuid a(true), b(true);
+ ostringstream os;
+ os << a << endl << b;
+ Uuid aa, bb;
+ istringstream is(os.str());
+ is >> aa >> ws >> bb;
+ BOOST_CHECK(os.good());
+ BOOST_CHECK_EQUAL(a, aa);
+ BOOST_CHECK_EQUAL(b, bb);
}
QPID_AUTO_TEST_CASE(testUuidEncodeDecode) {
diff --git a/cpp/src/tests/cluster_tests.py b/cpp/src/tests/cluster_tests.py
index 6a748e6f2a..893fb9928d 100755
--- a/cpp/src/tests/cluster_tests.py
+++ b/cpp/src/tests/cluster_tests.py
@@ -310,7 +310,6 @@ class StoreTests(BrokerTest):
c = cluster.start("c", expect=EXPECT_EXIT_OK, wait=True)
a.send_message("q", Message("4", durable=True))
a.kill()
- time.sleep(0.1) # pause for b to write status.
b.kill()
self.assertEqual(c.get_message("q").content, "4")
c.send_message("q", Message("clean", durable=True))
@@ -356,11 +355,6 @@ class StoreTests(BrokerTest):
self.assertRaises(Exception, lambda: a.ready())
self.assertRaises(Exception, lambda: b.ready())
- def assert_dirty_store(self, broker):
- assert retry(lambda: os.path.exists(broker.log)), "Missing log file %s"%broker.log
- msg = re.compile("critical.*no clean store")
- assert retry(lambda: msg.search(readfile(broker.log))), "Expected dirty store message in %s"%broker.log
-
def test_solo_store_clean(self):
# A single node cluster should always leave a clean store.
cluster = self.cluster(0, self.args())
@@ -378,29 +372,25 @@ class StoreTests(BrokerTest):
# store.
cluster = self.cluster(0, self.args())
a = cluster.start("a", expect=EXPECT_EXIT_FAIL)
+ self.assertEqual(a.store_state(), "clean")
b = cluster.start("b", expect=EXPECT_EXIT_FAIL)
c = cluster.start("c", expect=EXPECT_EXIT_FAIL)
+ self.assertEqual(b.store_state(), "dirty")
+ self.assertEqual(c.store_state(), "dirty")
+ retry(lambda: a.store_state() == "dirty")
+
a.send_message("q", Message("x", durable=True))
a.kill()
- # FIXME aconway 2010-03-29: this test has too many sleeps.
- # Need to tighten up status persistence to be more atomic and less
- # prone to interruption.
- time.sleep(0.1) # pause for b to update status.
- b.kill() # c is last man
- time.sleep(0.1) # pause for c to find out hes last.
+ b.kill() # c is last man, will mark store clean
+ retry(lambda: c.store_state() == "clean")
a = cluster.start("a", expect=EXPECT_EXIT_FAIL) # c no longer last man
- time.sleep(0.1) # pause for c to find out hes no longer last.
- c.kill() # a is now last man
- time.sleep(0.1) # pause for a to find out hes last.
- a.kill() # really last, should be clean.
- # b & c should be dirty
- b = cluster.start("b", wait=False, expect=EXPECT_EXIT_FAIL)
- self.assert_dirty_store(b)
- c = cluster.start("c", wait=False, expect=EXPECT_EXIT_FAIL)
- self.assert_dirty_store(c)
- # a should be clean
- a = cluster.start("a")
- self.assertEqual(a.get_message("q").content, "x")
+ retry(lambda: c.store_state() == "dirty")
+ c.kill() # a is now last man
+ retry(lambda: a.store_state() == "clean")
+ a.kill()
+ self.assertEqual(a.store_state(), "clean")
+ self.assertEqual(b.store_state(), "dirty")
+ self.assertEqual(c.store_state(), "dirty")
def test_restart_clean(self):
"""Verify that we can re-start brokers one by one in a
@@ -426,7 +416,6 @@ class StoreTests(BrokerTest):
a.send_message("q", Message("x", durable=True))
a.send_message("q", Message("y", durable=True))
a.kill()
- time.sleep(0.1) # pause for b to write status.
b.kill()
a = cluster.start("a")
self.assertEqual(c.get_message("q").content, "x")
diff --git a/cpp/src/tests/testagent.mk b/cpp/src/tests/testagent.mk
index f5a84b07ff..cca380214f 100644
--- a/cpp/src/tests/testagent.mk
+++ b/cpp/src/tests/testagent.mk
@@ -36,7 +36,7 @@ TESTAGENT_GEN_SRC= \
$(TESTAGENT_GEN_SRC): testagent_gen.timestamp
-testagent_gen.timestamp: testagent.xml
+testagent_gen.timestamp: testagent.xml $(mgen_generator)
$(QMF_GEN) -o testagent_gen/qmf $(srcdir)/testagent.xml
touch testagent_gen.timestamp