Author: gtully
Date: Wed Jan 28 17:44:14 2009
New Revision: 738566
URL: http://svn.apache.org/viewvc?rev=738566&view=rev
Log:
test case for https://issues.apache.org/activemq/browse/AMQ-2087
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java
(with props)
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java?rev=738566&view=auto
==============================================================================
---
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java
(added)
+++
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java
Wed Jan 28 17:44:14 2009
@@ -0,0 +1,99 @@
+/**
+ * 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.activemq;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class JmsRollbackRedeliveryTest extends TestCase {
+ protected static final Log LOG =
LogFactory.getLog(JmsRollbackRedeliveryTest.class);
+ private boolean consumerClose = true;
+
+ public void testRedeliveryNoConsumerClose() throws Exception {
+ consumerClose = false;
+ testRedelivery();
+ }
+
+ public void testRedelivery() throws Exception {
+
+ final int nbMessages = 10;
+ final String destinationName = "Destination";
+
+ BrokerService broker = new BrokerService();
+ broker.setPersistent(false);
+ broker.setUseJmx(false);
+ broker.start();
+
+ ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("vm://localhost?jms.redeliveryPolicy.maximumRedeliveries=100");
+
+ Connection connection = connectionFactory.createConnection();
+ connection.start();
+
+ // Enqueue nbMessages messages
+ {
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue(destinationName);
+ MessageProducer producer = session.createProducer(destination);
+ for (int i = 1; i <= nbMessages; i++) {
+ producer.send(session.createTextMessage("<hello id='" + i +
"'/>"));
+ }
+ producer.close();
+ session.close();
+ }
+
+ // Consume messages and rollback transactions
+ {
+ AtomicInteger received = new AtomicInteger();
+ Map<String, Boolean> rolledback = new ConcurrentHashMap<String,
Boolean>();
+ while (received.get() < nbMessages) {
+ Session session = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
+ Destination destination = session.createQueue(destinationName);
+ MessageConsumer consumer = session.createConsumer(destination);
+ TextMessage msg = (TextMessage) consumer.receive(6000000);
+ if (msg != null) {
+ if (msg != null && rolledback.put(msg.getText(),
Boolean.TRUE) != null) {
+ LOG.info("Received message " + msg.getText() + " (" +
received.getAndIncrement() + ")" + msg.getJMSMessageID());
+ session.commit();
+ } else {
+ LOG.info("Rollback message " + msg.getText() + " id: "
+ msg.getJMSMessageID());
+ session.rollback();
+ }
+ }
+ if (consumerClose ) {
+ consumer.close();
+ }
+ session.close();
+ }
+ }
+ }
+}
Propchange:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JmsRollbackRedeliveryTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date