1 18 19 package org.apache.activemq.usecases; 20 import java.util.HashMap ; 21 import javax.jms.Connection ; 22 import javax.jms.Destination ; 23 import javax.jms.MessageConsumer ; 24 import javax.jms.MessageProducer ; 25 import javax.jms.ObjectMessage ; 26 import javax.jms.Session ; 27 28 import org.apache.activemq.test.TestSupport; 29 30 33 public class ChangeSentMessageTest extends TestSupport { 34 private static final int COUNT = 200; 35 private static final String VALUE_NAME = "value"; 36 37 41 public void testDoChangeSentMessage() throws Exception { 42 Destination destination = createDestination("test-"+ChangeSentMessageTest.class.getName()); 43 Connection connection = createConnection(); 44 connection.start(); 45 Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 46 MessageConsumer consumer = consumerSession.createConsumer(destination); 47 Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 48 MessageProducer producer = publisherSession.createProducer(destination); 49 HashMap map = new HashMap (); 50 ObjectMessage message = publisherSession.createObjectMessage(); 51 for (int i = 0;i < COUNT;i++) { 52 map.put(VALUE_NAME, new Integer (i)); 53 message.setObject(map); 54 producer.send(message); 55 assertTrue(message.getObject()==map); 56 } 57 for (int i = 0;i < COUNT;i++) { 58 ObjectMessage msg = (ObjectMessage ) consumer.receive(); 59 HashMap receivedMap = (HashMap ) msg.getObject(); 60 Integer intValue = (Integer ) receivedMap.get(VALUE_NAME); 61 assertTrue(intValue.intValue() == i); 62 } 63 } 64 } 65 | Popular Tags |