You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2007/04/05 14:19:32 UTC
svn commit: r525804 -
/incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
Author: ritchiem
Date: Thu Apr 5 05:19:31 2007
New Revision: 525804
URL: http://svn.apache.org/viewvc?view=rev&rev=525804
Log:
QPID-308 Updated HeapExhaustion to be able to be run from command line
Modified:
incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
Modified: incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java?view=diff&rev=525804&r1=525803&r2=525804
==============================================================================
--- incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java (original)
+++ incubator/qpid/branches/M2/java/systests/src/main/java/org/apache/qpid/server/failure/HeapExhaustion.java Thu Apr 5 05:19:31 2007
@@ -2,11 +2,20 @@
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 @@
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 @@
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 @@
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 @@
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();
}
}