Guest User

QueueBrowsingTestFail

a guest
Jul 2nd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import org.apache.activemq.ActiveMQConnectionFactory;
  2. import org.apache.activemq.command.ActiveMQQueue;
  3. import org.junit.After;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.slf4j.Logger;
  7. import org.slf4j.LoggerFactory;
  8.  
  9. import javax.jms.*;
  10.  
  11. import java.util.Enumeration;
  12.  
  13. import static org.junit.Assert.*;
  14.  
  15. public class QueueBrowsingTest {
  16.  
  17.     private static final Logger LOG = LoggerFactory.getLogger(QueueBrowsingTest.class);
  18.  
  19.     private ActiveMQConnectionFactory factory;
  20.  
  21.     @Before
  22.     public void startBroker() throws Exception {
  23.         factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
  24.     }
  25.  
  26.     @Test
  27.     public void testBrowsing() throws JMSException {
  28.  
  29.         int messageToSend = 370;
  30.  
  31.         ActiveMQQueue queue = new ActiveMQQueue("hello");
  32.         Connection connection = factory.createConnection();
  33.         connection.start();
  34.         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  35.         MessageProducer producer = session.createProducer(queue);
  36.  
  37.         String data = "";
  38.         for( int i=0; i < 1024*2; i++ ) {
  39.             data += "x";
  40.         }
  41.  
  42.         for( int i=0; i < messageToSend; i++ ) {
  43.             producer.send(session.createTextMessage(data));
  44.         }
  45.  
  46.         QueueBrowser browser = session.createBrowser(queue);
  47.         Enumeration enumeration = browser.getEnumeration();
  48.         int received = 0;
  49.         while (enumeration.hasMoreElements()) {
  50.             Message m = (Message) enumeration.nextElement();
  51.             received++;
  52.         }
  53.  
  54.         browser.close();
  55.  
  56.         assertEquals(messageToSend, received);
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment