diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/tests/brokertest.py | 28 | ||||
-rw-r--r-- | cpp/src/tests/cluster.mk | 2 | ||||
-rw-r--r-- | cpp/src/tests/cluster_tests.fail | 2 | ||||
-rwxr-xr-x | cpp/src/tests/cluster_tests.py | 47 | ||||
-rwxr-xr-x | cpp/src/tests/run_cluster_tests | 38 |
5 files changed, 82 insertions, 35 deletions
diff --git a/cpp/src/tests/brokertest.py b/cpp/src/tests/brokertest.py index c176024789..ec25201505 100644 --- a/cpp/src/tests/brokertest.py +++ b/cpp/src/tests/brokertest.py @@ -23,6 +23,7 @@ import os, signal, string, tempfile, popen2, socket, threading, time import qpid from qpid import connection, messaging, util +from qpid.compat import format_exc from qpid.harness import Skipped from unittest import TestCase from copy import copy @@ -141,7 +142,7 @@ class Broker(Popen): Popen.__init__(self, cmd, expect) try: self.port = int(self.stdout.readline()) except Exception: - raise Exception("Failed to start broker: "+self.cmd_str()) + raise Exception("Failed to start broker, log: "+self.log) test.cleanup_popen(self) self.host = "localhost" # Placeholder for remote brokers. @@ -162,6 +163,18 @@ class Broker(Popen): s.queue_declare(queue=queue) c.close() + def send_message(self, queue, message): + s = self.connect().session() + s.sender(queue+" {create:always}").send(message) + s.connection.close() + + def get_message(self, queue): + s = self.connect().session() + m = s.receiver(queue+" {create:always}", capacity=1).fetch(timeout=1) + s.acknowledge() + s.connection.close() + return m + class Cluster: """A cluster of brokers in a test.""" @@ -213,9 +226,12 @@ class BrokerTest(TestCase): qpidRoute_exec = os.getenv("QPID_ROUTE_EXEC") receiver_exec = os.getenv("RECEIVER_EXEC") sender_exec = os.getenv("SENDER_EXEC") + store_lib = os.getenv("STORE_LIB") + def configure(self, config): self.config=config + def setUp(self): - self.dir = os.path.join("brokertest.tmp", self.id()) + self.dir = os.path.join(self.config.defines["OUTDIR"], self.id()) os.makedirs(self.dir) self.popens = [] @@ -282,7 +298,7 @@ class Sender(StoppableThread): self.sender.stdin.write(str(self.sent)+"\n") self.sender.stdin.flush() self.sent += 1 - except Exception, e: self.error = e + except Exception, e: self.error = RethrownException(e) class Receiver(Thread): """ @@ -309,7 +325,7 @@ class Receiver(Thread): finally: self.lock.release() except Exception, e: - self.error = e + self.error = RethrownException(e) def stop(self, count): """Returns when received >= count""" @@ -319,3 +335,7 @@ class Receiver(Thread): self.join() if self.error: raise self.error +class RethrownException(Exception): + """Captures the original stack trace to be thrown later""" + def __init__(self, e): + Exception.__init__(self, format_exc()) diff --git a/cpp/src/tests/cluster.mk b/cpp/src/tests/cluster.mk index 5bc5795f76..9a907f9cce 100644 --- a/cpp/src/tests/cluster.mk +++ b/cpp/src/tests/cluster.mk @@ -79,6 +79,6 @@ cluster_test_SOURCES = \ cluster_test_LDADD=$(lib_client) $(lib_broker) -lboost_unit_test_framework -qpidtest_SCRIPTS += run_cluster_tests cluster_tests.py run_long_cluster_tests long_cluster_tests.py testlib.py brokertest.py +qpidtest_SCRIPTS += run_cluster_tests cluster_tests.py run_long_cluster_tests long_cluster_tests.py testlib.py brokertest.py cluster_tests.fail endif diff --git a/cpp/src/tests/cluster_tests.fail b/cpp/src/tests/cluster_tests.fail new file mode 100644 index 0000000000..ca445e3ee6 --- /dev/null +++ b/cpp/src/tests/cluster_tests.fail @@ -0,0 +1,2 @@ +cluster_tests.ClusterTests.test_failover + diff --git a/cpp/src/tests/cluster_tests.py b/cpp/src/tests/cluster_tests.py index e61d114713..682e25fbd3 100755 --- a/cpp/src/tests/cluster_tests.py +++ b/cpp/src/tests/cluster_tests.py @@ -23,6 +23,7 @@ from threading import Thread from brokertest import * from qpid import datatypes, messaging from qpid.harness import Skipped +from qpid.messaging import Message class ClusterTests(BrokerTest): @@ -47,7 +48,7 @@ class ClusterTests(BrokerTest): # Start member 2 and verify messages available. s2 = cluster.start().connect().session() m = s2.receiver("q", capacity=1).fetch(timeout=1) - s1.acknowledge() + s2.acknowledge() self.assertEqual("y", m.content) s2.connection.close() @@ -55,7 +56,6 @@ class ClusterTests(BrokerTest): """Test fail-over during continuous send-receive""" # FIXME aconway 2009-11-09: this test is failing, showing lost messages. # Enable when fixed - return # FIXME should be raise Skipped or negative test? # Original cluster will all be killed so expect exit with failure cluster = self.cluster(3, expect=EXPECT_EXIT_FAIL) @@ -75,3 +75,46 @@ class ClusterTests(BrokerTest): self.sender.stop() self.receiver.stop(self.sender.sent) + + +class ClusterStoreTests(BrokerTest): + """ + Cluster tests that can only be run if there is a store available. + """ + args = ["--load-module",BrokerTest.store_lib] + + def test_store_loaded(self): + """Ensure we are indeed loading a working store""" + broker = self.broker(self.args, name="recoverme", expect=EXPECT_EXIT_FAIL) + m = messaging.Message("x", durable=True) + broker.send_message("q", m) + broker.kill() + broker = self.broker(self.args, name="recoverme") + self.assertEqual("x", broker.get_message("q").content) + + def test_kill_restart(self): + """Verify we can kill/resetart a broker with store in a cluster""" + cluster = self.cluster(1, self.args) + cluster.start("restartme", expect=EXPECT_EXIT_FAIL).kill() + + # Send a message, retrieve from the restarted broker + cluster[0].send_message("q", "x") + m = cluster.start("restartme").get_message("q") + self.assertEqual("x", m.content) + + def test_total_shutdown(self): + """Test we use the correct store to recover after total shutdown""" + cluster = self.cluster(2, args=self.args, expect=EXPECT_EXIT_FAIL) + cluster[0].send_message("q", Message("a", durable=True)) + cluster[0].kill() + self.assertEqual("a", cluster[1].get_message("q").content) + cluster[1].send_message("q", Message("b", durable=True)) + cluster[1].kill() + + # Start 1 first, we should see its store used. + cluster.start(name=cluster.name+"-1") + cluster.start(name=cluster.name+"-0") + self.assertEqual("b", cluster[2].get_message("q").content) + + + diff --git a/cpp/src/tests/run_cluster_tests b/cpp/src/tests/run_cluster_tests index 71a1a1781b..9f9b6735f6 100755 --- a/cpp/src/tests/run_cluster_tests +++ b/cpp/src/tests/run_cluster_tests @@ -20,24 +20,11 @@ # absdir() { echo `cd $1; pwd`; } - srcdir=$(absdir $(dirname $0)) top_builddir=$(absdir ../..) . $srcdir/python_env.sh - -# Check AIS requirements -. $srcdir/ais_check - -# Check XML exchange requirements -XML_LIB=$srcdir/../.libs/xml.so -if [ -f ${XML_LIB} ]; then - export XML_LIB -fi - - -# Set up environment for python tests -export PYTHONPATH=${srcdir}:${PYTHON_DIR} +export PYTHONPATH=${srcdir}:${PYTHONPATH} export QPIDD_EXEC=${top_builddir}/src/qpidd export CLUSTER_LIB=${top_builddir}/src/.libs/cluster.so export QPID_CONFIG_EXEC=${srcdir}/../../../python/commands/qpid-config @@ -45,26 +32,21 @@ export QPID_ROUTE_EXEC=${srcdir}/../../../python/commands/qpid-route export RECEIVER_EXEC=${top_builddir}/src/tests/receiver export SENDER_EXEC=${top_builddir}/src/tests/sender +# Check XML exchange requirements +XML_LIB=$srcdir/../.libs/xml.so +test -f ${XML_LIB} && export XML_LIB -# Check for existence of qpid tools (either in svn tree or full install) -# This prevents make dist / make distcheck from failing without python tools being present -if test ! -x ${top_builddir}/../python/commands/qpid-config; then - path=`which qpid-config` - if test $?; then - echo "WARNING: qpid tools not found, skipping test ${CLUSTER_TEST}" - exit 0 - fi -fi +# Check AIS requirements +. $srcdir/ais_check # Delete old cluster test data OUTDIR=brokertest.tmp rm -rf $OUTDIR mkdir -p $OUTDIR -# FIXME aconway 2009-11-06: pass OUTDIR to test. +# Ignore tests requiring a store by default. +TESTS="-i cluster_tests.ClusterStoreTests.* -I $srcdir/cluster_tests.fail" -# Run the test -with_ais_group $PYTHON_COMMANDS/qpid-python-test -m cluster_tests -## || exit 1 -#rm -rf $OUTDIR +with_ais_group $PYTHON_COMMANDS/qpid-python-test -DOUTDIR=$OUTDIR -m cluster_tests $TESTS || exit 1 +rm -rf $OUTDIR #exit 0 |