From e4be6373770e2e639aec8ca25f076990b9823e94 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Tue, 23 Jan 2007 10:55:00 +0000 Subject: FailOver added flag FAIL_ONCE so that only the first call is stopped for failover.. the default. Updated POM with Failover Tests git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@498984 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/ping/AbstractPingProducer.java | 31 +++++++++++--- .../java/org/apache/qpid/ping/TestPingItself.java | 47 +++++++++++++--------- .../org/apache/qpid/ping/TestPingProducer.java | 13 ++++-- .../apache/qpid/requestreply/PingPongProducer.java | 26 ++++++------ .../java/org/apache/qpid/ping/PingTestPerf.java | 10 +++-- .../apache/qpid/requestreply/PingPongTestPerf.java | 4 +- 6 files changed, 85 insertions(+), 46 deletions(-) (limited to 'java/perftests/src') diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/AbstractPingProducer.java b/java/perftests/src/main/java/org/apache/qpid/ping/AbstractPingProducer.java index 4cca77a70e..999f4c9100 100644 --- a/java/perftests/src/main/java/org/apache/qpid/ping/AbstractPingProducer.java +++ b/java/perftests/src/main/java/org/apache/qpid/ping/AbstractPingProducer.java @@ -78,6 +78,7 @@ public abstract class AbstractPingProducer implements Runnable, ExceptionListene protected boolean _failAfterCommit = false; protected boolean _failBeforeSend = false; protected boolean _failAfterSend = false; + protected boolean _failOnce = true; protected int _sentMessages = 0; protected int _batchSize = 1; @@ -257,12 +258,28 @@ public abstract class AbstractPingProducer implements Runnable, ExceptionListene { if ((++_sentMessages % _batchSize) == 0) { + _logger.trace("Batch time reached"); + if (_failAfterSend) + { + if (_failOnce) + { + _failAfterSend = false; + } + _logger.trace("Failing After Send"); + doFailover(); + } + + if (session.getTransacted()) { try { if (_failBeforeCommit) { + if (_failOnce) + { + _failBeforeCommit = false; + } _logger.trace("Failing Before Commit"); doFailover(); } @@ -271,6 +288,10 @@ public abstract class AbstractPingProducer implements Runnable, ExceptionListene if (_failAfterCommit) { + if (_failOnce) + { + _failAfterCommit = false; + } _logger.trace("Failing After Commit"); doFailover(); } @@ -312,6 +333,10 @@ public abstract class AbstractPingProducer implements Runnable, ExceptionListene { if (_failBeforeSend) { + if (_failOnce) + { + _failBeforeSend = false; + } _logger.trace("Failing Before Send"); doFailover(); } @@ -325,11 +350,7 @@ public abstract class AbstractPingProducer implements Runnable, ExceptionListene _producer.send(q, message); } - if (_failAfterSend) - { - _logger.trace("Failing After Send"); - doFailover(); - } + commitTx(); } protected void doFailover(String broker) diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingItself.java b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingItself.java index 5a1ec691a7..6bfc2af541 100644 --- a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingItself.java +++ b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingItself.java @@ -38,6 +38,7 @@ public class TestPingItself extends PingPongProducer /** * This creates a client for pinging to a Queue. There will be one producer and one consumer instance. Consumer * listening to the same Queue, producer is sending to + * * @param brokerDetails * @param username * @param password @@ -57,17 +58,18 @@ public class TestPingItself extends PingPongProducer */ public TestPingItself(String brokerDetails, String username, String password, String virtualpath, String queueName, String selector, boolean transacted, boolean persistent, int messageSize, boolean verbose, - boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, + boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, boolean failOnce, int batchSize) throws Exception { super(brokerDetails, username, password, virtualpath, queueName, selector, transacted, persistent, messageSize, - verbose, afterCommit, beforeCommit, afterSend, beforeSend, batchSize, 0); + verbose, afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize, 0); } /** * This creats a client for tests with multiple queues. Creates as many consumer instances as there are queues, * each listening to a Queue. A producer is created which picks up a queue from the list of queues to send message. + * * @param brokerDetails * @param username * @param password @@ -87,12 +89,12 @@ public class TestPingItself extends PingPongProducer */ public TestPingItself(String brokerDetails, String username, String password, String virtualpath, String selector, boolean transacted, boolean persistent, int messageSize, boolean verbose, - boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, + boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, boolean failOnce, int batchSize, int queueCount) throws Exception { super(brokerDetails, username, password, virtualpath, null, null, transacted, persistent, messageSize, - verbose, afterCommit, beforeCommit, afterSend, beforeSend, batchSize, queueCount); + verbose, afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize, queueCount); createQueues(queueCount); @@ -117,7 +119,8 @@ public class TestPingItself extends PingPongProducer } /** - * Starts a ping-pong loop running from the command line. + * Starts a ping-pong loop running from the command line. + * * @param args The command line arguments as defined above. */ public static void main(String[] args) throws Exception @@ -145,6 +148,7 @@ public class TestPingItself extends PingPongProducer boolean beforeCommit = false; boolean afterSend = false; boolean beforeSend = false; + boolean failOnce = false; for (String arg : args) { @@ -165,6 +169,11 @@ public class TestPingItself extends PingPongProducer afterSend = parts[1].equals("after"); beforeSend = parts[1].equals("before"); } + if (parts[1].equals("once")) + { + failOnce = true; + } + } else { @@ -178,18 +187,18 @@ public class TestPingItself extends PingPongProducer if (queueCount > 1) { pingItself = new TestPingItself(brokerDetails, "guest", "guest", virtualpath, null, - transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, - batchSize, queueCount); + transacted, persistent, messageSize, verbose, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, + batchSize, queueCount); } else { pingItself = new TestPingItself(brokerDetails, "guest", "guest", virtualpath, queue, null, - transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, - batchSize); + transacted, persistent, messageSize, verbose, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, + batchSize); } - + pingItself.getConnection().start(); // Create a shutdown hook to terminate the ping-pong producer. @@ -225,13 +234,13 @@ public class TestPingItself extends PingPongProducer private static void usage() { System.err.println("Usage: TestPingPublisher \n" + - "-host : broker host" + - "-port : broker port" + - "-transacted : (true/false). Default is false" + - "-persistent : (true/false). Default is false" + - "-payload : paylaod size. Default is 0" + - "-queues : no of queues" + - "-messages : no of messages to be sent (if 0, the ping loop will run indefinitely)"); + "-host : broker host" + + "-port : broker port" + + "-transacted : (true/false). Default is false" + + "-persistent : (true/false). Default is false" + + "-payload : paylaod size. Default is 0" + + "-queues : no of queues" + + "-messages : no of messages to be sent (if 0, the ping loop will run indefinitely)"); System.exit(0); } } diff --git a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java index e53d7bb521..adf1c4dd9b 100644 --- a/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java +++ b/java/perftests/src/main/java/org/apache/qpid/ping/TestPingProducer.java @@ -88,7 +88,8 @@ class TestPingProducer extends AbstractPingProducer public TestPingProducer(String brokerDetails, String username, String password, String virtualpath, String queueName, boolean transacted, boolean persistent, int messageSize, boolean verbose, boolean afterCommit, - boolean beforeCommit, boolean afterSend, boolean beforeSend,int batchSize) throws Exception + boolean beforeCommit, boolean afterSend, boolean beforeSend, boolean failOnce, + int batchSize) throws Exception { // Create a connection to the broker. InetAddress address = InetAddress.getLocalHost(); @@ -115,6 +116,7 @@ class TestPingProducer extends AbstractPingProducer _failBeforeSend = beforeSend; _sentMessages = 0; _batchSize = batchSize; + _failOnce = failOnce; } /** @@ -129,7 +131,7 @@ class TestPingProducer extends AbstractPingProducer if (args.length < 2) { System.err.println( - "Usage: TestPingPublisher "+ + "Usage: TestPingPublisher " + "[ "); System.exit(0); } @@ -147,6 +149,7 @@ class TestPingProducer extends AbstractPingProducer boolean beforeCommit = false; boolean afterSend = false; boolean beforeSend = false; + boolean failOnce = false; for (String arg : args) { @@ -167,6 +170,10 @@ class TestPingProducer extends AbstractPingProducer afterSend = parts[1].equals("after"); beforeSend = parts[1].equals("before"); } + if (parts[1].equals("once")) + { + failOnce = true; + } } else { @@ -178,7 +185,7 @@ class TestPingProducer extends AbstractPingProducer // Create a ping producer to generate the pings. _pingProducer = new TestPingProducer(brokerDetails, "guest", "guest", virtualpath, PING_QUEUE_NAME, transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize); // Start the connection running. diff --git a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java index 3c3e31dd55..c0a041037d 100644 --- a/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java +++ b/java/perftests/src/main/java/org/apache/qpid/requestreply/PingPongProducer.java @@ -145,7 +145,7 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, private PingPongProducer(String brokerDetails, String username, String password, String virtualpath, boolean transacted, boolean persistent, int messageSize, boolean verbose, - boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, + boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, boolean failOnce, int batchSize) throws Exception { @@ -168,6 +168,7 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, _failBeforeCommit = beforeCommit; _failAfterSend = afterSend; _failBeforeSend = beforeSend; + _failOnce = failOnce; _batchSize = batchSize; _sentMessages = 0; } @@ -184,12 +185,12 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, */ public PingPongProducer(String brokerDetails, String username, String password, String virtualpath, String queueName, String selector, boolean transacted, boolean persistent, int messageSize, boolean verbose, - boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, + boolean afterCommit, boolean beforeCommit, boolean afterSend, boolean beforeSend, boolean failOnce, int batchSize, int queueCount) throws Exception { this(brokerDetails, username, password, virtualpath, transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, batchSize); + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize); if (queueName != null) { @@ -311,16 +312,18 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, int messageSize = (args.length >= 6) ? Integer.parseInt(args[5]) : DEFAULT_MESSAGE_SIZE; int batchSize = (args.length >= 7) ? Integer.parseInt(args[6]) : 1; + boolean afterCommit = false; boolean beforeCommit = false; boolean afterSend = false; boolean beforeSend = false; + boolean failOnce = false; for (String arg : args) { if (arg.startsWith("failover:")) { - //failover:: + //failover:: | failover:once String[] parts = arg.split(":"); if (parts.length == 3) { @@ -335,6 +338,10 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, afterSend = parts[1].equals("after"); beforeSend = parts[1].equals("before"); } + if (parts[1].equals("once")) + { + failOnce = true; + } } else { @@ -346,7 +353,7 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, // Create a ping producer to handle the request/wait/reply cycle. _pingProducer = new PingPongProducer(brokerDetails, "guest", "guest", virtualpath, PING_QUEUE_NAME, null, transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize, 0); _pingProducer.getConnection().start(); @@ -382,8 +389,6 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, sendMessage(first); - commitTx(); - try { Thread.sleep(100); @@ -482,10 +487,6 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, } } - // Commit the transaction if running in transactional mode. This must happen now, rather than at the end of - // this method, as the message will not be sent until the transaction is committed. - commitTx(); - // Keep the messageId to correlate with the reply. //String messageId = message.getJMSMessageID(); if (_verbose) @@ -556,9 +557,6 @@ public class PingPongProducer extends AbstractPingProducer implements Runnable, _logger.info(timestampFormatter.format(new Date()) + ": Pinged at."); } } - - // Commit the transaction if running in transactional mode, to force the send now. - commitTx(); } /** diff --git a/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java b/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java index e416d31031..446888f8c1 100644 --- a/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java +++ b/java/perftests/src/test/java/org/apache/qpid/ping/PingTestPerf.java @@ -122,7 +122,7 @@ public class PingTestPerf extends AsymptoticTestCase //implements TimingControll private static final String FAIL_AFTER_SEND = "FailAfterSend"; private static final String FAIL_BEFORE_SEND = "FailBeforeSend"; private static final String BATCH_SIZE = "BatchSize"; - + private static final String FAIL_ONCE = "FailOnce"; /** @@ -147,6 +147,7 @@ public class PingTestPerf extends AsymptoticTestCase //implements TimingControll setSystemPropertyIfNull(FAIL_BEFORE_COMMIT, "false"); setSystemPropertyIfNull(FAIL_AFTER_SEND, "false"); setSystemPropertyIfNull(FAIL_BEFORE_SEND, "false"); + setSystemPropertyIfNull(FAIL_ONCE, "true"); setSystemPropertyIfNull(BATCH_SIZE, Integer.toString(BATCH_SIZE_DEFAULT)); setSystemPropertyIfNull(MESSAGE_SIZE_PROPNAME, Integer.toString(MESSAGE_SIZE_DEFAULT)); @@ -156,7 +157,7 @@ public class PingTestPerf extends AsymptoticTestCase //implements TimingControll setSystemPropertyIfNull(BROKER_PROPNAME, BROKER_DEFAULT); setSystemPropertyIfNull(VIRTUAL_PATH_PROPNAME, VIRTUAL_PATH_DEFAULT); setSystemPropertyIfNull(TIMEOUT_PROPNAME, Long.toString(TIMEOUT_DEFAULT)); - setSystemPropertyIfNull(PING_QUEUE_COUNT_PROPNAME, Integer.toString(1)); + setSystemPropertyIfNull(PING_QUEUE_COUNT_PROPNAME, Integer.toString(1)); } /** @@ -246,6 +247,7 @@ public class PingTestPerf extends AsymptoticTestCase //implements TimingControll boolean beforeCommit = Boolean.parseBoolean(testParameters.getProperty(FAIL_BEFORE_COMMIT)); boolean afterSend = Boolean.parseBoolean(testParameters.getProperty(FAIL_AFTER_SEND)); boolean beforeSend = Boolean.parseBoolean(testParameters.getProperty(FAIL_BEFORE_SEND)); + boolean failOnce = Boolean.parseBoolean(testParameters.getProperty(FAIL_ONCE)); int batchSize = Integer.parseInt(testParameters.getProperty(BATCH_SIZE)); @@ -256,7 +258,7 @@ public class PingTestPerf extends AsymptoticTestCase //implements TimingControll perThreadSetup._pingItselfClient = new TestPingItself(brokerDetails, username, password, virtualpath, selector, transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize, queueCount); } else @@ -265,7 +267,7 @@ public class PingTestPerf extends AsymptoticTestCase //implements TimingControll perThreadSetup._pingItselfClient = new TestPingItself(brokerDetails, username, password, virtualpath, queueName, selector, transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize); } diff --git a/java/perftests/src/test/java/org/apache/qpid/requestreply/PingPongTestPerf.java b/java/perftests/src/test/java/org/apache/qpid/requestreply/PingPongTestPerf.java index 3e1035ce05..df0508c881 100644 --- a/java/perftests/src/test/java/org/apache/qpid/requestreply/PingPongTestPerf.java +++ b/java/perftests/src/test/java/org/apache/qpid/requestreply/PingPongTestPerf.java @@ -136,6 +136,7 @@ public class PingPongTestPerf extends AsymptoticTestCase //implements TimingCont private static final String FAIL_AFTER_SEND = "FailAfterSend"; private static final String FAIL_BEFORE_SEND = "FailBeforeSend"; private static final String BATCH_SIZE = "BatchSize"; + private static final String FAIL_ONCE = "FailOnce"; public PingPongTestPerf(String name) @@ -221,6 +222,7 @@ public class PingPongTestPerf extends AsymptoticTestCase //implements TimingCont boolean afterSend = Boolean.parseBoolean(testParameters.getProperty(FAIL_AFTER_SEND)); boolean beforeSend = Boolean.parseBoolean(testParameters.getProperty(FAIL_BEFORE_SEND)); int batchSize = Integer.parseInt(testParameters.getProperty(BATCH_SIZE)); + Boolean failOnce = Boolean.parseBoolean(testParameters.getProperty(FAIL_ONCE)); // Establish a bounce back client on the ping queue to bounce back the pings. perThreadSetup._testPingBouncer = new PingPongBouncer(brokerDetails, username, password, virtualpath, queueName, @@ -233,7 +235,7 @@ public class PingPongTestPerf extends AsymptoticTestCase //implements TimingCont perThreadSetup._testPingProducer = new PingPongProducer(brokerDetails, username, password, virtualpath, queueName, selector, transacted, persistent, messageSize, verbose, - afterCommit, beforeCommit, afterSend, beforeSend, + afterCommit, beforeCommit, afterSend, beforeSend, failOnce, batchSize, 0); perThreadSetup._testPingProducer.getConnection().start(); -- cgit v1.2.1