diff options
author | Benoit Foucher <benoit@zeroc.com> | 2016-11-25 13:13:22 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2016-11-25 13:13:22 +0100 |
commit | dcdc32af1fced49d80a8ccd93230e15d91ab45d8 (patch) | |
tree | eb69e2555fbd54496fce8a33f4dd610e1473ff51 /cpp/test/IceStorm/federation2 | |
parent | C# IceSSL/configuration log expired certificate exceptions. (diff) | |
download | ice-dcdc32af1fced49d80a8ccd93230e15d91ab45d8.tar.bz2 ice-dcdc32af1fced49d80a8ccd93230e15d91ab45d8.tar.xz ice-dcdc32af1fced49d80a8ccd93230e15d91ab45d8.zip |
Refactored test scripts
Diffstat (limited to 'cpp/test/IceStorm/federation2')
-rw-r--r-- | cpp/test/IceStorm/federation2/0.db/.gitignore | 1 | ||||
-rw-r--r-- | cpp/test/IceStorm/federation2/Publisher.cpp | 9 | ||||
-rw-r--r-- | cpp/test/IceStorm/federation2/Subscriber.cpp | 4 | ||||
-rwxr-xr-x | cpp/test/IceStorm/federation2/run.py | 275 | ||||
-rw-r--r-- | cpp/test/IceStorm/federation2/test.py | 196 |
5 files changed, 203 insertions, 282 deletions
diff --git a/cpp/test/IceStorm/federation2/0.db/.gitignore b/cpp/test/IceStorm/federation2/0.db/.gitignore deleted file mode 100644 index 72e8ffc0db8..00000000000 --- a/cpp/test/IceStorm/federation2/0.db/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/cpp/test/IceStorm/federation2/Publisher.cpp b/cpp/test/IceStorm/federation2/Publisher.cpp index 8daf34a8297..c07f3df88c5 100644 --- a/cpp/test/IceStorm/federation2/Publisher.cpp +++ b/cpp/test/IceStorm/federation2/Publisher.cpp @@ -12,6 +12,7 @@ #include <Ice/Ice.h> #include <IceStorm/IceStorm.h> #include <Event.h> +#include <TestCommon.h> using namespace std; using namespace Ice; @@ -60,7 +61,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; - + } EventPrx eventFed1 = EventPrx::uncheckedCast(fed1->getPublisher()->ice_oneway()); @@ -71,7 +72,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator) { count = atoi(arg.c_str()); } - + while(true) { for(int i = 0; i < 10; ++i) @@ -100,10 +101,10 @@ main(int argc, char* argv[]) { int status; CommunicatorPtr communicator; - + InitializationData initData = getTestInitData(argc, argv); try { - communicator = initialize(argc, argv); + communicator = initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Exception& ex) diff --git a/cpp/test/IceStorm/federation2/Subscriber.cpp b/cpp/test/IceStorm/federation2/Subscriber.cpp index 28e006f7bf9..6bce9c9d84d 100644 --- a/cpp/test/IceStorm/federation2/Subscriber.cpp +++ b/cpp/test/IceStorm/federation2/Subscriber.cpp @@ -189,10 +189,10 @@ main(int argc, char* argv[]) { int status; CommunicatorPtr communicator; - + InitializationData initData = getTestInitData(argc, argv); try { - communicator = initialize(argc, argv); + communicator = initialize(argc, argv, initData); status = run(argc, argv, communicator); } catch(const Exception& ex) diff --git a/cpp/test/IceStorm/federation2/run.py b/cpp/test/IceStorm/federation2/run.py deleted file mode 100755 index f479c7b411c..00000000000 --- a/cpp/test/IceStorm/federation2/run.py +++ /dev/null @@ -1,275 +0,0 @@ -#!/usr/bin/env python -# ********************************************************************** -# -# Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. -# -# This copy of Ice is licensed to you under the terms described in the -# ICE_LICENSE file included in this distribution. -# -# ********************************************************************** - -import os, sys, time, threading, re - -path = [ ".", "..", "../..", "../../..", "../../../.." ] -head = os.path.dirname(sys.argv[0]) -if len(head) > 0: - path = [os.path.join(head, p) for p in path] -path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] -if len(path) == 0: - raise RuntimeError("can't find toplevel directory!") -sys.path.append(os.path.join(path[0], "scripts")) -import TestUtil, IceStormUtil, Expect - -iceStormAdmin = os.path.join(TestUtil.getCppBinDir(), "icestormadmin") - -publisher = os.path.join(os.getcwd(), TestUtil.getTestExecutable("publisher")) -subscriber = os.path.join(os.getcwd(), TestUtil.getTestExecutable("subscriber")) - -targets = [] -if TestUtil.appverifier: - targets = [TestUtil.getIceBox(), publisher, subscriber, TestUtil.getIceBoxAdmin(), TestUtil.getIceStormAdmin()] - TestUtil.setAppVerifierSettings(targets, cwd = os.getcwd()) - -def admin(ref, command): - proc = TestUtil.startClient(iceStormAdmin, ref + ' -e "%s"' % command, echo = False) - proc.waitTestSuccess() - return proc.buf - -def runPublisher(icestorm1, opt = ""): - proc = TestUtil.startClient(publisher, opt + icestorm1.reference()) - proc.waitTestSuccess() - -def doTest(icestorm1, icestorm2, batch, subscriberRef = None): - if batch: - name = "batch subscriber" - batchOptions = " -b" - else: - name = "subscriber" - batchOptions = "" - - if subscriberRef == None: - subscriberRef = icestorm2.reference() - - subscriberProc = TestUtil.startServer(subscriber, batchOptions + subscriberRef) - - # - # Start the publisher. This should publish events which eventually - # causes subscriber to terminate. - # - runPublisher(icestorm1) - - subscriberProc.waitTestSuccess() - -# -# Test #1: -# -# create a cross service link fed1->fed2 and ensure the events are -# published between them correctly. -# -def runtest(type, **args): - icestorm1 = IceStormUtil.init(TestUtil.toplevel, os.getcwd(), type, additional = '--IceStorm.Discard.Interval=2', - dbDir = "db", instanceName = "TestIceStorm1", port = 12000, **args) - icestorm1.start() - icestorm2 = IceStormUtil.init(TestUtil.toplevel, os.getcwd(), type, additional = '--IceStorm.Discard.Interval=2', - dbDir = "db2", instanceName = "TestIceStorm2", port = 12500, **args) - icestorm2.start() - - adminIceStormReference = ' --IceStormAdmin.TopicManager.Proxy="%s" --IceStormAdmin.TopicManager.Proxy2="%s"' % ( - icestorm1.proxy(), icestorm2.proxy()) - - sys.stdout.write("setting up the topics... ") - sys.stdout.flush() - admin(adminIceStormReference, "create TestIceStorm1/fed1 TestIceStorm2/fed1; link TestIceStorm1/fed1 TestIceStorm2/fed1") - print("ok") - - # - # Test oneway subscribers. - # - sys.stdout.write("testing federation with oneway subscribers... ") - sys.stdout.flush() - doTest(icestorm1, icestorm2, 0) - print("ok") - - # - # Test batch oneway subscribers. - # - sys.stdout.write("testing federation with batch subscribers... ") - sys.stdout.flush() - doTest(icestorm1, icestorm2, 1) - print("ok") - - # - # Test #2: - # - # Stop and restart the service and repeat the test. This ensures that - # the database is correct. - # - sys.stdout.write("restarting services to ensure that the database content is preserved... ") - sys.stdout.flush() - - # - # Shutdown icestorm. - # - icestorm1.stop() - icestorm2.stop() - - icestorm1.start(echo=False) - icestorm2.start(echo=False) - print("ok") - - # - # Test oneway subscribers. - # - sys.stdout.write("retesting federation with oneway subscribers... ") - sys.stdout.flush() - doTest(icestorm1, icestorm2, 0) - print("ok") - - # - # Test batch oneway subscribers. - # - sys.stdout.write("retesting federation with batch subscribers... ") - sys.stdout.flush() - doTest(icestorm1, icestorm2, 1) - print("ok") - - # - # Shutdown icestorm. - # - icestorm1.stop() - icestorm2.stop() - - # - # Restart the first server and publish some events. Attach a - # subscriber to the channel and make sure the events are received. - # - # Then re-start the linked downstream server and publish the events. - # Ensure they are received by the linked server. - # - if type != "replicated": - sys.stdout.write("restarting only one IceStorm server... ") - sys.stdout.flush() - proc = icestorm1.start(echo=False) - - #proc.expect("topic.fed1.*subscriber offline") - #proc.expect("connection refused") - print("ok") - - # - # Test oneway subscribers. - # - sys.stdout.write("testing that the federation link reports an error... ") - sys.stdout.flush() - doTest(icestorm1, icestorm2, 0, icestorm1.reference()) - - # Give some time for the output to be sent. - time.sleep(2) - - proc.expect("topic.fed1.*subscriber offline") - print("ok") - - sys.stdout.write("starting downstream icestorm server... ") - sys.stdout.flush() - icestorm2.start(echo=False) - print("ok") - - # - # Need to sleep for at least the discard interval. - # - time.sleep(3) - - # - # Test oneway subscribers. - # - sys.stdout.write("testing link is reestablished... ") - sys.stdout.flush() - doTest(icestorm1, icestorm2, 0) - print("ok") - - try: - proc.expect("topic.fed1.*subscriber offline") - assert False - except Expect.TIMEOUT: - pass - - icestorm1.stop() - icestorm2.stop() - - # - # Test #4: - # - # Trash the TestIceStorm2 database. Then restart the servers and - # verify that the link is removed. - # - sys.stdout.write("destroying the downstream IceStorm service database... ") - sys.stdout.flush() - icestorm2.clean() - - print("ok") - - sys.stdout.write("restarting IceStorm servers... ") - sys.stdout.flush() - icestorm1.start(echo = False) - icestorm2.start(echo = False) - print("ok") - - sys.stdout.write("checking link still exists... ") - sys.stdout.flush() - line = admin(adminIceStormReference, "links TestIceStorm1") - if not re.compile("fed1 with cost 0").search(line): - print(line) - sys.exit(1) - print("ok") - - sys.stdout.write("publishing some events... ") - sys.stdout.flush() - # The publisher must be run twice because all the events can be - # sent out in one batch to the linked subscriber which means that - # the link is not reaped until the next batch is - # sent. Furthermore, with a replicated IceStorm both sets of - # events must be set to the same replica. - runPublisher(icestorm1, opt = " --count 2") - print("ok") - - # Give the unsubscription time to propagate. - time.sleep(1) - - # Verify that the link has disappeared. - sys.stdout.write("verifying that the link has been destroyed... ") - sys.stdout.flush() - line = admin(adminIceStormReference, "links TestIceStorm1") - nRetry = 5 - while len(line) > 0 and nRetry > 0: - line = admin(adminIceStormReference, "links TestIceStorm1") - time.sleep(1) # Give more time for unsubscription to propagate. - nRetry -= 1 - if len(line) > 0: - print(line) - sys.exit(1) - print("ok") - - # - # Destroy the remaining topic. - # - sys.stdout.write("destroying topics... ") - sys.stdout.flush() - admin(adminIceStormReference, "destroy TestIceStorm1/fed1") - print("ok") - - # - # Shutdown icestorm. - # - sys.stdout.write("shutting down icestorm services... ") - sys.stdout.flush() - icestorm1.stop() - icestorm2.stop() - print("ok") - -runtest("persistent") -runtest("replicated", replicatedPublisher = False) -runtest("replicated", replicatedPublisher = True) - -if TestUtil.appverifier: - TestUtil.appVerifierAfterTestEnd(targets, cwd = os.getcwd()) - -sys.exit(0) diff --git a/cpp/test/IceStorm/federation2/test.py b/cpp/test/IceStorm/federation2/test.py new file mode 100644 index 00000000000..5ac2f315555 --- /dev/null +++ b/cpp/test/IceStorm/federation2/test.py @@ -0,0 +1,196 @@ +# -*- coding: utf-8 -*- +# ********************************************************************** +# +# Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +# +# Publisher/subscriber test cases, publisher publishes on TestIceStorm1 instance(s) and +# the subscriber subscribes to the TestIceStorm2 instance(s) +# +pub1Sub2Oneway=ClientServerTestCase(client=Publisher("TestIceStorm1"), server=Subscriber("TestIceStorm2")) +pub1Sub2Batch=ClientServerTestCase(client=Publisher("TestIceStorm1"), server=Subscriber("TestIceStorm2", args=["-b"])) + +pub1Sub1Oneway=ClientServerTestCase(client=Publisher("TestIceStorm1"), server=Subscriber("TestIceStorm1")) + +class IceStormFederation2TestCase(IceStormTestCase): + + def runClientSide(self, current): + + current.write("setting up the topics... ") + self.runadmin(current, "create TestIceStorm1/fed1 TestIceStorm2/fed1; link TestIceStorm1/fed1 TestIceStorm2/fed1") + current.writeln("ok") + + # + # Test oneway subscribers. + # + current.write("testing federation with oneway subscribers... ") + pub1Sub2Oneway.run(current) + current.writeln("ok") + + # + # Test batch oneway subscribers. + # + current.write("testing federation with batch subscribers... ") + pub1Sub2Batch.run(current) + current.writeln("ok") + + # + # Test #2: + # + # Stop and restart the service and repeat the test. This ensures that + # the database is correct. + # + current.write("restarting services to ensure that the database content is preserved... ") + self.restartIceStorm(current) + current.writeln("ok") + + # + # Test oneway subscribers. + # + current.write("retesting federation with oneway subscribers... ") + pub1Sub2Oneway.run(current) + current.writeln("ok") + + # + # Test batch oneway subscribers. + # + current.write("retesting federation with batch subscribers... ") + pub1Sub2Batch.run(current) + current.writeln("ok") + + # + # Shutdown icestorm. + # + self.stopIceStorm(current) + + icestorm1 = [icestorm for icestorm in self.icestorm if icestorm.getInstanceName() == "TestIceStorm1"] + icestorm2 = [icestorm for icestorm in self.icestorm if icestorm.getInstanceName() == "TestIceStorm2"] + + # + # Restart the first server and publish some events. Attach a + # subscriber to the channel and make sure the events are received. + # + # Then re-start the linked downstream server and publish the events. + # Ensure they are received by the linked server. + # + if self.getName().find("replicated") == -1: + + current.write("restarting only one IceStorm server... ") + icestorm1[0].start(current) + current.writeln("ok") + + # + # Test oneway subscribers. + # + current.write("testing that the federation link reports an error... ") + pub1Sub1Oneway.run(current) + + # Give some time for the output to be sent. + time.sleep(2) + + icestorm1[0].expect("topic.fed1.*subscriber offline") + current.writeln("ok") + + current.write("starting downstream icestorm server... ") + icestorm2[0].start(current) + current.writeln("ok") + + # + # Need to sleep for at least the discard interval. + # + time.sleep(3) + + # + # Test oneway subscribers. + # + current.write("testing link is reestablished... ") + pub1Sub2Oneway.run(current) + current.writeln("ok") + + try: + icestorm1[0].expect("topic.fed1.*subscriber offline", timeout=1) + assert False + except Expect.TIMEOUT: + pass + + self.stopIceStorm(current) + + # + # Test #4: + # + # Trash the TestIceStorm2 database. Then restart the servers and + # verify that the link is removed. + # + current.write("destroying the downstream IceStorm service database... ") + for s in icestorm2: + s.teardown(current, True) + s.setup(current) + + current.writeln("ok") + + current.write("restarting IceStorm servers... ") + self.startIceStorm(current) + current.writeln("ok") + + current.write("checking link still exists... ") + line = self.runadmin(current, "links TestIceStorm1", quiet=True) + if not re.compile("fed1 with cost 0").search(line): + raise RuntimeError("unexpected output (`{0}')".format(line)) + current.writeln("ok") + + current.write("publishing some events... ") + # The publisher must be run twice because all the events can be + # sent out in one batch to the linked subscriber which means that + # the link is not reaped until the next batch is + # sent. Furthermore, with a replicated IceStorm both sets of + # events must be set to the same replica. + Publisher("TestIceStorm1", args=["--count", 2]).run(current) + current.writeln("ok") + + # Give the unsubscription time to propagate. + time.sleep(1) + + # Verify that the link has disappeared. + current.write("verifying that the link has been destroyed... ") + line = self.runadmin(current, "links TestIceStorm1") + nRetry = 5 + while len(line) > 0 and nRetry > 0: + line = self.runadmin(current, "links TestIceStorm1") + time.sleep(1) # Give more time for unsubscription to propagate. + nRetry -= 1 + if len(line) > 0: + raise RuntimeError("unexpected output (`{0}')".format(line)) + current.writeln("ok") + + # + # Destroy the remaining topic. + # + current.write("destroying topics... ") + self.runadmin(current, "destroy TestIceStorm1/fed1links TestIceStorm1", quiet=True) + current.writeln("ok") + + self.stopIceStorm(current) + +# Override ReplicatedPublishEndpoints property to empty for testing without replicated publisher +props = { 'IceStorm.Discard.Interval' : 2 } +nonRepProps = { 'IceStorm.Discard.Interval' : 2, 'IceStorm.ReplicatedPublishEndpoints' : '' } + +TestSuite(__file__, [ + + IceStormFederation2TestCase("persistent", icestorm= + [IceStorm("TestIceStorm1", quiet=True, props=props), + IceStorm("TestIceStorm2", quiet=True,portnum=20, props=props)]), + + IceStormFederation2TestCase("replicated with non-replicated publisher", icestorm= + [IceStorm("TestIceStorm1", i, 3, quiet=True, props=nonRepProps) for i in range(0,3)] + + [IceStorm("TestIceStorm2", i, 3, quiet=True, portnum=20, props=nonRepProps) for i in range(0,3)]), + + IceStormFederation2TestCase("replicated with replicated publisher", icestorm= + [IceStorm("TestIceStorm1", i, 3, quiet=True, props=props) for i in range(0,3)] + + [IceStorm("TestIceStorm2", i, 3, quiet=True, portnum=20, props=props) for i in range(0,3)]), +], multihost=False) |