Author: dejanb
Date: Tue Oct 5 11:38:22 2010
New Revision: 1004616
URL: http://svn.apache.org/viewvc?rev=1004616&view=rev
Log:
spring message listener container tests
Added:
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/Listener.java
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/ListenerTest.java
activemq/trunk/activemq-spring/src/test/resources/spring/
activemq/trunk/activemq-spring/src/test/resources/spring/spring.xml
Modified:
activemq/trunk/activemq-spring/pom.xml
Modified: activemq/trunk/activemq-spring/pom.xml
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-spring/pom.xml?rev=1004616&r1=1004615&r2=1004616&view=diff
==============================================================================
--- activemq/trunk/activemq-spring/pom.xml (original)
+++ activemq/trunk/activemq-spring/pom.xml Tue Oct 5 11:38:22 2010
@@ -84,6 +84,11 @@
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring-version}</version>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-core</artifactId>
<type>test-jar</type>
Added:
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/Listener.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/Listener.java?rev=1004616&view=auto
==============================================================================
---
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/Listener.java
(added)
+++
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/Listener.java
Tue Oct 5 11:38:22 2010
@@ -0,0 +1,47 @@
+/**
+ * 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.spring;
+
+import org.apache.activemq.command.ActiveMQTextMessage;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Listener implements MessageListener {
+
+ List<Message> messages = new ArrayList<Message>();
+ long lastReceived = 0L;
+
+
+ public void onMessage(Message message) {
+
+ try {
+ System.out.println("LISTENER received " +
message.getJMSDestination() + " " + ((ActiveMQTextMessage)message).getText());
+ lastReceived = System.currentTimeMillis();
+ synchronized (messages) {
+ messages.add(message);
+ }
+ } catch (JMSException e) {
+ e.printStackTrace(); //To change body of catch statement use File
| Settings | File Templates.
+ }
+
+ }
+
+}
Added:
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/ListenerTest.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/ListenerTest.java?rev=1004616&view=auto
==============================================================================
---
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/ListenerTest.java
(added)
+++
activemq/trunk/activemq-spring/src/test/java/org/apache/activemq/spring/ListenerTest.java
Tue Oct 5 11:38:22 2010
@@ -0,0 +1,76 @@
+/**
+ * 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.spring;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.TransactionConfiguration;
+
+import javax.annotation.Resource;
+import javax.jms.*;
+
+...@runwith(SpringJUnit4ClassRunner.class)
+
+...@contextconfiguration(locations = {"classpath:spring/spring.xml"})
+...@transactionconfiguration(transactionManager = "transactionManager",
defaultRollback = false)
+public class ListenerTest {
+
+ protected String bindAddress = "vm://localhost";
+
+ @Resource
+ Listener listener;
+
+ @Test
+ @DirtiesContext
+ public void testSimple() throws Exception {
+ sendMessages("SIMPLE", 10);
+
+ Thread.sleep(3000);
+
+ System.out.println(listener.messages.size());
+ Assert.assertEquals(listener.messages.size(), 10);
+ }
+
+
+ @Test
+ @DirtiesContext
+ public void testComposite() throws Exception {
+ sendMessages("TEST.1,TEST.2,TEST.3,TEST.4,TEST.5,TEST.6", 10);
+
+ Thread.sleep(3000);
+
+ System.out.println(listener.messages.size());
+ Assert.assertEquals(listener.messages.size(), 60);
+ }
+
+ public void sendMessages(String destName, int msgNum) throws Exception {
+ ConnectionFactory factory = new
org.apache.activemq.ActiveMQConnectionFactory("tcp://localhost:61616");
+ Connection conn = factory.createConnection();
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Destination dest = sess.createQueue(destName);
+ MessageProducer producer = sess.createProducer(dest);
+ for (int i = 0; i < msgNum; i++) {
+ producer.send(sess.createTextMessage("test"));
+ }
+ }
+
+
+}
Added: activemq/trunk/activemq-spring/src/test/resources/spring/spring.xml
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-spring/src/test/resources/spring/spring.xml?rev=1004616&view=auto
==============================================================================
--- activemq/trunk/activemq-spring/src/test/resources/spring/spring.xml (added)
+++ activemq/trunk/activemq-spring/src/test/resources/spring/spring.xml Tue Oct
5 11:38:22 2010
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:amq="http://activemq.apache.org/schema/core"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
+ http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd">
+
+ <amq:broker brokerName="test" useJmx="false" persistent="false">
+ <amq:transportConnectors>
+ <amq:transportConnector name="transport"
uri="nio://0.0.0.0:61616"/>
+ </amq:transportConnectors>
+ </amq:broker>
+
+
+ <bean id="connectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
+ <property name="maxConnections" value="100"/>
+ <property name="maximumActive" value="50"/>
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61616"/>
+ </bean>
+ </property>
+ </bean>
+
+ <bean id="transactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
+ <property name="connectionFactory" ref="connectionFactory"/>
+ </bean>
+
+ <bean id="messageListener" class="org.apache.activemq.spring.Listener"/>
+
+ <bean id="simpleContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
+ <property name="connectionFactory" ref="connectionFactory"/>
+ <property name="messageListener" ref="messageListener"/>
+ <property name="destinationName" value="SIMPLE"/>
+ <property name="sessionTransacted" value="true"/>
+ </bean>
+
+ <bean id="compositeContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
+ <property name="connectionFactory" ref="connectionFactory"/>
+ <property name="messageListener" ref="messageListener"/>
+ <property name="destinationName" value="TEST.>"/>
+ <property name="sessionTransacted" value="true"/>
+ </bean>
+
+</beans>
\ No newline at end of file