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

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

1. 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");
}

2. 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");
}

3. 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);
}

4. 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");
}

5. 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());
}

6. 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());
}

7. 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());
}

8. 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();
}

9. 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();
}

10. 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();
}

11. 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);
}

12. 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();
}

13. ScaleDownHandler#getQueueID()

View license
private Integer getQueueID(ClientSession session, SimpleString queueName) throws Exception {
    Integer queueID = -1;
    ClientRequestor requestor = new ClientRequestor(session, "jms.queue.activemq.management");
    ClientMessage managementMessage = session.createMessage(false);
    ManagementHelper.putAttribute(managementMessage, "core.queue." + queueName, "ID");
    session.start();
    logger.debug("Requesting ID for: " + queueName);
    ClientMessage reply = requestor.request(managementMessage);
    Object result = ManagementHelper.getResult(reply);
    if (result != null && result instanceof Integer) {
        queueID = (Integer) result;
    }
    requestor.close();
    return queueID;
}

14. AckBatchSizeTest#getMessageEncodeSize()

View license
/*ackbatchSize tests*/
/*
   * tests that wed don't acknowledge until the correct ackBatchSize is reached
   * */
private int getMessageEncodeSize(final SimpleString address) throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    ClientMessage message = session.createMessage(false);
    // we need to set the destination so we can calculate the encodesize correctly
    message.setAddress(address);
    int encodeSize = message.getEncodeSize();
    session.close();
    cf.close();
    return encodeSize;
}

15. ConsumerWindowSizeTest#getMessageEncodeSize()

View license
private int getMessageEncodeSize(final SimpleString address) throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    ClientMessage message = session.createMessage(false);
    // we need to set the destination so we can calculate the encodesize correctly
    message.setAddress(address);
    int encodeSize = message.getEncodeSize();
    session.close();
    cf.close();
    return encodeSize;
}

16. 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());
}

17. 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();
}

18. 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);
}

19. InVMNonPersistentMessageBufferTest#testSimpleSendReceive()

View license
/*
    * Test message can be read after being sent
    * Message can be sent multiple times
    * After sending, local message can be read
    * After sending, local message body can be added to and sent
    * When reset message body it should only reset to after packet headers
    * Should not be able to read past end of body into encoded message
    */
@Test
public void testSimpleSendReceive() throws Exception {
    ClientMessage message = session.createMessage(false);
    final String body = RandomUtil.randomString();
    message.getBodyBuffer().writeString(body);
    ClientMessage received = sendAndReceive(message);
    Assert.assertNotNull(received);
    Assert.assertEquals(body, received.getBodyBuffer().readString());
}

20. InVMNonPersistentMessageBufferTest#testCannotReadPastEndOfMessageBody()

View license
@Test
public void testCannotReadPastEndOfMessageBody() throws Exception {
    ClientMessage message = session.createMessage(false);
    final String body = RandomUtil.randomString();
    message.getBodyBuffer().writeString(body);
    ClientMessage received = sendAndReceive(message);
    Assert.assertNotNull(received);
    Assert.assertEquals(body, received.getBodyBuffer().readString());
    try {
        received.getBodyBuffer().readByte();
        Assert.fail("Should throw exception");
    } catch (IndexOutOfBoundsException e) {
    }
}

21. 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!");
}

22. SessionStopStartTest#getMessageEncodeSize()

View license
private int getMessageEncodeSize(final SimpleString address) throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    ClientMessage message = session.createMessage(false);
    // we need to set the destination so we can calculate the encodesize correctly
    message.setAddress(address);
    int encodeSize = message.getEncodeSize();
    session.close();
    cf.close();
    return encodeSize;
}

23. 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);
}

24. 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);
}

25. 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);
}

26. 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);
}

27. 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);
}

28. 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);
}

29. BridgeTest#createLargeMessage()

Project: activemq-artemis
Source File: BridgeTest.java
View license
private ClientMessage createLargeMessage(ClientSession session, long largeMessageSize) throws Exception {
    File fileInput = new File(getTemporaryDir(), "huge_message_to_send.dat");
    createFile(fileInput, largeMessageSize);
    System.out.println("File created at: " + fileInput.getAbsolutePath());
    ClientMessage message = session.createMessage(ClientMessage.BYTES_TYPE, true);
    FileInputStream fileInputStream = new FileInputStream(fileInput);
    BufferedInputStream bufferedInput = new BufferedInputStream(fileInputStream);
    message.setBodyInputStream(bufferedInput);
    return message;
}

30. LargeMessageTestBase#readMessage()

View license
/**
    * @param session
    * @param queueToRead
    * @param numberOfBytes
    * @throws ActiveMQException
    * @throws IOException
    */
protected void readMessage(final ClientSession session, final SimpleString queueToRead, final int numberOfBytes) throws ActiveMQException, IOException {
    session.start();
    ClientConsumer consumer = session.createConsumer(queueToRead);
    ClientMessage clientMessage = consumer.receive(5000);
    Assert.assertNotNull(clientMessage);
    clientMessage.acknowledge();
    session.commit();
    consumer.close();
}

31. CoreMessagingProxy#retrieveAttributeValue()

View license
public Object retrieveAttributeValue(final String attributeName, final Class desiredType) {
    ClientMessage m = session.createMessage(false);
    ManagementHelper.putAttribute(m, resourceName, attributeName);
    ClientMessage reply;
    try {
        reply = requestor.request(m);
        Object result = ManagementHelper.getResult(reply);
        if (desiredType != null && desiredType != result.getClass()) {
            // Conversions
            if (desiredType == Long.class && result.getClass() == Integer.class) {
                Integer in = (Integer) result;
                result = new Long(in.intValue());
            }
        }
        return result;
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

32. CoreMessagingProxy#invokeOperation()

View license
public Object invokeOperation(final String operationName, final Object... args) throws Exception {
    ClientMessage m = session.createMessage(false);
    ManagementHelper.putOperationInvocation(m, resourceName, operationName, args);
    ClientMessage reply = requestor.request(m);
    if (reply != null) {
        if (ManagementHelper.hasOperationSucceeded(reply)) {
            return ManagementHelper.getResult(reply);
        } else {
            throw new Exception((String) ManagementHelper.getResult(reply));
        }
    } else {
        return null;
    }
}

33. 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);
}

34. AbstractAdmin#invokeSyncOperation()

Project: activemq-artemis
Source File: AbstractAdmin.java
View license
protected Object invokeSyncOperation(final String resourceName, final String operationName, final Object... parameters) throws Exception {
    ClientMessage message = clientSession.createMessage(false);
    ManagementHelper.putOperationInvocation(message, resourceName, operationName, parameters);
    ClientMessage reply;
    try {
        reply = requestor.request(message, 3000);
    } catch (Exception e) {
        throw new IllegalStateException("Exception while invoking " + operationName + " on " + resourceName, e);
    }
    if (reply == null) {
        throw new IllegalStateException("no reply received when invoking " + operationName + " on " + resourceName);
    }
    if (!ManagementHelper.hasOperationSucceeded(reply)) {
        throw new IllegalStateException("operation failed when invoking " + operationName + " on " + resourceName + ": " + ManagementHelper.getResult(reply));
    }
    return ManagementHelper.getResult(reply);
}

35. ClientConsumerImpl#receive()

View license
@Override
public ClientMessage receive(final long timeout) throws ActiveMQException {
    if (logger.isTraceEnabled()) {
        logger.trace(this + ":: receive(" + timeout + ")");
    }
    ClientMessage msg = receive(timeout, false);
    if (msg == null && !closed) {
        if (logger.isTraceEnabled()) {
            logger.trace(this + ":: receive(" + timeout + ") -> null, trying again with receive(0)");
        }
        msg = receive(0, true);
    }
    if (logger.isTraceEnabled()) {
        logger.trace(this + ":: returning " + msg);
    }
    return msg;
}

36. QueueConsumer#receiveFromConsumer()

Project: activemq-artemis
Source File: QueueConsumer.java
View license
protected ClientMessage receiveFromConsumer(long timeoutSecs) throws Exception {
    ClientMessage m = null;
    if (timeoutSecs <= 0) {
        m = consumer.receive(1);
    } else {
        m = consumer.receive(timeoutSecs * 1000);
    }
    ActiveMQRestLogger.LOGGER.debug("Returning message " + m + " from consumer: " + consumer);
    return m;
}

37. InVMNonPersistentMessageBufferTest#testSendSameMessageMultipleTimes()

View license
@Test
public void testSendSameMessageMultipleTimes() throws Exception {
    ClientMessage message = session.createMessage(false);
    final String body = RandomUtil.randomString();
    message.getBodyBuffer().writeString(body);
    int bodySize = message.getBodySize();
    for (int i = 0; i < 10; i++) {
        ClientMessage received = sendAndReceive(message);
        Assert.assertNotNull(received);
        Assert.assertEquals(bodySize, received.getBodySize());
        Assert.assertEquals(body, received.getBodyBuffer().readString());
        Assert.assertFalse(received.getBodyBuffer().readable());
    }
}

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. ReceiveImmediateTest#doConsumerReceiveImmediateWithNoMessages()

View license
private void doConsumerReceiveImmediateWithNoMessages(final boolean browser) throws Exception {
    locator.setBlockOnNonDurableSend(true).setBlockOnAcknowledge(true).setAckBatchSize(0);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(ADDRESS, QUEUE, null, false);
    ClientConsumer consumer = session.createConsumer(QUEUE, null, browser);
    session.start();
    ClientMessage message = consumer.receiveImmediate();
    Assert.assertNull(message);
    session.close();
}

40. 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();
}

41. NotificationTest#testBINDING_ADDED()

View license
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testBINDING_ADDED() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    boolean durable = RandomUtil.randomBoolean();
    NotificationTest.flush(notifConsumer);
    session.createQueue(address, queue, durable);
    ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
    Assert.assertEquals(BINDING_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
    Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString());
    Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
    session.deleteQueue(queue);
}

42. NotificationTest#testBINDING_ADDEDWithMatchingFilter()

View license
@Test
public void testBINDING_ADDEDWithMatchingFilter() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    boolean durable = RandomUtil.randomBoolean();
    System.out.println(queue);
    notifConsumer.close();
    notifConsumer = session.createConsumer(notifQueue.toString(), ManagementHelper.HDR_ROUTING_NAME + "= '" + queue + "'");
    NotificationTest.flush(notifConsumer);
    session.createQueue(address, queue, durable);
    ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
    Assert.assertEquals(BINDING_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
    Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString());
    Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
    session.deleteQueue(queue);
}

43. NotificationTest#testBINDING_REMOVED()

View license
@Test
public void testBINDING_REMOVED() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    boolean durable = RandomUtil.randomBoolean();
    session.createQueue(address, queue, durable);
    NotificationTest.flush(notifConsumer);
    session.deleteQueue(queue);
    ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer);
    Assert.assertEquals(BINDING_REMOVED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
    Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString());
    Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString());
}

44. SecurityNotificationTest#testSECURITY_AUTHENTICATION_VIOLATION()

View license
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testSECURITY_AUTHENTICATION_VIOLATION() throws Exception {
    String unknownUser = RandomUtil.randomString();
    SecurityNotificationTest.flush(notifConsumer);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    try {
        sf.createSession(unknownUser, RandomUtil.randomString(), false, true, true, false, 1);
        Assert.fail("authentication must fail and a notification of security violation must be sent");
    } catch (Exception e) {
    }
    ClientMessage[] notifications = SecurityNotificationTest.consumeMessages(1, notifConsumer);
    Assert.assertEquals(SECURITY_AUTHENTICATION_VIOLATION.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString());
}

45. PagingReceiveTest#receiveMessage()

View license
private ClientMessage receiveMessage() throws Exception {
    final ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage message = consumer.receive(1000);
    session.commit();
    if (message != null) {
        message.acknowledge();
    }
    consumer.close();
    session.close();
    return message;
}

46. 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());
    }
}

47. 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");
}

48. MessageHeaderTest#testCopyOnJBossMessage()

View license
@Test
public void testCopyOnJBossMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    ActiveMQMessage jbossMessage = ActiveMQMessage.createMessage(clientMessage, session);
    jbossMessage.clearProperties();
    MessageHeaderTestBase.configureMessage(jbossMessage);
    ActiveMQMessage copy = new ActiveMQMessage(jbossMessage, session);
    MessageHeaderTestBase.ensureEquivalent(jbossMessage, copy);
}

49. MessageHeaderTest#testCopyOnForeignMessage()

View license
@Test
public void testCopyOnForeignMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    Message foreignMessage = new SimpleJMSMessage();
    ActiveMQMessage copy = new ActiveMQMessage(foreignMessage, session);
    MessageHeaderTestBase.ensureEquivalent(foreignMessage, copy);
}

50. MessageHeaderTest#testCopyOnForeignBytesMessage()

View license
@Test
public void testCopyOnForeignBytesMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
    for (int i = 0; i < 20; i++) {
        foreignBytesMessage.writeByte((byte) i);
    }
    ActiveMQBytesMessage copy = new ActiveMQBytesMessage(foreignBytesMessage, session);
    foreignBytesMessage.reset();
    copy.reset();
    MessageHeaderTestBase.ensureEquivalent(foreignBytesMessage, copy);
}

51. MessageHeaderTest#testCopyOnForeignMapMessage()

View license
@Test
public void testCopyOnForeignMapMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    MapMessage foreignMapMessage = new SimpleJMSMapMessage();
    foreignMapMessage.setInt("int", 1);
    foreignMapMessage.setString("string", "test");
    ActiveMQMapMessage copy = new ActiveMQMapMessage(foreignMapMessage, session);
    MessageHeaderTestBase.ensureEquivalent(foreignMapMessage, copy);
}

52. MessageHeaderTest#testCopyOnForeignStreamMessage()

View license
@Test
public void testCopyOnForeignStreamMessage() throws JMSException {
    ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
    ClientSession session = new FakeSession(clientMessage);
    StreamMessage foreignStreamMessage = new SimpleJMSStreamMessage();
    foreignStreamMessage.writeByte((byte) 1);
    foreignStreamMessage.writeByte((byte) 2);
    foreignStreamMessage.writeByte((byte) 3);
    ActiveMQStreamMessage copy = new ActiveMQStreamMessage(foreignStreamMessage, session);
    MessageHeaderTestBase.ensureEquivalent(foreignStreamMessage, copy);
}

53. 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);
}

54. PageStressTest#readMessages()

View license
private int readMessages(final ClientSession session, final ClientConsumer consumer, final SimpleString queue) throws ActiveMQException {
    session.start();
    int msgs = 0;
    ClientMessage msg = null;
    do {
        msg = consumer.receive(1000);
        if (msg != null) {
            msg.acknowledge();
            if (++msgs % 10000 == 0) {
                System.out.println("received " + msgs);
                session.commit();
            }
        }
    } while (msg != null);
    session.commit();
    return msgs;
}

55. 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);
}

56. 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);
}

57. 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);
}

58. 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);
}

59. XaTimeoutTest#testSimpleTimeoutOnSendAndReceive()

Project: activemq-artemis
Source File: XaTimeoutTest.java
View license
@Test
public void testSimpleTimeoutOnSendAndReceive() throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    ClientMessage m7 = createTextMessage(clientSession, "m7");
    ClientMessage m8 = createTextMessage(clientSession, "m8");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.setTransactionTimeout(2);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    CountDownLatch latch = new CountDownLatch(1);
    server.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    try {
        clientSession.commit(xid, true);
    } catch (XAException e) {
        Assert.assertTrue(e.errorCode == XAException.XAER_NOTA);
    }
    clientSession.setTransactionTimeout(0);
    clientConsumer.close();
    clientSession2 = sessionFactory.createSession(false, true, true);
    ClientConsumer consumer = clientSession2.createConsumer(atestq);
    clientSession2.start();
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = consumer.receive(500);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
    clientSession2.close();
}

60. XaTimeoutTest#testPreparedTransactionNotTimedOut()

Project: activemq-artemis
Source File: XaTimeoutTest.java
View license
@Test
public void testPreparedTransactionNotTimedOut() throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    ClientMessage m5 = createTextMessage(clientSession, "m5");
    ClientMessage m6 = createTextMessage(clientSession, "m6");
    ClientMessage m7 = createTextMessage(clientSession, "m7");
    ClientMessage m8 = createTextMessage(clientSession, "m8");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.setTransactionTimeout(2);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    CountDownLatch latch = new CountDownLatch(1);
    server.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
    Assert.assertFalse(latch.await(2600, TimeUnit.MILLISECONDS));
    clientSession.commit(xid, false);
    clientSession.setTransactionTimeout(0);
    clientConsumer.close();
    clientSession2 = sessionFactory.createSession(false, true, true);
    ClientConsumer consumer = clientSession2.createConsumer(atestq);
    clientSession2.start();
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = consumer.receive(500);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
    clientSession2.close();
}

61. ScheduledMessageTest#testScheduledMessagesDeliveredCorrectly()

View license
public void testScheduledMessagesDeliveredCorrectly(final boolean recover) throws Exception {
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, true, false);
    session.createQueue(atestq, atestq, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientMessage m1 = createDurableMessage(session, "m1");
    ClientMessage m2 = createDurableMessage(session, "m2");
    ClientMessage m3 = createDurableMessage(session, "m3");
    ClientMessage m4 = createDurableMessage(session, "m4");
    ClientMessage m5 = createDurableMessage(session, "m5");
    long time = System.currentTimeMillis();
    time += 10000;
    m1.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m1);
    time += 1000;
    m2.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m2);
    time += 1000;
    m3.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m3);
    time += 1000;
    m4.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m4);
    time += 1000;
    m5.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m5);
    time -= 4000;
    if (recover) {
        producer.close();
        session.close();
        server.stop();
        server = null;
        server = createServer(true, configuration);
        server.start();
        sessionFactory = createSessionFactory(locator);
        session = sessionFactory.createSession(false, true, true);
    }
    ClientConsumer consumer = session.createConsumer(atestq);
    session.start();
    ClientMessage message = consumer.receive(11000);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m1", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m2", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m3", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m4", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m5", message.getBodyBuffer().readString());
    message.acknowledge();
    // Make sure no more messages
    consumer.close();
    consumer = session.createConsumer(atestq);
    Assert.assertNull(consumer.receiveImmediate());
    session.close();
}

62. ScheduledMessageTest#testScheduledMessagesDeliveredCorrectlyDifferentOrder()

View license
public void testScheduledMessagesDeliveredCorrectlyDifferentOrder(final boolean recover) throws Exception {
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, true, false);
    session.createQueue(atestq, atestq, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientMessage m1 = createDurableMessage(session, "m1");
    ClientMessage m2 = createDurableMessage(session, "m2");
    ClientMessage m3 = createDurableMessage(session, "m3");
    ClientMessage m4 = createDurableMessage(session, "m4");
    ClientMessage m5 = createDurableMessage(session, "m5");
    long time = System.currentTimeMillis();
    time += 10000;
    m1.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m1);
    time += 3000;
    m2.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m2);
    time -= 2000;
    m3.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m3);
    time += 3000;
    m4.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m4);
    time -= 2000;
    m5.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m5);
    time -= 2000;
    ClientConsumer consumer = null;
    if (recover) {
        producer.close();
        session.close();
        server.stop();
        server = null;
        server = createServer(true, configuration);
        server.start();
        sessionFactory = createSessionFactory(locator);
        session = sessionFactory.createSession(false, true, true);
    }
    consumer = session.createConsumer(atestq);
    session.start();
    ClientMessage message = consumer.receive(10250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m1", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m3", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m5", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m2", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m4", message.getBodyBuffer().readString());
    message.acknowledge();
    // Make sure no more messages
    consumer.close();
    consumer = session.createConsumer(atestq);
    Assert.assertNull(consumer.receiveImmediate());
    session.close();
}

63. LVQTest#testMultipleMessagesInTxRollback()

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

64. ScheduledMessageTest#testScheduledAndNormalMessagesDeliveredCorrectly()

View license
public void testScheduledAndNormalMessagesDeliveredCorrectly(final boolean recover) throws Exception {
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, true, false);
    session.createQueue(atestq, atestq, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientMessage m1 = createDurableMessage(session, "m1");
    ClientMessage m2 = createDurableMessage(session, "m2");
    ClientMessage m3 = createDurableMessage(session, "m3");
    ClientMessage m4 = createDurableMessage(session, "m4");
    ClientMessage m5 = createDurableMessage(session, "m5");
    long time = System.currentTimeMillis();
    time += 10000;
    m1.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m1);
    producer.send(m2);
    time += 1000;
    m3.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m3);
    producer.send(m4);
    time += 1000;
    m5.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time);
    producer.send(m5);
    time -= 2000;
    ClientConsumer consumer = null;
    if (recover) {
        producer.close();
        session.close();
        server.stop();
        server = null;
        server = createServer(true, configuration);
        server.start();
        sessionFactory = createSessionFactory(locator);
        session = sessionFactory.createSession(false, true, true);
    }
    consumer = session.createConsumer(atestq);
    session.start();
    ClientMessage message = consumer.receive(1000);
    Assert.assertEquals("m2", message.getBodyBuffer().readString());
    message.acknowledge();
    message = consumer.receive(1000);
    Assert.assertEquals("m4", message.getBodyBuffer().readString());
    message.acknowledge();
    message = consumer.receive(10250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m1", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m3", message.getBodyBuffer().readString());
    message.acknowledge();
    time += 1000;
    message = consumer.receive(1250);
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m5", message.getBodyBuffer().readString());
    message.acknowledge();
    // Make sure no more messages
    consumer.close();
    consumer = session.createConsumer(atestq);
    Assert.assertNull(consumer.receiveImmediate());
    session.close();
}

65. 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);
}

66. 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");
}

67. XaTimeoutTest#testSimpleTimeoutOnReceive()

Project: activemq-artemis
Source File: XaTimeoutTest.java
View license
@Test
public void testSimpleTimeoutOnReceive() throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage(clientSession, "m1");
    ClientMessage m2 = createTextMessage(clientSession, "m2");
    ClientMessage m3 = createTextMessage(clientSession, "m3");
    ClientMessage m4 = createTextMessage(clientSession, "m4");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.setTransactionTimeout(2);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    CountDownLatch latch = new CountDownLatch(1);
    server.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    try {
        clientSession.commit(xid, true);
    } catch (XAException e) {
        Assert.assertTrue(e.errorCode == XAException.XAER_NOTA);
    }
    clientSession.setTransactionTimeout(0);
    clientConsumer.close();
    clientSession2 = sessionFactory.createSession(false, true, true);
    ClientConsumer consumer = clientSession2.createConsumer(atestq);
    clientSession2.start();
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = consumer.receive(500);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = consumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession2.close();
}

68. AeroGearBasicServerTest#aerogearSimpleReceiveTest()

View license
@Test
public void aerogearSimpleReceiveTest() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    AeroGearHandler aeroGearHandler = new AeroGearHandler(latch);
    jetty.addHandler(aeroGearHandler);
    locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    ClientProducer producer = session.createProducer("testQueue");
    ClientMessage m = session.createMessage(true);
    m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "hello from ActiveMQ!");
    m.putStringProperty("AEROGEAR_PROP1", "prop1");
    m.putBooleanProperty("AEROGEAR_PROP2", true);
    producer.send(m);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertNotNull(aeroGearHandler.jsonObject);
    JSONObject body = (JSONObject) aeroGearHandler.jsonObject.get("message");
    assertNotNull(body);
    String prop1 = body.getString("AEROGEAR_PROP1");
    assertNotNull(prop1);
    assertEquals(prop1, "prop1");
    prop1 = body.getString("AEROGEAR_PROP2");
    assertNotNull(prop1);
    assertEquals(prop1, "true");
    String alert = body.getString("alert");
    assertNotNull(alert);
    assertEquals(alert, "hello from ActiveMQ!");
    String sound = body.getString("sound");
    assertNotNull(sound);
    assertEquals(sound, "sound1");
    String badge = body.getString("badge");
    assertNotNull(badge);
    assertEquals(badge, "99");
    JSONArray jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("variants");
    assertNotNull(jsonArray);
    assertEquals(jsonArray.getString(0), "variant1");
    assertEquals(jsonArray.getString(1), "variant2");
    jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("alias");
    assertNotNull(jsonArray);
    assertEquals(jsonArray.getString(0), "me");
    assertEquals(jsonArray.getString(1), "him");
    assertEquals(jsonArray.getString(2), "them");
    jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("deviceType");
    assertNotNull(jsonArray);
    assertEquals(jsonArray.getString(0), "android");
    assertEquals(jsonArray.getString(1), "ipad");
    Integer ttl = (Integer) aeroGearHandler.jsonObject.get("ttl");
    assertNotNull(ttl);
    assertEquals(ttl.intValue(), 3600);
    latch = new CountDownLatch(1);
    aeroGearHandler.resetLatch(latch);
    //now override the properties
    m = session.createMessage(true);
    m.putStringProperty(AeroGearConstants.AEROGEAR_ALERT.toString(), "another hello from ActiveMQ!");
    m.putStringProperty(AeroGearConstants.AEROGEAR_BADGE.toString(), "111");
    m.putStringProperty(AeroGearConstants.AEROGEAR_SOUND.toString(), "s1");
    m.putIntProperty(AeroGearConstants.AEROGEAR_TTL.toString(), 10000);
    m.putStringProperty(AeroGearConstants.AEROGEAR_ALIASES.toString(), "alias1,alias2");
    m.putStringProperty(AeroGearConstants.AEROGEAR_DEVICE_TYPES.toString(), "dev1,dev2");
    m.putStringProperty(AeroGearConstants.AEROGEAR_VARIANTS.toString(), "v1,v2");
    producer.send(m);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertNotNull(aeroGearHandler.jsonObject);
    body = (JSONObject) aeroGearHandler.jsonObject.get("message");
    assertNotNull(body);
    alert = body.getString("alert");
    assertNotNull(alert);
    assertEquals(alert, "another hello from ActiveMQ!");
    sound = body.getString("sound");
    assertNotNull(sound);
    assertEquals(sound, "s1");
    badge = body.getString("badge");
    assertNotNull(badge);
    assertEquals(badge, "111");
    jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("variants");
    assertNotNull(jsonArray);
    assertEquals(jsonArray.getString(0), "v1");
    assertEquals(jsonArray.getString(1), "v2");
    jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("alias");
    assertNotNull(jsonArray);
    assertEquals(jsonArray.getString(0), "alias1");
    assertEquals(jsonArray.getString(1), "alias2");
    jsonArray = (JSONArray) aeroGearHandler.jsonObject.get("deviceType");
    assertNotNull(jsonArray);
    assertEquals(jsonArray.getString(0), "dev1");
    assertEquals(jsonArray.getString(1), "dev2");
    ttl = (Integer) aeroGearHandler.jsonObject.get("ttl");
    assertNotNull(ttl);
    assertEquals(ttl.intValue(), 10000);
    session.start();
    ClientMessage message = session.createConsumer("testQueue").receiveImmediate();
    assertNull(message);
}

69. 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();
}

70. 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();
}

71. LVQRecoveryTest#testMultipleMessagesAfterRecovery()

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

72. LVQTest#testMultipleMessages()

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

73. LVQTest#testMultipleMessagesInTx()

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

74. 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);
}

75. 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);
}

76. LVQTest#testMultipleAcksPersistedCorrectly2()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Test
public void testMultipleAcksPersistedCorrectly2() 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);
    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");
    assertEquals(0, queue.getDeliveringCount());
}

77. BasicXaRecoveryTest#testMultipleBeforeSendWithCommit()

View license
public void testMultipleBeforeSendWithCommit(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".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, false, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 1);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.commit(xid, false);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
}

78. BasicXaRecoveryTest#testMultipleTxSendWithCommit()

View license
public void testMultipleTxSendWithCommit(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(true, false, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 2);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.commit(xid, false);
    clientSession.commit(xid2, false);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
}

79. BasicXaRecoveryTest#testMultipleTxSendWithRollback()

View license
public void testMultipleTxSendWithRollback(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(true, false, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 2);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.rollback(xid2);
    clientSession.start();
    ClientMessage m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

80. BasicXaRecoveryTest#testMultipleTxSendWithCommitAndRollback()

View license
public void testMultipleTxSendWithCommitAndRollback(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(true, false, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientSession2.start(xid2, XAResource.TMNOFLAGS);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.end(xid2, XAResource.TMSUCCESS);
    clientSession2.prepare(xid2);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 2);
    assertEqualXids(xids, xid, xid2);
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.commit(xid2, false);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
}

81. BasicXaRecoveryTest#testMultipleTxSameXidSendWithCommit()

View license
public void testMultipleTxSameXidSendWithCommit(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".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(true, false, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientSession2.start(xid, XAResource.TMNOFLAGS);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.end(xid, XAResource.TMSUCCESS);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMJOIN);
    clientProducer.send(m5);
    clientProducer.send(m6);
    clientProducer.send(m7);
    clientProducer.send(m8);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 1);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.commit(xid, false);
    clientSession.start();
    ClientMessage m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m5");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m6");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m7");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m8");
}

82. BasicXaRecoveryTest#testBasicReceiveWithCommit()

View license
public void testBasicReceiveWithCommit(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    ClientMessage 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);
    Assert.assertEquals("Expected XA_OK", XAResource.XA_OK, clientSession.prepare(xid));
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(xids.length, 1);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.commit(xid, false);
    clientSession.start();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    //check deliveringCount Zero
    checkQueueDeliveryCount(atestq, 0);
}

83. BasicXaRecoveryTest#testBasicReceiveWithRollback()

View license
public void testBasicReceiveWithRollback(final boolean stopServer) throws Exception {
    Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
    ClientMessage m1 = createTextMessage("m1");
    ClientMessage m2 = createTextMessage("m2");
    ClientMessage m3 = createTextMessage("m3");
    ClientMessage m4 = createTextMessage("m4");
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer2 = clientSession2.createProducer(atestq);
    clientProducer2.send(m1);
    clientProducer2.send(m2);
    clientProducer2.send(m3);
    clientProducer2.send(m4);
    clientSession2.close();
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    ClientMessage 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);
    BasicXaRecoveryTest.log.info("stopping and restarting");
    if (stopServer) {
        stopAndRestartServer();
    } else {
        recreateClients();
    }
    BasicXaRecoveryTest.log.info("Restarted");
    Xid[] xids = clientSession.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(1, xids.length);
    Assert.assertEquals(xids[0].getFormatId(), xid.getFormatId());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
    ActiveMQTestBase.assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
    xids = clientSession.recover(XAResource.TMENDRSCAN);
    Assert.assertEquals(xids.length, 0);
    clientSession.rollback(xid);
    clientSession.start();
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m1");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m2");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
}

84. BasicXaTest#testReceivePrepareDoesntRollbackOnClose()

Project: activemq-artemis
Source File: BasicXaTest.java
View license
@Test
public void testReceivePrepareDoesntRollbackOnClose() throws Exception {
    Xid xid = newXID();
    ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
    ClientProducer clientProducer = clientSession2.createProducer(atestq);
    ClientMessage m1 = createTextMessage(clientSession2, "m1");
    ClientMessage m2 = createTextMessage(clientSession2, "m2");
    ClientMessage m3 = createTextMessage(clientSession2, "m3");
    ClientMessage m4 = createTextMessage(clientSession2, "m4");
    clientProducer.send(m1);
    clientProducer.send(m2);
    clientProducer.send(m3);
    clientProducer.send(m4);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(atestq);
    ClientMessage 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);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m3");
    m = clientConsumer.receive(1000);
    Assert.assertNotNull(m);
    m.acknowledge();
    Assert.assertEquals(m.getBodyBuffer().readString(), "m4");
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    clientSession.close();
    clientSession = sessionFactory.createSession(true, false, false);
    clientSession.commit(xid, false);
    clientSession.start();
    clientConsumer = clientSession.createConsumer(atestq);
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientSession2.close();
}

85. 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);
}

86. 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);
}

87. DuplicateDetectionTest#testPersistTransactional()

View license
@Test
public void testPersistTransactional() throws Exception {
    ClientSession session = sf.createSession(false, false, false);
    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, 1);
    SimpleString dupID = new SimpleString("abcdefg");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    session.commit();
    ClientMessage message2 = consumer.receive(1000);
    message2.acknowledge();
    session.commit();
    Assert.assertEquals(1, message2.getObjectProperty(propKey));
    message = createMessage(session, 2);
    SimpleString dupID2 = new SimpleString("hijklmnopqr");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
    producer.send(message);
    session.commit();
    message2 = consumer.receive(1000);
    message2.acknowledge();
    session.commit();
    Assert.assertEquals(2, message2.getObjectProperty(propKey));
    session.close();
    sf.close();
    server.stop();
    waitForServerToStop(server);
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, false, false);
    session.start();
    session.createQueue(queueName, queueName, null, false);
    producer = session.createProducer(queueName);
    consumer = session.createConsumer(queueName);
    message = createMessage(session, 1);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    try {
        session.commit();
    } catch (ActiveMQDuplicateIdException die) {
        session.rollback();
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    message = createMessage(session, 2);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
    producer.send(message);
    try {
        session.commit();
    } catch (ActiveMQDuplicateIdException die) {
        session.rollback();
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
}

88. ActiveMQServerControlTest#testListPreparedTransactionDetails()

View license
@Test
public void testListPreparedTransactionDetails() throws Exception {
    SimpleString atestq = new SimpleString("BasicXaTestq");
    Xid xid = newXID();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession clientSession = csf.createSession(true, false, false);
    clientSession.createQueue(atestq, atestq, null, true);
    ClientMessage m1 = createTextMessage(clientSession, "");
    ClientMessage m2 = createTextMessage(clientSession, "");
    ClientMessage m3 = createTextMessage(clientSession, "");
    ClientMessage m4 = createTextMessage(clientSession, "");
    m1.putStringProperty("m1", "m1");
    m2.putStringProperty("m2", "m2");
    m3.putStringProperty("m3", "m3");
    m4.putStringProperty("m4", "m4");
    ClientProducer clientProducer = clientSession.createProducer(atestq);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m1);
    clientProducer.send(m2);
    clientProducer.send(m3);
    clientProducer.send(m4);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    ActiveMQServerControl serverControl = createManagementControl();
    JSONArray jsonArray = new JSONArray(serverControl.listProducersInfoAsJSON());
    assertEquals(1, jsonArray.length());
    assertEquals(4, ((JSONObject) jsonArray.get(0)).getInt("msgSent"));
    clientSession.close();
    locator.close();
    String txDetails = serverControl.listPreparedTransactionDetailsAsJSON();
    Assert.assertTrue(txDetails.matches(".*m1.*"));
    Assert.assertTrue(txDetails.matches(".*m2.*"));
    Assert.assertTrue(txDetails.matches(".*m3.*"));
    Assert.assertTrue(txDetails.matches(".*m4.*"));
}

89. ActiveMQServerControlTest#testListPreparedTransactionDetailsAsHTML()

View license
@Test
public void testListPreparedTransactionDetailsAsHTML() throws Exception {
    SimpleString atestq = new SimpleString("BasicXaTestq");
    Xid xid = newXID();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession clientSession = csf.createSession(true, false, false);
    clientSession.createQueue(atestq, atestq, null, true);
    ClientMessage m1 = createTextMessage(clientSession, "");
    ClientMessage m2 = createTextMessage(clientSession, "");
    ClientMessage m3 = createTextMessage(clientSession, "");
    ClientMessage m4 = createTextMessage(clientSession, "");
    m1.putStringProperty("m1", "m1");
    m2.putStringProperty("m2", "m2");
    m3.putStringProperty("m3", "m3");
    m4.putStringProperty("m4", "m4");
    ClientProducer clientProducer = clientSession.createProducer(atestq);
    clientSession.start(xid, XAResource.TMNOFLAGS);
    clientProducer.send(m1);
    clientProducer.send(m2);
    clientProducer.send(m3);
    clientProducer.send(m4);
    clientSession.end(xid, XAResource.TMSUCCESS);
    clientSession.prepare(xid);
    clientSession.close();
    locator.close();
    ActiveMQServerControl serverControl = createManagementControl();
    String html = serverControl.listPreparedTransactionDetailsAsHTML();
    Assert.assertTrue(html.matches(".*m1.*"));
    Assert.assertTrue(html.matches(".*m2.*"));
    Assert.assertTrue(html.matches(".*m3.*"));
    Assert.assertTrue(html.matches(".*m4.*"));
}

90. String64KLimitTest#test64KLimitWithWriteString()

View license
@Test
public void test64KLimitWithWriteString() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, false);
    ClientProducer producer = session.createProducer(address);
    ClientConsumer consumer = session.createConsumer(queue);
    session.start();
    String s1 = genString(16 * 1024);
    String s2 = genString(32 * 1024);
    String s3 = genString(64 * 1024);
    String s4 = genString(10 * 64 * 1024);
    ClientMessage tm1 = session.createMessage(false);
    tm1.getBodyBuffer().writeString(s1);
    ClientMessage tm2 = session.createMessage(false);
    tm2.getBodyBuffer().writeString(s2);
    ClientMessage tm3 = session.createMessage(false);
    tm3.getBodyBuffer().writeString(s3);
    ClientMessage tm4 = session.createMessage(false);
    tm4.getBodyBuffer().writeString(s4);
    producer.send(tm1);
    producer.send(tm2);
    producer.send(tm3);
    producer.send(tm4);
    ClientMessage rm1 = consumer.receive(1000);
    Assert.assertNotNull(rm1);
    Assert.assertEquals(s1, rm1.getBodyBuffer().readString());
    ClientMessage rm2 = consumer.receive(1000);
    Assert.assertNotNull(rm2);
    Assert.assertEquals(s2, rm2.getBodyBuffer().readString());
    ClientMessage rm3 = consumer.receive(1000);
    Assert.assertEquals(s3, rm3.getBodyBuffer().readString());
    Assert.assertNotNull(rm3);
    ClientMessage rm4 = consumer.receive(1000);
    Assert.assertEquals(s4, rm4.getBodyBuffer().readString());
    Assert.assertNotNull(rm4);
}

91. 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();
}

92. 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();
}

93. ScheduledMessageTest#testPagedMessageDeliveredMultipleConsumersCorrectly()

View license
@Test
public void testPagedMessageDeliveredMultipleConsumersCorrectly() throws Exception {
    AddressSettings qs = new AddressSettings().setRedeliveryDelay(5000L);
    server.getAddressSettingsRepository().addMatch(atestq.toString(), qs);
    // then we create a client as normal
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, true, false);
    session.createQueue(atestq, atestq, null, true);
    session.createQueue(atestq, atestq2, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientMessage message = createDurableMessage(session, "m1");
    producer.send(message);
    producer.close();
    ClientConsumer consumer = session.createConsumer(atestq);
    ClientConsumer consumer2 = session.createConsumer(atestq2);
    session.start();
    ClientMessage message3 = consumer.receive(1000);
    message3.acknowledge();
    ClientMessage message2 = consumer2.receive(1000);
    message2.acknowledge();
    Assert.assertEquals("m1", message3.getBodyBuffer().readString());
    Assert.assertEquals("m1", message2.getBodyBuffer().readString());
    long time = System.currentTimeMillis();
    // force redelivery
    consumer.close();
    consumer2.close();
    // this will make it redelivery-delay
    session.rollback();
    consumer = session.createConsumer(atestq);
    consumer2 = session.createConsumer(atestq2);
    message3 = consumer.receive(5250);
    message2 = consumer2.receive(1000);
    time += 5000;
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m1", message3.getBodyBuffer().readString());
    Assert.assertEquals("m1", message2.getBodyBuffer().readString());
    message2.acknowledge();
    message3.acknowledge();
    // Make sure no more messages
    consumer.close();
    consumer2.close();
    consumer = session.createConsumer(atestq);
    Assert.assertNull(consumer.receiveImmediate());
    session.close();
}

94. ScheduledMessageTest#testPagedMessageDeliveredMultipleConsumersAfterRecoverCorrectly()

View license
@Test
public void testPagedMessageDeliveredMultipleConsumersAfterRecoverCorrectly() throws Exception {
    AddressSettings qs = new AddressSettings().setRedeliveryDelay(5000L);
    server.getAddressSettingsRepository().addMatch(atestq.toString(), qs);
    // then we create a client as normal
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(false, true, false);
    session.createQueue(atestq, atestq, null, true);
    session.createQueue(atestq, atestq2, null, true);
    ClientProducer producer = session.createProducer(atestq);
    ClientMessage message = createDurableMessage(session, "m1");
    producer.send(message);
    producer.close();
    ClientConsumer consumer = session.createConsumer(atestq);
    ClientConsumer consumer2 = session.createConsumer(atestq2);
    session.start();
    ClientMessage message3 = consumer.receive(1000);
    Assert.assertNotNull(message3);
    message3.acknowledge();
    ClientMessage message2 = consumer2.receive(1000);
    Assert.assertNotNull(message2);
    message2.acknowledge();
    Assert.assertEquals("m1", message3.getBodyBuffer().readString());
    Assert.assertEquals("m1", message2.getBodyBuffer().readString());
    long time = System.currentTimeMillis();
    // force redelivery
    consumer.close();
    consumer2.close();
    session.rollback();
    producer.close();
    session.close();
    server.stop();
    server = null;
    server = createServer(true, configuration);
    server.start();
    sessionFactory = createSessionFactory(locator);
    session = sessionFactory.createSession(false, true, true);
    consumer = session.createConsumer(atestq);
    consumer2 = session.createConsumer(atestq2);
    session.start();
    message3 = consumer.receive(5250);
    Assert.assertNotNull(message3);
    message2 = consumer2.receive(1000);
    Assert.assertNotNull(message2);
    time += 5000;
    Assert.assertTrue(System.currentTimeMillis() >= time);
    Assert.assertEquals("m1", message3.getBodyBuffer().readString());
    Assert.assertEquals("m1", message2.getBodyBuffer().readString());
    message2.acknowledge();
    message3.acknowledge();
    // Make sure no more messages
    consumer.close();
    consumer2.close();
    consumer = session.createConsumer(atestq);
    Assert.assertNull(consumer.receiveImmediate());
    session.close();
}

95. ConsumerFilterTest#testTwoConsumers()

View license
@Test
public void testTwoConsumers() throws Exception {
    ClientConsumer consumer2 = session.createConsumer("foo", "animal='elephant'");
    //Create and consume message that matches the first consumer's filter
    ClientMessage message = session.createMessage(false);
    message.putStringProperty("animal", "giraffe");
    producer.send(message);
    ClientMessage received = consumer.receive(10000);
    assertNotNull(received);
    assertEquals("giraffe", received.getStringProperty("animal"));
    assertNull(consumer.receiveImmediate());
    assertNull(consumer2.receiveImmediate());
    //Create and consume another message that matches the first consumer's filter
    message = session.createMessage(false);
    message.putStringProperty("animal", "giraffe");
    producer.send(message);
    received = consumer.receive(10000);
    assertNotNull(received);
    assertEquals("giraffe", received.getStringProperty("animal"));
    assertNull(consumer.receiveImmediate());
    assertNull(consumer2.receiveImmediate());
    //Create and consume a message that matches the second consumer's filter
    message = session.createMessage(false);
    message.putStringProperty("animal", "elephant");
    producer.send(message);
    received = consumer2.receive(10000);
    assertNotNull(received);
    assertEquals("elephant", received.getStringProperty("animal"));
    assertNull(consumer.receiveImmediate());
    assertNull(consumer2.receiveImmediate());
    //Create and consume another message that matches the second consumer's filter
    message = session.createMessage(false);
    message.putStringProperty("animal", "elephant");
    producer.send(message);
    received = consumer2.receive(1000);
    assertNotNull(received);
    assertEquals("elephant", received.getStringProperty("animal"));
    assertNull(consumer.receiveImmediate());
    assertNull(consumer2.receiveImmediate());
    session.close();
}

96. PagingTest#testRouteOnTopWithMultipleQueues()

Project: activemq-artemis
Source File: PagingTest.java
View license
@Test
public void testRouteOnTopWithMultipleQueues() throws Exception {
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnDurableSend(false);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, 0);
    session.createQueue("Q", "Q1", "dest=1", true);
    session.createQueue("Q", "Q2", "dest=2", true);
    session.createQueue("Q", "Q3", "dest=3", true);
    Queue queue = server.locateQueue(new SimpleString("Q1"));
    queue.getPageSubscription().getPagingStore().startPaging();
    ClientProducer prod = session.createProducer("Q");
    ClientMessage msg = session.createMessage(true);
    msg.putIntProperty("dest", 1);
    prod.send(msg);
    session.commit();
    msg = session.createMessage(true);
    msg.putIntProperty("dest", 2);
    prod.send(msg);
    session.commit();
    session.start();
    ClientConsumer cons1 = session.createConsumer("Q1");
    msg = cons1.receive(5000);
    assertNotNull(msg);
    msg.acknowledge();
    ClientConsumer cons2 = session.createConsumer("Q2");
    msg = cons2.receive(5000);
    assertNotNull(msg);
    queue.getPageSubscription().getPagingStore().forceAnotherPage();
    msg = session.createMessage(true);
    msg.putIntProperty("dest", 1);
    prod.send(msg);
    session.commit();
    msg = cons1.receive(5000);
    assertNotNull(msg);
    msg.acknowledge();
    queue.getPageSubscription().cleanupEntries(false);
    System.out.println("Waiting there");
    server.stop();
}

97. TransactionDurabilityTest#testRolledBackAcknowledgeWithSameMessageAckedByOtherSession()

View license
/*
    * This tests the following situation:
    *
    * (With the old implementation)
    * Currently when a new persistent message is routed to persistent queues, the message is first stored, then the message is routed.
    * Let's say it has been routed to two different queues A, B.
    * Ref R1 gets consumed and acknowledged by transacted session S1, this decrements the ref count and causes an acknowledge record to be written to storage,
    * transactionally, but it's not committed yet.
    * Ref R2 then gets consumed and acknowledged by non transacted session S2, this causes a delete record to be written to storage.
    * R1 then rolls back, and the server is restarted - unfortunatelt since the delete record was written R1 is not ready to be consumed again.
    *
    * It's therefore crucial the messages aren't deleted from storage until AFTER any ack records are committed to storage.
    *
    *
    */
@Test
public void testRolledBackAcknowledgeWithSameMessageAckedByOtherSession() throws Exception {
    final SimpleString testAddress = new SimpleString("testAddress");
    final SimpleString queue1 = new SimpleString("queue1");
    final SimpleString queue2 = new SimpleString("queue2");
    ActiveMQServer server = createServer(true, createDefaultInVMConfig());
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session1 = addClientSession(sf.createSession(false, true, true));
    ClientSession session2 = addClientSession(sf.createSession(false, false, false));
    session1.createQueue(testAddress, queue1, null, true);
    session1.createQueue(testAddress, queue2, null, true);
    ClientProducer producer = session1.createProducer(testAddress);
    ClientMessage message = session1.createMessage(true);
    producer.send(message);
    session1.start();
    session2.start();
    ClientConsumer consumer1 = session1.createConsumer(queue1);
    ClientConsumer consumer2 = session2.createConsumer(queue2);
    ClientMessage m1 = consumer1.receive(1000);
    Assert.assertNotNull(m1);
    ClientMessage m2 = consumer2.receive(1000);
    Assert.assertNotNull(m2);
    m2.acknowledge();
    // Don't commit session 2
    m1.acknowledge();
    session2.rollback();
    session1.close();
    session2.close();
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    session1 = addClientSession(sf.createSession(false, true, true));
    session2 = addClientSession(sf.createSession(false, true, true));
    session1.start();
    session2.start();
    consumer1 = session1.createConsumer(queue1);
    consumer2 = session2.createConsumer(queue2);
    m1 = consumer1.receiveImmediate();
    Assert.assertNull(m1);
    m2 = consumer2.receive(1000);
    Assert.assertNotNull(m2);
    m2.acknowledge();
    session1.close();
    session2.close();
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    session1 = addClientSession(sf.createSession(false, true, true));
    session2 = addClientSession(sf.createSession(false, true, true));
    session1.start();
    session2.start();
    consumer1 = session1.createConsumer(queue1);
    consumer2 = session2.createConsumer(queue2);
    m1 = consumer1.receiveImmediate();
    Assert.assertNull(m1);
    m2 = consumer2.receiveImmediate();
    Assert.assertNull(m2);
    session1.close();
    session2.close();
    locator.close();
    server.stop();
}

98. ClusteredGroupingTest#testGroupingSimpleFail2nd()

View license
// Fail a node where there's a consumer only.. with messages being sent by a node that is not the local
@Test
public void testGroupingSimpleFail2nd() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupServer(2, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1, 2);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0, 2);
    setupClusterConnection("cluster2", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 2, 0, 1);
    final int TIMEOUT_GROUPS = 5000;
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.LOCAL, 0, TIMEOUT_GROUPS, -1, -1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 1, TIMEOUT_GROUPS, -1, -1);
    setUpGroupHandler(GroupingHandlerConfiguration.TYPE.REMOTE, 2, TIMEOUT_GROUPS, -1, -1);
    startServers(0, 1, 2);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    setupSessionFactory(2, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, true);
    createQueue(1, "queues.testaddress", "queue0", null, true);
    createQueue(2, "queues.testaddress", "queue0", null, true);
    addConsumer(0, 0, "queue0", null);
    addConsumer(1, 1, "queue0", null);
    addConsumer(2, 2, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForBindings(2, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 2, 2, false);
    waitForBindings(1, "queues.testaddress", 2, 2, false);
    waitForBindings(2, "queues.testaddress", 2, 2, false);
    sendWithProperty(0, "queues.testaddress", 1, false, Message.HDR_GROUP_ID, new SimpleString("id1"));
    sendWithProperty(0, "queues.testaddress", 1, false, Message.HDR_GROUP_ID, new SimpleString("id2"));
    sendWithProperty(0, "queues.testaddress", 1, false, Message.HDR_GROUP_ID, new SimpleString("id3"));
    // It should receive one message on each server
    ClientMessage msg = consumers[0].getConsumer().receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    assertNull(consumers[0].getConsumer().receiveImmediate());
    msg = consumers[1].getConsumer().receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    SimpleString groupIDOnConsumer1 = msg.getSimpleStringProperty(Message.HDR_GROUP_ID);
    assertNull(consumers[1].getConsumer().receiveImmediate());
    msg = consumers[2].getConsumer().receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    assertNull(consumers[2].getConsumer().receiveImmediate());
    // it should be bound to server1 as we used the group from server1
    sendWithProperty(2, "queues.testaddress", 1, false, Message.HDR_GROUP_ID, groupIDOnConsumer1);
    msg = consumers[1].getConsumer().receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    closeAllConsumers();
    closeAllSessionFactories();
    SimpleString node1ID = servers[1].getNodeID();
    // Validating if it's the right server
    Response response = servers[0].getGroupingHandler().getProposal(groupIDOnConsumer1.concat(".").concat("queue0"), false);
    assertTrue(response.getClusterName().toString().equals("queue0" + node1ID));
    stopServers(0, 1, 2);
    long time = System.currentTimeMillis();
    startServers(2, 0);
    assertTrue("The group start should have waited the timeout on groups", System.currentTimeMillis() >= time + TIMEOUT_GROUPS);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(2, isNetty());
    addConsumer(0, 0, "queue0", null);
    addConsumer(2, 2, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, false);
    waitForBindings(2, "queues.testaddress", 1, 1, false);
    sendWithProperty(2, "queues.testaddress", 1, false, Message.HDR_GROUP_ID, groupIDOnConsumer1);
    // server1 is dead, so either 0 or 2 should receive since the group is now dead
    msg = consumers[0].getConsumer().receive(500);
    if (msg == null) {
        msg = consumers[2].getConsumer().receive(500);
    }
    response = servers[0].getGroupingHandler().getProposal(groupIDOnConsumer1.concat(".").concat("queue0"), false);
    assertFalse("group should have been reassigned since server is not up yet", response.getClusterName().toString().equals("queue0" + node1ID));
    assertNotNull(msg);
    msg.acknowledge();
}

99. 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();
}

100. DuplicateDetectionTest#testDuplicateCachePersisted()

View license
@Test
public void testDuplicateCachePersisted() throws Exception {
    server.stop();
    config = createDefaultInVMConfig().setIDCacheSize(cacheSize);
    server = createServer(config);
    server.start();
    sf = createSessionFactory(locator);
    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, 1);
    SimpleString dupID = new SimpleString("abcdefg");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    ClientMessage message2 = consumer.receive(1000);
    Assert.assertEquals(1, message2.getObjectProperty(propKey));
    message = createMessage(session, 2);
    SimpleString dupID2 = new SimpleString("hijklmnopqr");
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
    producer.send(message);
    message2 = consumer.receive(1000);
    Assert.assertEquals(2, message2.getObjectProperty(propKey));
    session.close();
    sf.close();
    server.stop();
    waitForServerToStop(server);
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.start();
    session.createQueue(queueName, queueName, null, false);
    producer = session.createProducer(queueName);
    consumer = session.createConsumer(queueName);
    message = createMessage(session, 1);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
    message = createMessage(session, 2);
    message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID2.getData());
    producer.send(message);
    message2 = consumer.receiveImmediate();
    Assert.assertNull(message2);
}