org.apache.activemq.artemis.api.core.client.ClientProducer

Here are the examples of the java api class org.apache.activemq.artemis.api.core.client.ClientProducer taken from open source projects.

1. SessionTest#testRollbackWithSend()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testRollbackWithSend() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, false, true);
    clientSession.createQueue(queueName, queueName, false);
    ClientProducer cp = clientSession.createProducer(queueName);
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
    Assert.assertEquals(0, getMessageCount(q));
    clientSession.rollback();
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    clientSession.commit();
    Assert.assertEquals(2, getMessageCount(q));
    clientSession.close();
}

2. SessionTest#testCommitWithSend()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testCommitWithSend() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, false, true);
    clientSession.createQueue(queueName, queueName, false);
    ClientProducer cp = clientSession.createProducer(queueName);
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
    Assert.assertEquals(0, getMessageCount(q));
    clientSession.commit();
    Assert.assertEquals(10, getMessageCount(q));
    clientSession.close();
}

3. WildCardRoutingTest#testWildcardRoutingPartialMatchStar()

View license
@Test
public void testWildcardRoutingPartialMatchStar() throws Exception {
    SimpleString addressAB = new SimpleString("a.b");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("*.b");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer(addressAB);
    ClientProducer producer2 = clientSession.createProducer(addressAC);
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(createTextMessage(clientSession, "m1"));
    producer2.send(createTextMessage(clientSession, "m2"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m1", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

4. WildCardRoutingTest#testWildcardRoutingVariableLengthsStar()

View license
@Test
public void testWildcardRoutingVariableLengthsStar() throws Exception {
    SimpleString addressAB = new SimpleString("a.b.c");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("a.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer(addressAB);
    ClientProducer producer2 = clientSession.createProducer(addressAC);
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(createTextMessage(clientSession, "m1"));
    producer2.send(createTextMessage(clientSession, "m2"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m2", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

5. WildCardRoutingTest#testWildcardRoutingMultipleStars()

View license
@Test
public void testWildcardRoutingMultipleStars() throws Exception {
    SimpleString addressAB = new SimpleString("a.b.c");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("*.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer(addressAB);
    ClientProducer producer2 = clientSession.createProducer(addressAC);
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(createTextMessage(clientSession, "m1"));
    producer2.send(createTextMessage(clientSession, "m2"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m2", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

6. WildCardRoutingTest#testWildcardRoutingStarInMiddle()

View license
@Test
public void testWildcardRoutingStarInMiddle() throws Exception {
    SimpleString addressAB = new SimpleString("a.b.c");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("*.b.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer(addressAB);
    ClientProducer producer2 = clientSession.createProducer(addressAC);
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(createTextMessage(clientSession, "m1"));
    producer2.send(createTextMessage(clientSession, "m2"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m1", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

7. WildCardRoutingTest#testWildcardRoutingStarAndHash()

View license
@Test
public void testWildcardRoutingStarAndHash() throws Exception {
    SimpleString addressAB = new SimpleString("a.b.c.d");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("*.b.#");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer(addressAB);
    ClientProducer producer2 = clientSession.createProducer(addressAC);
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(createTextMessage(clientSession, "m1"));
    producer2.send(createTextMessage(clientSession, "m2"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m1", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

8. WildCardRoutingTest#testWildcardRoutingHashAndStar()

View license
@Test
public void testWildcardRoutingHashAndStar() throws Exception {
    SimpleString addressAB = new SimpleString("a.b.c");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("#.b.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer(addressAB);
    ClientProducer producer2 = clientSession.createProducer(addressAC);
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(createTextMessage(clientSession, "m1"));
    producer2.send(createTextMessage(clientSession, "m2"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m1", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

9. SessionTest#testQueueQuery()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testQueueQuery() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, true, true);
    clientSession.createQueue("a1", queueName, false);
    clientSession.createConsumer(queueName);
    clientSession.createConsumer(queueName);
    ClientProducer cp = clientSession.createProducer("a1");
    cp.send(clientSession.createMessage(true));
    cp.send(clientSession.createMessage(true));
    flushQueue();
    QueueQuery resp = clientSession.queueQuery(new SimpleString(queueName));
    Assert.assertEquals(new SimpleString("a1"), resp.getAddress());
    Assert.assertEquals(2, resp.getConsumerCount());
    Assert.assertEquals(2, resp.getMessageCount());
    Assert.assertEquals(null, resp.getFilterString());
    clientSession.close();
}

10. QueueControlTest#testGetMessagesAdded()

View license
@Test
public void testGetMessagesAdded() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, getMessagesAdded(queueControl));
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    Assert.assertEquals(1, getMessagesAdded(queueControl));
    producer.send(session.createMessage(false));
    Assert.assertEquals(2, getMessagesAdded(queueControl));
    consumeMessages(2, session, queue);
    Assert.assertEquals(2, getMessagesAdded(queueControl));
    session.deleteQueue(queue);
}

11. QueueControlTest#testGetMessagesAcknowledged()

View license
@Test
public void testGetMessagesAcknowledged() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getMessagesAcknowledged());
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    consumeMessages(1, session, queue);
    Assert.assertEquals(1, queueControl.getMessagesAcknowledged());
    producer.send(session.createMessage(false));
    consumeMessages(1, session, queue);
    Assert.assertEquals(2, queueControl.getMessagesAcknowledged());
    //      ManagementTestBase.consumeMessages(2, session, queue);
    //      Assert.assertEquals(2, getMessagesAdded(queueControl));
    session.deleteQueue(queue);
}

12. QueueControlTest#testListMessagesWithNullFilter()

View license
@Test
public void testListMessagesWithNullFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    producer.send(session.createMessage(false));
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(2, messages.length);
    consumeMessages(2, session, queue);
    messages = queueControl.listMessages(null);
    Assert.assertEquals(0, messages.length);
    session.deleteQueue(queue);
}

13. QueueControlTest#testListMessagesWithEmptyFilter()

View license
@Test
public void testListMessagesWithEmptyFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    producer.send(session.createMessage(false));
    Map<String, Object>[] messages = queueControl.listMessages("");
    Assert.assertEquals(2, messages.length);
    consumeMessages(2, session, queue);
    messages = queueControl.listMessages("");
    Assert.assertEquals(0, messages.length);
    session.deleteQueue(queue);
}

14. QueueControlTest#testRemoveMessagesWithNullFilter()

View license
@Test
public void testRemoveMessagesWithNullFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    producer.send(session.createMessage(false));
    producer.send(session.createMessage(false));
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(2, getMessageCount(queueControl));
    // removed matching messages to otherQueue
    int removedMatchedMessagesCount = queueControl.removeMessages(null);
    Assert.assertEquals(2, removedMatchedMessagesCount);
    Assert.assertEquals(0, getMessageCount(queueControl));
    session.deleteQueue(queue);
}

15. QueueControlTest#testRemoveMessagesWithEmptyFilter()

View license
@Test
public void testRemoveMessagesWithEmptyFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    producer.send(session.createMessage(false));
    producer.send(session.createMessage(false));
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(2, getMessageCount(queueControl));
    // removed matching messages to otherQueue
    int removedMatchedMessagesCount = queueControl.removeMessages("");
    Assert.assertEquals(2, removedMatchedMessagesCount);
    Assert.assertEquals(0, getMessageCount(queueControl));
    session.deleteQueue(queue);
}

16. QueueControlTest#testResetMessagesAcknowledged()

View license
@Test
public void testResetMessagesAcknowledged() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getMessagesAcknowledged());
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    consumeMessages(1, session, queue);
    Assert.assertEquals(1, queueControl.getMessagesAcknowledged());
    producer.send(session.createMessage(false));
    consumeMessages(1, session, queue);
    Assert.assertEquals(2, queueControl.getMessagesAcknowledged());
    queueControl.resetMessagesAcknowledged();
    Assert.assertEquals(0, queueControl.getMessagesAcknowledged());
    session.deleteQueue(queue);
}

17. LVQTest#testSimple()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testSimple() throws Exception {
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    SimpleString rh = new SimpleString("SMID1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    producer.send(m1);
    producer.send(m2);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
}

18. LVQTest#testFirstMessageReceivedButAckedAfter()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testFirstMessageReceivedButAckedAfter() throws Exception {
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    SimpleString rh = new SimpleString("SMID1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    producer.send(m1);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    producer.send(m2);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
}

19. LVQTest#testFirstMessageReceivedAndCancelled()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testFirstMessageReceivedAndCancelled() throws Exception {
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    SimpleString rh = new SimpleString("SMID1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    producer.send(m1);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    producer.send(m2);
    consumer.close();
    consumer = clientSession.createConsumer(qName1);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals("m2", m.getBodyBuffer().readString());
    m.acknowledge();
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
}

20. LVQTest#testSimpleInTx()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testSimpleInTx() throws Exception {
    ClientProducer producer = clientSessionTxReceives.createProducer(address);
    ClientConsumer consumer = clientSessionTxReceives.createConsumer(qName1);
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    SimpleString rh = new SimpleString("SMID1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    producer.send(m1);
    producer.send(m2);
    clientSessionTxReceives.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
}

21. LVQTest#testRemoveMessageThroughManagement()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testRemoveMessageThroughManagement() throws Exception {
    Queue queue = server.locateQueue(qName1);
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m1.setDurable(true);
    producer.send(m1);
    queue.deleteAllReferences();
    producer.send(m1);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    assertEquals(0, queue.getDeliveringCount());
}

22. ConsumerTest#testInVMURI()

Project: activemq-artemis
Source File: ConsumerTest.java
View license
// https://jira.jboss.org/jira/browse/HORNETQ-111
// Test that, on rollback credits are released for messages cleared in the buffer
@Test
public void testInVMURI() throws Exception {
    locator.close();
    ServerLocator locator = addServerLocator(ServerLocatorImpl.newLocator("vm:/1"));
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession();
    session.createQueue(QUEUE, QUEUE);
    ClientProducer producer = session.createProducer(QUEUE);
    producer.send(session.createMessage(true));
    ClientConsumer consumer = session.createConsumer(QUEUE);
    session.start();
    Assert.assertNotNull(consumer.receiveImmediate());
    session.close();
    factory.close();
}

23. DeadLetterAddressTest#testBasicSendWithDLAButNoBinding()

View license
// HORNETQ- 1084
@Test
public void testBasicSendWithDLAButNoBinding() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    //SimpleString dlq = new SimpleString("DLQ1");
    //clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
    Queue q = (Queue) server.getPostOffice().getBinding(qName).getBindable();
    Assert.assertEquals(0, q.getDeliveringCount());
}

24. DeadLetterAddressTest#testReceiveWithListeners()

View license
@Test
public void testReceiveWithListeners() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(2).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    SimpleString dlq = new SimpleString("DLQ1");
    clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    final CountDownLatch latch = new CountDownLatch(2);
    TestHandler handler = new TestHandler(latch, clientSession);
    clientConsumer.setMessageHandler(handler);
    clientSession.start();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertEquals(handler.count, 2);
    clientConsumer = clientSession.createConsumer(dlq);
    Message m = clientConsumer.receive(5000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}

25. DeadLetterAddressTest#testBasicSendToNoQueue()

View license
@Test
public void testBasicSendToNoQueue() throws Exception {
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
}

26. DurableQueueTest#testConsumeFromDurableQueue()

View license
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testConsumeFromDurableQueue() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, true);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message = consumer.receive(500);
    Assert.assertNotNull(message);
    message.acknowledge();
    consumer.close();
    session.deleteQueue(queue);
}

27. ExpiryAddressTest#testBasicSendToNoQueue()

View license
@Test
public void testBasicSendToNoQueue() throws Exception {
    SimpleString ea = new SimpleString("EA");
    SimpleString qName = new SimpleString("q1");
    SimpleString eq = new SimpleString("EQ1");
    SimpleString eq2 = new SimpleString("EQ2");
    clientSession.createQueue(ea, eq, null, false);
    clientSession.createQueue(ea, eq2, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    ClientMessage clientMessage = createTextMessage(clientSession, "heyho!");
    clientMessage.setExpiration(System.currentTimeMillis());
    producer.send(clientMessage);
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
}

28. LargeMessageTest#testDeleteOnNoBinding()

View license
@Test
public void testDeleteOnNoBinding() throws Exception {
    final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    ActiveMQServer server = createServer(true, isNetty(), storeType);
    server.start();
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = addClientSession(sf.createSession(false, true, false));
    ClientProducer producer = session.createProducer(UUID.randomUUID().toString());
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    producer.send(clientFile);
    session.close();
    validateNoFilesOnLargeDir();
}

29. LargeMessageTest#testDeleteOnDrop()

View license
@Test
public void testDeleteOnDrop() throws Exception {
    fillAddress();
    final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = addClientSession(sf.createSession(false, true, false));
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    // Send large message which should be dropped and deleted from the filesystem
    producer.send(clientFile);
    validateNoFilesOnLargeDir();
}

30. MessageDurabilityTest#testNonDurableMessageOnNonDurableQueue()

View license
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testNonDurableMessageOnNonDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, !durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(!durable));
    restart();
    session.start();
    try {
        session.createConsumer(queue);
    } catch (ActiveMQNonExistentQueueException neqe) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}

31. MessageDurabilityTest#testNonDurableMessageOnDurableQueue()

View license
@Test
public void testNonDurableMessageOnDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(!durable));
    restart();
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    Assert.assertNull(consumer.receiveImmediate());
    consumer.close();
    session.deleteQueue(queue);
}

32. MessageDurabilityTest#testDurableMessageOnDurableQueue()

View license
@Test
public void testDurableMessageOnDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    restart();
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    Assert.assertNotNull(consumer.receive(500));
    consumer.close();
    session.deleteQueue(queue);
}

33. MessageDurabilityTest#testDurableMessageOnNonDurableQueue()

View license
/**
    * we can send a durable msg to a non durable queue but the msg won't be persisted
    */
@Test
public void testDurableMessageOnNonDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    final SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, !durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    restart();
    session.start();
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createConsumer(queue);
        }
    });
}

34. MessageDurabilityTest#testDurableMessageOnTemporaryQueue()

View license
/**
    * we can send a durable msg to a temp queue but the msg won't be persisted
    */
@Test
public void testDurableMessageOnTemporaryQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    final SimpleString queue = RandomUtil.randomSimpleString();
    session.createTemporaryQueue(address, queue);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    restart();
    session.start();
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createConsumer(queue);
        }
    });
}

35. MessageExpirationTest#testMessageExpiredWithoutExpiryAddress()

View license
@Test
public void testMessageExpiredWithoutExpiryAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, false);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(false);
    message.setExpiration(System.currentTimeMillis() + MessageExpirationTest.EXPIRATION);
    producer.send(message);
    Thread.sleep(MessageExpirationTest.EXPIRATION * 2);
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    consumer.close();
    session.deleteQueue(queue);
}

36. NewDeadLetterAddressTest#testSendToDLAWhenNoRoute()

View license
@Test
public void testSendToDLAWhenNoRoute() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString address = new SimpleString("empty_address");
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dla).setSendToDLAOnNoRoute(true);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    SimpleString dlq = new SimpleString("DLQ1");
    clientSession.createQueue(dla, dlq, null, false);
    ClientProducer producer = clientSession.createProducer(address);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(dlq);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}

37. ProducerCloseTest#testCanNotUseAClosedProducer()

View license
@Test
public void testCanNotUseAClosedProducer() throws Exception {
    final ClientProducer producer = session.createProducer(RandomUtil.randomSimpleString());
    Assert.assertFalse(producer.isClosed());
    producer.close();
    Assert.assertTrue(producer.isClosed());
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            producer.send(session.createMessage(false));
        }
    });
}

38. ProducerTest#testProducerWithSmallWindowSizeAndLargeMessage()

Project: activemq-artemis
Source File: ProducerTest.java
View license
@Test
public void testProducerWithSmallWindowSizeAndLargeMessage() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    server.getRemotingService().addIncomingInterceptor(new Interceptor() {

        @Override
        public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
            if (packet.getType() == PacketImpl.SESS_SEND) {
                latch.countDown();
            }
            return true;
        }
    });
    ServerLocator locator = createInVMNonHALocator().setConfirmationWindowSize(100);
    ClientSessionFactory cf = locator.createSessionFactory();
    ClientSession session = cf.createSession(false, true, true);
    ClientProducer producer = session.createProducer(QUEUE);
    ClientMessage message = session.createMessage(true);
    byte[] body = new byte[1000];
    message.getBodyBuffer().writeBytes(body);
    producer.send(message);
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    session.close();
    locator.close();
}

39. ReceiveTest#testBasicReceive()

Project: activemq-artemis
Source File: ReceiveTest.java
View license
@Test
public void testBasicReceive() throws Exception {
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    ClientProducer cp = sendSession.createProducer(addressA);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    session.start();
    cp.send(sendSession.createMessage(false));
    Assert.assertNotNull(cc.receive());
    session.close();
    sendSession.close();
}

40. SessionTest#testClose()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testClose() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, true, true);
    clientSession.createQueue(queueName, queueName, false);
    ClientProducer p = clientSession.createProducer();
    ClientProducer p1 = clientSession.createProducer(queueName);
    ClientConsumer c = clientSession.createConsumer(queueName);
    ClientConsumer c1 = clientSession.createConsumer(queueName);
    clientSession.close();
    Assert.assertTrue(clientSession.isClosed());
    Assert.assertTrue(p.isClosed());
    Assert.assertTrue(p1.isClosed());
    Assert.assertTrue(c.isClosed());
    Assert.assertTrue(c1.isClosed());
}

41. TemporaryQueueTest#testConsumeFromTemporaryQueue()

View license
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testConsumeFromTemporaryQueue() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createTemporaryQueue(address, queue);
    ClientProducer producer = session.createProducer(address);
    ClientMessage msg = session.createMessage(false);
    producer.send(msg);
    session.start();
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message = consumer.receive(500);
    assertNotNull(message);
    message.acknowledge();
    consumer.close();
    session.deleteQueue(queue);
    session.close();
}

42. TemporaryQueueTest#testConsumeFromTemporaryQueueCreatedByOtherSession()

View license
@Test
public void testConsumeFromTemporaryQueueCreatedByOtherSession() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createTemporaryQueue(address, queue);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    ClientSession session2 = sf.createSession(false, true, true);
    session2.start();
    ClientConsumer consumer = session2.createConsumer(queue);
    ClientMessage message = consumer.receive(500);
    assertNotNull(message);
    session2.close();
    session.close();
}

43. QueueControlTest#testGetMessageCount()

View license
@Test
public void testGetMessageCount() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, getMessageCount(queueControl));
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    Assert.assertEquals(1, getMessageCount(queueControl));
    consumeMessages(1, session, queue);
    Assert.assertEquals(0, getMessageCount(queueControl));
    session.deleteQueue(queue);
}

44. QueueControlTest#testGetDeliveringCount()

View license
@Test
public void testGetDeliveringCount() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, null, false);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getDeliveringCount());
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message = consumer.receive(500);
    Assert.assertNotNull(message);
    Assert.assertEquals(1, queueControl.getDeliveringCount());
    message.acknowledge();
    session.commit();
    Assert.assertEquals(0, queueControl.getDeliveringCount());
    consumer.close();
    session.deleteQueue(queue);
}

45. SecurityTest#testNonBlockSendWithoutRole()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testNonBlockSendWithoutRole() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    Role role = new Role("arole", false, false, true, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    securityRepository.addMatch(SecurityTest.addressA, roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
    ClientProducer cp = session.createProducer(SecurityTest.addressA);
    cp.send(session.createMessage(false));
    session.close();
    Queue binding = (Queue) server.getPostOffice().getBinding(new SimpleString(SecurityTest.queueA)).getBindable();
    Assert.assertEquals(0, getMessageCount(binding));
}

46. SecurityTest#testSendManagementWithRole()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testSendManagementWithRole() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    Role role = new Role("arole", false, false, false, false, false, false, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    securityRepository.addMatch(configuration.getManagementAddress().toString(), roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    locator.setBlockOnNonDurableSend(true);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    ClientProducer cp = session.createProducer(configuration.getManagementAddress());
    cp.send(session.createMessage(false));
    session.close();
}

47. SecurityTest#testNonBlockSendManagementWithoutRole()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testNonBlockSendManagementWithoutRole() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    Role role = new Role("arole", false, false, true, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    securityRepository.addMatch(configuration.getManagementAddress().toString(), roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    session.createQueue(configuration.getManagementAddress().toString(), SecurityTest.queueA, true);
    ClientProducer cp = session.createProducer(configuration.getManagementAddress());
    cp.send(session.createMessage(false));
    session.close();
    Queue binding = (Queue) server.getPostOffice().getBinding(new SimpleString(SecurityTest.queueA)).getBindable();
    Assert.assertEquals(0, getMessageCount(binding));
}

48. SecurityTest#checkUserSendNoReceive()

Project: activemq-artemis
Source File: SecurityTest.java
View license
// Check the user can send message but cannot receive message
private void checkUserSendNoReceive(final String queue, final ClientSession connection) throws Exception {
    ClientProducer prod = connection.createProducer(queue);
    ClientMessage m = connection.createMessage(false);
    prod.send(m);
    try {
        connection.createConsumer(queue);
        Assert.fail("should throw exception");
    } catch (ActiveMQSecurityException se) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}

49. ExpiryRunnerTest#testExpireFromMultipleQueues()

View license
@Test
public void testExpireFromMultipleQueues() throws Exception {
    ClientProducer producer = clientSession.createProducer(qName);
    clientSession.createQueue(qName2, qName2, null, false);
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
    server.getAddressSettingsRepository().addMatch(qName2.toString(), addressSettings);
    ClientProducer producer2 = clientSession.createProducer(qName2);
    int numMessages = 100;
    long expiration = System.currentTimeMillis();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = createTextMessage(clientSession, "m" + i);
        m.setExpiration(expiration);
        producer.send(m);
        m = createTextMessage(clientSession, "m" + i);
        m.setExpiration(expiration);
        producer2.send(m);
    }
    Thread.sleep(1600);
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getMessageCount());
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getDeliveringCount());
}

50. LVQTest#testSingleTXRollback()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testSingleTXRollback() throws Exception {
    ClientProducer producer = clientSessionTxReceives.createProducer(address);
    ClientConsumer consumer = clientSessionTxReceives.createConsumer(qName1);
    SimpleString messageId1 = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, messageId1);
    producer.send(m1);
    clientSessionTxReceives.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    clientSessionTxReceives.rollback();
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    Assert.assertNull(consumer.receiveImmediate());
}

51. BasicXaTest#testSendWithoutXID()

Project: activemq-artemis
Source File: BasicXaTest.java
View license
@Test
public void testSendWithoutXID() throws Exception {
    // Since both resources have same RM, TM will probably use 1PC optimization
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = createSessionFactory(locator);
    ClientSession session = addClientSession(factory.createSession(true, false, false));
    session.createQueue("Test", "Test");
    ClientProducer prod = session.createProducer("Test");
    prod.send(session.createMessage(true));
    session.start();
    ClientConsumer cons = session.createConsumer("Test");
    assertNotNull("Send went through an invalid XA Session", cons.receiveImmediate());
}

52. ClientSessionImpl#closeChildren()

View license
private void closeChildren() throws ActiveMQException {
    Set<ClientConsumerInternal> consumersClone = cloneConsumers();
    for (ClientConsumer consumer : consumersClone) {
        consumer.close();
    }
    Set<ClientProducerInternal> producersClone = cloneProducers();
    for (ClientProducer producer : producersClone) {
        producer.close();
    }
}

53. ScaleDownHandler#scaleDownDuplicateIDs()

View license
public void scaleDownDuplicateIDs(Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap, ClientSessionFactory sessionFactory, SimpleString managementAddress, String user, String password) throws Exception {
    try (ClientSession session = sessionFactory.createSession(user, password, true, false, false, false, 0);
        ClientProducer producer = session.createProducer(managementAddress)) {
        //todo - https://issues.jboss.org/browse/HORNETQ-1336
        for (SimpleString address : duplicateIDMap.keySet()) {
            ClientMessage message = session.createMessage(false);
            List<Pair<byte[], Long>> list = duplicateIDMap.get(address);
            String[] array = new String[list.size()];
            for (int i = 0; i < list.size(); i++) {
                Pair<byte[], Long> pair = list.get(i);
                array[i] = new String(pair.getA());
            }
            ManagementHelper.putOperationInvocation(message, ResourceNames.CORE_SERVER, "updateDuplicateIdCache", address.toString(), array);
            producer.send(message);
        }
    }
}

54. MessagePropertyTest#sendMessages()

View license
private void sendMessages() throws Exception {
    ClientSession session = sf.createSession(true, true);
    session.createQueue(ADDRESS, ADDRESS, null, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(true);
        setBody(i, message);
        message.putIntProperty("int", i);
        message.putShortProperty("short", (short) i);
        message.putByteProperty("byte", (byte) i);
        message.putFloatProperty("float", floatValue(i));
        message.putStringProperty(SIMPLE_STRING_KEY, new SimpleString(Integer.toString(i)));
        message.putBytesProperty("byte[]", byteArray(i));
        message.putObjectProperty("null-value", null);
        producer.send(message);
    }
    session.commit();
}

55. DeliveryOrderTest#testSendDeliveryOrderOnCommit()

View license
@Test
public void testSendDeliveryOrderOnCommit() throws Exception {
    ClientSession sendSession = cf.createSession(false, false, true);
    ClientProducer cp = sendSession.createProducer(addressA);
    int numMessages = 1000;
    sendSession.createQueue(addressA, queueA, false);
    for (int i = 0; i < numMessages; i++) {
        ClientMessage cm = sendSession.createMessage(false);
        cm.getBodyBuffer().writeInt(i);
        cp.send(cm);
        if (i % 10 == 0) {
            sendSession.commit();
        }
        sendSession.commit();
    }
    ClientConsumer c = sendSession.createConsumer(queueA);
    sendSession.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage cm = c.receive(5000);
        Assert.assertNotNull(cm);
        Assert.assertEquals(i, cm.getBodyBuffer().readInt());
    }
    sendSession.close();
}

56. MessageConsumerRollbackTest#sendMessages()

View license
/**
    * @param numberOfMessages
    * @param session
    * @throws Exception
    */
private void sendMessages(int numberOfMessages, ClientSession session) throws Exception {
    ClientProducer producer = session.createProducer(inQueue);
    for (int i = 0; i < numberOfMessages; i++) {
        ActiveMQTextMessage txt = new ActiveMQTextMessage(session);
        txt.setIntProperty("msg", i);
        txt.setText("Message Number (" + i + ")");
        txt.doBeforeSend();
        producer.send(txt.getCoreMessage());
    }
    session.commit();
}

57. MessageGroupingConnectionFactoryTest#doTestBasicGroupingUsingConnectionFactory()

View license
private void doTestBasicGroupingUsingConnectionFactory() throws Exception {
    ClientProducer clientProducer = clientSession.createProducer(qName);
    ClientConsumer consumer = clientSession.createConsumer(qName);
    ClientConsumer consumer2 = clientSession.createConsumer(qName);
    clientSession.start();
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(clientSession, "m" + i);
        clientProducer.send(message);
    }
    CountDownLatch latch = new CountDownLatch(numMessages);
    DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
    consumer.setMessageHandler(dummyMessageHandler);
    DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
    consumer2.setMessageHandler(dummyMessageHandler2);
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    Assert.assertEquals(100, dummyMessageHandler.list.size());
    Assert.assertEquals(0, dummyMessageHandler2.list.size());
    consumer.close();
    consumer2.close();
}

58. MessageGroupingTest#doTestBasicGrouping()

View license
private void doTestBasicGrouping() throws Exception {
    ClientProducer clientProducer = clientSession.createProducer(qName);
    ClientConsumer consumer = clientSession.createConsumer(qName);
    ClientConsumer consumer2 = clientSession.createConsumer(qName);
    clientSession.start();
    SimpleString groupId = new SimpleString("grp1");
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(clientSession, "m" + i);
        message.putStringProperty(Message.HDR_GROUP_ID, groupId);
        clientProducer.send(message);
    }
    CountDownLatch latch = new CountDownLatch(numMessages);
    DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
    consumer.setMessageHandler(dummyMessageHandler);
    DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
    consumer2.setMessageHandler(dummyMessageHandler2);
    Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    Assert.assertEquals(100, dummyMessageHandler.list.size());
    Assert.assertEquals(0, dummyMessageHandler2.list.size());
    consumer.close();
    consumer2.close();
}

59. MessageRateTest#testProduceRate()

View license
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testProduceRate() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    locator.setProducerMaxRate(10);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        producer.send(session.createMessage(false));
    }
    long end = System.currentTimeMillis();
    Assert.assertTrue("TotalTime = " + (end - start), end - start >= 1000);
    session.close();
}

60. RoutingTest#testRouteToSingleNonDurableQueue()

Project: activemq-artemis
Source File: RoutingTest.java
View license
@Test
public void testRouteToSingleNonDurableQueue() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    sendSession.createQueue(addressA, queueA, false);
    int numMessages = 300;
    ClientProducer p = sendSession.createProducer(addressA);
    for (int i = 0; i < numMessages; i++) {
        p.send(sendSession.createMessage(false));
    }
    ClientSession session = cf.createSession(false, true, true);
    ClientConsumer c1 = session.createConsumer(queueA);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = c1.receive(5000);
        Assert.assertNotNull(m);
        m.acknowledge();
    }
    Assert.assertNull(c1.receiveImmediate());
    sendSession.close();
    session.close();
}

61. RoutingTest#testRouteToSingleDurableQueue()

Project: activemq-artemis
Source File: RoutingTest.java
View license
@Test
public void testRouteToSingleDurableQueue() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    sendSession.createQueue(addressA, queueA, true);
    int numMessages = 300;
    ClientProducer p = sendSession.createProducer(addressA);
    for (int i = 0; i < numMessages; i++) {
        p.send(sendSession.createMessage(false));
    }
    ClientSession session = cf.createSession(false, true, true);
    ClientConsumer c1 = session.createConsumer(queueA);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = c1.receive(5000);
        Assert.assertNotNull(m);
        m.acknowledge();
    }
    Assert.assertNull(c1.receiveImmediate());
    sendSession.close();
    session.close();
}

62. RoutingTest#testRouteToSingleQueueWithFilter()

Project: activemq-artemis
Source File: RoutingTest.java
View license
@Test
public void testRouteToSingleQueueWithFilter() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    sendSession.createQueue(addressA, queueA, new SimpleString("foo = 'bar'"), false);
    int numMessages = 300;
    ClientProducer p = sendSession.createProducer(addressA);
    for (int i = 0; i < numMessages; i++) {
        ClientMessage clientMessage = sendSession.createMessage(false);
        clientMessage.putStringProperty(new SimpleString("foo"), new SimpleString("bar"));
        p.send(clientMessage);
    }
    ClientSession session = cf.createSession(false, true, true);
    ClientConsumer c1 = session.createConsumer(queueA);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = c1.receive(5000);
        Assert.assertNotNull(m);
        m.acknowledge();
    }
    Assert.assertNull(c1.receiveImmediate());
    sendSession.close();
    session.close();
}

63. RoutingTest#testRouteToSingleTemporaryQueue()

Project: activemq-artemis
Source File: RoutingTest.java
View license
@Test
public void testRouteToSingleTemporaryQueue() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    sendSession.createTemporaryQueue(addressA, queueA);
    int numMessages = 300;
    ClientProducer p = sendSession.createProducer(addressA);
    for (int i = 0; i < numMessages; i++) {
        p.send(sendSession.createMessage(false));
    }
    ClientSession session = cf.createSession(false, true, true);
    ClientConsumer c1 = session.createConsumer(queueA);
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = c1.receive(5000);
        Assert.assertNotNull(m);
        m.acknowledge();
    }
    Assert.assertNull(c1.receiveImmediate());
    sendSession.close();
    session.close();
}

64. SessionCloseTest#testCloseHierarchy()

View license
@Test
public void testCloseHierarchy() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(address, queue, false);
    ClientProducer producer = session.createProducer(address);
    ClientConsumer consumer = session.createConsumer(queue);
    session.close();
    Assert.assertTrue(session.isClosed());
    Assert.assertTrue(producer.isClosed());
    Assert.assertTrue(consumer.isClosed());
}

65. SessionSendAcknowledgementHandlerTest#verifySendAcknowledgementsProducerOnly()

View license
public void verifySendAcknowledgementsProducerOnly(int windowSize) throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    locator.setConfirmationWindowSize(windowSize);
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession(null, null, false, true, true, false, 1);
    session.createQueue(address, queueName, false);
    ClientProducer prod = session.createProducer(address);
    final int numMessages = 1000;
    LatchAckHandler producerHandler = new LatchAckHandler("producer", new CountDownLatch(numMessages));
    for (int i = 0; i < numMessages; i++) {
        ClientMessage msg2 = session.createMessage(false);
        prod.send(address, msg2, producerHandler);
    }
    Assert.assertTrue("producer specific handler must have acked, " + producerHandler, producerHandler.latch.await(5, TimeUnit.SECONDS));
}

66. SlowConsumerTest#testSlowConsumerSpared()

View license
@Test
public void testSlowConsumerSpared() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(true, true));
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = addClientProducer(session.createProducer(QUEUE));
    final int numMessages = 5;
    for (int i = 0; i < numMessages; i++) {
        producer.send(createTextMessage(session, "m" + i));
    }
    ClientConsumer consumer = addClientConsumer(session.createConsumer(QUEUE));
    session.start();
    Thread.sleep(3000);
    for (int i = 0; i < numMessages; i++) {
        assertNotNull(consumer.receive(500));
    }
}

67. TransactionalSendTest#testSendWithCommit()

View license
@Test
public void testSendWithCommit() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, false, false);
    session.createQueue(addressA, queueA, false);
    ClientProducer cp = session.createProducer(addressA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(session.createMessage(false));
    }
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(0, getMessageCount(q));
    session.commit();
    Assert.assertEquals(getMessageCount(q), numMessages);
    // now send some more
    for (int i = 0; i < numMessages; i++) {
        cp.send(session.createMessage(false));
    }
    Assert.assertEquals(numMessages, getMessageCount(q));
    session.commit();
    Assert.assertEquals(numMessages * 2, getMessageCount(q));
    session.close();
}

68. TransactionalSendTest#testSendWithRollback()

View license
@Test
public void testSendWithRollback() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, false, false);
    session.createQueue(addressA, queueA, false);
    ClientProducer cp = session.createProducer(addressA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(session.createMessage(false));
    }
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(getMessageCount(q), 0);
    session.rollback();
    Assert.assertEquals(getMessageCount(q), 0);
    // now send some more
    for (int i = 0; i < numMessages; i++) {
        cp.send(session.createMessage(false));
    }
    Assert.assertEquals(0, getMessageCount(q));
    session.commit();
    Assert.assertEquals(numMessages, getMessageCount(q));
    session.close();
}

69. FailoverTest#testFailoverOnInitialConnection()

Project: activemq-artemis
Source File: FailoverTest.java
View license
// https://jira.jboss.org/jira/browse/HORNETQ-285
@Test
public void testFailoverOnInitialConnection() throws Exception {
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setFailoverOnInitialConnection(true).setReconnectAttempts(-1);
    sf = createSessionFactoryAndWaitForTopology(locator, 2);
    // Crash live server
    crash();
    ClientSession session = createSession(sf);
    session.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, null, true);
    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    sendMessages(session, producer, NUM_MESSAGES);
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    receiveMessages(consumer);
    session.close();
}

70. FailoverTest#testFailWithBrowser()

Project: activemq-artemis
Source File: FailoverTest.java
View license
/*
    * Browser will get reset to beginning after failover
    */
@Test
public void testFailWithBrowser() throws Exception {
    createSessionFactory();
    ClientSession session = createSession(sf, true, true);
    session.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, null, true);
    ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
    sendMessagesSomeDurable(session, producer);
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS, true);
    session.start();
    receiveMessages(consumer, 0, NUM_MESSAGES, false);
    crash(session);
    receiveDurableMessages(consumer);
}

71. CoreClientOverHttpTest#testCoreHttpClientIdle()

View license
@Test
public void testCoreHttpClientIdle() throws Exception {
    locator.setConnectionTTL(500);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    Thread.sleep(500 * 5);
    session.close();
}

72. PagingSendTest#sendMessageBatch()

View license
public List<String> sendMessageBatch(int batchSize, ClientSession session, SimpleString queueAddr) throws ActiveMQException {
    List<String> messageIds = new ArrayList<>();
    ClientProducer producer = session.createProducer(queueAddr);
    for (int i = 0; i < batchSize; i++) {
        Message message = session.createMessage(true);
        message.getBodyBuffer().writeBytes(new byte[1024]);
        String id = UUID.randomUUID().toString();
        message.putStringProperty("id", id);
        // this is to make the print-data easier to debug
        message.putIntProperty("seq", i);
        messageIds.add(id);
        producer.send(message);
    }
    session.commit();
    return messageIds;
}

73. BatchDelayTest#testSendReceiveMany()

View license
@Test
public void testSendReceiveMany() throws Exception {
    ClientSessionFactory sf = createSessionFactory();
    ClientSession session = sf.createSession();
    final String foo = "foo";
    session.createQueue(foo, foo);
    ClientProducer prod = session.createProducer(foo);
    ClientConsumer cons = session.createConsumer(foo);
    session.start();
    sendMessages(session, prod, N);
    receiveMessages(cons, 0, N, true);
}

74. ExpiryRunnerTest#testBasicExpire()

View license
@Test
public void testBasicExpire() throws Exception {
    ClientProducer producer = clientSession.createProducer(qName);
    int numMessages = 100;
    long expiration = System.currentTimeMillis();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = createTextMessage(clientSession, "m" + i);
        m.setExpiration(expiration);
        producer.send(m);
    }
    Thread.sleep(1600);
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getMessageCount());
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getDeliveringCount());
}

75. ExpiryRunnerTest#testExpireHalf()

View license
@Test
public void testExpireHalf() throws Exception {
    ClientProducer producer = clientSession.createProducer(qName);
    int numMessages = 100;
    long expiration = System.currentTimeMillis();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = createTextMessage(clientSession, "m" + i);
        if (i % 2 == 0) {
            m.setExpiration(expiration);
        }
        producer.send(m);
    }
    Thread.sleep(1600);
    Assert.assertEquals(numMessages / 2, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getMessageCount());
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getDeliveringCount());
}

76. ExpiryRunnerTest#testExpireConsumeHalf()

View license
@Test
public void testExpireConsumeHalf() throws Exception {
    ClientProducer producer = clientSession.createProducer(qName);
    int numMessages = 100;
    long expiration = System.currentTimeMillis() + 1000;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage m = createTextMessage(clientSession, "m" + i);
        m.setExpiration(expiration);
        producer.send(m);
    }
    ClientConsumer consumer = clientSession.createConsumer(qName);
    clientSession.start();
    for (int i = 0; i < numMessages / 2; i++) {
        ClientMessage cm = consumer.receive(500);
        Assert.assertNotNull("message not received " + i, cm);
        cm.acknowledge();
        Assert.assertEquals("m" + i, cm.getBodyBuffer().readString());
    }
    consumer.close();
    Thread.sleep(2100);
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getMessageCount());
    Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(qName).getBindable()).getDeliveringCount());
}

77. MeasurePagingMultiThreadTest#sendInitialBatch()

View license
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
/**
    * @param adr
    * @param nMessages
    * @param messageSize
    * @param factory
    * @throws ActiveMQException
    */
private void sendInitialBatch(final SimpleString adr, final int nMessages, final int messageSize, final ClientSessionFactory factory) throws ActiveMQException {
    ClientSession session = factory.createSession(false, true, true);
    ClientProducer producer = session.createProducer(adr);
    ClientMessage msg = session.createMessage(true);
    msg.getBodyBuffer().writeBytes(new byte[messageSize]);
    sendMessages(nMessages, producer, msg);
}

78. NIOMultiThreadCompactorStressTest#addBogusData()

View license
/**
    * @throws ActiveMQException
    */
private void addBogusData(final int nmessages, final String queue) throws ActiveMQException {
    ClientSession session = sf.createSession(false, false);
    try {
        session.createQueue(queue, queue, true);
    } catch (Exception ignored) {
    }
    ClientProducer prod = session.createProducer(queue);
    for (int i = 0; i < nmessages; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.getBodyBuffer().writeBytes(new byte[1024]);
        prod.send(msg);
    }
    session.commit();
    session.start();
    ClientConsumer cons = session.createConsumer(queue);
    Assert.assertNotNull(cons.receive(1000));
    session.rollback();
    session.close();
}

79. SessionTest#testCommitWithReceive()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testCommitWithReceive() throws Exception {
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    ClientProducer cp = sendSession.createProducer(queueName);
    ClientSession clientSession = cf.createSession(false, true, false);
    clientSession.createQueue(queueName, queueName, false);
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
    Assert.assertEquals(10, getMessageCount(q));
    ClientConsumer cc = clientSession.createConsumer(queueName);
    clientSession.start();
    ClientMessage m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    clientSession.commit();
    Assert.assertEquals(0, getMessageCount(q));
    clientSession.close();
    sendSession.close();
}

80. SessionTest#testRollbackWithReceive()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testRollbackWithReceive() throws Exception {
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    ClientProducer cp = sendSession.createProducer(queueName);
    ClientSession clientSession = cf.createSession(false, true, false);
    clientSession.createQueue(queueName, queueName, false);
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    cp.send(clientSession.createMessage(false));
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
    Assert.assertEquals(10, getMessageCount(q));
    ClientConsumer cc = clientSession.createConsumer(queueName);
    clientSession.start();
    ClientMessage m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    m = cc.receive(5000);
    Assert.assertNotNull(m);
    m.acknowledge();
    clientSession.rollback();
    Assert.assertEquals(10, getMessageCount(q));
    clientSession.close();
    sendSession.close();
}

81. WildCardRoutingTest#testWildcardRoutingLotsOfQueuesAddedThenDeleted()

View license
@Test
public void testWildcardRoutingLotsOfQueuesAddedThenDeleted() throws Exception {
    SimpleString addressAB = new SimpleString("a.b");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString addressAD = new SimpleString("a.d");
    SimpleString addressAE = new SimpleString("a.e");
    SimpleString addressAF = new SimpleString("a.f");
    SimpleString addressAG = new SimpleString("a.g");
    SimpleString addressAH = new SimpleString("a.h");
    SimpleString addressAJ = new SimpleString("a.j");
    SimpleString addressAK = new SimpleString("a.k");
    SimpleString address = new SimpleString("a.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName3 = new SimpleString("Q3");
    SimpleString queueName4 = new SimpleString("Q4");
    SimpleString queueName5 = new SimpleString("Q5");
    SimpleString queueName6 = new SimpleString("Q6");
    SimpleString queueName7 = new SimpleString("Q7");
    SimpleString queueName8 = new SimpleString("Q8");
    SimpleString queueName9 = new SimpleString("Q9");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(addressAD, queueName3, null, false);
    clientSession.createQueue(addressAE, queueName4, null, false);
    clientSession.createQueue(addressAF, queueName5, null, false);
    clientSession.createQueue(addressAG, queueName6, null, false);
    clientSession.createQueue(addressAH, queueName7, null, false);
    clientSession.createQueue(addressAJ, queueName8, null, false);
    clientSession.createQueue(addressAK, queueName9, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer();
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(addressAB, createTextMessage(clientSession, "m1"));
    producer.send(addressAC, createTextMessage(clientSession, "m2"));
    producer.send(addressAD, createTextMessage(clientSession, "m3"));
    producer.send(addressAE, createTextMessage(clientSession, "m4"));
    producer.send(addressAF, createTextMessage(clientSession, "m5"));
    producer.send(addressAG, createTextMessage(clientSession, "m6"));
    producer.send(addressAH, createTextMessage(clientSession, "m7"));
    producer.send(addressAJ, createTextMessage(clientSession, "m8"));
    producer.send(addressAK, createTextMessage(clientSession, "m9"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m1", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m2", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m3", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m4", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m5", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m6", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m7", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m8", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m9", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    // now remove all the queues
    clientSession.deleteQueue(queueName1);
    clientSession.deleteQueue(queueName2);
    clientSession.deleteQueue(queueName3);
    clientSession.deleteQueue(queueName4);
    clientSession.deleteQueue(queueName5);
    clientSession.deleteQueue(queueName6);
    clientSession.deleteQueue(queueName7);
    clientSession.deleteQueue(queueName8);
    clientSession.deleteQueue(queueName9);
    clientConsumer.close();
    clientSession.deleteQueue(queueName);
}

82. WildCardRoutingTest#testWildcardRoutingLotsOfQueuesAddedThenDeletedHash()

View license
@Test
public void testWildcardRoutingLotsOfQueuesAddedThenDeletedHash() throws Exception {
    SimpleString addressAB = new SimpleString("a.b");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString addressAD = new SimpleString("a.d");
    SimpleString addressAE = new SimpleString("a.e");
    SimpleString addressAF = new SimpleString("a.f");
    SimpleString addressAG = new SimpleString("a.g");
    SimpleString addressAH = new SimpleString("a.h");
    SimpleString addressAJ = new SimpleString("a.j");
    SimpleString addressAK = new SimpleString("a.k");
    SimpleString address = new SimpleString("#");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName3 = new SimpleString("Q3");
    SimpleString queueName4 = new SimpleString("Q4");
    SimpleString queueName5 = new SimpleString("Q5");
    SimpleString queueName6 = new SimpleString("Q6");
    SimpleString queueName7 = new SimpleString("Q7");
    SimpleString queueName8 = new SimpleString("Q8");
    SimpleString queueName9 = new SimpleString("Q9");
    SimpleString queueName = new SimpleString("Q");
    clientSession.createQueue(addressAB, queueName1, null, false);
    clientSession.createQueue(addressAC, queueName2, null, false);
    clientSession.createQueue(addressAD, queueName3, null, false);
    clientSession.createQueue(addressAE, queueName4, null, false);
    clientSession.createQueue(addressAF, queueName5, null, false);
    clientSession.createQueue(addressAG, queueName6, null, false);
    clientSession.createQueue(addressAH, queueName7, null, false);
    clientSession.createQueue(addressAJ, queueName8, null, false);
    clientSession.createQueue(addressAK, queueName9, null, false);
    clientSession.createQueue(address, queueName, null, false);
    ClientProducer producer = clientSession.createProducer();
    ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
    clientSession.start();
    producer.send(addressAB, createTextMessage(clientSession, "m1"));
    producer.send(addressAC, createTextMessage(clientSession, "m2"));
    producer.send(addressAD, createTextMessage(clientSession, "m3"));
    producer.send(addressAE, createTextMessage(clientSession, "m4"));
    producer.send(addressAF, createTextMessage(clientSession, "m5"));
    producer.send(addressAG, createTextMessage(clientSession, "m6"));
    producer.send(addressAH, createTextMessage(clientSession, "m7"));
    producer.send(addressAJ, createTextMessage(clientSession, "m8"));
    producer.send(addressAK, createTextMessage(clientSession, "m9"));
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m1", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m2", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m3", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m4", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m5", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m6", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m7", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m8", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals("m9", m.getBodyBuffer().readString());
    m.acknowledge();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    // now remove all the queues
    clientSession.deleteQueue(queueName1);
    clientSession.deleteQueue(queueName2);
    clientSession.deleteQueue(queueName3);
    clientSession.deleteQueue(queueName4);
    clientSession.deleteQueue(queueName5);
    clientSession.deleteQueue(queueName6);
    clientSession.deleteQueue(queueName7);
    clientSession.deleteQueue(queueName8);
    clientSession.deleteQueue(queueName9);
    clientConsumer.close();
    clientSession.deleteQueue(queueName);
}

83. ScheduledMessageTest#scheduledDelivery()

View license
// Private -------------------------------------------------------
private void scheduledDelivery(final boolean tx) throws Exception {
    ActiveMQTestBase.forceGC();
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(tx, false, false);
    session.createQueue(atestq, atestq, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientConsumer consumer = session.createConsumer(atestq);
    session.start();
    if (tx) {
        session.start(xid, XAResource.TMNOFLAGS);
    }
    // Send one scheduled
    long now = System.currentTimeMillis();
    ClientMessage tm1 = createDurableMessage(session, "testScheduled1");
    tm1.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 7000);
    producer.send(tm1);
    // First send some non scheduled messages
    ClientMessage tm2 = createDurableMessage(session, "testScheduled2");
    producer.send(tm2);
    ClientMessage tm3 = createDurableMessage(session, "testScheduled3");
    producer.send(tm3);
    ClientMessage tm4 = createDurableMessage(session, "testScheduled4");
    producer.send(tm4);
    // Now send some more scheduled messages
    ClientMessage tm5 = createDurableMessage(session, "testScheduled5");
    tm5.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 5000);
    producer.send(tm5);
    ClientMessage tm6 = createDurableMessage(session, "testScheduled6");
    tm6.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 4000);
    producer.send(tm6);
    ClientMessage tm7 = createDurableMessage(session, "testScheduled7");
    tm7.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 3000);
    producer.send(tm7);
    ClientMessage tm8 = createDurableMessage(session, "testScheduled8");
    tm8.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, now + 6000);
    producer.send(tm8);
    // And one scheduled with a -ve number
    ClientMessage tm9 = createDurableMessage(session, "testScheduled9");
    tm9.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, -3);
    producer.send(tm9);
    if (tx) {
        session.end(xid, XAResource.TMSUCCESS);
        session.prepare(xid);
        session.commit(xid, false);
    } else {
        session.commit();
    }
    if (tx) {
        session.start(xid, XAResource.TMNOFLAGS);
    }
    ClientMessage rm1 = consumer.receive(250);
    Assert.assertNotNull(rm1);
    Assert.assertEquals("testScheduled2", rm1.getBodyBuffer().readString());
    ClientMessage rm2 = consumer.receive(250);
    Assert.assertNotNull(rm2);
    Assert.assertEquals("testScheduled3", rm2.getBodyBuffer().readString());
    ClientMessage rm3 = consumer.receive(250);
    Assert.assertNotNull(rm3);
    Assert.assertEquals("testScheduled4", rm3.getBodyBuffer().readString());
    // Now the one with a scheduled with a -ve number
    ClientMessage rm5 = consumer.receive(250);
    Assert.assertNotNull(rm5);
    Assert.assertEquals("testScheduled9", rm5.getBodyBuffer().readString());
    // Now the scheduled
    ClientMessage rm6 = consumer.receive(3250);
    Assert.assertNotNull(rm6);
    Assert.assertEquals("testScheduled7", rm6.getBodyBuffer().readString());
    long now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 3000);
    ClientMessage rm7 = consumer.receive(1250);
    Assert.assertNotNull(rm7);
    Assert.assertEquals("testScheduled6", rm7.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 4000);
    ClientMessage rm8 = consumer.receive(1250);
    Assert.assertNotNull(rm8);
    Assert.assertEquals("testScheduled5", rm8.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 5000);
    ClientMessage rm9 = consumer.receive(1250);
    Assert.assertNotNull(rm9);
    Assert.assertEquals("testScheduled8", rm9.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 6000);
    ClientMessage rm10 = consumer.receive(1250);
    Assert.assertNotNull(rm10);
    Assert.assertEquals("testScheduled1", rm10.getBodyBuffer().readString());
    now2 = System.currentTimeMillis();
    Assert.assertTrue(now2 - now >= 7000);
    if (tx) {
        session.end(xid, XAResource.TMSUCCESS);
        session.prepare(xid);
        session.commit(xid, false);
    }
    session.close();
    sessionFactory.close();
}

84. BasicXaRecoveryTest#testMultipleTxReceiveWithCommit()

View license
public void testMultipleTxReceiveWithCommit(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientMessage m5 = createTextMessage("m5");
    ClientMessage m6 = createTextMessage("m6");
    ClientMessage m7 = createTextMessage("m7");
    ClientMessage m8 = createTextMessage("m8");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    SimpleString anewtestq = new SimpleString("anewtestq");
    clientSession.createQueue(anewtestq, anewtestq, null, true);
    ClientProducer clientProducer3 = clientSession2.createProducer(anewtestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientProducer3.send(m5);
    clientProducer3.send(m6);
    clientProducer3.send(m7);
    clientProducer3.send(m8);
    clientSession2.close();
    clientSession2 = sessionFactory.createSession(true, false, false);
    ClientConsumer clientConsumer2 = clientSession2.createConsumer(anewtestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientSession2.start();
    ClientMessage m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer2.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession2 = null;
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.commit(xid, false);
    clientSession.start();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

85. BasicXaRecoveryTest#testMultipleTxReceiveWithRollback()

View license
public void testMultipleTxReceiveWithRollback(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientMessage m5 = createTextMessage("m5");
    ClientMessage m6 = createTextMessage("m6");
    ClientMessage m7 = createTextMessage("m7");
    ClientMessage m8 = createTextMessage("m8");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    SimpleString anewtestq = new SimpleString("anewtestq");
    clientSession.createQueue(anewtestq, anewtestq, null, true);
    ClientProducer clientProducer3 = clientSession2.createProducer(anewtestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientProducer3.send(m5);
    clientProducer3.send(m6);
    clientProducer3.send(m7);
    clientProducer3.send(m8);
    clientSession2.close();
    clientSession2 = sessionFactory.createSession(true, false, false);
    ClientConsumer clientConsumer2 = clientSession2.createConsumer(anewtestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientSession2.start();
    ClientMessage m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer2.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer2.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession2 = null;
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.start();
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
}

86. DuplicateDetectionTest#testSimpleDuplicateDetecion()

View license
@Test
public void testSimpleDuplicateDetecion() throws Exception {
    ClientSession session = sf.createSession(false, true, true);
    session.start();
    final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
    session.createQueue(queueName, queueName, null, false);
    ClientProducer producer = session.createProducer(queueName);
    ClientConsumer consumer = session.createConsumer(queueName);
    ClientMessage message = createMessage(session, 0);
    producer.send(message);
    ClientMessage message2 = consumer.receive(1000);
    Assert.assertEquals(0, message2.getObjectProperty(propKey));
    message = createMessage(session, 1);
    SimpleString dupID = new SimpleString("abcdefg");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    message2 = consumer.receive(1000);
    Assert.assertEquals(1, message2.getObjectProperty(propKey));
    message = createMessage(session, 2);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    message = createMessage(session, 3);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    // Now try with a different id
    message = createMessage(session, 4);
    SimpleString dupID2 = new SimpleString("hijklmnop");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
    producer.send(message);
    message2 = consumer.receive(1000);
    Assert.assertEquals(4, message2.getObjectProperty(propKey));
    message = createMessage(session, 5);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    message = createMessage(session, 6);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
}

87. DuplicateDetectionTest#testSimpleDuplicateDetectionWithString()

View license
@Test
public void testSimpleDuplicateDetectionWithString() throws Exception {
    ClientSession session = sf.createSession(false, true, true);
    session.start();
    final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
    session.createQueue(queueName, queueName, null, false);
    ClientProducer producer = session.createProducer(queueName);
    ClientConsumer consumer = session.createConsumer(queueName);
    ClientMessage message = createMessage(session, 0);
    producer.send(message);
    ClientMessage message2 = consumer.receive(1000);
    Assert.assertEquals(0, message2.getObjectProperty(propKey));
    message = createMessage(session, 1);
    SimpleString dupID = new SimpleString("abcdefg");
    message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID);
    producer.send(message);
    message2 = consumer.receive(1000);
    Assert.assertEquals(1, message2.getObjectProperty(propKey));
    message = createMessage(session, 2);
    message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID);
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    message = createMessage(session, 3);
    message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID);
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    // Now try with a different id
    message = createMessage(session, 4);
    SimpleString dupID2 = new SimpleString("hijklmnop");
    message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2);
    producer.send(message);
    message2 = consumer.receive(1000);
    Assert.assertEquals(4, message2.getObjectProperty(propKey));
    message = createMessage(session, 5);
    message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2);
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    message = createMessage(session, 6);
    message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID);
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
}

88. DuplicateDetectionTest#testEntireTransactionRejected()

View license
/*
    * Entire transaction should be rejected on duplicate detection
    * Even if not all entries have dupl id header
    */
@Test
public void testEntireTransactionRejected() throws Exception {
    ClientSession session = sf.createSession(false, false, false);
    session.start();
    final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue");
    final SimpleString queue2 = new SimpleString("queue2");
    session.createQueue(queueName, queueName, null, false);
    session.createQueue(queue2, queue2, null, false);
    ClientProducer producer = session.createProducer(queueName);
    ClientMessage message = createMessage(session, 0);
    SimpleString dupID = new SimpleString("abcdefg");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    ClientMessage message2 = createMessage(session, 0);
    ClientProducer producer2 = session.createProducer(queue2);
    producer2.send(message2);
    session.commit();
    session.close();
    session = sf.createSession(false, false, false);
    session.start();
    ClientConsumer consumer2 = session.createConsumer(queue2);
    producer = session.createProducer(queueName);
    message = createMessage(session, 1);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    message = createMessage(session, 2);
    producer.send(message);
    message = createMessage(session, 3);
    producer.send(message);
    message = createMessage(session, 4);
    producer.send(message);
    message = consumer2.receive(5000);
    assertNotNull(message);
    message.acknowledge();
    try {
        session.commit();
    } catch (ActiveMQDuplicateIdException die) {
        session.rollback();
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    ClientConsumer consumer = session.createConsumer(queueName);
    message = consumer.receive(250);
    Assert.assertEquals(0, message.getObjectProperty(propKey));
    message = consumer.receiveImmediate();
    Assert.assertNull(message);
    message = consumer2.receive(5000);
    assertNotNull(message);
    message.acknowledge();
    session.commit();
}

89. XmlImportExportTest#testMessageTypes()

View license
@Test
public void testMessageTypes() throws Exception {
    ClientSession session = basicSetUp();
    session.createQueue(QUEUE_NAME, QUEUE_NAME, true);
    ClientProducer producer = session.createProducer(QUEUE_NAME);
    ClientMessage msg = session.createMessage(Message.BYTES_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.DEFAULT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.MAP_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.OBJECT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.STREAM_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(Message.TEXT_TYPE, true);
    producer.send(msg);
    msg = session.createMessage(true);
    producer.send(msg);
    session.close();
    locator.close();
    server.stop();
    ByteArrayOutputStream xmlOutputStream = new ByteArrayOutputStream();
    XmlDataExporter xmlDataExporter = new XmlDataExporter();
    xmlDataExporter.process(xmlOutputStream, server.getConfiguration().getBindingsDirectory(), server.getConfiguration().getJournalDirectory(), server.getConfiguration().getPagingDirectory(), server.getConfiguration().getLargeMessagesDirectory());
    System.out.print(new String(xmlOutputStream.toByteArray()));
    clearDataRecreateServerDirs();
    server.start();
    checkForLongs();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    session = factory.createSession(false, true, true);
    ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(xmlOutputStream.toByteArray());
    XmlDataImporter xmlDataImporter = new XmlDataImporter();
    xmlDataImporter.process(xmlInputStream, session);
    ClientConsumer consumer = session.createConsumer(QUEUE_NAME);
    session.start();
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.BYTES_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.DEFAULT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.MAP_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.OBJECT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.STREAM_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.TEXT_TYPE, msg.getType());
    msg = consumer.receive(CONSUMER_TIMEOUT);
    assertEquals(Message.DEFAULT_TYPE, msg.getType());
}

90. SecurityTest#testSendMessageUpdateSender()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testSendMessageUpdateSender() throws Exception {
    Configuration configuration = createDefaultInVMConfig().setSecurityEnabled(true).setSecurityInvalidationInterval(-1);
    ActiveMQServer server = createServer(false, configuration);
    server.start();
    HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("auser", "pass");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().addRole("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    Role role = new Role("arole", false, false, false, false, false, false, false);
    System.out.println("guest:" + role);
    Role sendRole = new Role("guest", true, false, true, false, false, false, false);
    System.out.println("guest:" + sendRole);
    Role receiveRole = new Role("receiver", false, true, false, false, false, false, false);
    System.out.println("guest:" + receiveRole);
    Set<Role> roles = new HashSet<>();
    roles.add(sendRole);
    roles.add(role);
    roles.add(receiveRole);
    securityRepository.addMatch(SecurityTest.addressA, roles);
    securityManager.getConfiguration().addRole("auser", "arole");
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession senSession = cf.createSession(false, true, true);
    ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1);
    senSession.createQueue(SecurityTest.addressA, SecurityTest.queueA, true);
    ClientProducer cp = senSession.createProducer(SecurityTest.addressA);
    cp.send(session.createMessage(false));
    try {
        session.createConsumer(SecurityTest.queueA);
    } catch (ActiveMQSecurityException se) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    securityManager.getConfiguration().addRole("auser", "receiver");
    session.createConsumer(SecurityTest.queueA);
    // Removing the Role... the check should be cached... but we used
    // setSecurityInvalidationInterval(0), so the
    // next createConsumer should fail
    securityManager.getConfiguration().removeRole("auser", "guest");
    ClientSession sendingSession = cf.createSession("auser", "pass", false, false, false, false, 0);
    ClientProducer prod = sendingSession.createProducer(SecurityTest.addressA);
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    try {
        sendingSession.commit();
        Assert.fail("Expected exception");
    } catch (ActiveMQException e) {
    }
    sendingSession.close();
    Xid xid = newXID();
    sendingSession = cf.createSession("auser", "pass", true, false, false, false, 0);
    sendingSession.start(xid, XAResource.TMNOFLAGS);
    prod = sendingSession.createProducer(SecurityTest.addressA);
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    prod.send(CreateMessage.createTextMessage(sendingSession, "Test", true));
    sendingSession.end(xid, XAResource.TMSUCCESS);
    try {
        sendingSession.prepare(xid);
        Assert.fail("Exception was expected");
    } catch (Exception e) {
        e.printStackTrace();
    }
    // A prepare shouldn't mark any recoverable resources
    Xid[] xids = sendingSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(0, xids.length);
    session.close();
    senSession.close();
    sendingSession.close();
}

91. LVQRecoveryTest#testManyMessagesReceivedWithRollback()

View license
@Test
public void testManyMessagesReceivedWithRollback() throws Exception {
    Xid xid = new XidImpl("bq1".getBytes(), 4, "gtid1".getBytes());
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSessionXa.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m1.setDurable(true);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m2.setDurable(true);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m3.setDurable(true);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m4.setDurable(true);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m5.setDurable(true);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m6.setDurable(true);
    clientSessionXa.start(xid, XAResource.TMNOFLAGS);
    clientSessionXa.start();
    producer.send(m1);
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    producer.send(m2);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    producer.send(m3);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    producer.send(m4);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    producer.send(m5);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    producer.send(m6);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    clientSessionXa.end(xid, XAResource.TMSUCCESS);
    clientSessionXa.prepare(xid);
    clientSession.close();
    clientSessionXa.close();
    restartServer();
    clientSessionXa.rollback(xid);
    consumer = clientSession.createConsumer(qName1);
    clientSession.start();
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
}

92. LVQTest#testManyMessagesReceivedAndCancelled()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testManyMessagesReceivedAndCancelled() throws Exception {
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    clientSession.start();
    producer.send(m1);
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    producer.send(m2);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    producer.send(m3);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    producer.send(m4);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    producer.send(m5);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    producer.send(m6);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    consumer.close();
    consumer = clientSession.createConsumer(qName1);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
}

93. LVQTest#testMultipleMessagesInTxSend()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testMultipleMessagesInTxSend() throws Exception {
    ClientProducer producer = clientSessionTxSends.createProducer(address);
    ClientConsumer consumer = clientSessionTxSends.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    producer.send(m1);
    producer.send(m2);
    producer.send(m3);
    producer.send(m4);
    producer.send(m5);
    producer.send(m6);
    clientSessionTxSends.commit();
    clientSessionTxSends.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
}

94. LVQTest#testMultipleMessagesPersistedCorrectly()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testMultipleMessagesPersistedCorrectly() throws Exception {
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m1.setDurable(true);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m2.setDurable(true);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m3.setDurable(true);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m4.setDurable(true);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m5.setDurable(true);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m6.setDurable(true);
    producer.send(m1);
    producer.send(m2);
    producer.send(m3);
    producer.send(m4);
    producer.send(m5);
    producer.send(m6);
    clientSession.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
}

95. LVQTest#testMultipleMessagesPersistedCorrectlyInTx()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testMultipleMessagesPersistedCorrectlyInTx() throws Exception {
    ClientProducer producer = clientSessionTxSends.createProducer(address);
    ClientConsumer consumer = clientSessionTxSends.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m1.setDurable(true);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m2.setDurable(true);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m3.setDurable(true);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m4.setDurable(true);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m5.setDurable(true);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m6.setDurable(true);
    producer.send(m1);
    producer.send(m2);
    producer.send(m3);
    producer.send(m4);
    producer.send(m5);
    producer.send(m6);
    clientSessionTxSends.commit();
    clientSessionTxSends.start();
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
}

96. LVQTest#testMultipleAcksPersistedCorrectly()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testMultipleAcksPersistedCorrectly() throws Exception {
    Queue queue = server.locateQueue(qName1);
    ClientProducer producer = clientSession.createProducer(address);
    ClientConsumer consumer = clientSession.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m1.setDurable(true);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m2.setDurable(true);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m3.setDurable(true);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m4.setDurable(true);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m5.setDurable(true);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m6.setDurable(true);
    clientSession.start();
    producer.send(m1);
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    producer.send(m2);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    producer.send(m3);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    producer.send(m4);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    producer.send(m5);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    producer.send(m6);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    assertEquals(0, queue.getDeliveringCount());
}

97. LVQTest#testMultipleAcksPersistedCorrectlyInTx()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testMultipleAcksPersistedCorrectlyInTx() throws Exception {
    ClientProducer producer = clientSessionTxReceives.createProducer(address);
    ClientConsumer consumer = clientSessionTxReceives.createConsumer(qName1);
    SimpleString rh = new SimpleString("SMID1");
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    m1.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m1.setDurable(true);
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    m2.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m2.setDurable(true);
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    m3.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m3.setDurable(true);
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    m4.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m4.setDurable(true);
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    m5.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m5.setDurable(true);
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    m6.putStringProperty(Message.HDR_LAST_VALUE_NAME, rh);
    m6.setDurable(true);
    clientSessionTxReceives.start();
    producer.send(m1);
    ClientMessage m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    producer.send(m2);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    producer.send(m3);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    producer.send(m4);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    producer.send(m5);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    producer.send(m6);
    m = consumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    clientSessionTxReceives.commit();
}

98. AddressSettingsTest#test3LevelHierarchyWithDLA()

View license
@Test
public void test3LevelHierarchyWithDLA() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dlaA).setMaxDeliveryAttempts(1);
    AddressSettings addressSettings2 = new AddressSettings().setDeadLetterAddress(dlaB).setMaxDeliveryAttempts(1);
    AddressSettings addressSettings3 = new AddressSettings().setDeadLetterAddress(dlaC).setMaxDeliveryAttempts(1);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(addressA2.toString(), addressSettings);
    repos.addMatch("add.*", addressSettings2);
    repos.addMatch("#", addressSettings3);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(addressA2, queueA, false);
    session.createQueue(addressB2, queueB, false);
    session.createQueue(addressC, queueC, false);
    session.createQueue(dlaA, dlqA, false);
    session.createQueue(dlaB, dlqB, false);
    session.createQueue(dlaC, dlqC, false);
    ClientSession sendSession = sf.createSession(false, true, true);
    ClientMessage cm = sendSession.createMessage(true);
    cm.getBodyBuffer().writeString("A");
    ClientMessage cm2 = sendSession.createMessage(true);
    cm2.getBodyBuffer().writeString("B");
    ClientMessage cm3 = sendSession.createMessage(true);
    cm3.getBodyBuffer().writeString("C");
    ClientProducer cp1 = sendSession.createProducer(addressA2);
    ClientProducer cp2 = sendSession.createProducer(addressB2);
    ClientProducer cp3 = sendSession.createProducer(addressC);
    cp1.send(cm);
    cp2.send(cm2);
    cp3.send(cm3);
    ClientConsumer dlqARec = session.createConsumer(dlqA);
    ClientConsumer dlqBrec = session.createConsumer(dlqB);
    ClientConsumer dlqCrec = session.createConsumer(dlqC);
    ClientConsumer cc1 = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueB);
    ClientConsumer cc3 = session.createConsumer(queueC);
    session.start();
    ClientMessage message = cc1.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc2.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc3.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    session.rollback();
    cc1.close();
    cc2.close();
    cc3.close();
    message = dlqARec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("A", message.getBodyBuffer().readString());
    message = dlqBrec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("B", message.getBodyBuffer().readString());
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("C", message.getBodyBuffer().readString());
    sendSession.close();
    session.close();
}

99. AddressSettingsTest#testOverrideHierarchyWithDLA()

View license
@Test
public void testOverrideHierarchyWithDLA() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1);
    AddressSettings addressSettings2 = new AddressSettings().setMaxDeliveryAttempts(1);
    AddressSettings addressSettings3 = new AddressSettings().setDeadLetterAddress(dlaC).setMaxDeliveryAttempts(1);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(addressA2.toString(), addressSettings);
    repos.addMatch("add.*", addressSettings2);
    repos.addMatch("#", addressSettings3);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(addressA2, queueA, false);
    session.createQueue(addressB2, queueB, false);
    session.createQueue(addressC, queueC, false);
    session.createQueue(dlaA, dlqA, false);
    session.createQueue(dlaB, dlqB, false);
    session.createQueue(dlaC, dlqC, false);
    ClientSession sendSession = sf.createSession(false, true, true);
    ClientMessage cm = sendSession.createMessage(true);
    ClientMessage cm2 = sendSession.createMessage(true);
    ClientMessage cm3 = sendSession.createMessage(true);
    ClientProducer cp1 = sendSession.createProducer(addressA2);
    ClientProducer cp2 = sendSession.createProducer(addressB2);
    ClientProducer cp3 = sendSession.createProducer(addressC);
    cp1.send(cm);
    cp2.send(cm2);
    cp3.send(cm3);
    ClientConsumer dlqCrec = session.createConsumer(dlqC);
    ClientConsumer cc1 = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueB);
    ClientConsumer cc3 = session.createConsumer(queueC);
    session.start();
    ClientMessage message = cc1.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc2.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc3.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    session.rollback();
    cc1.close();
    cc2.close();
    cc3.close();
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    sendSession.close();
    session.close();
}

100. ProducerFlowControlTest#testProducerCreditsRefCounting()

View license
@Test
public void testProducerCreditsRefCounting() throws Exception {
    server = createServer(false, isNetty());
    server.start();
    waitForServerToStart(server);
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true, true);
    session.createQueue("address", "queue1", null, false);
    ClientProducer prod1 = session.createProducer("address");
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
    Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
    ClientProducer prod2 = session.createProducer("address");
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
    Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
    ClientProducer prod3 = session.createProducer("address");
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
    Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
    prod1.close();
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
    Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
    prod2.close();
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
    Assert.assertEquals(0, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
    prod3.close();
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().creditsMapSize());
    Assert.assertEquals(1, ((ClientSessionInternal) session).getProducerCreditManager().unReferencedCreditsSize());
}