summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/src/tests')
-rwxr-xr-xqpid/cpp/src/tests/ha_test.py16
-rwxr-xr-xqpid/cpp/src/tests/ha_tests.py13
-rw-r--r--qpid/cpp/src/tests/test_store.cpp24
3 files changed, 41 insertions, 12 deletions
diff --git a/qpid/cpp/src/tests/ha_test.py b/qpid/cpp/src/tests/ha_test.py
index 602a62ca17..cceb9795eb 100755
--- a/qpid/cpp/src/tests/ha_test.py
+++ b/qpid/cpp/src/tests/ha_test.py
@@ -265,16 +265,19 @@ acl allow all all
class HaCluster(object):
_cluster_count = 0
- def __init__(self, test, n, promote=True, wait=True, args=[], **kwargs):
+ def __init__(self, test, n, promote=True, wait=True, args=[], s_args=[], **kwargs):
"""Start a cluster of n brokers.
@test: The test being run
@n: start n brokers
@promote: promote self[0] to primary
@wait: wait for primary active and backups ready. Ignored if promote=False
+ @args: args for all brokers in the cluster.
+ @s_args: args for specific brokers: s_args[i] for broker i.
"""
self.test = test
self.args = args
+ self.s_args = s_args
self.kwargs = kwargs
self._ports = [HaPort(test) for i in xrange(n)]
self._set_url()
@@ -294,9 +297,12 @@ class HaCluster(object):
self.broker_id += 1
return name
- def _ha_broker(self, ha_port, name):
+ def _ha_broker(self, i, name):
+ args = self.args
+ if i < len(self.s_args): args += self.s_args[i]
+ ha_port = self._ports[i]
b = HaBroker(ha_port.test, ha_port, brokers_url=self.url, name=name,
- args=self.args, **self.kwargs)
+ args=args, **self.kwargs)
b.ready()
return b
@@ -308,7 +314,7 @@ class HaCluster(object):
self._ports.append(HaPort(self.test))
self._set_url()
self._update_urls()
- b = self._ha_broker(self._ports[i], self.next_name())
+ b = self._ha_broker(i, self.next_name())
self._brokers.append(b)
return b
@@ -334,7 +340,7 @@ class HaCluster(object):
a separate log file: foo.n.log"""
if self._ports[i].stopped: raise Exception("Restart after final kill: %s"%(self))
b = self._brokers[i]
- self._brokers[i] = self._ha_broker(self._ports[i], b.name)
+ self._brokers[i] = self._ha_broker(i, b.name)
self._brokers[i].ready()
def bounce(self, i, promote_next=True):
diff --git a/qpid/cpp/src/tests/ha_tests.py b/qpid/cpp/src/tests/ha_tests.py
index 55715639a4..e97614d785 100755
--- a/qpid/cpp/src/tests/ha_tests.py
+++ b/qpid/cpp/src/tests/ha_tests.py
@@ -1381,7 +1381,18 @@ class TransactionTests(BrokerTest):
self.assertEqual(open_read(cluster[0].store_log), expect)
self.assertEqual(open_read(cluster[1].store_log), expect)
-# FIXME aconway 2013-07-23: test with partial acknowledgement.
+ def test_tx_backup_fail(self):
+ # FIXME aconway 2013-07-31: check exception types, reduce timeout.
+ cluster = HaCluster(
+ self, 2, test_store=True, s_args=[[],["--test-store-throw=bang"]])
+ c = cluster[0].connect()
+ tx = c.session(transactional=True)
+ s = tx.sender("q;{create:always,node:{durable:true}}")
+ for m in ["foo","bang","bar"]: s.send(Message(m, durable=True))
+ self.assertRaises(Exception, tx.commit)
+ for b in cluster: b.assert_browse_backup("q", [])
+ self.assertEqual(open_read(cluster[0].store_log), "<begin tx 1>\n<abort tx=1>\n")
+ self.assertEqual(open_read(cluster[1].store_log), "<begin tx 1>\n<enqueue q foo tx=1>\n<enqueue q bang tx=1>\n<abort tx=1>\n")
if __name__ == "__main__":
outdir = "ha_tests.tmp"
diff --git a/qpid/cpp/src/tests/test_store.cpp b/qpid/cpp/src/tests/test_store.cpp
index fc44889f33..e299161c68 100644
--- a/qpid/cpp/src/tests/test_store.cpp
+++ b/qpid/cpp/src/tests/test_store.cpp
@@ -63,12 +63,18 @@ struct TestStoreOptions : public Options {
string name;
string dump;
string events;
+ vector<string> throwMsg; // Throw exception if message content matches.
TestStoreOptions() : Options("Test Store Options") {
addOptions()
- ("test-store-name", optValue(name, "NAME"), "Name of test store instance.")
- ("test-store-dump", optValue(dump, "FILE"), "File to dump enqueued messages.")
- ("test-store-events", optValue(events, "FILE"), "File to log events, 1 line per event.")
+ ("test-store-name", optValue(name, "NAME"),
+ "Name of test store instance.")
+ ("test-store-dump", optValue(dump, "FILE"),
+ "File to dump enqueued messages.")
+ ("test-store-events", optValue(events, "FILE"),
+ "File to log events, 1 line per event.")
+ ("test-store-throw", optValue(throwMsg, "CONTENT"),
+ "Throw exception if message content matches.")
;
}
};
@@ -91,7 +97,8 @@ class TestStore : public NullMessageStore {
{
QPID_LOG(info, "TestStore name=" << name
<< " dump=" << options.dump
- << " events=" << options.events);
+ << " events=" << options.events
+ << " throw messages =" << options.throwMsg.size());
if (!options.dump.empty())
dump.reset(new ofstream(options.dump.c_str()));
@@ -148,7 +155,8 @@ class TestStore : public NullMessageStore {
const PersistableQueue& queue)
{
QPID_LOG(debug, "TestStore enqueue " << queue.getName());
- qpid::broker::amqp_0_10::MessageTransfer* msg = dynamic_cast<qpid::broker::amqp_0_10::MessageTransfer*>(pmsg.get());
+ qpid::broker::amqp_0_10::MessageTransfer* msg =
+ dynamic_cast<qpid::broker::amqp_0_10::MessageTransfer*>(pmsg.get());
assert(msg);
ostringstream o;
@@ -170,7 +178,11 @@ class TestStore : public NullMessageStore {
string data = msg->getFrames().getContent();
size_t i = string::npos;
size_t j = string::npos;
- if (strncmp(data.c_str(), TEST_STORE_DO.c_str(), strlen(TEST_STORE_DO.c_str())) == 0
+ const vector<string>& throwMsg(options.throwMsg);
+ if (find(throwMsg.begin(), throwMsg.end(), data) != throwMsg.end()) {
+ throw Exception(QPID_MSG("TestStore " << name << " throwing exception for: " << data));
+ }
+ else if (strncmp(data.c_str(), TEST_STORE_DO.c_str(), strlen(TEST_STORE_DO.c_str())) == 0
&& (i = data.find(name+"[")) != string::npos
&& (j = data.find("]", i)) != string::npos)
{