You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2009/05/12 13:30:56 UTC

svn commit: r773862 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java

Author: gtully
Date: Tue May 12 11:30:56 2009
New Revision: 773862

URL: http://svn.apache.org/viewvc?rev=773862&view=rev
Log:
test case for https://issues.apache.org/activemq/browse/AMQ-2233 with prefetch  workaround

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java   (with props)

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java?rev=773862&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java Tue May 12 11:30:56 2009
@@ -0,0 +1,135 @@
+/**
+ * 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.bugs;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class RawRollbackTests {
+	
+	private static ConnectionFactory connectionFactory;
+	private static Destination queue;
+	private static BrokerService broker;
+
+	@BeforeClass
+	public static void clean() throws Exception {
+		broker = new BrokerService();
+		broker.setDeleteAllMessagesOnStartup(true);
+		broker.setUseJmx(true);
+		broker.start();
+		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
+		connectionFactory.setBrokerURL("vm://localhost?async=false&waitForStart=5000&jms.prefetchPolicy.all=0");
+		RawRollbackTests.connectionFactory = connectionFactory;
+		queue = new ActiveMQQueue("queue");
+	}
+
+	@AfterClass
+	public static void close() throws Exception {
+		broker.stop();
+	}
+
+	@Before
+	public void clearData() throws Exception {
+		getMessages(false); // drain queue
+		convertAndSend("foo");
+		convertAndSend("bar");
+	}
+
+
+	@After
+	public void checkPostConditions() throws Exception {
+
+		Thread.sleep(1000L);
+		List<String> list = getMessages(false);
+		assertEquals(2, list.size());
+
+	}
+
+	@Test
+	public void testReceiveMessages() throws Exception {
+
+		List<String> list = getMessages(true);
+		assertEquals(2, list.size());
+		assertTrue(list.contains("foo"));
+
+	}
+	
+	private void convertAndSend(String msg) throws Exception {
+		Connection connection = connectionFactory.createConnection();
+		connection.start();
+		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+		MessageProducer producer = session.createProducer(queue);
+		producer.send(session.createTextMessage(msg));
+		producer.close();
+		session.commit();
+		session.close();
+		connection.close();
+	}
+
+	private List<String> getMessages(boolean rollback) throws Exception {
+		Connection connection = connectionFactory.createConnection();
+		connection.start();
+		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+		String next = "";
+		List<String> msgs = new ArrayList<String>();
+		while (next != null) {
+			next = (String) receiveAndConvert(session);
+			if (next != null)
+				msgs.add(next);
+		}
+		if (rollback) {
+			session.rollback();
+		} else {
+			session.commit();
+		}
+		session.close();
+		connection.close();
+		return msgs;
+	}
+
+	private String receiveAndConvert(Session session) throws Exception {
+		MessageConsumer consumer = session.createConsumer(queue);
+		Message message = consumer.receive(100L);
+		consumer.close();
+		if (message==null) {
+			return null;
+		}
+		return ((TextMessage)message).getText();
+	}
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/RawRollbackTests.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date