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

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

1. SessionTest#testBindingQuery()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testBindingQuery() throws Exception {
    cf = createSessionFactory(locator);
    ClientSession clientSession = cf.createSession(false, true, true);
    clientSession.createQueue("a1", "q1", false);
    clientSession.createQueue("a1", "q2", false);
    clientSession.createQueue("a2", "q3", false);
    clientSession.createQueue("a2", "q4", false);
    clientSession.createQueue("a2", "q5", false);
    ClientSession.AddressQuery resp = clientSession.addressQuery(new SimpleString("a"));
    List<SimpleString> queues = resp.getQueueNames();
    Assert.assertTrue(queues.isEmpty());
    resp = clientSession.addressQuery(new SimpleString("a1"));
    queues = resp.getQueueNames();
    Assert.assertEquals(queues.size(), 2);
    Assert.assertTrue(queues.contains(new SimpleString("q1")));
    Assert.assertTrue(queues.contains(new SimpleString("q2")));
    resp = clientSession.addressQuery(new SimpleString("a2"));
    queues = resp.getQueueNames();
    Assert.assertEquals(queues.size(), 3);
    Assert.assertTrue(queues.contains(new SimpleString("q3")));
    Assert.assertTrue(queues.contains(new SimpleString("q4")));
    Assert.assertTrue(queues.contains(new SimpleString("q5")));
    clientSession.close();
}

2. MultiThreadRandomReattachTestBase#doTestO()

View license
protected void doTestO(final ClientSessionFactory sf, final int threadNum) throws Exception {
    ClientSession sessCreate = sf.createSession(false, true, true);
    sessCreate.createQueue(MultiThreadRandomReattachTestBase.ADDRESS, new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()), null, false);
    ClientSession sess = sf.createSession(false, true, true);
    sess.start();
    ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()));
    for (int i = 0; i < 100; i++) {
        Assert.assertNull(consumer.receiveImmediate());
    }
    sess.close();
    sessCreate.deleteQueue(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()));
    sessCreate.close();
}

3. ReceiveTest#testBasicReceive()

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

4. RoutingTest#testRouteToSingleNonDurableQueue()

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

5. RoutingTest#testRouteToSingleDurableQueue()

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

6. RoutingTest#testRouteToSingleQueueWithFilter()

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

7. RoutingTest#testRouteToSingleTemporaryQueue()

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

8. ReceiveTest#testReceiveOnClosedException()

Project: activemq-artemis
Source File: ReceiveTest.java
View license
@Test
public void testReceiveOnClosedException() throws Exception {
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    session.start();
    session.close();
    try {
        cc.receive();
        Assert.fail("should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    } catch (ActiveMQException e) {
        Assert.fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}

9. SessionTest#testQueueQuery()

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

10. SessionTest#testQueueQueryWithFilter()

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

11. SessionTest#testRollbackWithSend()

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

12. TransactionalSendTest#testSendWithCommit()

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

13. TransactionalSendTest#testSendWithRollback()

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

14. MultiThreadRandomReattachTestBase#doTestK()

View license
protected void doTestK(final ClientSessionFactory sf, final int threadNum) throws Exception {
    ClientSession s = sf.createSession(false, false, false);
    s.addMetaData("data", RandomUtil.randomString());
    s.createQueue(MultiThreadRandomReattachTestBase.ADDRESS, new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()), null, false);
    final int numConsumers = 100;
    for (int i = 0; i < numConsumers; i++) {
        ClientConsumer consumer = s.createConsumer(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()));
        consumer.close();
    }
    s.deleteQueue(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()));
    s.close();
}

15. NIOMultiThreadCompactorStressTest#addBogusData()

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

16. ConsumerTest#testInVMURI()

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

17. DeliveryOrderTest#testSendDeliveryOrderOnCommit()

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

18. MessageConsumerRollbackTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(true, true);
    AddressSettings settings = new AddressSettings().setRedeliveryDelay(100);
    server.getConfiguration().getAddressesSettings().put("#", settings);
    server.start();
    locator = createNettyNonHALocator();
    sf = createSessionFactory(locator);
    ClientSession session = sf.createTransactedSession();
    session.createQueue(inQueue, inQueue, true);
    session.createQueue(outQueue, outQueue, true);
    session.close();
}

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

20. ReceiveTest#testReceiveTimesoutCorrectly()

Project: activemq-artemis
Source File: ReceiveTest.java
View license
@Test
public void testReceiveTimesoutCorrectly() throws Exception {
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    session.start();
    long time = System.currentTimeMillis();
    cc.receive(1000);
    Assert.assertTrue(System.currentTimeMillis() - time >= 1000);
    session.close();
}

21. ReceiveTest#testReceiveThrowsExceptionWhenHandlerSet()

Project: activemq-artemis
Source File: ReceiveTest.java
View license
@Test
public void testReceiveThrowsExceptionWhenHandlerSet() throws Exception {
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    session.start();
    cc.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(final ClientMessage message) {
        }
    });
    try {
        cc.receive();
        Assert.fail("should throw exception");
    } catch (ActiveMQIllegalStateException ise) {
    } catch (ActiveMQException e) {
        Assert.fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}

22. SessionTest#testCommitWithSend()

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

23. TemporaryQueueTest#testDeleteTemporaryQueueAfterConnectionIsClosed_2()

View license
@Test
public void testDeleteTemporaryQueueAfterConnectionIsClosed_2() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createTemporaryQueue(address, queue);
    assertEquals(1, server.getConnectionCount());
    // we create a second session. the temp queue must be present
    // even after we closed the session which created it
    ClientSession session2 = sf.createSession(false, true, true);
    session.close();
    // let some time for the server to clean the connections
    // Thread.sleep(1000);
    session2.start();
    session2.createConsumer(queue);
    session2.close();
}

24. TransientQueueTest#testSimpleTransientQueue()

View license
@Test
public void testSimpleTransientQueue() throws Exception {
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    session.createSharedQueue(address, queue, false);
    assertEquals(1, server.getConnectionCount());
    // we create a second session. the temp queue must be present
    // even after we closed the session which created it
    ClientSession session2 = sf.createSession(false, true, true);
    session.close();
    session2.start();
    session2.createConsumer(queue);
    session2.close();
}

25. FailoverTest#testFailoverOnInitialConnection()

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

26. RandomReattachTest#doTestK()

View license
protected void doTestK(final ClientSessionFactory sf) throws Exception {
    ClientSession s = sf.createSession(false, false, false);
    s.createQueue(RandomReattachTest.ADDRESS, RandomReattachTest.ADDRESS, null, false);
    final int numConsumers = 100;
    for (int i = 0; i < numConsumers; i++) {
        ClientConsumer consumer = s.createConsumer(RandomReattachTest.ADDRESS);
        consumer.close();
    }
    s.deleteQueue(RandomReattachTest.ADDRESS);
    s.close();
}

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

28. SecurityTest#testDeleteDurableQueueWithRole()

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

29. SecurityTest#testDeleteTempQueueWithRole()

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

30. MessagePropertyTest#sendMessages()

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

31. MessagePropertyTest#receiveMessages()

View license
private void receiveMessages() throws Exception {
    ClientSession session = sf.createSession(true, true);
    session.start();
    try (ClientConsumer consumer = session.createConsumer(ADDRESS)) {
        for (int i = 0; i < numMessages; i++) {
            ClientMessage message = consumer.receive(100);
            assertNotNull("Expecting a message " + i, message);
            assertMessageBody(i, message);
            assertEquals(i, message.getIntProperty("int").intValue());
            assertEquals((short) i, message.getShortProperty("short").shortValue());
            assertEquals((byte) i, message.getByteProperty("byte").byteValue());
            assertEquals(floatValue(i), message.getFloatProperty("float").floatValue(), 0.001);
            assertEquals(new SimpleString(Integer.toString(i)), message.getSimpleStringProperty(SIMPLE_STRING_KEY.toString()));
            assertEqualsByteArrays(byteArray(i), message.getBytesProperty("byte[]"));
            assertTrue(message.containsProperty("null-value"));
            assertEquals(message.getObjectProperty("null-value"), null);
            message.acknowledge();
        }
        assertNull("no more messages", consumer.receive(50));
    }
    session.commit();
}

32. ConsumerTest#testClearListener()

Project: activemq-artemis
Source File: ConsumerTest.java
View license
@Test
public void testClearListener() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientConsumer consumer = session.createConsumer(QUEUE);
    consumer.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(final ClientMessage msg) {
        }
    });
    consumer.setMessageHandler(null);
    consumer.receiveImmediate();
    session.close();
}

33. MessageRateTest#testProduceRate()

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

34. SessionCloseTest#testCloseHierarchy()

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

35. SessionTest#testClose()

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

36. SlowConsumerTest#testSlowConsumerSpared()

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

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

38. ClusterTestBase#deleteQueue()

View license
protected void deleteQueue(final int node, final String queueName) throws Exception {
    ClientSessionFactory sf = sfs[node];
    if (sf == null) {
        throw new IllegalArgumentException("No sf at " + node);
    }
    ClientSession session = sf.createSession(false, true, true);
    session.deleteQueue(queueName);
    session.close();
}

39. FailBackAutoTest#verifyMessageOnServer()

View license
/**
    * @throws Exception
    * @throws Exception
    */
private void verifyMessageOnServer(final int server, final int numberOfMessages) throws Exception {
    ServerLocator backupLocator = createInVMLocator(server);
    ClientSessionFactory factorybkp = addSessionFactory(createSessionFactory(backupLocator));
    ClientSession sessionbkp = factorybkp.createSession(false, false);
    sessionbkp.start();
    ClientConsumer consumerbkp = sessionbkp.createConsumer(ADDRESS);
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage msg = consumerbkp.receive(1000);
        assertNotNull(msg);
        msg.acknowledge();
        sessionbkp.commit();
    }
    sessionbkp.close();
    factorybkp.close();
    backupLocator.close();
}

40. FailoverListenerTest#verifyMessageOnServer()

View license
/**
    * @throws Exception
    */
private void verifyMessageOnServer(final int server, final int numberOfMessages) throws Exception {
    ServerLocator backupLocator = createInVMLocator(server);
    ClientSessionFactory factorybkp = addSessionFactory(createSessionFactory(backupLocator));
    ClientSession sessionbkp = factorybkp.createSession(false, false);
    sessionbkp.start();
    ClientConsumer consumerbkp = sessionbkp.createConsumer(ADDRESS);
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage msg = consumerbkp.receive(1000);
        assertNotNull(msg);
        msg.acknowledge();
        sessionbkp.commit();
    }
    sessionbkp.close();
    factorybkp.close();
    backupLocator.close();
}

41. FailoverTest#testFailWithBrowser()

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

42. CoreClientOverHttpTest#testCoreHttpClientIdle()

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

43. ExportFormatTest#testConsumeFromFormat()

View license
@Test
public void testConsumeFromFormat() throws Exception {
    ActiveMQServer server = createServer(true);
    DecodeJournal.importJournal(server.getConfiguration().getJournalLocation().getAbsolutePath(), "activemq-data", "amq", 2, 102400, new StringReader(journalFile));
    DecodeJournal.importJournal(server.getConfiguration().getBindingsLocation().getAbsolutePath(), "activemq-bindings", "bindings", 2, 1048576, new StringReader(bindingsFile));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = createSessionFactory(locator);
    ClientSession session = factory.createSession();
    session.start();
    ClientConsumer consumer = session.createConsumer("A1");
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
        assertEquals(i, msg.getIntProperty("key").intValue());
    }
    session.commit();
}

44. BatchDelayTest#testSendReceiveMany()

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

45. SecurityTest#testCreateDurableQueueWithRole()

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

46. SecurityTest#testCreateTempQueueWithRole()

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

47. SecurityTest#testNonBlockSendWithoutRole()

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

48. SecurityTest#testNonBlockSendManagementWithoutRole()

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

49. BasicXaTest#testSendWithoutXID()

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

50. BasicXaTest#testSendMultipleSuspendErrorCheck()

Project: activemq-artemis
Source File: BasicXaTest.java
View license
@Test
public void testSendMultipleSuspendErrorCheck() throws Exception {
    ClientSession session = null;
    session = sessionFactory.createSession(true, false, false);
    Xid xid = newXID();
    session.start(xid, XAResource.TMNOFLAGS);
    try {
        session.start(xid, XAResource.TMRESUME);
        Assert.fail("XAException expected");
    } catch (XAException e) {
        Assert.assertEquals(XAException.XAER_PROTO, e.errorCode);
    }
    session.close();
}

51. BasicXaTest#testEmptyXID()

Project: activemq-artemis
Source File: BasicXaTest.java
View license
@Test
public void testEmptyXID() throws Exception {
    Xid xid = newXID();
    ClientSession session = sessionFactory.createSession(true, false, false);
    session.start(xid, XAResource.TMNOFLAGS);
    session.end(xid, XAResource.TMSUCCESS);
    session.rollback(xid);
    session.close();
    messagingService.stop();
    // do the same test with a file persistence now
    messagingService = createServer(true, configuration, -1, -1, addressSettings);
    messagingService.start();
    sessionFactory = createSessionFactory(locator);
    xid = newXID();
    session = sessionFactory.createSession(true, false, false);
    session.start(xid, XAResource.TMNOFLAGS);
    session.end(xid, XAResource.TMSUCCESS);
    session.rollback(xid);
    xid = newXID();
    session.start(xid, XAResource.TMNOFLAGS);
    session.end(xid, XAResource.TMSUCCESS);
    session.prepare(xid);
    session.commit(xid, false);
    session.close();
    xid = newXID();
    session = sessionFactory.createSession(true, false, false);
    session.start(xid, XAResource.TMNOFLAGS);
    session.end(xid, XAResource.TMSUCCESS);
    session.prepare(xid);
    session.rollback(xid);
    session.close();
    messagingService.start();
    sessionFactory = createSessionFactory(locator);
    xid = newXID();
    session = sessionFactory.createSession(true, false, false);
    session.start(xid, XAResource.TMNOFLAGS);
    session.end(xid, XAResource.TMSUCCESS);
    session.rollback(xid);
    session.close();
    messagingService.stop();
    messagingService.start();
    // This is not really necessary... But since the server has stopped, I would prefer to keep recreating the factory
    sessionFactory = createSessionFactory(locator);
    session = sessionFactory.createSession(true, false, false);
    Xid[] xids = session.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(0, xids.length);
    session.close();
}

52. SimpleSendReceiveSoakTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    clearDataRecreateServerDirs();
    Configuration config = createDefaultConfig(isNetty()).setJournalFileSize(10 * 1024 * 1024);
    server = createServer(IS_JOURNAL, config, -1, -1, new HashMap<String, AddressSettings>());
    server.start();
    ServerLocator locator = createFactory(isNetty());
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession();
    session.createQueue(SimpleSendReceiveSoakTest.ADDRESS, SimpleSendReceiveSoakTest.ADDRESS, true);
    session.close();
}

53. NIOMultiThreadCompactorStressTest#checkEmptyXID()

View license
private void checkEmptyXID(final Xid xid) throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(true, false, false);
    Xid[] xids = session.recover(XAResource.TMSTARTRSCAN);
    Assert.assertEquals(1, xids.length);
    Assert.assertEquals(xid, xids[0]);
    session.rollback(xid);
    session.close();
    sf.close();
}

54. NIOMultiThreadCompactorStressTest#drainQueue()

View license
/**
    * @param numberOfMessagesExpected
    * @param queue
    * @throws ActiveMQException
    */
private void drainQueue(final int numberOfMessagesExpected, final SimpleString queue) throws ActiveMQException {
    ClientSession sess = sf.createSession(true, true);
    ClientConsumer consumer = sess.createConsumer(queue);
    sess.start();
    for (int i = 0; i < numberOfMessagesExpected; i++) {
        ClientMessage msg = consumer.receive(5000);
        Assert.assertNotNull(msg);
        if (i % 100 == 0) {
        // System.out.println("Received #" + i + "  on thread after start");
        }
        msg.acknowledge();
    }
    Assert.assertNull(consumer.receiveImmediate());
    sess.close();
}

55. LatencyTest#testLatency()

Project: activemq-artemis
Source File: LatencyTest.java
View license
/*
   * simple test to make sure connect still works with some network latency  built into netty
   * */
@Test
@BMRules(rules = { @BMRule(name = "trace ClientBootstrap.connect", targetClass = "org.jboss.netty.bootstrap.ClientBootstrap", targetMethod = "connect", targetLocation = "ENTRY", action = "System.out.println(\"netty connecting\")"), @BMRule(name = "sleep OioWorker.run", targetClass = "org.jboss.netty.channel.socket.oio.OioWorker", targetMethod = "run", targetLocation = "ENTRY", action = "Thread.sleep(500)") })
public void testLatency() throws Exception {
    ActiveMQServer server = createServer(createDefaultNettyConfig());
    server.start();
    ServerLocator locator = createNettyNonHALocator();
    ClientSessionFactory factory = createSessionFactory(locator);
    ClientSession session = factory.createSession();
    session.close();
    server.stop();
}

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

57. AutoCloseCoreTest#testAutClose()

View license
@Test
public void testAutClose() throws Exception {
    ServerLocator locatorx;
    ClientSession sessionx;
    ClientSessionFactory factoryx;
    try (ServerLocator locator = createInVMNonHALocator();
        ClientSessionFactory factory = locator.createSessionFactory();
        ClientSession session = factory.createSession(false, false)) {
        locatorx = locator;
        sessionx = session;
        factoryx = factory;
    }
    assertTrue(locatorx.isClosed());
    assertTrue(sessionx.isClosed());
    assertTrue(factoryx.isClosed());
}

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

59. CreateQueueIdempotentTest#testSequentialCreateQueueIdempotency()

View license
@Test
public void testSequentialCreateQueueIdempotency() throws Exception {
    final SimpleString QUEUE = new SimpleString("SequentialCreateQueueIdempotency");
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, true);
    try {
        session.createQueue(QUEUE, QUEUE, null, true);
        fail("Expected exception, queue already exists");
    } catch (ActiveMQQueueExistsException qee) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}

60. LargeMessageTest#testDeleteOnNoBinding()

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

61. PagingTest#testPreparedACKAndRestart()

Project: activemq-artemis
Source File: PagingTest.java
View license
@Test
public void testPreparedACKAndRestart() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int numberOfMessages = 50;
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setAckBatchSize(0);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    Queue queue = server.locateQueue(PagingTest.ADDRESS);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    queue.getPageSubscription().getPagingStore().startPaging();
    forcePage(queue);
    // Send many messages, 5 on each page
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("count", i);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        producer.send(message);
        if ((i + 1) % 5 == 0) {
            System.out.println("Forcing at " + i);
            session.commit();
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    session.close();
    session = sf.createSession(true, false, false);
    Xid xidConsumeNoCommit = newXID();
    session.start(xidConsumeNoCommit, XAResource.TMNOFLAGS);
    ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    // First message is consumed, prepared, will be rolled back later
    ClientMessage firstMessageConsumed = cons.receive(5000);
    assertNotNull(firstMessageConsumed);
    firstMessageConsumed.acknowledge();
    session.end(xidConsumeNoCommit, XAResource.TMSUCCESS);
    session.prepare(xidConsumeNoCommit);
    Xid xidConsumeCommit = newXID();
    session.start(xidConsumeCommit, XAResource.TMNOFLAGS);
    Xid neverCommittedXID = newXID();
    for (int i = 1; i < numberOfMessages; i++) {
        if (i == 20) {
            // I elected a single message to be in prepared state, it won't ever be committed
            session.end(xidConsumeCommit, XAResource.TMSUCCESS);
            session.commit(xidConsumeCommit, true);
            session.start(neverCommittedXID, XAResource.TMNOFLAGS);
        }
        ClientMessage message = cons.receive(5000);
        assertNotNull(message);
        System.out.println("ACK " + i);
        message.acknowledge();
        assertEquals(i, message.getIntProperty("count").intValue());
        if (i == 20) {
            session.end(neverCommittedXID, XAResource.TMSUCCESS);
            session.prepare(neverCommittedXID);
            xidConsumeCommit = newXID();
            session.start(xidConsumeCommit, XAResource.TMNOFLAGS);
        }
    }
    session.end(xidConsumeCommit, XAResource.TMSUCCESS);
    session.commit(xidConsumeCommit, true);
    session.close();
    sf.close();
    // Restart the server, and we expect cleanup to not destroy any page with prepared data
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    queue = server.locateQueue(ADDRESS);
    assertTrue(queue.getPageSubscription().getPagingStore().isPaging());
    producer = session.createProducer(ADDRESS);
    for (int i = numberOfMessages; i < numberOfMessages * 2; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("count", i);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        producer.send(message);
        if ((i + 1) % 5 == 0) {
            session.commit();
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    cons = session.createConsumer(ADDRESS);
    session.start();
    for (int i = numberOfMessages; i < numberOfMessages * 2; i++) {
        ClientMessage message = cons.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty("count").intValue());
        message.acknowledge();
    }
    assertNull(cons.receiveImmediate());
    session.commit();
    System.out.println("count = " + getMessageCount(queue));
    session.commit();
    session.close();
    session = sf.createSession(true, false, false);
    session.rollback(xidConsumeNoCommit);
    session.start();
    xidConsumeCommit = newXID();
    session.start(xidConsumeCommit, XAResource.TMNOFLAGS);
    cons = session.createConsumer(ADDRESS);
    session.start();
    ClientMessage message = cons.receive(5000);
    assertNotNull(message);
    message.acknowledge();
    session.end(xidConsumeCommit, XAResource.TMSUCCESS);
    session.commit(xidConsumeCommit, true);
    session.close();
}

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

63. RedeliveryConsumerTest#setUp()

View license
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
/**
    * @param persistDeliveryCountBeforeDelivery
    * @throws Exception
    */
private void setUp(final boolean persistDeliveryCountBeforeDelivery) throws Exception {
    Configuration config = createDefaultInVMConfig().setPersistDeliveryCountBeforeDelivery(persistDeliveryCountBeforeDelivery);
    server = createServer(true, config);
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    ClientSession session = addClientSession(factory.createSession(false, false, false));
    try {
        session.createQueue(ADDRESS, ADDRESS, true);
    } catch (ActiveMQException expected) {
    }
    session.close();
}

64. RequestorTest#testClientRequestorConstructorWithClosedSession()

Project: activemq-artemis
Source File: RequestorTest.java
View license
@Test
public void testClientRequestorConstructorWithClosedSession() throws Exception {
    final SimpleString requestAddress = RandomUtil.randomSimpleString();
    ClientSessionFactory sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession(false, true, true);
    session.close();
    ActiveMQAction activeMQAction = new ActiveMQAction() {

        @Override
        public void run() throws Exception {
            new ClientRequestor(session, requestAddress);
        }
    };
    ActiveMQTestBase.expectActiveMQException("ClientRequestor's session must not be closed", ActiveMQExceptionType.OBJECT_CLOSED, activeMQAction);
}

65. SessionCloseOnGCTest#testValidateFactoryGC4()

View license
@Test
public void testValidateFactoryGC4() throws Exception {
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession s1 = factory.createSession();
    ClientSession s2 = factory.createSession();
    WeakReference<ClientSession> wrs1 = new WeakReference<>(s1);
    WeakReference<ClientSession> wrs2 = new WeakReference<>(s2);
    s1 = null;
    s2 = null;
    locator.close();
    locator = null;
    ActiveMQTestBase.checkWeakReferences(wrs1, wrs2);
    WeakReference<ClientSessionFactory> fref = new WeakReference<>(factory);
    factory = null;
    ActiveMQTestBase.checkWeakReferences(fref, wrs1, wrs2);
}

66. SessionCreateAndDeleteQueueTest#testDeleteQueueNotExist()

View license
@Test
public void testDeleteQueueNotExist() throws Exception {
    ClientSession session = createSessionFactory(locator).createSession(false, true, true);
    try {
        session.deleteQueue(queueName);
        Assert.fail("should throw exception");
    } catch (ActiveMQNonExistentQueueException neqe) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}

67. SessionFactoryTest#testDiscoveryConstructor()

View license
@Test
public void testDiscoveryConstructor() throws Exception {
    ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(groupConfiguration);
    assertFactoryParams(locator, null, groupConfiguration, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    Assert.assertNotNull(session);
    session.close();
    testSettersThrowException(cf);
    cf.close();
    locator.close();
}

68. SessionFactoryTest#testStaticConnectorListConstructor()

View license
@Test
public void testStaticConnectorListConstructor() throws Exception {
    TransportConfiguration[] tc = new TransportConfiguration[] { liveTC };
    ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(tc);
    assertFactoryParams(locator, tc, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    Assert.assertNotNull(session);
    session.close();
    testSettersThrowException(cf);
    cf.close();
}

69. SessionSendAcknowledgementHandlerTest#testSetInvalidSendACK()

View license
@Test
public void testSetInvalidSendACK() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    locator.setConfirmationWindowSize(-1);
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession(null, null, false, true, true, false, 1);
    boolean failed = false;
    try {
        session.setSendAcknowledgementHandler(new SendAcknowledgementHandler() {

            @Override
            public void sendAcknowledged(Message message) {
            }
        });
    } catch (Throwable expected) {
        failed = true;
    }
    assertTrue("Expected a failure on setting ACK Handler", failed);
    session.createQueue(address, queueName, false);
}

70. SessionSendAcknowledgementHandlerTest#verifySendAcknowledgementsProducerOnly()

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

71. 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;
}

72. SecurityTest#testSendManagementWithRole()

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

73. MultiThreadConsumerStressTest#setupServer()

View license
private void setupServer(final JournalType journalType) throws Exception {
    Configuration config = createDefaultNettyConfig().setJournalType(journalType).setJournalFileSize(ActiveMQDefaultConfiguration.getDefaultJournalFileSize()).setJournalMinFiles(ActiveMQDefaultConfiguration.getDefaultJournalMinFiles()).setJournalCompactMinFiles(2).setJournalCompactPercentage(50);
    server = createServer(true, config);
    server.start();
    ServerLocator locator = createNettyNonHALocator().setBlockOnDurableSend(false).setBlockOnNonDurableSend(false).setBlockOnAcknowledge(false);
    sf = createSessionFactory(locator);
    ClientSession sess = sf.createSession();
    try {
        sess.createQueue(ADDRESS, QUEUE, true);
    } catch (Exception ignored) {
    }
    sess.close();
    locator.close();
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
}

74. PushConsumer#stop()

Project: activemq-artemis
Source File: PushConsumer.java
View license
public void stop() {
    for (ClientSession session : sessions) {
        try {
            if (session != null) {
                session.close();
            }
        } catch (ActiveMQException e) {
        }
    }
    try {
        if (strategy != null) {
            strategy.stop();
        }
    } catch (Exception e) {
    }
}

75. QueueResource#deleteQueue()

Project: activemq-artemis
Source File: QueueResource.java
View license
@DELETE
public void deleteQueue(@Context UriInfo uriInfo) throws Exception {
    ActiveMQRestLogger.LOGGER.debug("Handling DELETE request for \"" + uriInfo.getPath() + "\"");
    queueDestinationsResource.getQueues().remove(destination);
    stop();
    ClientSession session = serviceManager.getSessionFactory().createSession(false, false, false);
    try {
        SimpleString queueName = new SimpleString(destination);
        session.deleteQueue(queueName);
    } finally {
        try {
            session.close();
        } catch (Exception ignored) {
        }
    }
}

76. QueueServiceManager#deploy()

View license
public void deploy(QueueDeployment queueDeployment) throws Exception {
    if (!started) {
        throw new Exception("You must start() this class instance before deploying");
    }
    String queueName = queueDeployment.getName();
    try (ClientSession session = sessionFactory.createSession(false, false, false)) {
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
        if (!query.isExists()) {
            session.createQueue(queueName, queueName, queueDeployment.isDurableSend());
        }
    }
    destination.createQueueResource(queueName, queueDeployment.isDurableSend(), queueDeployment.getConsumerSessionTimeoutSeconds(), queueDeployment.isDuplicatesAllowed());
}

77. PushSubscription#deleteSubscriberQueue()

View license
protected void deleteSubscriberQueue() {
    String subscriptionName = registration.getDestination();
    ClientSession session = null;
    try {
        session = factory.createSession();
        session.deleteQueue(subscriptionName);
    } catch (ActiveMQException e) {
        ActiveMQRestLogger.LOGGER.errorDeletingSubscriberQueue(e);
    } finally {
        try {
            if (session != null)
                session.close();
        } catch (ActiveMQException e) {
        }
    }
}

78. PushSubscriptionsResource#createSubscription()

View license
public ClientSession createSubscription(String subscriptionName, boolean durable) {
    ClientSession session = null;
    try {
        session = sessionFactory.createSession();
        if (durable) {
            session.createQueue(destination, subscriptionName, true);
        } else {
            session.createTemporaryQueue(destination, subscriptionName);
        }
        return session;
    } catch (ActiveMQException e) {
        throw new RuntimeException(e);
    }
}

79. PushSubscriptionsResource#deleteSubscriberQueue()

View license
private void deleteSubscriberQueue(PushConsumer consumer) {
    String subscriptionName = consumer.getDestination();
    ClientSession session = null;
    try {
        session = sessionFactory.createSession();
        session.deleteQueue(subscriptionName);
    } catch (ActiveMQException e) {
    } finally {
        closeSession(session);
    }
}

80. SubscriptionsResource#subscriptionExists()

View license
private boolean subscriptionExists(String subscriptionId) {
    ClientSession session = null;
    try {
        session = sessionFactory.createSession();
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString(subscriptionId));
        return query.isExists();
    } catch (ActiveMQException e) {
        throw new RuntimeException(e);
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
}

81. SubscriptionsResource#deleteSubscriberQueue()

View license
private void deleteSubscriberQueue(QueueConsumer consumer) {
    String subscriptionName = consumer.getId();
    ClientSession session = null;
    try {
        session = sessionFactory.createSession();
        session.deleteQueue(subscriptionName);
    } catch (ActiveMQException e) {
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
}

82. TopicServiceManager#deploy()

View license
public void deploy(TopicDeployment topicDeployment) throws Exception {
    if (!started) {
        throw new Exception("You must start() this class instance before deploying");
    }
    String queueName = topicDeployment.getName();
    boolean defaultDurable;
    try (ClientSession session = sessionFactory.createSession(false, false, false)) {
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
        defaultDurable = topicDeployment.isDurableSend();
        if (query.isExists()) {
            defaultDurable = query.isDurable();
        } else {
            session.createQueue(queueName, queueName, topicDeployment.isDurableSend());
        }
    }
    destination.createTopicResource(queueName, defaultDurable, topicDeployment.getConsumerSessionTimeoutSeconds(), topicDeployment.isDuplicatesAllowed());
}

83. TransformTest#publish()

Project: activemq-artemis
Source File: TransformTest.java
View license
public static void publish(String destination, Serializable object, String contentType) throws Exception {
    ClientSession session = manager.getQueueManager().getSessionFactory().createSession();
    try {
        ClientProducer producer = session.createProducer(destination);
        ClientMessage message = session.createMessage(Message.OBJECT_TYPE, false);
        if (contentType == null) {
            ActiveMQ.setEntity(message, object);
        } else
            ActiveMQ.setEntity(message, object, contentType);
        producer.send(message);
        session.start();
    } finally {
        session.close();
    }
}

84. ScaleDownHandler#scaleDownDuplicateIDs()

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

85. ActiveMQTestBase#createQueue()

View license
protected void createQueue(final String address, final String queue) throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = locator.createSessionFactory();
    ClientSession session = sf.createSession();
    try {
        session.createQueue(address, queue);
    } finally {
        session.close();
        closeSessionFactory(sf);
        closeServerLocator(locator);
    }
}

86. ActiveMQTestBase#crashAndWaitForFailure()

View license
public static void crashAndWaitForFailure(ActiveMQServer server, ClientSession... sessions) throws Exception {
    CountDownLatch latch = new CountDownLatch(sessions.length);
    for (ClientSession session : sessions) {
        CountDownSessionFailureListener listener = new CountDownSessionFailureListener(latch, session);
        session.addFailureListener(listener);
    }
    ClusterManager clusterManager = server.getClusterManager();
    clusterManager.flushExecutor();
    clusterManager.clear();
    Assert.assertTrue("server should be running!", server.isStarted());
    server.stop(true);
    if (sessions.length > 0) {
        // Wait to be informed of failure
        boolean ok = latch.await(10000, TimeUnit.MILLISECONDS);
        Assert.assertTrue("Failed to stop the server! Latch count is " + latch.getCount() + " out of " + sessions.length, ok);
    }
}

87. ActiveMQTestBase#crashAndWaitForFailure()

View license
public static void crashAndWaitForFailure(ActiveMQServer server, ServerLocator locator) throws Exception {
    ClientSessionFactory sf = locator.createSessionFactory();
    ClientSession session = sf.createSession();
    try {
        crashAndWaitForFailure(server, session);
    } finally {
        try {
            session.close();
            sf.close();
        } catch (Exception ignored) {
        }
    }
}

88. JmsQueueCompositeSendReceiveTest#testDuplicate()

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

89. LargeMessageTest#testDeleteOnDrop()

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

90. ClusterWithBackupFailoverTestBase#exploreSessions()

View license
private ClientSession[] exploreSessions(final int node) {
    HashSet<ClientSession> sessions = new HashSet<>();
    for (ConsumerHolder holder : consumers) {
        if (holder != null && holder.getNode() == node && holder.getSession() != null) {
            sessions.add(holder.getSession());
        }
    }
    ClientSession[] sessionsArray = sessions.toArray(new ClientSession[sessions.size()]);
    return sessionsArray;
}

91. CloseDestroyedConnectionTest#testClosingTemporaryTopicDeletesQueue()

View license
@Test
public void testClosingTemporaryTopicDeletesQueue() throws JMSException, ActiveMQException {
    conn = cf.createConnection();
    Assert.assertEquals(1, server.getRemotingService().getConnections().size());
    session1 = (ActiveMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQTemporaryTopic topic = (ActiveMQTemporaryTopic) session1.createTemporaryTopic();
    String address = topic.getAddress();
    session1.close();
    conn.close();
    conn2 = cf.createConnection();
    session2 = (ActiveMQSession) conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ClientSession cs = session2.getCoreSession();
    try {
        cs.createConsumer(address);
        fail("the address from the TemporaryTopic still exists!");
    } catch (ActiveMQException e) {
        assertEquals("expecting 'queue does not exist'", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, e.getType());
    }
}

92. OutgoingConnectionTestJTA#testSimpleSendNoXAJMSContext()

View license
@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer("jms.queue." + MDBQUEUE);
        JMSContext jmsctx = qraConnectionFactory.createContext()) {
        session.start();
        // These next 4 lines could be written in a single line however it makes difficult for debugging
        JMSProducer producer = jmsctx.createProducer();
        producer.setProperty("strvalue", "hello");
        TextMessage msgsend = jmsctx.createTextMessage("hello");
        producer.send(q, msgsend);
        ClientMessage msg = consVerify.receive(1000);
        assertNotNull(msg);
        assertEquals("hello", msg.getStringProperty("strvalue"));
    }
}

93. OutgoingConnectionTestJTA#testSimpleSendNoXAJMS1()

View license
@Test
public void testSimpleSendNoXAJMS1() throws Exception {
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer("jms.queue." + MDBQUEUE);
        Connection conn = qraConnectionFactory.createConnection()) {
        Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        session.start();
        MessageProducer producer = jmsSess.createProducer(q);
        // These next 4 lines could be written in a single line however it makes difficult for debugging
        TextMessage msgsend = jmsSess.createTextMessage("hello");
        msgsend.setStringProperty("strvalue", "hello");
        producer.send(msgsend);
        ClientMessage msg = consVerify.receive(1000);
        assertNotNull(msg);
        assertEquals("hello", msg.getStringProperty("strvalue"));
    }
}

94. ConnectionLimitTest#testNettyConnectionLimit()

View license
@Test
public void testNettyConnectionLimit() throws Exception {
    ServerLocator locator = createNonHALocator(true).setCallTimeout(3000);
    ClientSessionFactory clientSessionFactory = locator.createSessionFactory();
    ClientSession clientSession = addClientSession(clientSessionFactory.createSession());
    try {
        ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory();
        ClientSession extraClientSession = addClientSession(extraClientSessionFactory.createSession());
        fail("creating a session here should fail");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQConnectionTimedOutException);
    }
}

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

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

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

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

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

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