diff options
author | Martin Ritchie <ritchiem@apache.org> | 2007-04-05 12:19:31 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2007-04-05 12:19:31 +0000 |
commit | b5ccce73d4e874ae1c44c92b4f9b2660d6fb5edb (patch) | |
tree | 87a4ba580a98b16db33daf8b05f167fbf30fc185 | |
parent | 720a8868ba50ce4fc61cf666c71750d7af933e42 (diff) | |
download | qpid-python-b5ccce73d4e874ae1c44c92b4f9b2660d6fb5edb.tar.gz |
QPID-308 Updated HeapExhaustion to be able to be run from command line
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@525804 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java | 149 |
1 files changed, 135 insertions, 14 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java index c3a0e0d47b..52eb5414ff 100644 --- a/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java +++ b/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java @@ -2,11 +2,20 @@ package org.apache.qpid.server.failure; import junit.framework.TestCase; import org.apache.qpid.testutil.QpidClientConnection; +import org.apache.qpid.client.failover.FailoverException; +import org.apache.qpid.AMQException; +import org.apache.qpid.protocol.AMQConstant; +import org.apache.log4j.Logger; + +import javax.jms.JMSException; +import java.io.IOException; /** Test Case provided by client Non-functional Test NF101: heap exhaustion behaviour */ public class HeapExhaustion extends TestCase { + private static final Logger _logger = Logger.getLogger(HeapExhaustion.class); + protected QpidClientConnection conn; protected final String BROKER = "localhost"; protected final String vhost = "/test"; @@ -15,11 +24,6 @@ public class HeapExhaustion extends TestCase protected String hundredK; protected String megabyte; - protected void log(String msg) - { - System.out.println(msg); - } - protected String generatePayloadOfSize(Integer numBytes) { return new String(new byte[numBytes]); @@ -27,28 +31,27 @@ public class HeapExhaustion extends TestCase protected void setUp() throws Exception { - super.setUp(); conn = new QpidClientConnection(BROKER); conn.setVirtualHost(vhost); conn.connect(); // clear queue - log("setup: clearing test queue"); + _logger.debug("setup: clearing test queue"); conn.consume(queue, 2000); hundredK = generatePayloadOfSize(1024 * 100); megabyte = generatePayloadOfSize(1024 * 1024); } - @Override protected void tearDown() throws Exception { - super.tearDown(); conn.disconnect(); } - /** PUT at maximum rate (although we commit after each PUT) until failure + /** + * PUT at maximum rate (although we commit after each PUT) until failure + * * @throws Exception on error */ public void testUntilFailure() throws Exception @@ -62,12 +65,14 @@ public class HeapExhaustion extends TestCase conn.put(queue, payload, 1); copies++; total += size; - log("put copy " + copies + " OK for total bytes: " + total); + _logger.info("put copy " + copies + " OK for total bytes: " + total); } } - /** PUT at lower rate (5 per second) until failure - * @throws Exception on error + /** + * PUT at lower rate (5 per second) until failure + * + * @throws Exception on error */ public void testUntilFailureWithDelays() throws Exception { @@ -80,8 +85,124 @@ public class HeapExhaustion extends TestCase conn.put(queue, payload, 1); copies++; total += size; - log("put copy " + copies + " OK for total bytes: " + total); + _logger.debug("put copy " + copies + " OK for total bytes: " + total); Thread.sleep(200); } } + + public static void noDelay() + { + HeapExhaustion he = new HeapExhaustion(); + + try + { + he.setUp(); + } + catch (Exception e) + { + _logger.info("Unable to connect"); + System.exit(0); + } + + try + { + _logger.info("Running testUntilFailure"); + try + { + he.testUntilFailure(); + } + catch (FailoverException fe) + { + _logger.error("Caught failover:" + fe); + } + _logger.info("Finishing Connection "); + + try + { + he.tearDown(); + } + catch (JMSException jmse) + { + if (((AMQException) jmse.getLinkedException()).getErrorCode() == AMQConstant.REQUEST_TIMEOUT) + { + _logger.info("Successful test of testUntilFailure"); + } + else + { + _logger.error("Test Failed due to:" + jmse); + } + } + } + catch (Exception e) + { + _logger.error("Test Failed due to:" + e); + } + } + + public static void withDelay() + { + HeapExhaustion he = new HeapExhaustion(); + + try + { + he.setUp(); + } + catch (Exception e) + { + _logger.info("Unable to connect"); + System.exit(0); + } + + try + { + _logger.info("Running testUntilFailure"); + try + { + he.testUntilFailureWithDelays(); + } + catch (FailoverException fe) + { + _logger.error("Caught failover:" + fe); + } + _logger.info("Finishing Connection "); + + try + { + he.tearDown(); + } + catch (JMSException jmse) + { + if (((AMQException) jmse.getLinkedException()).getErrorCode() == AMQConstant.REQUEST_TIMEOUT) + { + _logger.info("Successful test of testUntilFailure"); + } + else + { + _logger.error("Test Failed due to:" + jmse); + } + } + } + catch (Exception e) + { + _logger.error("Test Failed due to:" + e); + } + } + + public static void main(String args[]) + { + noDelay(); + + + try + { + System.out.println("Restart failed broker now to retest broker with delays in send."); + System.in.read(); + } + catch (IOException e) + { + _logger.info("Continuing"); + } + + withDelay(); + } } |