Modified:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java
(original)
+++
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java
Thu Apr 24 10:49:03 2008
@@ -1,132 +1,132 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.testcases;
-
-import org.apache.qpid.test.framework.Circuit;
-import org.apache.qpid.test.framework.FrameworkBaseCase;
-import org.apache.qpid.test.framework.MessagingTestConfigProperties;
-import static org.apache.qpid.test.framework.MessagingTestConfigProperties.*;
-import org.apache.qpid.test.framework.sequencers.CircuitFactory;
-
-import org.apache.qpid.junit.extensions.util.ParsedProperties;
-import org.apache.qpid.junit.extensions.util.TestContextProperties;
-
-/**
- * RollbackTest tests the rollback ability of transactional messaging.
- *
- * <p/><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Check messages sent but rolled back are never received.
- * <tr><td> Check messages received but rolled back are redelivered on
subsequent receives.
- * <tr><td> Attempting to rollback outside of a transaction results in an
IllegalStateException.
- * </table>
- */
-public class RollbackTest extends FrameworkBaseCase
-{
- /** Used to read the tests configurable properties through. */
- ParsedProperties testProps;
-
- /**
- * Creates a new test case with the specified name.
- *
- * @param name The test case name.
- */
- public RollbackTest(String name)
- {
- super(name);
- }
-
- /** Check messages sent but rolled back are never received. */
- public void testRolledbackMessageNotDelivered()
- {
- // Ensure transactional sessions are on.
- testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
- testProps.setProperty(ROLLBACK_PUBLISHER_PROPNAME, true);
-
- // Run the default test sequence over the test circuit checking for no
errors.
- CircuitFactory circuitFactory = getCircuitFactory();
- Circuit testCircuit = circuitFactory.createCircuit(testProps);
-
- assertNoFailures(testCircuit.test(1,
-
assertionList(testCircuit.getPublisher().noExceptionsAssertion(testProps),
-
testCircuit.getReceiver().noMessagesReceivedAssertion(testProps))));
- }
-
- /** Check messages received but rolled back are redelivered on subsequent
receives. */
- public void testRolledbackMessagesSubsequentlyReceived()
- {
- // Ensure transactional sessions are on.
- testProps.setProperty(TRANSACTED_RECEIVER_PROPNAME, true);
- testProps.setProperty(ROLLBACK_RECEIVER_PROPNAME, true);
-
- // Run the default test sequence over the test circuit checking for no
errors.
- CircuitFactory circuitFactory = getCircuitFactory();
- Circuit testCircuit = circuitFactory.createCircuit(testProps);
-
- assertNoFailures(testCircuit.test(1,
-
assertionList(testCircuit.getPublisher().noExceptionsAssertion(testProps),
-
testCircuit.getReceiver().allMessagesReceivedAssertion(testProps))));
- }
-
- /** Attempting to rollback outside of a transaction results in an
IllegalStateException. */
- public void testRollbackUnavailableOutsideTransactionPublisher()
- {
- // Ensure transactional sessions are on.
- testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
- testProps.setProperty(ROLLBACK_PUBLISHER_PROPNAME, true);
-
- // Run the default test sequence over the test circuit checking for no
errors.
- CircuitFactory circuitFactory = getCircuitFactory();
- Circuit testCircuit = circuitFactory.createCircuit(testProps);
-
- assertNoFailures(testCircuit.test(1,
assertionList(testCircuit.getPublisher().channelClosedAssertion(testProps))));
- }
-
- /** Attempting to rollback outside of a transaction results in an
IllegalStateException. */
- public void testRollbackUnavailableOutsideTransactionReceiver()
- {
- // Ensure transactional sessions are on.
- testProps.setProperty(TRANSACTED_RECEIVER_PROPNAME, false);
- testProps.setProperty(ROLLBACK_RECEIVER_PROPNAME, true);
-
- // Run the default test sequence over the test circuit checking for no
errors.
- CircuitFactory circuitFactory = getCircuitFactory();
- Circuit testCircuit = circuitFactory.createCircuit(testProps);
-
- assertNoFailures(testCircuit.test(1,
assertionList(testCircuit.getReceiver().channelClosedAssertion(testProps))));
- }
-
- /**
- * Sets up all tests to have an active outward route and consumer by
default.
- *
- * @throws Exception Any exceptions are allowed to fall through and fail
the test.
- */
- protected void setUp() throws Exception
- {
- super.setUp();
-
- testProps =
TestContextProperties.getInstance(MessagingTestConfigProperties.defaults);
-
- /** Bind the receivers consumer by default. */
- testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, true);
- testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, true);
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.test.testcases;
+
+import org.apache.qpid.test.framework.Circuit;
+import org.apache.qpid.test.framework.FrameworkBaseCase;
+import org.apache.qpid.test.framework.MessagingTestConfigProperties;
+import static org.apache.qpid.test.framework.MessagingTestConfigProperties.*;
+import org.apache.qpid.test.framework.sequencers.CircuitFactory;
+
+import org.apache.qpid.junit.extensions.util.ParsedProperties;
+import org.apache.qpid.junit.extensions.util.TestContextProperties;
+
+/**
+ * RollbackTest tests the rollback ability of transactional messaging.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Check messages sent but rolled back are never received.
+ * <tr><td> Check messages received but rolled back are redelivered on
subsequent receives.
+ * <tr><td> Attempting to rollback outside of a transaction results in an
IllegalStateException.
+ * </table>
+ */
+public class RollbackTest extends FrameworkBaseCase
+{
+ /** Used to read the tests configurable properties through. */
+ ParsedProperties testProps;
+
+ /**
+ * Creates a new test case with the specified name.
+ *
+ * @param name The test case name.
+ */
+ public RollbackTest(String name)
+ {
+ super(name);
+ }
+
+ /** Check messages sent but rolled back are never received. */
+ public void testRolledbackMessageNotDelivered()
+ {
+ // Ensure transactional sessions are on.
+ testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
+ testProps.setProperty(ROLLBACK_PUBLISHER_PROPNAME, true);
+
+ // Run the default test sequence over the test circuit checking for no
errors.
+ CircuitFactory circuitFactory = getCircuitFactory();
+ Circuit testCircuit = circuitFactory.createCircuit(testProps);
+
+ assertNoFailures(testCircuit.test(1,
+
assertionList(testCircuit.getPublisher().noExceptionsAssertion(testProps),
+
testCircuit.getReceiver().noMessagesReceivedAssertion(testProps))));
+ }
+
+ /** Check messages received but rolled back are redelivered on subsequent
receives. */
+ public void testRolledbackMessagesSubsequentlyReceived()
+ {
+ // Ensure transactional sessions are on.
+ testProps.setProperty(TRANSACTED_RECEIVER_PROPNAME, true);
+ testProps.setProperty(ROLLBACK_RECEIVER_PROPNAME, true);
+
+ // Run the default test sequence over the test circuit checking for no
errors.
+ CircuitFactory circuitFactory = getCircuitFactory();
+ Circuit testCircuit = circuitFactory.createCircuit(testProps);
+
+ assertNoFailures(testCircuit.test(1,
+
assertionList(testCircuit.getPublisher().noExceptionsAssertion(testProps),
+
testCircuit.getReceiver().allMessagesReceivedAssertion(testProps))));
+ }
+
+ /** Attempting to rollback outside of a transaction results in an
IllegalStateException. */
+ public void testRollbackUnavailableOutsideTransactionPublisher()
+ {
+ // Ensure transactional sessions are on.
+ testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
+ testProps.setProperty(ROLLBACK_PUBLISHER_PROPNAME, true);
+
+ // Run the default test sequence over the test circuit checking for no
errors.
+ CircuitFactory circuitFactory = getCircuitFactory();
+ Circuit testCircuit = circuitFactory.createCircuit(testProps);
+
+ assertNoFailures(testCircuit.test(1,
assertionList(testCircuit.getPublisher().channelClosedAssertion(testProps))));
+ }
+
+ /** Attempting to rollback outside of a transaction results in an
IllegalStateException. */
+ public void testRollbackUnavailableOutsideTransactionReceiver()
+ {
+ // Ensure transactional sessions are on.
+ testProps.setProperty(TRANSACTED_RECEIVER_PROPNAME, false);
+ testProps.setProperty(ROLLBACK_RECEIVER_PROPNAME, true);
+
+ // Run the default test sequence over the test circuit checking for no
errors.
+ CircuitFactory circuitFactory = getCircuitFactory();
+ Circuit testCircuit = circuitFactory.createCircuit(testProps);
+
+ assertNoFailures(testCircuit.test(1,
assertionList(testCircuit.getReceiver().channelClosedAssertion(testProps))));
+ }
+
+ /**
+ * Sets up all tests to have an active outward route and consumer by
default.
+ *
+ * @throws Exception Any exceptions are allowed to fall through and fail
the test.
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ testProps =
TestContextProperties.getInstance(MessagingTestConfigProperties.defaults);
+
+ /** Bind the receivers consumer by default. */
+ testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, true);
+ testProps.setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, true);
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/RollbackTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java
(original)
+++
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java
Thu Apr 24 10:49:03 2008
@@ -1,151 +1,151 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.testcases;
-
-import org.apache.qpid.test.framework.Circuit;
-import org.apache.qpid.test.framework.FrameworkBaseCase;
-import static
org.apache.qpid.test.framework.MessagingTestConfigProperties.ACK_MODE_PROPNAME;
-import static
org.apache.qpid.test.framework.MessagingTestConfigProperties.PUBSUB_PROPNAME;
-import org.apache.qpid.test.framework.TestUtils;
-import org.apache.qpid.test.framework.localcircuit.LocalCircuitImpl;
-import org.apache.qpid.test.framework.sequencers.CircuitFactory;
-
-import javax.jms.*;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-
-/**
- * TTLTest checks that time-to-live is applied to messages. The test sends
messages with a variety of TTL stamps on them
- * then after a pause attempts to receive those messages. Only messages with a
large enough TTL to have survived the pause
- * should be receiveable. This test case also applies an additional assertion
against the broker, that the message store
- * is empty at the end of the test.
- *
- * <p/>This test is designed to run over local circuits only, as it must
control a timed pause between sending and receiving
- * messages to that TTL can be applied to purge some of the messages.
- *
- * <p/><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td>
- * </table>
- *
- * @todo Use an interface or other method to mark this test as local only.
- *
- * @todo Implement the message store assertion for in-vm broker. Could also be
done for external broker, for example
- * by using diagnostic exchange.
- *
- * @todo Implement and add a queue depth assertion too. This might already be
in another test to copy from.
- *
- * @todo Create variations on test theme, for different ack mode and tx and
message sizes etc.
- *
- * @todo Add an allowable margin of error to the test, as ttl may not be
precise.
- */
-public class TTLTest extends FrameworkBaseCase
-{
- /**
- * Creates a new test case with the specified name.
- *
- * @param name The test case name.
- */
- public TTLTest(String name)
- {
- super(name);
- }
-
- /**
- * Checks that all messages sent with a TTL shorter than a pause between
sending them and attempting to receive them
- * will fail to arrive. Once all messages have been purged by TTL or
received, check that they no longer exist on
- * the broker.
- *
- * @throws javax.jms.JMSException Allowed to fall through and fail test.
- */
- public void testTTLP2P() throws JMSException
- {
- String errorMessages = "";
- Random r = new Random();
-
- // Used to accumulate correctly received messages in.
- List<Message> receivedMessages = new LinkedList<Message>();
-
- // Set up the test properties to match the test case requirements.
- testProps.setProperty(ACK_MODE_PROPNAME, Session.AUTO_ACKNOWLEDGE);
- testProps.setProperty(PUBSUB_PROPNAME, false);
-
- // Create the test circuit from the test configuration parameters.
- CircuitFactory circuitFactory = getCircuitFactory();
- Circuit testCircuit = circuitFactory.createCircuit(testProps);
-
- // This test case assumes it is using a local circuit.
- LocalCircuitImpl localCircuit = (LocalCircuitImpl) testCircuit;
-
- Session producerSession =
localCircuit.getLocalPublisherCircuitEnd().getSession();
- MessageProducer producer =
localCircuit.getLocalPublisherCircuitEnd().getProducer();
- MessageConsumer consumer =
localCircuit.getLocalReceiverCircuitEnd().getConsumer();
-
- // Send some tests messages, with random TTLs, some shorter and some
longer than the pause time.
- for (int i = 0; i < 100; i++)
- {
- Message testMessage =
TestUtils.createTestMessageOfSize(producerSession, 10);
-
- // Set the TTL on the message and record its value in the message
headers.
- long ttl = 500 + r.nextInt(1500);
- producer.setTimeToLive(ttl);
- testMessage.setLongProperty("testTTL", ttl);
-
- producer.send(testMessage);
- // producerSession.commit();
- }
-
- // Inject a pause to allow some messages to be purged by TTL.
- TestUtils.pause(1000);
-
- // Attempt to receive back all of the messages, confirming by the
message time stamps and TTLs that only
- // those received should have avoided being purged by the TTL.
- boolean timedOut = false;
-
- while (!timedOut)
- {
- Message testMessage = consumer.receive(1000);
-
- long ttl = testMessage.getLongProperty("testTTL");
- long timeStamp = testMessage.getJMSTimestamp();
- long now = System.currentTimeMillis();
-
- if ((timeStamp + ttl) < now)
- {
- errorMessages +=
- "Received message [sent: " + timeStamp + ", ttl: " + ttl +
", received: " + now
- + "] which should have been purged by its TTL.\n";
- }
- /*else
- {
- receivedMessages.add(testMessage);
- }*/
- }
-
- // Check that the queue and message store on the broker are empty.
- // assertTrue("Message store is not empty.",
messageStoreEmpty.apply());
- // assertTrue("Queue is not empty.", queueEmpty.apply());
-
- assertTrue(errorMessages, "".equals(errorMessages));
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.test.testcases;
+
+import org.apache.qpid.test.framework.Circuit;
+import org.apache.qpid.test.framework.FrameworkBaseCase;
+import static
org.apache.qpid.test.framework.MessagingTestConfigProperties.ACK_MODE_PROPNAME;
+import static
org.apache.qpid.test.framework.MessagingTestConfigProperties.PUBSUB_PROPNAME;
+import org.apache.qpid.test.framework.TestUtils;
+import org.apache.qpid.test.framework.localcircuit.LocalCircuitImpl;
+import org.apache.qpid.test.framework.sequencers.CircuitFactory;
+
+import javax.jms.*;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * TTLTest checks that time-to-live is applied to messages. The test sends
messages with a variety of TTL stamps on them
+ * then after a pause attempts to receive those messages. Only messages with a
large enough TTL to have survived the pause
+ * should be receiveable. This test case also applies an additional assertion
against the broker, that the message store
+ * is empty at the end of the test.
+ *
+ * <p/>This test is designed to run over local circuits only, as it must
control a timed pause between sending and receiving
+ * messages to that TTL can be applied to purge some of the messages.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td>
+ * </table>
+ *
+ * @todo Use an interface or other method to mark this test as local only.
+ *
+ * @todo Implement the message store assertion for in-vm broker. Could also be
done for external broker, for example
+ * by using diagnostic exchange.
+ *
+ * @todo Implement and add a queue depth assertion too. This might already be
in another test to copy from.
+ *
+ * @todo Create variations on test theme, for different ack mode and tx and
message sizes etc.
+ *
+ * @todo Add an allowable margin of error to the test, as ttl may not be
precise.
+ */
+public class TTLTest extends FrameworkBaseCase
+{
+ /**
+ * Creates a new test case with the specified name.
+ *
+ * @param name The test case name.
+ */
+ public TTLTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Checks that all messages sent with a TTL shorter than a pause between
sending them and attempting to receive them
+ * will fail to arrive. Once all messages have been purged by TTL or
received, check that they no longer exist on
+ * the broker.
+ *
+ * @throws javax.jms.JMSException Allowed to fall through and fail test.
+ */
+ public void testTTLP2P() throws JMSException
+ {
+ String errorMessages = "";
+ Random r = new Random();
+
+ // Used to accumulate correctly received messages in.
+ List<Message> receivedMessages = new LinkedList<Message>();
+
+ // Set up the test properties to match the test case requirements.
+ testProps.setProperty(ACK_MODE_PROPNAME, Session.AUTO_ACKNOWLEDGE);
+ testProps.setProperty(PUBSUB_PROPNAME, false);
+
+ // Create the test circuit from the test configuration parameters.
+ CircuitFactory circuitFactory = getCircuitFactory();
+ Circuit testCircuit = circuitFactory.createCircuit(testProps);
+
+ // This test case assumes it is using a local circuit.
+ LocalCircuitImpl localCircuit = (LocalCircuitImpl) testCircuit;
+
+ Session producerSession =
localCircuit.getLocalPublisherCircuitEnd().getSession();
+ MessageProducer producer =
localCircuit.getLocalPublisherCircuitEnd().getProducer();
+ MessageConsumer consumer =
localCircuit.getLocalReceiverCircuitEnd().getConsumer();
+
+ // Send some tests messages, with random TTLs, some shorter and some
longer than the pause time.
+ for (int i = 0; i < 100; i++)
+ {
+ Message testMessage =
TestUtils.createTestMessageOfSize(producerSession, 10);
+
+ // Set the TTL on the message and record its value in the message
headers.
+ long ttl = 500 + r.nextInt(1500);
+ producer.setTimeToLive(ttl);
+ testMessage.setLongProperty("testTTL", ttl);
+
+ producer.send(testMessage);
+ // producerSession.commit();
+ }
+
+ // Inject a pause to allow some messages to be purged by TTL.
+ TestUtils.pause(1000);
+
+ // Attempt to receive back all of the messages, confirming by the
message time stamps and TTLs that only
+ // those received should have avoided being purged by the TTL.
+ boolean timedOut = false;
+
+ while (!timedOut)
+ {
+ Message testMessage = consumer.receive(1000);
+
+ long ttl = testMessage.getLongProperty("testTTL");
+ long timeStamp = testMessage.getJMSTimestamp();
+ long now = System.currentTimeMillis();
+
+ if ((timeStamp + ttl) < now)
+ {
+ errorMessages +=
+ "Received message [sent: " + timeStamp + ", ttl: " + ttl +
", received: " + now
+ + "] which should have been purged by its TTL.\n";
+ }
+ /*else
+ {
+ receivedMessages.add(testMessage);
+ }*/
+ }
+
+ // Check that the queue and message store on the broker are empty.
+ // assertTrue("Message store is not empty.",
messageStoreEmpty.apply());
+ // assertTrue("Queue is not empty.", queueEmpty.apply());
+
+ assertTrue(errorMessages, "".equals(errorMessages));
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/TTLTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/ack/AcknowledgeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java
(original)
+++
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java
Thu Apr 24 10:49:03 2008
@@ -1,296 +1,296 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.qpid.testutil;
-
-import org.apache.log4j.Logger;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.client.JMSAMQException;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.Connection;
-import javax.jms.DeliveryMode;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-/**
- * @todo This was originally cut and paste from the client module leading to a
duplicate class, then altered very
- * slightly. To avoid the duplicate class the name was altered slightly
to have 'Helper' on the end in order
- * to distinguish it from the original. Delete this class and use the
original instead, just upgrade it to
- * provide the new features needed.
- */
-public class QpidClientConnectionHelper implements ExceptionListener
-{
-
- private static final Logger _logger =
Logger.getLogger(QpidClientConnectionHelper.class);
-
- private boolean transacted = true;
- private int ackMode = Session.CLIENT_ACKNOWLEDGE;
- private Connection connection;
-
- private String virtualHost;
- private String brokerlist;
- private int prefetch;
- protected Session session;
- protected boolean connected;
-
- public QpidClientConnectionHelper(String broker)
- {
- super();
- setVirtualHost("/test");
- setBrokerList(broker);
- setPrefetch(5000);
- }
-
- public void connect() throws JMSException
- {
- if (!connected)
- {
- /*
- * amqp://[user:[EMAIL PROTECTED]/virtualhost?
- *
brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
- * [&failover='method[?option='value'[&option='value']]']
- * [&option='value']"
- */
- String brokerUrl = "amqp://guest:guest@" + virtualHost +
"?brokerlist='" + brokerlist + "'";
- try
- {
- AMQConnectionFactory factory = new AMQConnectionFactory(new
AMQConnectionURL(brokerUrl));
- _logger.info("connecting to Qpid :" + brokerUrl);
- connection = factory.createConnection();
-
- // register exception listener
- connection.setExceptionListener(this);
-
- session = ((AMQConnection)
connection).createSession(transacted, ackMode, prefetch);
-
- _logger.info("starting connection");
- connection.start();
-
- connected = true;
- }
- catch (URLSyntaxException e)
- {
- throw new JMSAMQException("URL syntax error in [" + brokerUrl
+ "]: " + e.getMessage(), e);
- }
- }
- }
-
- public void disconnect() throws JMSException
- {
- if (connected)
- {
- session.commit();
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected");
- }
- }
-
- public void disconnectWithoutCommit() throws JMSException
- {
- if (connected)
- {
- session.close();
- connection.close();
- connected = false;
- _logger.info("disconnected without commit");
- }
- }
-
- public String getBrokerList()
- {
- return brokerlist;
- }
-
- public void setBrokerList(String brokerlist)
- {
- this.brokerlist = brokerlist;
- }
-
- public String getVirtualHost()
- {
- return virtualHost;
- }
-
- public void setVirtualHost(String virtualHost)
- {
- this.virtualHost = virtualHost;
- }
-
- public void setPrefetch(int prefetch)
- {
- this.prefetch = prefetch;
- }
-
- /** override as necessary */
- public void onException(JMSException exception)
- {
- _logger.info("ExceptionListener event: error " +
exception.getErrorCode() + ", message: " + exception.getMessage());
- }
-
- public boolean isConnected()
- {
- return connected;
- }
-
- public Session getSession()
- {
- return session;
- }
-
- /**
- * Put a String as a text messages, repeat n times. A null payload will
result in a null message.
- *
- * @param queueName The queue name to put to
- * @param payload the content of the payload
- * @param copies the number of messages to put
- *
- * @throws javax.jms.JMSException any exception that occurs
- */
- public void put(String queueName, String payload, int copies, int
deliveryMode) throws JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("putting to queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageProducer sender = session.createProducer(queue);
-
- sender.setDeliveryMode(deliveryMode);
-
- for (int i = 0; i < copies; i++)
- {
- Message m = session.createTextMessage(payload + i);
- m.setIntProperty("index", i + 1);
- sender.send(m);
- }
-
- session.commit();
- sender.close();
- _logger.info("put " + copies + " copies");
- }
-
- /**
- * GET the top message on a queue. Consumes the message. Accepts timeout
value.
- *
- * @param queueName The quename to get from
- * @param readTimeout The timeout to use
- *
- * @return the content of the text message if any
- *
- * @throws javax.jms.JMSException any exception that occured
- */
- public Message getNextMessage(String queueName, long readTimeout) throws
JMSException
- {
- if (!connected)
- {
- connect();
- }
-
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
-
- Message message = consumer.receive(readTimeout);
- session.commit();
- consumer.close();
-
- Message result;
-
- // all messages we consume should be TextMessages
- if (message instanceof TextMessage)
- {
- result = ((TextMessage) message);
- }
- else if (null == message)
- {
- result = null;
- }
- else
- {
- _logger.info("warning: received non-text message");
- result = message;
- }
-
- return result;
- }
-
- /**
- * GET the top message on a queue. Consumes the message.
- *
- * @param queueName The Queuename to get from
- *
- * @return The string content of the text message, if any received
- *
- * @throws javax.jms.JMSException any exception that occurs
- */
- public Message getNextMessage(String queueName) throws JMSException
- {
- return getNextMessage(queueName, 0);
- }
-
- /**
- * Completely clears a queue. For readTimeout behaviour see Javadocs for
javax.jms.MessageConsumer.
- *
- * @param queueName The Queue name to consume from
- * @param readTimeout The timeout for each consume
- *
- * @throws javax.jms.JMSException Any exception that occurs during the
consume
- * @throws InterruptedException If the consume thread was interrupted
during a consume.
- */
- public void consume(String queueName, int readTimeout) throws
JMSException, InterruptedException
- {
- if (!connected)
- {
- connect();
- }
-
- _logger.info("consuming queue " + queueName);
- Queue queue = session.createQueue(queueName);
-
- final MessageConsumer consumer = session.createConsumer(queue);
- int messagesReceived = 0;
-
- _logger.info("consuming...");
- while ((consumer.receive(readTimeout)) != null)
- {
- messagesReceived++;
- }
-
- session.commit();
- consumer.close();
- _logger.info("consumed: " + messagesReceived);
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.testutil;
+
+import org.apache.log4j.Logger;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQConnectionURL;
+import org.apache.qpid.client.JMSAMQException;
+import org.apache.qpid.url.URLSyntaxException;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+/**
+ * @todo This was originally cut and paste from the client module leading to a
duplicate class, then altered very
+ * slightly. To avoid the duplicate class the name was altered slightly
to have 'Helper' on the end in order
+ * to distinguish it from the original. Delete this class and use the
original instead, just upgrade it to
+ * provide the new features needed.
+ */
+public class QpidClientConnectionHelper implements ExceptionListener
+{
+
+ private static final Logger _logger =
Logger.getLogger(QpidClientConnectionHelper.class);
+
+ private boolean transacted = true;
+ private int ackMode = Session.CLIENT_ACKNOWLEDGE;
+ private Connection connection;
+
+ private String virtualHost;
+ private String brokerlist;
+ private int prefetch;
+ protected Session session;
+ protected boolean connected;
+
+ public QpidClientConnectionHelper(String broker)
+ {
+ super();
+ setVirtualHost("/test");
+ setBrokerList(broker);
+ setPrefetch(5000);
+ }
+
+ public void connect() throws JMSException
+ {
+ if (!connected)
+ {
+ /*
+ * amqp://[user:[EMAIL PROTECTED]/virtualhost?
+ *
brokerlist='[transport://]host[:port][?option='value'[&option='value']];'
+ * [&failover='method[?option='value'[&option='value']]']
+ * [&option='value']"
+ */
+ String brokerUrl = "amqp://guest:guest@" + virtualHost +
"?brokerlist='" + brokerlist + "'";
+ try
+ {
+ AMQConnectionFactory factory = new AMQConnectionFactory(new
AMQConnectionURL(brokerUrl));
+ _logger.info("connecting to Qpid :" + brokerUrl);
+ connection = factory.createConnection();
+
+ // register exception listener
+ connection.setExceptionListener(this);
+
+ session = ((AMQConnection)
connection).createSession(transacted, ackMode, prefetch);
+
+ _logger.info("starting connection");
+ connection.start();
+
+ connected = true;
+ }
+ catch (URLSyntaxException e)
+ {
+ throw new JMSAMQException("URL syntax error in [" + brokerUrl
+ "]: " + e.getMessage(), e);
+ }
+ }
+ }
+
+ public void disconnect() throws JMSException
+ {
+ if (connected)
+ {
+ session.commit();
+ session.close();
+ connection.close();
+ connected = false;
+ _logger.info("disconnected");
+ }
+ }
+
+ public void disconnectWithoutCommit() throws JMSException
+ {
+ if (connected)
+ {
+ session.close();
+ connection.close();
+ connected = false;
+ _logger.info("disconnected without commit");
+ }
+ }
+
+ public String getBrokerList()
+ {
+ return brokerlist;
+ }
+
+ public void setBrokerList(String brokerlist)
+ {
+ this.brokerlist = brokerlist;
+ }
+
+ public String getVirtualHost()
+ {
+ return virtualHost;
+ }
+
+ public void setVirtualHost(String virtualHost)
+ {
+ this.virtualHost = virtualHost;
+ }
+
+ public void setPrefetch(int prefetch)
+ {
+ this.prefetch = prefetch;
+ }
+
+ /** override as necessary */
+ public void onException(JMSException exception)
+ {
+ _logger.info("ExceptionListener event: error " +
exception.getErrorCode() + ", message: " + exception.getMessage());
+ }
+
+ public boolean isConnected()
+ {
+ return connected;
+ }
+
+ public Session getSession()
+ {
+ return session;
+ }
+
+ /**
+ * Put a String as a text messages, repeat n times. A null payload will
result in a null message.
+ *
+ * @param queueName The queue name to put to
+ * @param payload the content of the payload
+ * @param copies the number of messages to put
+ *
+ * @throws javax.jms.JMSException any exception that occurs
+ */
+ public void put(String queueName, String payload, int copies, int
deliveryMode) throws JMSException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+
+ _logger.info("putting to queue " + queueName);
+ Queue queue = session.createQueue(queueName);
+
+ final MessageProducer sender = session.createProducer(queue);
+
+ sender.setDeliveryMode(deliveryMode);
+
+ for (int i = 0; i < copies; i++)
+ {
+ Message m = session.createTextMessage(payload + i);
+ m.setIntProperty("index", i + 1);
+ sender.send(m);
+ }
+
+ session.commit();
+ sender.close();
+ _logger.info("put " + copies + " copies");
+ }
+
+ /**
+ * GET the top message on a queue. Consumes the message. Accepts timeout
value.
+ *
+ * @param queueName The quename to get from
+ * @param readTimeout The timeout to use
+ *
+ * @return the content of the text message if any
+ *
+ * @throws javax.jms.JMSException any exception that occured
+ */
+ public Message getNextMessage(String queueName, long readTimeout) throws
JMSException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+
+ Queue queue = session.createQueue(queueName);
+
+ final MessageConsumer consumer = session.createConsumer(queue);
+
+ Message message = consumer.receive(readTimeout);
+ session.commit();
+ consumer.close();
+
+ Message result;
+
+ // all messages we consume should be TextMessages
+ if (message instanceof TextMessage)
+ {
+ result = ((TextMessage) message);
+ }
+ else if (null == message)
+ {
+ result = null;
+ }
+ else
+ {
+ _logger.info("warning: received non-text message");
+ result = message;
+ }
+
+ return result;
+ }
+
+ /**
+ * GET the top message on a queue. Consumes the message.
+ *
+ * @param queueName The Queuename to get from
+ *
+ * @return The string content of the text message, if any received
+ *
+ * @throws javax.jms.JMSException any exception that occurs
+ */
+ public Message getNextMessage(String queueName) throws JMSException
+ {
+ return getNextMessage(queueName, 0);
+ }
+
+ /**
+ * Completely clears a queue. For readTimeout behaviour see Javadocs for
javax.jms.MessageConsumer.
+ *
+ * @param queueName The Queue name to consume from
+ * @param readTimeout The timeout for each consume
+ *
+ * @throws javax.jms.JMSException Any exception that occurs during the
consume
+ * @throws InterruptedException If the consume thread was interrupted
during a consume.
+ */
+ public void consume(String queueName, int readTimeout) throws
JMSException, InterruptedException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+
+ _logger.info("consuming queue " + queueName);
+ Queue queue = session.createQueue(queueName);
+
+ final MessageConsumer consumer = session.createConsumer(queue);
+ int messagesReceived = 0;
+
+ _logger.info("consuming...");
+ while ((consumer.receive(readTimeout)) != null)
+ {
+ messagesReceived++;
+ }
+
+ session.commit();
+ consumer.close();
+ _logger.info("consumed: " + messagesReceived);
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/testutil/QpidClientConnectionHelper.java
------------------------------------------------------------------------------
svn:eol-style = native