org.apache.activemq.command.ActiveMQDestination

Here are the examples of the java api class org.apache.activemq.command.ActiveMQDestination taken from open source projects.

1. DestinationRemoveRestartTest#doAddDestination()

View license
public void doAddDestination() throws Exception {
    boolean res = false;
    ActiveMQDestination amqDestination = ActiveMQDestination.createDestination(destinationName, destinationType);
    broker.getRegionBroker().addDestination(broker.getAdminConnectionContext(), amqDestination, true);
    final ActiveMQDestination[] list = broker.getRegionBroker().getDestinations();
    for (final ActiveMQDestination element : list) {
        final Destination destination = broker.getDestination(element);
        if (destination.getActiveMQDestination().getPhysicalName().equals(destinationName)) {
            res = true;
            break;
        }
    }
    assertTrue("Adding destination Failed", res);
}

2. ObjectFactoryTest#testDestination()

View license
public void testDestination() throws Exception {
    // Create sample destination
    ActiveMQDestination dest = new ActiveMQQueue();
    dest.setPhysicalName("TEST.FOO");
    // Create reference
    Reference ref = JNDIReferenceFactory.createReference(dest.getClass().getName(), dest);
    // Get object created based on reference
    ActiveMQDestination temp;
    JNDIReferenceFactory refFactory = new JNDIReferenceFactory();
    temp = (ActiveMQDestination) refFactory.getObjectInstance(ref, null, null, null);
    // Check settings
    assertEquals(dest.getPhysicalName(), temp.getPhysicalName());
}

3. QueueSubscriptionTest#doMultipleClientsTest()

View license
public void doMultipleClientsTest() throws Exception {
    // Create destination
    final ActiveMQDestination dest = createDestination();
    // Create consumers
    ActiveMQConnectionFactory consumerFactory = (ActiveMQConnectionFactory) createConnectionFactory();
    consumerFactory.getPrefetchPolicy().setAll(prefetchCount);
    startConsumers(consumerFactory, dest);
    startProducers(dest, messageCount);
    // Wait for messages to be received. Make it proportional to the
    // messages delivered.
    int totalMessageCount = messageCount * producerCount;
    if (dest.isTopic()) {
        totalMessageCount *= consumerCount;
    }
    waitForAllMessagesToBeReceived(totalMessageCount);
}

4. DestinationRemoveRestartTest#doRemoveDestination()

View license
public void doRemoveDestination() throws Exception {
    boolean res = true;
    broker.removeDestination(ActiveMQDestination.createDestination(destinationName, destinationType));
    final ActiveMQDestination[] list = broker.getRegionBroker().getDestinations();
    for (final ActiveMQDestination element : list) {
        final Destination destination = broker.getDestination(element);
        if (destination.getActiveMQDestination().getPhysicalName().equals(destinationName)) {
            res = false;
            break;
        }
    }
    assertTrue("Removing destination Failed", res);
}

5. DestinationRemoveRestartTest#doCheckRemoveActionAfterRestart()

View license
public void doCheckRemoveActionAfterRestart() throws Exception {
    boolean res = true;
    final ActiveMQDestination[] list = broker.getRegionBroker().getDestinations();
    for (final ActiveMQDestination element : list) {
        final Destination destination = broker.getDestination(element);
        if (destination.getActiveMQDestination().getPhysicalName().equals(destinationName)) {
            res = false;
            break;
        }
    }
    assertTrue("The removed destination is reloaded after restart !", res);
}

6. DestinationsPluginTest#testDestinationSave()

View license
@Test
public void testDestinationSave() throws Exception {
    BrokerView brokerView = broker.getAdminView();
    brokerView.addQueue("test-queue");
    broker.stop();
    broker.waitUntilStopped();
    broker = createBroker();
    broker.start();
    broker.waitUntilStarted();
    ActiveMQDestination[] destinations = broker.getRegionBroker().getDestinations();
    for (ActiveMQDestination destination : destinations) {
        if (destination.isQueue()) {
            assertEquals("test-queue", destination.getPhysicalName());
        }
    }
}

7. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicMatchDoubleWildcard()

View license
public void testReceiveWildcardTopicMatchDoubleWildcard() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic("a.*.>.>");
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createTopic("a.b");
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    consumer = session.createConsumer(destination1);
    sendMessage(session, destination2, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

8. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicMatchSinglePastTheEndWildcard()

View license
public void testReceiveWildcardTopicMatchSinglePastTheEndWildcard() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic("a.>");
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createTopic("a");
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    consumer = session.createConsumer(destination1);
    sendMessage(session, destination2, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

9. LDAPAuthorizationMapTest#testGetAdminACLs()

View license
/*
    * Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getAdminACLs(ActiveMQDestination)'
    */
@Test
public void testGetAdminACLs() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1");
    Set<GroupPrincipal> aclsq1 = authMap.getAdminACLs(q1);
    assertEquals(1, aclsq1.size());
    assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
    ActiveMQDestination t1 = new ActiveMQTopic("topic1");
    Set<GroupPrincipal> aclst1 = authMap.getAdminACLs(t1);
    assertEquals(1, aclst1.size());
    assertTrue(aclst1.contains(new GroupPrincipal("role1")));
}

10. LDAPAuthorizationMapTest#testGetReadACLs()

View license
/*
    * Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getReadACLs(ActiveMQDestination)'
    */
@Test
public void testGetReadACLs() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1");
    Set<GroupPrincipal> aclsq1 = authMap.getReadACLs(q1);
    assertEquals(1, aclsq1.size());
    assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
    ActiveMQDestination t1 = new ActiveMQTopic("topic1");
    Set<GroupPrincipal> aclst1 = authMap.getReadACLs(t1);
    assertEquals(1, aclst1.size());
    assertTrue(aclst1.contains(new GroupPrincipal("role2")));
}

11. LDAPAuthorizationMapTest#testGetWriteACLs()

View license
/*
    * Test method for 'org.apache.activemq.security.LDAPAuthorizationMap.getWriteACLs(ActiveMQDestination)'
    */
@Test
public void testGetWriteACLs() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1");
    Set<GroupPrincipal> aclsq1 = authMap.getWriteACLs(q1);
    assertEquals(2, aclsq1.size());
    assertTrue(aclsq1.contains(new GroupPrincipal("role1")));
    assertTrue(aclsq1.contains(new GroupPrincipal("role2")));
    ActiveMQDestination t1 = new ActiveMQTopic("topic1");
    Set<GroupPrincipal> aclst1 = authMap.getWriteACLs(t1);
    assertEquals(1, aclst1.size());
    assertTrue(aclst1.contains(new GroupPrincipal("role3")));
}

12. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicMatchDoubleWildcard()

View license
@Test
public void testReceiveWildcardTopicMatchDoubleWildcard() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic("a.*.>.>");
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createTopic("a.b");
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    consumer = session.createConsumer(destination1);
    sendMessage(session, destination2, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

13. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicMatchSinglePastTheEndWildcard()

View license
@Test
public void testReceiveWildcardTopicMatchSinglePastTheEndWildcard() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic("a.>");
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createTopic("a");
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    consumer = session.createConsumer(destination1);
    sendMessage(session, destination2, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

14. OpenWireMessageConverter#createMessageDispatch()

View license
public static MessageDispatch createMessageDispatch(MessageReference reference, ServerMessage message, AMQConsumer consumer) throws IOException, JMSException {
    ActiveMQMessage amqMessage = toAMQMessage(reference, message, consumer.getMarshaller(), consumer.getOpenwireDestination());
    //we can use core message id for sequenceId
    amqMessage.getMessageId().setBrokerSequenceId(message.getMessageID());
    MessageDispatch md = new MessageDispatch();
    md.setConsumerId(consumer.getId());
    md.setRedeliveryCounter(reference.getDeliveryCount() - 1);
    md.setDeliverySequenceId(amqMessage.getMessageId().getBrokerSequenceId());
    md.setMessage(amqMessage);
    ActiveMQDestination destination = amqMessage.getDestination();
    md.setDestination(destination);
    return md;
}

15. DestinationListenerTest#onDestinationEvent()

View license
@Override
public void onDestinationEvent(DestinationEvent event) {
    ActiveMQDestination destination = event.getDestination();
    if (event.isAddOperation()) {
        LOG.info("Added:   " + destination);
        newDestinations.add(destination);
    } else {
        LOG.info("Removed: " + destination);
        newDestinations.remove(destination);
    }
}

16. MessageGroupConfigTest#doTestGroupConfiguration()

View license
public MessageGroupMap doTestGroupConfiguration(String type, Class classType) throws Exception {
    broker = new BrokerService();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMessageGroupMapFactoryType(type);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
    super.topic = false;
    ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
    Queue brokerDestination = (Queue) broker.getDestination(destination);
    assertNotNull(brokerDestination);
    MessageGroupMap messageGroupMap = brokerDestination.getMessageGroupOwners();
    assertNotNull(messageGroupMap);
    assertTrue(messageGroupMap.getClass().isAssignableFrom(classType));
    return messageGroupMap;
}

17. MessageGroupTest#testAddingConsumer()

View license
public void testAddingConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(destination);
    //MessageConsumer consumer = session.createConsumer(destination);
    TextMessage message = session.createTextMessage("message");
    message.setStringProperty("JMSXGroupID", "TEST-GROUP");
    LOG.info("sending message: " + message);
    producer.send(message);
    MessageConsumer consumer = session.createConsumer(destination);
    TextMessage msg = (TextMessage) consumer.receive();
    assertNotNull(msg);
    boolean first = msg.getBooleanProperty("JMSXGroupFirstForConsumer");
    assertTrue(first);
}

18. JmsQueueCompositeSendReceiveTest#testDuplicate()

View license
public void testDuplicate() throws Exception {
    ActiveMQDestination queue = (ActiveMQDestination) session.createQueue("TEST,TEST");
    for (int i = 0; i < data.length; i++) {
        Message message = createMessage(i);
        configureMessage(message);
        if (verbose) {
            LOG.info("About to send a message: " + message + " with text: " + data[i]);
        }
        producer.send(queue, message);
    }
    // wait for messages to be queue;
    Thread.sleep(200);
    try (ServerLocator locator = ServerLocatorImpl.newLocator("tcp://localhost:61616");
        ClientSessionFactory factory = locator.createSessionFactory();
        ClientSession session = factory.createSession()) {
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString("jms.queue.TEST"));
        assertNotNull(query);
        assertEquals(data.length, query.getMessageCount());
    }
}

19. DemandForwardingBridgeFilterTest#assertReceiveMessageOn()

View license
private void assertReceiveMessageOn(String destinationName, byte destinationType) throws Exception, InterruptedException {
    ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, destinationType);
    // Send the message to the local broker.
    producerConnection.send(createMessage(producerInfo, destination, destinationType));
    // Make sure the message was delivered via the remote.
    Message m = createConsumerAndReceiveMessage(destination);
    assertNotNull(m);
}

20. DemandForwardingBridgeFilterTest#assertReceiveNoMessageOn()

View license
private void assertReceiveNoMessageOn(String destinationName, byte destinationType) throws Exception, InterruptedException {
    ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, destinationType);
    // Send the message to the local broker.
    producerConnection.send(createMessage(producerInfo, destination, destinationType));
    // Make sure the message was delivered via the remote.
    Message m = createConsumerAndReceiveMessage(destination);
    assertNull(m);
}

21. NetworkBrokerDetachTest#testNetworkedBrokerDetach()

View license
@Test
public void testNetworkedBrokerDetach() throws Exception {
    LOG.info("Creating Consumer on the networked broker ...");
    // Create a consumer on the networked broker
    ConnectionFactory consFactory = createConnectionFactory(networkedBroker);
    Connection consConn = consFactory.createConnection();
    Session consSession = consConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = (ActiveMQDestination) consSession.createQueue(DESTINATION_NAME);
    for (int i = 0; i < NUM_CONSUMERS; i++) {
        consSession.createConsumer(destination);
    }
    assertTrue("got expected consumer count from mbean within time limit", verifyConsumerCount(1, destination, broker));
    LOG.info("Stopping Consumer on the networked broker ...");
    // Closing the connection will also close the consumer
    consConn.close();
    // We should have 0 consumer for the queue on the local broker
    assertTrue("got expected 0 count from mbean within time limit", verifyConsumerCount(0, destination, broker));
}

22. JMSConsumer12Test#testDontStart()

View license
@Test
public void testDontStart() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    sendMessages(session, destination, 1);
    // Make sure no messages were delivered.
    assertNull(consumer.receive(1000));
}

23. JMSConsumer12Test#testStartAfterSend()

View license
@Test
public void testStartAfterSend() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    sendMessages(session, destination, 1);
    // Start the conncection after the message was sent.
    connection.start();
    // Make sure only 1 message was delivered.
    assertNotNull(consumer.receive(1000));
    assertNull(consumer.receiveNoWait());
}

24. JMSConsumer13Test#testReceiveMessageWithConsumer()

View license
@Test
public void testReceiveMessageWithConsumer() throws Exception {
    // Receive a message with the JMS API
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    sendMessages(session, destination, 1);
    // Make sure only 1 message was delivered.
    Message m = consumer.receive(1000);
    assertNotNull(m);
    assertEquals("0", ((TextMessage) m).getText());
    assertNull(consumer.receiveNoWait());
}

25. JMSConsumer2Test#testDupsOkConsumer()

View license
@Test
public void testDupsOkConsumer() throws Exception {
    // Receive a message with the JMS API
    connection.start();
    Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    MessageConsumer consumer = session.createConsumer(destination);
    // Send the messages
    sendMessages(session, destination, 4);
    // Make sure only 4 message are delivered.
    for (int i = 0; i < 4; i++) {
        Message m = consumer.receive(1000);
        assertNotNull(m);
    }
    assertNull(consumer.receive(1000));
    // Close out the consumer.. no other messages should be left on the queue.
    consumer.close();
    consumer = session.createConsumer(destination);
    assertNull(consumer.receive(1000));
}

26. JMSConsumer5Test#testSendReceiveBytesMessage()

View license
@Test
public void testSendReceiveBytesMessage() throws Exception {
    // Receive a message with the JMS API
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    BytesMessage message = session.createBytesMessage();
    message.writeBoolean(true);
    message.writeBoolean(false);
    producer.send(message);
    // Make sure only 1 message was delivered.
    BytesMessage m = (BytesMessage) consumer.receive(1000);
    assertNotNull(m);
    assertTrue(m.readBoolean());
    assertFalse(m.readBoolean());
    assertNull(consumer.receiveNoWait());
}

27. JMSUsecase1Test#testSendReceive()

View license
@Test
public void testSendReceive() throws Exception {
    // Send a message to the broker.
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    System.out.println("destionation: " + destination);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(this.deliveryMode);
    MessageConsumer consumer = session.createConsumer(destination);
    ActiveMQMessage message = new ActiveMQMessage();
    producer.send(message);
    // Make sure only 1 message was delivered.
    assertNotNull(consumer.receive(1000));
    assertNull(consumer.receiveNoWait());
}

28. JMSUsecaseTest#testQueueBrowser()

View license
@Test
public void testQueueBrowser() throws Exception {
    // Send a message to the broker.
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, destinationType);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(this.deliveryMode);
    sendMessages(session, producer, 5);
    producer.close();
    QueueBrowser browser = session.createBrowser((Queue) destination);
    Enumeration<?> enumeration = browser.getEnumeration();
    for (int i = 0; i < 5; i++) {
        Thread.sleep(100);
        assertTrue(enumeration.hasMoreElements());
        Message m = (Message) enumeration.nextElement();
        assertNotNull(m);
        assertEquals("" + i, ((TextMessage) m).getText());
    }
    assertFalse(enumeration.hasMoreElements());
}

29. CompressedInteropTest#sendCompressedStreamMessageUsingOpenWire()

View license
private void sendCompressedStreamMessageUsingOpenWire() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    StreamMessage streamMessage = session.createStreamMessage();
    streamMessage.writeBoolean(true);
    streamMessage.writeByte((byte) 10);
    streamMessage.writeBytes(TEXT.getBytes());
    streamMessage.writeChar('A');
    streamMessage.writeDouble(55.3D);
    streamMessage.writeFloat(79.1F);
    streamMessage.writeInt(37);
    streamMessage.writeLong(56652L);
    streamMessage.writeObject(new String("VVVV"));
    streamMessage.writeShort((short) 333);
    streamMessage.writeString(TEXT);
    producer.send(streamMessage);
}

30. CompressedInteropTest#sendCompressedMapMessageUsingOpenWire()

View license
private void sendCompressedMapMessageUsingOpenWire() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    MapMessage mapMessage = session.createMapMessage();
    mapMessage.setBoolean("boolean-type", true);
    mapMessage.setByte("byte-type", (byte) 10);
    mapMessage.setBytes("bytes-type", TEXT.getBytes());
    mapMessage.setChar("char-type", 'A');
    mapMessage.setDouble("double-type", 55.3D);
    mapMessage.setFloat("float-type", 79.1F);
    mapMessage.setInt("int-type", 37);
    mapMessage.setLong("long-type", 56652L);
    mapMessage.setObject("object-type", new String("VVVV"));
    mapMessage.setShort("short-type", (short) 333);
    mapMessage.setString("string-type", TEXT);
    producer.send(mapMessage);
}

31. GeneralInteropTest#testMutipleReceivingFromCore()

View license
@Test
public void testMutipleReceivingFromCore() throws Exception {
    final String text = "HelloWorld";
    final int num = 100;
    //text messages
    sendMultipleTextMessagesUsingCoreJms(queueName, text, 100);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
    for (int i = 0; i < num; i++) {
        TextMessage textMessage = (TextMessage) consumer.receive(5000);
        assertEquals(text + i, textMessage.getText());
        assertEquals(destination, textMessage.getJMSDestination());
    }
}

32. GeneralInteropTest#sendMessageUsingOpenWire()

View license
private void sendMessageUsingOpenWire(String queueName) throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    javax.jms.Message message = session.createMessage();
    message.setBooleanProperty("booleanProperty", false);
    message.setLongProperty("longProperty", 99999L);
    message.setByteProperty("byteProperty", (byte) 5);
    message.setIntProperty("intProperty", 979);
    message.setShortProperty("shortProperty", (short) 1099);
    message.setStringProperty("stringProperty", "HelloMessage");
    producer.send(message);
}

33. GeneralInteropTest#sendBytesMessageUsingOpenWire()

View license
private void sendBytesMessageUsingOpenWire(byte[] bytesData) throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    BytesMessage bytesMessage = session.createBytesMessage();
    bytesMessage.writeBytes(bytesData);
    bytesMessage.writeBoolean(true);
    bytesMessage.writeLong(99999L);
    bytesMessage.writeChar('h');
    bytesMessage.writeInt(987);
    bytesMessage.writeShort((short) 1099);
    bytesMessage.writeUTF("hellobytes");
    producer.send(bytesMessage);
}

34. GeneralInteropTest#sendStreamMessageUsingOpenWire()

View license
private void sendStreamMessageUsingOpenWire(String queueName) throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    StreamMessage streamMessage = session.createStreamMessage();
    streamMessage.writeBoolean(true);
    streamMessage.writeByte((byte) 2);
    streamMessage.writeBytes(new byte[] { 6, 7 });
    streamMessage.writeChar('b');
    streamMessage.writeDouble(6.5);
    streamMessage.writeFloat((float) 93.9);
    streamMessage.writeInt(7657);
    streamMessage.writeLong(239999L);
    streamMessage.writeShort((short) 34222);
    streamMessage.writeString("hello streammessage");
    producer.send(streamMessage);
}

35. GeneralInteropTest#sendMapMessageUsingOpenWire()

View license
private void sendMapMessageUsingOpenWire() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    MapMessage mapMessage = session.createMapMessage();
    mapMessage.setBoolean("aboolean", true);
    mapMessage.setByte("abyte", (byte) 4);
    mapMessage.setBytes("abytes", new byte[] { 4, 5 });
    mapMessage.setChar("achar", 'a');
    mapMessage.setDouble("adouble", 4.4);
    mapMessage.setFloat("afloat", 4.5f);
    mapMessage.setInt("aint", 40);
    mapMessage.setLong("along", 80L);
    mapMessage.setShort("ashort", (short) 65);
    mapMessage.setString("astring", "hello");
    producer.send(mapMessage);
}

36. ActiveMQOriginalDestinationTest#testActiveMQOriginalDestination()

View license
@Test
public void testActiveMQOriginalDestination() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("activemq:queue:foo", "Hello World");
    assertMockEndpointsSatisfied();
    // consume from bar
    Exchange out = consumer.receive("activemq:queue:bar", 5000);
    assertNotNull(out);
    // and we should have foo as the original destination
    JmsMessage msg = out.getIn(JmsMessage.class);
    Message jms = msg.getJmsMessage();
    ActiveMQMessage amq = assertIsInstanceOf(ActiveMQMessage.class, jms);
    ActiveMQDestination original = amq.getOriginalDestination();
    assertNotNull(original);
    assertEquals("foo", original.getPhysicalName());
    assertEquals("Queue", original.getDestinationTypeAsString());
}

37. AMQSession#createConsumer()

Project: activemq-artemis
Source File: AMQSession.java
View license
public List<AMQConsumer> createConsumer(ConsumerInfo info, SlowConsumerDetectionListener slowConsumerDetectionListener) throws Exception {
    //check destination
    ActiveMQDestination dest = info.getDestination();
    ActiveMQDestination[] dests = null;
    if (dest.isComposite()) {
        dests = dest.getCompositeDestinations();
    } else {
        dests = new ActiveMQDestination[] { dest };
    }
    List<AMQConsumer> consumersList = new java.util.LinkedList<>();
    for (ActiveMQDestination openWireDest : dests) {
        if (openWireDest.isQueue()) {
            SimpleString queueName = OpenWireUtil.toCoreAddress(openWireDest);
            getCoreServer().getJMSDestinationCreator().create(queueName);
        }
        AMQConsumer consumer = new AMQConsumer(this, openWireDest, info, scheduledPool);
        long nativeID = consumerIDGenerator.generateID();
        consumer.init(slowConsumerDetectionListener, nativeID);
        consumersList.add(consumer);
    }
    return consumersList;
}

38. RecoveryBrokerTest#XtestWildCardSubscriptionPreservedOnRestart()

View license
/**
    * Used to verify that after a broker restart durable subscriptions that use
    * wild cards are still wild card subscription after broker restart.
    *
    * @throws Exception
    */
//need to revist!!!
public void XtestWildCardSubscriptionPreservedOnRestart() throws Exception {
    ActiveMQDestination dest1 = new ActiveMQTopic("TEST.A");
    ActiveMQDestination dest2 = new ActiveMQTopic("TEST.B");
    ActiveMQDestination dest3 = new ActiveMQTopic("TEST.C");
    ActiveMQDestination wildDest = new ActiveMQTopic("TEST.>");
    ArrayList<MessageId> sentBeforeRestart = new ArrayList<>();
    ArrayList<MessageId> sentBeforeCreateConsumer = new ArrayList<>();
    ArrayList<MessageId> sentAfterCreateConsumer = new ArrayList<>();
    // Setup a first connection
    {
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        connectionInfo1.setClientId("A");
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo1);
        // Create the durable subscription.
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, wildDest);
        consumerInfo1.setSubscriptionName("test");
        consumerInfo1.setPrefetchSize(100);
        connection1.send(consumerInfo1);
        // Close the subscription.
        connection1.send(closeConsumerInfo(consumerInfo1));
        // Send the messages
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo1, dest1, DeliveryMode.PERSISTENT);
            connection1.send(m);
            sentBeforeRestart.add(m.getMessageId());
        }
        connection1.request(closeConnectionInfo(connectionInfo1));
        connection1.stop();
    }
    // Restart the broker.
    restartBroker();
    // Get a connection to the new broker.
    {
        StubConnection connection2 = createConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        connectionInfo2.setClientId("A");
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
        connection2.send(producerInfo2);
        // Send messages before the durable subscription is re-activated.
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo2, dest2, DeliveryMode.PERSISTENT);
            connection2.send(m);
            sentBeforeCreateConsumer.add(m.getMessageId());
        }
        // Re-open the subscription.
        ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, wildDest);
        consumerInfo2.setSubscriptionName("test");
        consumerInfo2.setPrefetchSize(100);
        connection2.send(consumerInfo2);
        // Send messages after the subscription is activated.
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo2, dest3, DeliveryMode.PERSISTENT);
            connection2.send(m);
            sentAfterCreateConsumer.add(m.getMessageId());
        }
        // We should get the recovered messages...
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("Recovered message missing: " + i, m2);
            assertEquals(sentBeforeRestart.get(i), m2.getMessageId());
        }
        // reactivated.
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("Before activated message missing: " + i, m2);
            assertEquals(sentBeforeCreateConsumer.get(i), m2.getMessageId());
        }
        // reactivated.
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("After activated message missing: " + i, m2);
            assertEquals("" + i, sentAfterCreateConsumer.get(i), m2.getMessageId());
        }
        assertNoMessagesLeft(connection2);
    }
}

39. JmsQueueWildcardSendReceiveTest#testReceiveWildcardQueueEndGreaterThan()

View license
public void testReceiveWildcardQueueEndGreaterThan() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String);
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createQueue(destination2String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createQueue(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination2, destination2String);
    sendMessage(session, destination3, destination3String);
    ActiveMQDestination destination7 = (ActiveMQDestination) session.createQueue("TEST.ONE.>");
    consumer = session.createConsumer(destination7);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

40. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicEndGreaterThan()

View license
public void testReceiveWildcardTopicEndGreaterThan() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createTopic(destination2String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createTopic(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination7 = (ActiveMQDestination) session.createTopic("TEST.ONE.>");
    consumer = session.createConsumer(destination7);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination2, destination2String);
    sendMessage(session, destination3, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

41. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicEndGreaterThan()

View license
@Test
public void testReceiveWildcardTopicEndGreaterThan() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination2 = (ActiveMQDestination) session.createTopic(destination2String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createTopic(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination7 = (ActiveMQDestination) session.createTopic("TEST.ONE.>");
    consumer = session.createConsumer(destination7);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination2, destination2String);
    sendMessage(session, destination3, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    if (!(text.equals(destination1String) || text.equals(destination2String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

42. AMQSession#send()

Project: activemq-artemis
Source File: AMQSession.java
View license
public void send(final ProducerInfo producerInfo, final Message messageSend, boolean sendProducerAck) throws Exception {
    messageSend.setBrokerInTime(System.currentTimeMillis());
    ActiveMQDestination destination = messageSend.getDestination();
    ActiveMQDestination[] actualDestinations = null;
    if (destination.isComposite()) {
        actualDestinations = destination.getCompositeDestinations();
        messageSend.setOriginalDestination(destination);
    } else {
        actualDestinations = new ActiveMQDestination[] { destination };
    }
    ServerMessage originalCoreMsg = getConverter().inbound(messageSend);
    /* ActiveMQ failover transport will attempt to reconnect after connection failure.  Any sent messages that did
      * not receive acks will be resent.  (ActiveMQ broker handles this by returning a last sequence id received to
      * the client).  To handle this in Artemis we use a duplicate ID cache.  To do this we check to see if the
      * message comes from failover connection.  If so we add a DUPLICATE_ID to handle duplicates after a resend. */
    if (connection.getContext().isFaultTolerant() && !messageSend.getProperties().containsKey(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID)) {
        originalCoreMsg.putStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString(), messageSend.getMessageId().toString());
    }
    Runnable runnable;
    if (sendProducerAck) {
        runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), messageSend.getSize());
                    connection.dispatchSync(ack);
                } catch (Exception e) {
                    ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
                    connection.sendException(e);
                }
            }
        };
    } else {
        final Connection transportConnection = connection.getTransportConnection();
        if (transportConnection == null) {
            // I don't think this could happen, but just in case, avoiding races
            runnable = null;
        } else {
            runnable = new Runnable() {

                @Override
                public void run() {
                    transportConnection.setAutoRead(true);
                }
            };
        }
    }
    internalSend(actualDestinations, originalCoreMsg, runnable);
}

43. BrokerTest#testWildcardConsume()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testWildcardConsume() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // setup the wildcard consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("WILD.*.TEST", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // These two message should NOT match the wild card.
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.CARD", destinationType), deliveryMode));
    connection1.send(createMessage(producerInfo1, ActiveMQDestination.createDestination("WILD.TEST", destinationType), deliveryMode));
    // These two message should match the wild card.
    ActiveMQDestination d1 = ActiveMQDestination.createDestination("WILD.CARD.TEST", destinationType);
    connection1.send(createMessage(producerInfo1, d1, deliveryMode));
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d1, m.getDestination());
    ActiveMQDestination d2 = ActiveMQDestination.createDestination("WILD.FOO.TEST", destinationType);
    connection1.request(createMessage(producerInfo1, d2, deliveryMode));
    m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(d2, m.getDestination());
    assertNoMessagesLeft(connection1);
    connection1.send(closeConnectionInfo(connectionInfo1));
}

44. BrokerTest#testCompositeConsume()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testCompositeConsume() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // setup the composite consumer.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, compositeDestination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Publish to the two destinations
    ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
    ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
    // Send a message to each destination .
    connection1.send(createMessage(producerInfo1, destinationA, deliveryMode));
    connection1.send(createMessage(producerInfo1, destinationB, deliveryMode));
    // The consumer should get both messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
    }
    assertNoMessagesLeft(connection1);
    connection1.send(closeConnectionInfo(connectionInfo1));
}

45. BrokerTest#testCompositeSend()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testCompositeSend() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ActiveMQDestination destinationA = ActiveMQDestination.createDestination("A", destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationA);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ActiveMQDestination destinationB = ActiveMQDestination.createDestination("B", destinationType);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationB);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    connection2.request(consumerInfo2);
    // Send the messages to the composite destination.
    ActiveMQDestination compositeDestination = ActiveMQDestination.createDestination("A,B", destinationType);
    for (int i = 0; i < 4; i++) {
        connection1.request(createMessage(producerInfo1, compositeDestination, deliveryMode));
    }
    // destination.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull(m1);
        assertNotNull(m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        assertEquals(compositeDestination, m1.getOriginalDestination());
        assertEquals(compositeDestination, m2.getOriginalDestination());
        connection1.request(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.request(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
    connection1.send(closeConnectionInfo(connectionInfo1));
    connection2.send(closeConnectionInfo(connectionInfo2));
}

46. JmsQueueWildcardSendReceiveTest#testReceiveWildcardQueueEndAsterisk()

View license
public void testReceiveWildcardQueueEndAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createQueue(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination3, destination3String);
    ActiveMQDestination destination6 = (ActiveMQDestination) session.createQueue("TEST.ONE.*");
    consumer = session.createConsumer(destination6);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

47. JmsQueueWildcardSendReceiveTest#testReceiveWildcardQueueMidAsterisk()

View license
public void testReceiveWildcardQueueMidAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createQueue(destination1String);
    ActiveMQDestination destination4 = (ActiveMQDestination) session.createQueue(destination4String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination4, destination4String);
    ActiveMQDestination destination8 = (ActiveMQDestination) session.createQueue("TEST.*.ONE");
    consumer = session.createConsumer(destination8);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

48. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicEndAsterisk()

View license
public void testReceiveWildcardTopicEndAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createTopic(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination6 = (ActiveMQDestination) session.createTopic("TEST.ONE.*");
    consumer = session.createConsumer(destination6);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination3, destination3String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

49. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicMidAsterisk()

View license
public void testReceiveWildcardTopicMidAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination4 = (ActiveMQDestination) session.createTopic(destination4String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination8 = (ActiveMQDestination) session.createTopic("TEST.*.ONE");
    consumer = session.createConsumer(destination8);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination4, destination4String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

50. AdvisoryTopicCleanUpTest#testAdvisoryTopic()

View license
@Test
public void testAdvisoryTopic() throws Exception {
    Connection connection = createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination queue = (ActiveMQDestination) session.createQueue("AdvisoryTopicCleanUpTestQueue");
    MessageProducer prod = session.createProducer(queue);
    Message message = session.createMessage();
    prod.send(message);
    message = session.createMessage();
    prod.send(message);
    message = session.createMessage();
    prod.send(message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, 1000);
    connection.close();
    connection = createConnection();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(queue);
    message = consumer.receive(60 * 1000);
    message.acknowledge();
    connection.close();
    connection = null;
    for (int i = 0; i < 2; i++) {
        connection = createConnection();
        session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
        consumer = session.createConsumer(queue);
        message = consumer.receive(60 * 1000);
        session.rollback();
        connection.close();
        connection = null;
    }
    Thread.sleep(2 * 1000);
    connection = createConnection();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    consumer = session.createConsumer(queue);
    message = consumer.receive(1000);
    if (message != null)
        message.acknowledge();
    connection.close();
    connection = null;
    TimeUnit.SECONDS.sleep(1);
    ActiveMQDestination dests[] = broker.getRegionBroker().getDestinations();
    for (ActiveMQDestination destination : dests) {
        String name = destination.getPhysicalName();
        if (name.contains(queue.getPhysicalName())) {
            LOG.info("Destination on Broker before removing the Queue: " + name);
        }
    }
    dests = broker.getRegionBroker().getDestinations();
    if (dests == null) {
        fail("Should have Destination for: " + queue.getPhysicalName());
    }
    broker.getAdminView().removeQueue(queue.getPhysicalName());
    dests = broker.getRegionBroker().getDestinations();
    if (dests != null) {
        for (ActiveMQDestination destination : dests) {
            String name = destination.getPhysicalName();
            LOG.info("Destination on broker after removing the Queue: " + name);
            assertFalse("Advisory topic should not exist. " + name, name.startsWith("ActiveMQ.Advisory") && name.contains(queue.getPhysicalName()));
        }
    }
}

51. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicEndAsterisk()

View license
@Test
public void testReceiveWildcardTopicEndAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination3 = (ActiveMQDestination) session.createTopic(destination3String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination6 = (ActiveMQDestination) session.createTopic("TEST.ONE.*");
    consumer = session.createConsumer(destination6);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination3, destination3String);
    m = consumer.receive(5000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(5000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination3String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

52. JmsTopicWildcardSendReceiveTest#testReceiveWildcardTopicMidAsterisk()

View license
@Test
public void testReceiveWildcardTopicMidAsterisk() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination1 = (ActiveMQDestination) session.createTopic(destination1String);
    ActiveMQDestination destination4 = (ActiveMQDestination) session.createTopic(destination4String);
    Message m = null;
    MessageConsumer consumer = null;
    String text = null;
    ActiveMQDestination destination8 = (ActiveMQDestination) session.createTopic("TEST.*.ONE");
    consumer = session.createConsumer(destination8);
    sendMessage(session, destination1, destination1String);
    sendMessage(session, destination4, destination4String);
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    m = consumer.receive(1000);
    assertNotNull(m);
    text = ((TextMessage) m).getText();
    if (!(text.equals(destination1String) || text.equals(destination4String))) {
        fail("unexpected message:" + text);
    }
    assertNull(consumer.receiveNoWait());
}

53. OpenWireConnection#addDestination()

View license
public void addDestination(DestinationInfo info) throws Exception {
    ActiveMQDestination dest = info.getDestination();
    if (dest.isQueue()) {
        SimpleString qName = OpenWireUtil.toCoreAddress(dest);
        QueueBinding binding = (QueueBinding) server.getPostOffice().getBinding(qName);
        if (binding == null) {
            if (dest.isTemporary()) {
                internalSession.createQueue(qName, qName, null, dest.isTemporary(), false);
            } else {
                ConnectionInfo connInfo = getState().getInfo();
                CheckType checkType = dest.isTemporary() ? CheckType.CREATE_NON_DURABLE_QUEUE : CheckType.CREATE_DURABLE_QUEUE;
                server.getSecurityStore().check(qName, checkType, this);
                server.checkQueueCreationLimit(getUsername());
                server.createQueue(qName, qName, null, connInfo == null ? null : SimpleString.toSimpleString(connInfo.getUserName()), true, false);
            }
        }
    }
    if (!AdvisorySupport.isAdvisoryTopic(dest)) {
        AMQConnectionContext context = getContext();
        DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.ADD_OPERATION_TYPE, dest);
        ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
        protocolManager.fireAdvisory(context, topic, advInfo);
    }
}

54. AdvisoryBrokerTest#testConsumerAdvisories()

View license
public void testConsumerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should not see and advisory for the advisory consumer.
    assertNoMessagesLeft(connection1);
    // Setup a second consumer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
    consumerInfo1.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // We should get an advisory of the new consumer.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the consumer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
    assertNoMessagesLeft(connection2);
}

55. AdvisoryBrokerTest#testConsumerAdvisoriesReplayed()

View license
public void testConsumerAdvisoriesReplayed() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Setup a second consumer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // We should get an advisory of the previous consumer.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the consumer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
    assertNoMessagesLeft(connection2);
}

56. AdvisoryBrokerTest#testProducerAdvisories()

View license
public void testProducerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    assertNoMessagesLeft(connection1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // We should get an advisory of the new produver.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}

57. AdvisoryBrokerTest#testProducerAdvisoriesReplayed()

View license
public void testProducerAdvisoriesReplayed() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    // Create the advisory consumer.. it should see the previous producer
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the producer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), producerInfo2.getProducerId());
    assertNoMessagesLeft(connection2);
}

58. AdvisoryBrokerTest#testProducerAdvisoriesReplayedOnlyTargetNewConsumer()

View license
public void testProducerAdvisoriesReplayedOnlyTargetNewConsumer() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getProducerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    // Create the first consumer..
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Setup a producer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    producerInfo2.setDestination(queue);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // Create the 2nd consumer..
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(consumerInfo2);
    // The second consumer should se a replay
    m1 = receiveMessage(connection2);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ProducerInfo) m1.getDataStructure()).getProducerId(), producerInfo2.getProducerId());
    // But the first consumer should not see the replay.
    assertNoMessagesLeft(connection1);
}

59. DestinationMapTest#testCompositeDestinations()

View license
public void testCompositeDestinations() throws Exception {
    ActiveMQDestination d1 = createDestination("TEST.BAR.D2");
    ActiveMQDestination d2 = createDestination("TEST.BAR.D3");
    map.put(d1, d1);
    map.put(d2, d2);
    map.get(createDestination("TEST.BAR.D2,TEST.BAR.D3"));
}

60. ActiveMQDestinationTestSupport#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQDestination info = (ActiveMQDestination) object;
    info.setPhysicalName("PhysicalName:1");
}

61. ActiveMQDestinationTestSupport#populateObject()

View license
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ActiveMQDestination info = (ActiveMQDestination) object;
    info.setPhysicalName("PhysicalName:1");
}

62. PeerTransportTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    connections = new Connection[NUMBER_IN_CLUSTER];
    producers = new MessageProducer[NUMBER_IN_CLUSTER];
    messageIdList = new MessageIdList[NUMBER_IN_CLUSTER];
    ActiveMQDestination destination = createDestination();
    for (int i = 0; i < NUMBER_IN_CLUSTER; i++) {
        connections[i] = createConnection(i);
        connections[i].setClientID("ClusterTest" + i);
        connections[i].start();
        Session session = connections[i].createSession(false, Session.AUTO_ACKNOWLEDGE);
        producers[i] = session.createProducer(destination);
        producers[i].setDeliveryMode(deliveryMode);
        MessageConsumer consumer = createMessageConsumer(session, destination);
        messageIdList[i] = new MessageIdList();
        consumer.setMessageListener(messageIdList[i]);
    }
    LOG.info("Waiting for cluster to be fully connected");
    // Each connection should see that NUMBER_IN_CLUSTER consumers get
    // registered on the destination.
    ActiveMQDestination advisoryDest = AdvisorySupport.getConsumerAdvisoryTopic(destination);
    for (int i = 0; i < NUMBER_IN_CLUSTER; i++) {
        Session session = connections[i].createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = createMessageConsumer(session, advisoryDest);
        int j = 0;
        while (j < NUMBER_IN_CLUSTER) {
            ActiveMQMessage message = (ActiveMQMessage) consumer.receive(1000);
            if (message == null) {
                fail("Connection " + i + " saw " + j + " consumers, expected: " + NUMBER_IN_CLUSTER);
            }
            if (message.getDataStructure() != null && message.getDataStructure().getDataStructureType() == ConsumerInfo.DATA_STRUCTURE_TYPE) {
                j++;
            }
        }
        session.close();
    }
    LOG.info("Cluster is online.");
}

63. AdvisoryTopicDeletionTest#doTest()

View license
public void doTest() throws Exception {
    Destination dest = createDestination();
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(dest);
    MessageProducer prod = producerSession.createProducer(dest);
    Message message = producerSession.createMessage();
    prod.send(message);
    consumer.receive(60 * 1000);
    connection.close();
    connection = null;
    if (topic) {
        broker.getAdminView().removeTopic(((ActiveMQDestination) dest).getPhysicalName());
    } else {
        broker.getAdminView().removeQueue(((ActiveMQDestination) dest).getPhysicalName());
    }
    ActiveMQDestination dests[] = broker.getRegionBroker().getDestinations();
    int matchingDestinations = 0;
    for (ActiveMQDestination destination : dests) {
        String name = destination.getPhysicalName();
        LOG.debug("Found destination " + name);
        if (name.startsWith("ActiveMQ.Advisory") && name.contains(getDestinationString())) {
            matchingDestinations++;
        }
    }
    assertEquals("No matching destinations should be found", 0, matchingDestinations);
}

64. BacklogNetworkCrossTalkTest#testProduceConsume()

View license
public void testProduceConsume() throws Exception {
    createBroker("A");
    createBroker("B");
    NetworkConnector nc = bridgeBrokers("A", "B");
    nc.setDuplex(true);
    nc.setDispatchAsync(false);
    startAllBrokers();
    waitForBridgeFormation();
    final int numMessages = 10000;
    // Create queue
    ActiveMQDestination destA = createDestination("AAA", false);
    sendMessages("A", destA, numMessages);
    ActiveMQDestination destB = createDestination("BBB", false);
    sendMessages("B", destB, numMessages);
    // consume across network
    LOG.info("starting consumers..");
    // Setup consumers
    MessageConsumer clientA = createConsumer("A", destB);
    // Setup consumers
    MessageConsumer clientB = createConsumer("B", destA);
    final long maxWait = 5 * 60 * 1000L;
    MessageIdList listA = getConsumerMessages("A", clientA);
    listA.setMaximumDuration(maxWait);
    listA.waitForMessagesToArrive(numMessages);
    MessageIdList listB = getConsumerMessages("B", clientB);
    listB.setMaximumDuration(maxWait);
    listB.waitForMessagesToArrive(numMessages);
    assertEquals("got all on A" + listA.getMessageCount(), numMessages, listA.getMessageCount());
    assertEquals("got all on B" + listB.getMessageCount(), numMessages, listB.getMessageCount());
}

65. StaticNetworkTest#testStaticNetwork()

View license
public void testStaticNetwork() throws Exception {
    // Setup destination
    ActiveMQDestination dest = createDestination("TEST", false);
    ActiveMQDestination dest1 = createDestination("TEST1", false);
    NetworkConnector bridgeAB = bridgeBrokers("BrokerA", "BrokerB", true);
    bridgeAB.addStaticallyIncludedDestination(dest);
    bridgeAB.setStaticBridge(true);
    startAllBrokers();
    waitForBridgeFormation();
    MessageConsumer consumer1 = createConsumer("BrokerB", dest);
    MessageConsumer consumer2 = createConsumer("BrokerB", dest1);
    Thread.sleep(1000);
    sendMessages("BrokerA", dest, 1);
    sendMessages("BrokerA", dest1, 1);
    MessageIdList msgs1 = getConsumerMessages("BrokerB", consumer1);
    MessageIdList msgs2 = getConsumerMessages("BrokerB", consumer2);
    msgs1.waitForMessagesToArrive(1);
    Thread.sleep(1000);
    assertEquals(1, msgs1.getMessageCount());
    assertEquals(0, msgs2.getMessageCount());
}

66. AdvisoryBrokerTest#testConnectionAdvisories()

View license
public void testConnectionAdvisories() throws Exception {
    ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should get an advisory of our own connection.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connection2.send(connectionInfo2);
    // We should get an advisory of the second connection.
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());
    // Close the second connection.
    connection2.send(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the second connection closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), connectionInfo2.getConnectionId());
    assertNoMessagesLeft(connection1);
}

67. BrokerTest#testQueueOnlyOnceDeliveryWith2Consumers()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueOnlyOnceDeliveryWith2Consumers() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.request(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        assertNotNull("m2 is null for index: " + i, m2);
        assertNotSame(m1.getMessageId(), m2.getMessageId());
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

68. BrokerTest#testQueueBrowserWith2Consumers()

Project: activemq-artemis
Source File: BrokerTest.java
View license
//https://issues.apache.org/jira/browse/ARTEMIS-384
public void testQueueBrowserWith2Consumers() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    //as the messages are sent async - need to synchronize the last
    //one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    for (int i = 0; i < 4; i++) {
        Message m1 = messages.get(i);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m2 is null for index: " + i, m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.DELIVERED_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

69. BrokerTest#testQueueBrowserWith2ConsumersBrowseFirst()

Project: activemq-artemis
Source File: BrokerTest.java
View license
/*
    * change the order of the above test
    */
public void testQueueBrowserWith2ConsumersBrowseFirst() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(10);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    //as the messages are sent async - need to synchronize the last
    //one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    // no messages present in queue browser as there were no messages when it
    // was created
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

70. BrokerTest#testQueueBrowserWith2ConsumersInterleaved()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueBrowserWith2ConsumersInterleaved() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(10);
    connection1.request(consumerInfo1);
    // Send the messages
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection with a queue browser.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setBrowser(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    //as the messages are sent async - need to synchronize the last
    //one to ensure they arrive in the order we want
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    List<Message> messages = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }
    for (int i = 0; i < 4; i++) {
        Message m1 = messages.get(i);
        Message m2 = receiveMessage(connection2);
        assertNotNull("m2 is null for index: " + i, m2);
        assertEquals(m1.getMessageId(), m2.getMessageId());
        connection2.send(createAck(consumerInfo2, m2, 1, MessageAck.DELIVERED_ACK_TYPE));
    }
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

71. BrokerTest#testTopicDurableSubscriptionCanBeRestored()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testTopicDurableSubscriptionCanBeRestored() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("clientid1");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setSubscriptionName("test");
    connection1.send(consumerInfo1);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.request(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    // Get the messages
    Message m = null;
    for (int i = 0; i < 2; i++) {
        m = receiveMessage(connection1);
        assertNotNull(m);
    }
    // Ack the last message.
    connection1.send(createAck(consumerInfo1, m, 2, MessageAck.STANDARD_ACK_TYPE));
    // Close the connection.
    connection1.request(closeConnectionInfo(connectionInfo1));
    connection1.stop();
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connectionInfo2.setClientId("clientid1");
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(100);
    consumerInfo2.setSubscriptionName("test");
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // Get the rest of the messages
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
    }
    assertNoMessagesLeft(connection2);
}

72. BrokerTest#testGroupedMessagesDeliveredToOnlyOneConsumer()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testGroupedMessagesDeliveredToOnlyOneConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    connection1.send(consumerInfo1);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination, deliveryMode);
        message.setGroupID("TEST-GROUP");
        message.setGroupSequence(i + 1);
        connection1.request(message);
    }
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    connection2.send(consumerInfo2);
    // the first 3
    for (int i = 0; i < 3; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.request(closeConsumerInfo(consumerInfo1));
    // The last messages should now go the the second consumer.
    for (int i = 0; i < 1; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull("m1 is null for index: " + i, m1);
        connection2.request(createAck(consumerInfo2, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection2);
}

73. BrokerTest#testTopicConsumerOnlySeeMessagesAfterCreation()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testTopicConsumerOnlySeeMessagesAfterCreation() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Send the 1st message
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    if (durableConsumer) {
        consumerInfo1.setSubscriptionName("test");
    }
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    Message m = createMessage(producerInfo1, destination, deliveryMode);
    connection1.send(m);
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Subscription should skip over the first message
    Message m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertEquals(m.getMessageId(), m2.getMessageId());
    m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertNoMessagesLeft(connection1);
}

74. BrokerTest#testTopicRetroactiveConsumerSeeMessagesBeforeCreation()

Project: activemq-artemis
Source File: BrokerTest.java
View license
// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicRetroactiveConsumerSeeMessagesBeforeCreation() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Send the messages
    Message m = createMessage(producerInfo1, destination, deliveryMode);
    connection1.send(m);
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    if (durableConsumer) {
        consumerInfo1.setSubscriptionName("test");
    }
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setRetroactive(true);
    connection1.send(consumerInfo1);
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.request(createMessage(producerInfo1, destination, deliveryMode));
    // the behavior is VERY dependent on the recovery policy used.
    // But the default broker settings try to make it as consistent as
    // possible
    // Subscription should see all messages sent.
    Message m2 = receiveMessage(connection1);
    assertNotNull(m2);
    assertEquals(m.getMessageId(), m2.getMessageId());
    for (int i = 0; i < 2; i++) {
        m2 = receiveMessage(connection1);
        assertNotNull(m2);
    }
    assertNoMessagesLeft(connection1);
}

75. BrokerTest#testExclusiveQueueDeliversToOnlyOneConsumer()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testExclusiveQueueDeliversToOnlyOneConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(1);
    consumerInfo1.setExclusive(true);
    connection1.send(consumerInfo1);
    // Send a message.. this should make consumer 1 the exclusive owner.
    connection1.request(createMessage(producerInfo, destination, deliveryMode));
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setPrefetchSize(1);
    consumerInfo2.setExclusive(true);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Second message should go to consumer 1 even though consumer 2 is
    // ready
    // for dispatch.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    // Acknowledge the first 2 messages
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        connection1.send(createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    // Close the first consumer.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // The last two messages should now go the the second consumer.
    connection1.send(createMessage(producerInfo, destination, deliveryMode));
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull(m1);
        connection2.send(createAck(consumerInfo2, m1, 1, MessageAck.STANDARD_ACK_TYPE));
    }
    assertNoMessagesLeft(connection2);
}

76. BrokerTest#testTopicNoLocal()

Project: activemq-artemis
Source File: BrokerTest.java
View license
// https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicNoLocal() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    consumerInfo1.setNoLocal(true);
    connection1.send(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(producerInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    consumerInfo2.setNoLocal(true);
    connection2.send(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // The 2nd connection should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection2);
        assertNotNull(m1);
    }
    // Send a message with the 2nd connection
    Message message = createMessage(producerInfo2, destination, deliveryMode);
    connection2.send(message);
    // The first connection should not see the initial 4 local messages sent
    // but should
    // see the messages from connection 2.
    Message m = receiveMessage(connection1);
    assertNotNull(m);
    assertEquals(message.getMessageId(), m.getMessageId());
    assertNoMessagesLeft(connection1);
    assertNoMessagesLeft(connection2);
}

77. BrokerTest#testTopicDispatchIsBroadcast()

Project: activemq-artemis
Source File: BrokerTest.java
View license
//https://issues.apache.org/jira/browse/ARTEMIS-402
public void testTopicDispatchIsBroadcast() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setRetroactive(true);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setRetroactive(true);
    consumerInfo2.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    connection1.send(createMessage(producerInfo1, destination, deliveryMode));
    // Get the messages
    for (int i = 0; i < 4; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        m1 = receiveMessage(connection2);
        assertNotNull(m1);
    }
}

78. AbortSlowConsumer0Test#testSlowConsumerIsAbortedViaJmx()

View license
@Test
public void testSlowConsumerIsAbortedViaJmx() throws Exception {
    // so jmx does the abort
    underTest.setMaxSlowDuration(60 * 1000);
    startConsumers(withPrefetch(2, destination));
    Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next();
    consumertoAbort.getValue().setProcessingDelay(8 * 1000);
    for (Connection c : connections) {
        c.setExceptionListener(this);
    }
    startProducers(destination, 100);
    consumertoAbort.getValue().assertMessagesReceived(1);
    ActiveMQDestination amqDest = (ActiveMQDestination) destination;
    ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
    DestinationViewMBean queue = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
    ObjectName slowConsumerPolicyMBeanName = queue.getSlowConsumerStrategy();
    assertNotNull(slowConsumerPolicyMBeanName);
    AbortSlowConsumerStrategyViewMBean abortPolicy = (AbortSlowConsumerStrategyViewMBean) broker.getManagementContext().newProxyInstance(slowConsumerPolicyMBeanName, AbortSlowConsumerStrategyViewMBean.class, true);
    TimeUnit.SECONDS.sleep(3);
    TabularData slowOnes = abortPolicy.getSlowConsumers();
    assertEquals("one slow consumers", 1, slowOnes.size());
    LOG.info("slow ones:" + slowOnes);
    CompositeData slowOne = (CompositeData) slowOnes.values().iterator().next();
    LOG.info("Slow one: " + slowOne);
    assertTrue("we have an object name", slowOne.get("subscription") instanceof ObjectName);
    abortPolicy.abortConsumer((ObjectName) slowOne.get("subscription"));
    consumertoAbort.getValue().assertAtMostMessagesReceived(1);
    slowOnes = abortPolicy.getSlowConsumers();
    assertEquals("no slow consumers left", 0, slowOnes.size());
    // verify mbean gone with destination
    broker.getAdminView().removeTopic(amqDest.getPhysicalName());
    try {
        abortPolicy.getSlowConsumers();
        fail("expect not found post destination removal");
    } catch (UndeclaredThrowableException expected) {
        assertTrue("correct exception: " + expected.getCause(), expected.getCause() instanceof InstanceNotFoundException);
    }
}

79. AbortSlowConsumer0Test#testAbortConsumerOnDeadConnection()

View license
@Test
public void testAbortConsumerOnDeadConnection() throws Exception {
    TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0");
    transportConnector.setBrokerService(broker);
    transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory());
    transportConnector.start();
    SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI());
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl());
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setAll(4);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    Connection c = connectionFactory.createConnection();
    connections.add(c);
    c.start();
    Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
    startProducers(destination, 10);
    messageconsumer.receive(4000).acknowledge();
    assertNotNull(messageconsumer.receive(4000));
    assertNotNull(messageconsumer.receive(4000));
    assertNotNull(messageconsumer.receive(4000));
    // close control command won't get through
    socketProxy.pause();
    ActiveMQDestination amqDest = (ActiveMQDestination) destination;
    ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
    final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
    assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("DestView {} comsumerCount {}", destView, destView.getConsumerCount());
            return 0 == destView.getConsumerCount();
        }
    }));
    socketProxy.goOn();
    assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            boolean closed = false;
            try {
                messageconsumer.receive(400);
            } catch (javax.jms.IllegalStateException expected) {
                closed = expected.toString().contains("closed");
            }
            return closed;
        }
    }));
}

80. DestinationCursorConfigTest#testQueueConfiguration()

View license
public void testQueueConfiguration() throws Exception {
    super.topic = false;
    ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
    PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(destination);
    PendingQueueMessageStoragePolicy policy = entry.getPendingQueuePolicy();
    assertNotNull(policy);
    assertTrue("Policy is: " + policy, policy instanceof VMPendingQueueMessageStoragePolicy);
}

81. DestinationCursorConfigTest#testTopicConfiguration()

View license
public void testTopicConfiguration() throws Exception {
    super.topic = true;
    ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
    PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(destination);
    PendingSubscriberMessageStoragePolicy policy = entry.getPendingSubscriberPolicy();
    assertNotNull(policy);
    assertFalse(entry.isProducerFlowControl());
    assertTrue(entry.getMemoryLimit() == (1024 * 1024));
    assertTrue("subscriberPolicy is: " + policy, policy instanceof VMPendingSubscriberMessageStoragePolicy);
}

82. RecoveryBrokerTest#testConsumedQueuePersistentMessagesLostOnRestart()

View license
public void testConsumedQueuePersistentMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // The we should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m2 = receiveMessage(connection);
        assertNotNull(m2);
    }
    // restart the broker.
    restartBroker();
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}

83. RecoveryBrokerTest#testQueuePersistentUncommitedMessagesLostOnRestart()

View license
public void testQueuePersistentUncommitedMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}

84. RecoveryBrokerTest#testTopicDurableConsumerHoldsPersistentMessageAfterRestart()

View license
public void testTopicDurableConsumerHoldsPersistentMessageAfterRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQTopic("TEST");
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    connectionInfo1.setClientId("A");
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    // Create the durable subscription.
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setSubscriptionName("test");
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Close the subscription.
    connection1.send(closeConsumerInfo(consumerInfo1));
    // Send the messages
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.send(createMessage(producerInfo1, destination, DeliveryMode.PERSISTENT));
    connection1.request(closeConnectionInfo(connectionInfo1));
    // Restart the broker.
    restartBroker();
    // Get a connection to the new broker.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connectionInfo2.setClientId("A");
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    // Re-open the subscription.
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    consumerInfo2.setSubscriptionName("test");
    consumerInfo2.setPrefetchSize(100);
    connection2.send(consumerInfo2);
    // The we should get the messages.
    for (int i = 0; i < 4; i++) {
        Message m2 = receiveMessage(connection2);
        assertNotNull("Did not get message " + i, m2);
    }
    assertNoMessagesLeft(connection2);
}

85. RecoveryBrokerTest#testQueuePersistentMessagesNotLostOnRestart()

View license
public void testQueuePersistentMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(true);
    connection.send(message);
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Message should have been dropped due to broker restart.
    Message m = receiveMessage(connection);
    assertNotNull("Should have received a message by now!", m);
    assertEquals(m.getMessageId(), message.getMessageId());
}

86. RecoveryBrokerTest#testQueueNonPersistentMessagesLostOnRestart()

View license
public void testQueueNonPersistentMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(false);
    connection.send(message);
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Message should have been dropped due to broker restart.
    assertNoMessagesLeft(connection);
}

87. RecoveryBrokerTest#testQueuePersistentCommittedMessagesNotLostOnRestart()

View license
public void testQueuePersistentCommittedMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}

88. RecoveryBrokerTest#testQueuePersistentCommittedAcksNotLostOnRestart()

View license
public void testQueuePersistentCommittedAcksNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
        MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}

89. RecoveryBrokerTest#testQueuePersistentUncommitedAcksLostOnRestart()

View license
public void testQueuePersistentUncommitedAcksLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
        MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // All messages should be re-delivered.
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}

90. RecoveryBrokerTest#testQueuePersistentXAUncommitedAcksLostOnRestart()

View license
public void testQueuePersistentXAUncommitedAcksLostOnRestart() throws Exception {
    int NUMBER = 100;
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    for (int i = 0; i < NUMBER; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Setup the consumer and receive the message.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    Message m = null;
    for (int i = 0; i < NUMBER; i++) {
        m = receiveMessage(connection);
        assertNotNull(m);
    }
    MessageAck ack = createAck(consumerInfo, m, NUMBER, MessageAck.STANDARD_ACK_TYPE);
    ack.setTransactionId(txid);
    connection.send(ack);
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // All messages should be re-delivered.
    for (int i = 0; i < NUMBER; i++) {
        m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}

91. MessageGroupTest#testGroupedMessagesDeliveredToOnlyOneConsumer()

View license
public void testGroupedMessagesDeliveredToOnlyOneConsumer() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer1 = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        TextMessage message = session.createTextMessage("message " + i);
        message.setStringProperty("JMSXGroupID", "TEST-GROUP");
        message.setIntProperty("JMSXGroupSeq", i + 1);
        LOG.info("sending message: " + message);
        producer.send(message);
    }
    // the first 3
    for (int i = 0; i < 3; i++) {
        TextMessage m1 = (TextMessage) consumer1.receive(500);
        assertNotNull("m1 is null for index: " + i, m1);
        assertEquals(m1.getIntProperty("JMSXGroupSeq"), i + 1);
    }
    // Setup a second connection
    Connection connection1 = factory.createConnection(userName, password);
    connection1.start();
    Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer2 = session2.createConsumer(destination);
    // Close the first consumer.
    consumer1.close();
    // The last messages should now go the the second consumer.
    for (int i = 0; i < 1; i++) {
        TextMessage m1 = (TextMessage) consumer2.receive(500);
        assertNotNull("m1 is null for index: " + i, m1);
        assertEquals(m1.getIntProperty("JMSXGroupSeq"), 4 + i);
    }
    //assert that there are no other messages left for the consumer 2
    Message m = consumer2.receive(100);
    assertNull("consumer 2 has some messages left", m);
}

92. MessageGroupTest#testClosingMessageGroup()

View license
public void testClosingMessageGroup() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup a first connection
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer1 = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    // Send the messages.
    for (int i = 0; i < 4; i++) {
        TextMessage message = session.createTextMessage("message " + i);
        message.setStringProperty("JMSXGroupID", "TEST-GROUP");
        LOG.info("sending message: " + message);
        producer.send(message);
    }
    // the first 3
    for (int i = 0; i < 3; i++) {
        TextMessage m1 = (TextMessage) consumer1.receive(500);
        assertNotNull("m1 is null for index: " + i, m1);
    }
    // Setup a second consumer
    Connection connection1 = factory.createConnection(userName, password);
    connection1.start();
    Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer2 = session2.createConsumer(destination);
    //assert that there are no messages for the consumer 2
    Message m = consumer2.receive(100);
    assertNull("consumer 2 has some messages", m);
    // Close the group
    TextMessage message = session.createTextMessage("message " + 5);
    message.setStringProperty("JMSXGroupID", "TEST-GROUP");
    message.setIntProperty("JMSXGroupSeq", -1);
    LOG.info("sending message: " + message);
    producer.send(message);
    //Send some more messages
    for (int i = 0; i < 4; i++) {
        message = session.createTextMessage("message " + i);
        message.setStringProperty("JMSXGroupID", "TEST-GROUP");
        LOG.info("sending message: " + message);
        producer.send(message);
    }
    // Receive the fourth message
    TextMessage m1 = (TextMessage) consumer1.receive(500);
    assertNotNull("m1 is null for index: " + 4, m1);
    // Receive the closing message
    m1 = (TextMessage) consumer1.receive(500);
    assertNotNull("m1 is null for index: " + 5, m1);
    //assert that there are no messages for the consumer 1
    m = consumer1.receive(100);
    assertNull("consumer 1 has some messages left: " + m, m);
    // The messages should now go to the second consumer.
    for (int i = 0; i < 4; i++) {
        m1 = (TextMessage) consumer2.receive(500);
        assertNotNull("m1 is null for index: " + i, m1);
    }
}

93. LoadTester#testQueueSendThenAddConsumer()

Project: activemq-artemis
Source File: LoadTester.java
View license
public void testQueueSendThenAddConsumer() throws Exception {
    ProgressPrinter printer = new ProgressPrinter(produceCount, 20);
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    connection.setUseCompression(false);
    connection.getPrefetchPolicy().setAll(10);
    connection.start();
    Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    LOG.info("Sending " + produceCount + " messages that are " + (messageSize / 1024.0) + "k large, for a total of " + (produceCount * messageSize / (1024.0 * 1024.0)) + " megs of data.");
    // Send a message to the broker.
    long start = System.currentTimeMillis();
    for (int i = 0; i < produceCount; i++) {
        printer.increment();
        BytesMessage msg = session.createBytesMessage();
        msg.writeBytes(new byte[messageSize]);
        producer.send(msg);
    }
    long end1 = System.currentTimeMillis();
    LOG.info("Produced messages/sec: " + (produceCount * 1000.0 / (end1 - start)));
    printer = new ProgressPrinter(produceCount, 10);
    start = System.currentTimeMillis();
    MessageConsumer consumer = session.createConsumer(destination);
    for (int i = 0; i < produceCount; i++) {
        printer.increment();
        assertNotNull("Getting message: " + i, consumer.receive(20000));
    }
    end1 = System.currentTimeMillis();
    LOG.info("Consumed messages/sec: " + (produceCount * 1000.0 / (end1 - start)));
}

94. DestinationMapTest#remove()

View license
protected void remove(String name, Object value) {
    ActiveMQDestination destination = createDestination(name);
    map.remove(destination, value);
}

95. DestinationMapTest#assertMapValue()

View license
protected void assertMapValue(String destinationName, Object expected) {
    ActiveMQDestination destination = createDestination(destinationName);
    assertMapValue(destination, expected);
}

96. MessageListenerRedeliveryTest#testQueueSessionListenerExceptionDlq()

View license
public void testQueueSessionListenerExceptionDlq() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("queue-" + getName());
    MessageProducer producer = createProducer(session, queue);
    Message message = createTextMessage(session);
    producer.send(message);
    final Message[] dlqMessage = new Message[1];
    ActiveMQDestination dlqDestination = new ActiveMQQueue("ActiveMQ.DLQ");
    MessageConsumer dlqConsumer = session.createConsumer(dlqDestination);
    final CountDownLatch gotDlqMessage = new CountDownLatch(1);
    dlqConsumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            LOG.info("DLQ Message Received: " + message);
            dlqMessage[0] = message;
            gotDlqMessage.countDown();
        }
    });
    MessageConsumer consumer = session.createConsumer(queue);
    final int maxDeliveries = getRedeliveryPolicy().getMaximumRedeliveries();
    final CountDownLatch gotMessage = new CountDownLatch(maxDeliveries);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            LOG.info("Message Received: " + message);
            gotMessage.countDown();
            throw new RuntimeException(getName() + " force a redelivery");
        }
    });
    assertTrue("got message before retry expiry", gotMessage.await(20, TimeUnit.SECONDS));
    // check DLQ
    assertTrue("got dlq message", gotDlqMessage.await(20, TimeUnit.SECONDS));
    // check DLQ message cause is captured
    message = dlqMessage[0];
    assertNotNull("dlq message captured", message);
    String cause = message.getStringProperty(ActiveMQMessage.DLQ_DELIVERY_FAILURE_CAUSE_PROPERTY);
    LOG.info("DLQ'd message cause reported as: {}", cause);
    assertTrue("cause 'cause' exception is remembered", cause.contains("RuntimeException"));
    assertTrue("is correct exception", cause.contains(getName()));
    assertTrue("cause exception is remembered", cause.contains("Throwable"));
    assertTrue("cause policy is remembered", cause.contains("RedeliveryPolicy"));
    session.close();
}

97. FailoverStaticNetworkTest#doTestNetworkSendReceive()

View license
private void doTestNetworkSendReceive(final BrokerService to, final BrokerService from) throws Exception, JMSException {
    LOG.info("Creating Consumer on the networked broker ..." + from);
    SslContext.setCurrentSslContext(sslContext);
    // Create a consumer on brokerA
    ConnectionFactory consFactory = createConnectionFactory(from);
    Connection consConn = consFactory.createConnection();
    consConn.start();
    Session consSession = consConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = (ActiveMQDestination) consSession.createQueue(DESTINATION_NAME);
    final MessageConsumer consumer = consSession.createConsumer(destination);
    LOG.info("publishing to " + to);
    sendMessageTo(destination, to);
    boolean gotMessage = Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            Message message = consumer.receive(5000);
            LOG.info("from:  " + from.getBrokerObjectName().getKeyProperty("BrokerName") + ", received: " + message);
            return message != null;
        }
    });
    try {
        consConn.close();
    } catch (JMSException ignored) {
    }
    assertTrue("consumer on A got message", gotMessage);
}

98. LDAPAuthorizationMapTest#testComposite()

View license
@Test
public void testComposite() {
    ActiveMQDestination q1 = new ActiveMQQueue("queue1,topic://topic1");
    Set<GroupPrincipal> aclsq1 = authMap.getWriteACLs(q1);
    assertEquals(0, aclsq1.size());
}

99. LDAPAuthorizationMapTest#testAdvisory()

View license
@Test
public void testAdvisory() {
    ActiveMQDestination dest = AdvisorySupport.getConnectionAdvisoryTopic();
    Set<GroupPrincipal> acls = authMap.getWriteACLs(dest);
    assertEquals(1, acls.size());
    assertTrue(acls.contains(new GroupPrincipal("role3")));
}

100. DiscoveryTransportBrokerTest#testPublisherFailsOver()

View license
public void testPublisherFailsOver() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    int deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a failover publisher.
    StubConnection connection3 = createFailoverConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    // The message will be sent to one of the brokers.
    FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
    // See which broker we were connected to.
    StubConnection connectionA;
    StubConnection connectionB;
    TransportConnector serverA;
    if (connector.getServer().getConnectURI().getPort() == ft.getConnectedTransportURI().getPort()) {
        connectionA = connection1;
        connectionB = connection2;
        serverA = connector;
    } else {
        connectionA = connection2;
        connectionB = connection1;
        serverA = remoteConnector;
    }
    assertNotNull(receiveMessage(connectionA));
    assertNoMessagesLeft(connectionB);
    // Dispose the server so that it fails over to the other server.
    LOG.info("Disconnecting active server");
    serverA.stop();
    LOG.info("Sending request that should failover");
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    assertNotNull(receiveMessage(connectionB));
    assertNoMessagesLeft(connectionA);
}