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

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

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

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

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

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

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

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

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

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

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

10. SynchronousCloseTest#testSynchronousClose()

View license
/*
    * Server side resources should be cleaned up befor call to close has returned or client could launch
    * DoS attack
    */
@Test
public void testSynchronousClose() throws Exception {
    Assert.assertEquals(0, server.getActiveMQServerControl().listRemoteAddresses().length);
    ClientSessionFactory sf = createSessionFactory();
    for (int i = 0; i < 2000; i++) {
        ClientSession session = sf.createSession(false, true, true);
        session.close();
    }
    sf.close();
    sf.getServerLocator().close();
}

11. LDAPSecurityTest#testJAASSecurityManagerAuthentication()

View license
@Test
public void testJAASSecurityManagerAuthentication() throws Exception {
    server.start();
    ClientSessionFactory cf = locator.createSessionFactory();
    try {
        ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
        session.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception");
    }
    cf.close();
}

12. LDAPSecurityTest#testJAASSecurityManagerAuthenticationBadPassword()

View license
@Test
public void testJAASSecurityManagerAuthenticationBadPassword() throws Exception {
    server.start();
    ClientSessionFactory cf = locator.createSessionFactory();
    try {
        cf.createSession("first", "badpassword", false, true, true, false, 0);
        Assert.fail("should throw exception here");
    } catch (Exception e) {
    }
    cf.close();
}

13. LegacyLDAPSecuritySettingPluginTest#testBasicPluginAuthorization()

View license
@Test
public void testBasicPluginAuthorization() throws Exception {
    server.start();
    ClientSessionFactory cf = locator.createSessionFactory();
    String name = "queue1";
    try {
        ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
        session.createQueue(SimpleString.toSimpleString(name), SimpleString.toSimpleString(name));
        ClientProducer producer = session.createProducer();
        producer.send(name, session.createMessage(false));
        session.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception");
    }
    cf.close();
}

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

15. XmlDataImporter#process()

View license
public void process(InputStream inputStream, String host, int port, boolean transactional) throws Exception {
    reader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
    HashMap<String, Object> connectionParams = new HashMap<>();
    connectionParams.put(TransportConstants.HOST_PROP_NAME, host);
    connectionParams.put(TransportConstants.PORT_PROP_NAME, Integer.toString(port));
    ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams));
    ClientSessionFactory sf = serverLocator.createSessionFactory();
    if (user != null || password != null) {
        session = sf.createSession(user, password, false, !transactional, true, false, 0);
        managementSession = sf.createSession(user, password, false, true, true, false, 0);
    } else {
        session = sf.createSession(false, !transactional, true);
        managementSession = sf.createSession(false, true, true);
    }
    localSession = true;
    processXml();
}

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

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

18. JmsQueueCompositeSendReceiveTest#testDuplicate()

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

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

20. ConsumerFilterTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(false);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession();
    session.start();
    session.createQueue("foo", "foo");
    producer = session.createProducer("foo");
    consumer = session.createConsumer("foo", "animal='giraffe'");
}

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

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

23. ExpiryAddressTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), false));
    server.start();
    // then we create a client as normal
    locator = createInVMNonHALocator().setBlockOnAcknowledge(true);
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    // There are assertions over sizes that needs to be done after the ACK
    // was received on server
    clientSession = addClientSession(sessionFactory.createSession(null, null, false, true, true, false, 0));
}

24. IncompatibleVersionTest#setUp()

View license
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(false, false);
    server.getConfiguration().setConnectionTTLOverride(500);
    server.start();
    locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    connection = (CoreRemotingConnection) csf.getConnection();
}

25. InVMNonPersistentMessageBufferTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(isPersistent(), isNetty());
    server.start();
    ServerLocator locator = createFactory();
    ClientSessionFactory cf = createSessionFactory(locator);
    session = cf.createSession();
    session.createQueue(InVMNonPersistentMessageBufferTest.address, InVMNonPersistentMessageBufferTest.queueName);
    producer = session.createProducer(InVMNonPersistentMessageBufferTest.address);
    consumer = session.createConsumer(InVMNonPersistentMessageBufferTest.queueName);
    session.start();
}

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

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

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

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

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

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

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

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

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

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

36. SessionCloseOnGCTest#testValidateFactoryGC5()

View license
@Test
public void testValidateFactoryGC5() throws Exception {
    ClientSessionFactory factory = locator.createSessionFactory();
    WeakReference<ClientSessionFactory> fref = new WeakReference<>(factory);
    factory = null;
    locator.close();
    locator = null;
    ActiveMQTestBase.checkWeakReferences(fref);
}

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

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

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

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

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

42. ClientExitTest#setUp()

View license
// Package protected ----------------------------------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ServerLocator locator = createNettyNonHALocator();
    addServerLocator(locator);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ClientExitTest.QUEUE, ClientExitTest.QUEUE, null, false);
    consumer = session.createConsumer(ClientExitTest.QUEUE);
    session.start();
}

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

44. ClusterTestBase#setupSessionFactory()

View license
protected void setupSessionFactory(final int node, final boolean netty, int reconnectAttempts) throws Exception {
    if (sfs[node] != null) {
        throw new IllegalArgumentException("Already a server at " + node);
    }
    Map<String, Object> params = generateParams(node, netty);
    TransportConfiguration serverTotc;
    if (netty) {
        serverTotc = new TransportConfiguration(ActiveMQTestBase.NETTY_CONNECTOR_FACTORY, params);
    } else {
        serverTotc = new TransportConfiguration(INVM_CONNECTOR_FACTORY, params);
    }
    locators[node] = ActiveMQClient.createServerLocatorWithoutHA(serverTotc).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setReconnectAttempts(reconnectAttempts);
    addServerLocator(locators[node]);
    ClientSessionFactory sf = createSessionFactory(locators[node]);
    sfs[node] = sf;
}

45. ClusterTestBase#setupSessionFactory()

View license
protected void setupSessionFactory(final int node, final int backupNode, final boolean netty, final boolean blocking) throws Exception {
    if (sfs[node] != null) {
        throw new IllegalArgumentException("Already a server at " + node);
    }
    Map<String, Object> params = generateParams(node, netty);
    TransportConfiguration serverToTC = createTransportConfiguration(netty, false, params);
    locators[node] = addServerLocator(ActiveMQClient.createServerLocatorWithHA(serverToTC)).setRetryInterval(100).setRetryIntervalMultiplier(1d).setReconnectAttempts(-1).setBlockOnNonDurableSend(blocking).setBlockOnDurableSend(blocking);
    final String identity = "TestClientConnector,live=" + node + ",backup=" + backupNode;
    ((ServerLocatorInternal) locators[node]).setIdentity(identity);
    ClientSessionFactory sf = createSessionFactory(locators[node]);
    sfs[node] = sf;
}

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

47. ActiveMQServerControlUsingCoreTest#restartServer()

View license
@Override
protected void restartServer() throws Exception {
    session.close();
    super.restartServer();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.start();
}

48. AddressControlTest#testGetNumberOfBytesPerPage()

View license
@Test
public void testGetNumberOfBytesPerPage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createQueue(address, address, true);
    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), addressControl.getNumberOfBytesPerPage());
    session.close();
    server.stop();
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setPageSizeBytes(1024);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    server.start();
    ServerLocator locator2 = createInVMNonHALocator();
    ClientSessionFactory sf2 = createSessionFactory(locator2);
    session = sf2.createSession(false, true, false);
    session.createQueue(address, address, true);
    Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage());
}

49. AddressControlUsingCoreTest#setUp()

View license
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true);
    server = createServer(false, config);
    server.setMBeanServer(mbeanServer);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnNonDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, false);
    session.start();
}

50. ManagementWithPagingServerTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true);
    server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, true));
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(5120).setMaxSizeBytes(10240).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(false).setConsumerWindowSize(0);
    ClientSessionFactory sf = createSessionFactory(locator);
    session1 = sf.createSession(false, true, false);
    session1.start();
    session2 = sf.createSession(false, true, false);
    session2.start();
}

51. NotificationTest#setUp()

View license
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), false));
    server.start();
    locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.start();
    notifQueue = RandomUtil.randomSimpleString();
    session.createQueue(ActiveMQDefaultConfiguration.getDefaultManagementNotificationAddress(), notifQueue, null, false);
    notifConsumer = session.createConsumer(notifQueue);
}

52. QueueControlTest#setUp()

View license
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration conf = createDefaultInVMConfig().setJMXManagementEnabled(true);
    server = addServer(ActiveMQServers.newActiveMQServer(conf, mbeanServer, false));
    server.start();
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setConsumerWindowSize(0);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, false);
    session.start();
}

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

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

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

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

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

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

59. SecurityTest#testJAASSecurityManagerAuthentication()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testJAASSecurityManagerAuthentication() throws Exception {
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
        session.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception");
    }
}

60. SecurityTest#testJAASSecurityManagerAuthenticationBadPassword()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testJAASSecurityManagerAuthenticationBadPassword() throws Exception {
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("PropertiesLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        cf.createSession("first", "badpassword", false, true, true, false, 0);
        Assert.fail("should throw exception here");
    } catch (Exception e) {
    }
}

61. SecurityTest#testJAASSecurityManagerAuthenticationGuest()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testJAASSecurityManagerAuthenticationGuest() throws Exception {
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager("GuestLogin");
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig().setSecurityEnabled(true), ManagementFactory.getPlatformMBeanServer(), securityManager, false));
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        ClientSession session = cf.createSession("first", "secret", false, true, true, false, 0);
        session.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
        Assert.fail("should not throw exception");
    }
}

62. SecurityTest#testCreateSessionWithNullUserPass()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testCreateSessionWithNullUserPass() throws Exception {
    ActiveMQServer server = createServer();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        ClientSession session = cf.createSession(false, true, true);
        session.close();
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception");
    }
}

63. SecurityTest#testCreateSessionWithNullUserPassNoGuest()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testCreateSessionWithNullUserPassNoGuest() throws Exception {
    ActiveMQServer server = createServer();
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        cf.createSession(false, true, true);
        Assert.fail("should throw exception");
    } catch (ActiveMQSecurityException se) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}

64. SecurityTest#testCreateSessionWithCorrectUserWrongPass()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testCreateSessionWithCorrectUserWrongPass() throws Exception {
    ActiveMQServer server = createServer();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("newuser", "apass");
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        cf.createSession("newuser", "awrongpass", false, true, true, false, -1);
        Assert.fail("should not throw exception");
    } catch (ActiveMQSecurityException se) {
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}

65. SecurityTest#testCreateSessionWithCorrectUserCorrectPass()

Project: activemq-artemis
Source File: SecurityTest.java
View license
@Test
public void testCreateSessionWithCorrectUserCorrectPass() throws Exception {
    ActiveMQServer server = createServer();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("newuser", "apass");
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    try {
        ClientSession session = cf.createSession("newuser", "apass", false, true, true, false, -1);
        session.close();
    } catch (ActiveMQException e) {
        Assert.fail("should not throw exception");
    }
}

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

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

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

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

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

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

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

73. ConnectionLimitTest#testInVMConnectionLimit()

View license
@Test
public void testInVMConnectionLimit() throws Exception {
    ServerLocator locator = addServerLocator(createNonHALocator(false));
    ClientSessionFactory clientSessionFactory = locator.createSessionFactory();
    try {
        ClientSessionFactory extraClientSessionFactory = locator.createSessionFactory();
        fail("creating a session factory here should fail");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQNotConnectedException);
    }
}

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

75. ExpiryRunnerTest#setUp()

View license
//
//   public static void main(final String[] args) throws Exception
//   {
//      for (int i = 0; i < 1000; i++)
//      {
//         TestSuite suite = new TestSuite();
//         ExpiryRunnerTest expiryRunnerTest = new ExpiryRunnerTest();
//         expiryRunnerTest.setName("testExpireWhilstConsuming");
//         suite.addTest(expiryRunnerTest);
//
//         TestResult result = TestRunner.run(suite);
//         if (result.errorCount() > 0 || result.failureCount() > 0)
//         {
//            System.exit(1);
//         }
//      }
//   }
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ConfigurationImpl configuration = (ConfigurationImpl) createDefaultInVMConfig().setMessageExpiryScanPeriod(1000);
    server = addServer(ActiveMQServers.newActiveMQServer(configuration, false));
    // start the server
    server.start();
    // then we create a client as normal
    locator = createInVMNonHALocator().setBlockOnAcknowledge(true);
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    clientSession = sessionFactory.createSession(false, true, true);
    clientSession.createQueue(qName, qName, null, false);
    expiryAddress = new SimpleString("EA");
    expiryQueue = new SimpleString("expiryQ");
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    server.getAddressSettingsRepository().addMatch(qName2.toString(), addressSettings);
    clientSession.createQueue(expiryAddress, expiryQueue, null, false);
}

76. LVQRecoveryTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    configuration = createDefaultInVMConfig();
    server = createServer(true, configuration);
    server.start();
    qs = new AddressSettings().setLastValueQueue(true);
    server.getAddressSettingsRepository().addMatch(address.toString(), qs);
    // then we create a client as normal
    locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    clientSession = sessionFactory.createSession(false, true, true);
    clientSessionXa = sessionFactory.createSession(true, false, false);
    clientSession.createQueue(address, qName1, null, true);
}

77. LVQRecoveryTest#restartServer()

View license
private void restartServer() throws Exception {
    server.stop();
    server = null;
    server = createServer(true, configuration);
    server.getAddressSettingsRepository().addMatch(address.toString(), qs);
    // start the server
    server.start();
    server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings().setLastValueQueue(true));
    // then we create a client as normal
    locator.close();
    locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    clientSession = sessionFactory.createSession(false, true, true);
    clientSessionXa = sessionFactory.createSession(true, false, false);
}

78. LVQTest#setUp()

Project: activemq-artemis
Source File: LVQTest.java
View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig(), false));
    // start the server
    server.start();
    server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings().setLastValueQueue(true));
    // then we create a client as normalServer
    ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
    ClientSessionFactory sf = createSessionFactory(locator);
    clientSession = addClientSession(sf.createSession(false, true, true));
    clientSessionTxReceives = addClientSession(sf.createSession(false, true, false));
    clientSessionTxSends = addClientSession(sf.createSession(false, false, true));
    clientSession.createQueue(address, qName1, null, true);
}

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

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

81. BridgeTest#testLargeMessageBridge()

Project: activemq-artemis
Source File: BridgeTest.java
View license
@Test
public void testLargeMessageBridge() throws Exception {
    long time = System.currentTimeMillis();
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    HashMap<String, TransportConfiguration> connectors = new HashMap<>();
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    final int messageSize = 1024 * 1024 * 5;
    final int numMessages = 10;
    ArrayList<String> connectorConfig = new ArrayList<>();
    connectorConfig.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(numMessages * messageSize / 2).setStaticConnectors(connectorConfig);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = addSessionFactory(locator.createSessionFactory(server0tc));
    ClientSessionFactory sf1 = addSessionFactory(locator.createSessionFactory(server1tc));
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final byte[] bytes = new byte[messageSize];
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putIntProperty(propKey, i);
        message.getBodyBuffer().writeBytes(bytes);
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(500000);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        readLargeMessages(message, 10);
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    closeFields();
    if (server0.getConfiguration().isPersistenceEnabled()) {
        assertEquals(0, loadQueues(server0).size());
    }
    long timeTaken = System.currentTimeMillis() - time;
    System.out.println(timeTaken + "ms");
}

82. BridgeTest#internaltestSimpleBridge()

Project: activemq-artemis
Source File: BridgeTest.java
View license
public void internaltestSimpleBridge(final boolean largeMessage, final boolean useFiles) throws Exception {
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, useFiles, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, useFiles, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    // Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    HashMap<String, TransportConfiguration> connectors = new HashMap<>();
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    final int messageSize = 1024;
    final int numMessages = 10;
    ArrayList<String> connectorConfig = new ArrayList<>();
    connectorConfig.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(numMessages * messageSize / 2).setStaticConnectors(connectorConfig);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = addSessionFactory(locator.createSessionFactory(server0tc));
    ClientSessionFactory sf1 = addSessionFactory(locator.createSessionFactory(server1tc));
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final byte[] bytes = new byte[messageSize];
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        if (largeMessage) {
            message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(10 * 1024));
        }
        message.putIntProperty(propKey, i);
        message.getBodyBuffer().writeBytes(bytes);
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(5000);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        if (largeMessage) {
            readLargeMessages(message, 10);
        }
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    closeFields();
    if (server0.getConfiguration().isPersistenceEnabled()) {
        assertEquals(0, loadQueues(server0).size());
    }
}

83. BridgeTest#internalTestMessageLoss()

Project: activemq-artemis
Source File: BridgeTest.java
View license
/**
    * This test will ignore messages
    * What will cause the bridge to fail with a timeout
    * The bridge should still recover the failure and reconnect on that case
    */
public void internalTestMessageLoss(final boolean largeMessage) throws Exception {
    class MyInterceptor implements Interceptor {

        public boolean ignoreSends = true;

        public CountDownLatch latch;

        MyInterceptor(int numberOfIgnores) {
            latch = new CountDownLatch(numberOfIgnores);
        }

        @Override
        public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
            if (ignoreSends && packet instanceof SessionSendMessage || ignoreSends && packet instanceof SessionSendLargeMessage || ignoreSends && packet instanceof SessionSendContinuationMessage && !((SessionSendContinuationMessage) packet).isContinues()) {
                IntegrationTestLogger.LOGGER.info("IGNORED: " + packet);
                latch.countDown();
                return false;
            } else {
                IntegrationTestLogger.LOGGER.info(packet);
                return true;
            }
        }
    }
    MyInterceptor myInterceptor = new MyInterceptor(3);
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    HashMap<String, TransportConfiguration> connectors = new HashMap<>();
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    final int messageSize = 1024;
    final int numMessages = 1;
    ArrayList<String> connectorConfig = new ArrayList<>();
    connectorConfig.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(100).setReconnectAttempts(-1).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(numMessages * messageSize / 2).setStaticConnectors(connectorConfig).setCallTimeout(500);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server1.getRemotingService().addIncomingInterceptor(myInterceptor);
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = addSessionFactory(locator.createSessionFactory(server0tc));
    ClientSessionFactory sf1 = addSessionFactory(locator.createSessionFactory(server1tc));
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final byte[] bytes = new byte[messageSize];
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        if (largeMessage) {
            message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(10 * 1024));
        }
        message.putIntProperty(propKey, i);
        message.getBodyBuffer().writeBytes(bytes);
        producer0.send(message);
    }
    assertTrue("where is the countDown?", myInterceptor.latch.await(30, TimeUnit.SECONDS));
    myInterceptor.ignoreSends = false;
    server1.getRemotingService().removeIncomingInterceptor(myInterceptor);
    IntegrationTestLogger.LOGGER.info("No longer ignoring packets.");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(30000);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        if (largeMessage) {
            readLargeMessages(message, 10);
        }
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    closeFields();
    assertEquals("there should be no queues", 0, loadQueues(server0).size());
}

84. BridgeTest#internalTestWithFilter()

Project: activemq-artemis
Source File: BridgeTest.java
View license
public void internalTestWithFilter(final boolean largeMessage, final boolean useFiles) throws Exception {
    final int numMessages = 10;
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, useFiles, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, useFiles, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    final String filterString = "animal='goat'";
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setFilterString(filterString).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(0).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final SimpleString propKey = new SimpleString("testkey");
    final SimpleString selectorKey = new SimpleString("animal");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putIntProperty(propKey, i);
        message.putStringProperty(selectorKey, new SimpleString("monkey"));
        if (largeMessage) {
            message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(10 * 1024));
        }
        producer0.send(message);
    }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putIntProperty(propKey, i);
        message.putStringProperty(selectorKey, new SimpleString("goat"));
        if (largeMessage) {
            message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(10 * 1024));
        }
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(4000);
        Assert.assertNotNull(message);
        Assert.assertEquals("goat", message.getStringProperty(selectorKey));
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
        if (largeMessage) {
            readLargeMessages(message, 10);
        }
    }
    session0.commit();
    session1.commit();
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    closeFields();
    if (useFiles) {
        Map<Long, AtomicInteger> counters = loadQueues(server0);
        assertEquals(1, counters.size());
        Long key = counters.keySet().iterator().next();
        AtomicInteger value = counters.get(key);
        assertNotNull(value);
        assertEquals(numMessages, counters.get(key).intValue());
    }
}

85. BridgeTest#testStartLater()

Project: activemq-artemis
Source File: BridgeTest.java
View license
// Created to verify JBPAPP-6057
@Test
public void testStartLater() throws Exception {
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "jms.queue.forwardAddress";
    final String queueName1 = "forwardAddress";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(100).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(1024).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    final int numMessages = 100;
    final SimpleString propKey = new SimpleString("testkey");
    final SimpleString selectorKey = new SimpleString("animal");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.getBodyBuffer().writeBytes(new byte[1024]);
        message.putIntProperty(propKey, i);
        message.putStringProperty(selectorKey, new SimpleString("monkey" + i));
        producer0.send(message);
    }
    server1.start();
    Thread.sleep(1000);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session1 = sf1.createSession(false, true, true);
    try {
        session1.createQueue(forwardAddress, queueName1);
    } catch (Throwable ignored) {
        ignored.printStackTrace();
    }
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(5000);
        assertNotNull(message);
        message.acknowledge();
    }
    session1.commit();
    Assert.assertNull(consumer1.receiveImmediate());
    consumer1.close();
    session1.deleteQueue(queueName1);
    session1.close();
    sf1.close();
    server1.stop();
    session0.close();
    sf0.close();
    closeFields();
    assertEquals(0, loadQueues(server0).size());
}

86. BridgeTest#testWithDuplicates()

Project: activemq-artemis
Source File: BridgeTest.java
View license
@Test
public void testWithDuplicates() throws Exception {
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "jms.queue.forwardAddress";
    final String queueName1 = "forwardAddress";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(100).setReconnectAttemptsOnSameNode(-1).setConfirmationWindowSize(0).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    final int numMessages = 1000;
    final SimpleString propKey = new SimpleString("testkey");
    final SimpleString selectorKey = new SimpleString("animal");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.getBodyBuffer().writeBytes(new byte[1024]);
        message.putIntProperty(propKey, i);
        message.putStringProperty(selectorKey, new SimpleString("monkey" + i));
        producer0.send(message);
    }
    server1.start();
    // Inserting the duplicateIDs so the bridge will fail in a few
    {
        long[] ids = new long[100];
        Queue queue = server0.locateQueue(new SimpleString(queueName0));
        LinkedListIterator<MessageReference> iterator = queue.iterator();
        for (int i = 0; i < 100; i++) {
            iterator.hasNext();
            ids[i] = iterator.next().getMessage().getMessageID();
        }
        iterator.close();
        DuplicateIDCache duplicateTargetCache = server1.getPostOffice().getDuplicateIDCache(PostOfficeImpl.BRIDGE_CACHE_STR.concat(forwardAddress));
        TransactionImpl tx = new TransactionImpl(server1.getStorageManager());
        for (long id : ids) {
            byte[] duplicateArray = BridgeImpl.getDuplicateBytes(server0.getNodeManager().getUUID(), id);
            duplicateTargetCache.addToCache(duplicateArray, tx);
        }
        tx.commit();
    }
    Thread.sleep(1000);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session1 = sf1.createSession(false, true, true);
    try {
        session1.createQueue(forwardAddress, queueName1);
    } catch (Throwable ignored) {
        ignored.printStackTrace();
    }
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    for (int i = 100; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    session1.commit();
    Assert.assertNull(consumer1.receiveImmediate());
    consumer1.close();
    session1.deleteQueue(queueName1);
    session1.close();
    sf1.close();
    server1.stop();
    session0.close();
    sf0.close();
    closeFields();
    assertEquals(0, loadQueues(server0).size());
}

87. BridgeTest#internaltestWithTransformer()

Project: activemq-artemis
Source File: BridgeTest.java
View license
public void internaltestWithTransformer(final boolean useFiles) throws Exception {
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, false, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, false, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setTransformerClassName(SimpleTransformer.class.getName()).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(1024).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("wibble");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putStringProperty(propKey, new SimpleString("bing"));
        message.getBodyBuffer().writeString("doo be doo be doo be doo");
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);
        Assert.assertNotNull(message);
        SimpleString val = (SimpleString) message.getObjectProperty(propKey);
        Assert.assertEquals(new SimpleString("bong"), val);
        String sval = message.getBodyBuffer().readString();
        Assert.assertEquals("dee be dee be dee be dee", sval);
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    if (server0.getConfiguration().isPersistenceEnabled()) {
        assertEquals(0, loadQueues(server0).size());
    }
}

88. BridgeTest#testNullForwardingAddress()

Project: activemq-artemis
Source File: BridgeTest.java
View license
@Test
public void testNullForwardingAddress() throws Exception {
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, false, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, false, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String queueName1 = "queue1";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    final int messageSize = 1024;
    final int numMessages = 10;
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    // do not set forwarding address (defaults to null) to use messages' original address
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(numMessages * messageSize / 2).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    // on server #1, we bind queueName1 to same address testAddress
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final byte[] bytes = new byte[messageSize];
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putIntProperty(propKey, i);
        message.getBodyBuffer().writeBytes(bytes);
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    closeFields();
}

89. ConsumerTest#testAcksWithSmallSendWindow()

Project: activemq-artemis
Source File: ConsumerTest.java
View license
@Test
public void testAcksWithSmallSendWindow() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 10000;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(session, "m" + i);
        producer.send(message);
    }
    session.close();
    sf.close();
    final CountDownLatch latch = new CountDownLatch(numMessages);
    server.getRemotingService().addIncomingInterceptor(new Interceptor() {

        @Override
        public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
            if (packet.getType() == PacketImpl.SESS_ACKNOWLEDGE) {
                latch.countDown();
            }
            return true;
        }
    });
    ServerLocator locator = createInVMNonHALocator().setConfirmationWindowSize(100).setAckBatchSize(-1);
    ClientSessionFactory sfReceive = createSessionFactory(locator);
    ClientSession sessionRec = sfReceive.createSession(false, true, true);
    ClientConsumer consumer = sessionRec.createConsumer(QUEUE);
    consumer.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(final ClientMessage message) {
            try {
                message.acknowledge();
            } catch (ActiveMQException e) {
                e.printStackTrace();
            }
        }
    });
    sessionRec.start();
    Assert.assertTrue(latch.await(60, TimeUnit.SECONDS));
    sessionRec.close();
    locator.close();
}

90. ExpiryLargeMessageTest#testExpiryMessagesThenDLQ()

View license
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testExpiryMessagesThenDLQ() throws Exception {
    ActiveMQServer server = createServer(true);
    server.getConfiguration().setMessageExpiryScanPeriod(600000);
    AddressSettings setting = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE).setMaxDeliveryAttempts(5).setMaxSizeBytes(50 * 1024).setPageSizeBytes(10 * 1024).setExpiryAddress(EXPIRY).setDeadLetterAddress(DLQ);
    server.getAddressSettingsRepository().addMatch(MY_QUEUE.toString(), setting);
    server.getAddressSettingsRepository().addMatch(EXPIRY.toString(), setting);
    server.start();
    server.createQueue(EXPIRY, EXPIRY, null, true, false);
    server.createQueue(DLQ, DLQ, null, true, false);
    server.createQueue(MY_QUEUE, MY_QUEUE, null, true, false);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = sf.createSession(true, true, 0);
    byte[] bufferSample = new byte[messageSize];
    for (int i = 0; i < bufferSample.length; i++) {
        bufferSample[i] = getSamplebyte(i);
    }
    ClientProducer producer = session.createProducer(MY_QUEUE);
    long timeToExpiry = System.currentTimeMillis() + 1000;
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("count", i);
        // Send a few regular messages first, then all is just large messages
        if (i % 2 == 0) {
            message.putBooleanProperty("tst-large", false);
            message.getBodyBuffer().writeBytes(bufferSample);
        } else {
            message.putBooleanProperty("tst-large", true);
            message.setBodyInputStream(createFakeLargeStream(messageSize));
        }
        message.setExpiration(timeToExpiry);
        producer.send(message);
    }
    session.close();
    server.stop();
    server.start();
    Queue queueExpiry = server.locateQueue(EXPIRY);
    Queue myQueue = server.locateQueue(MY_QUEUE);
    sf = createSessionFactory(locator);
    Thread.sleep(1500);
    long timeout = System.currentTimeMillis() + 5000;
    while (timeout > System.currentTimeMillis() && getMessageCount(queueExpiry) != numberOfMessages) {
        // What the Expiry Scan would be doing
        myQueue.expireReferences();
        Thread.sleep(50);
    }
    assertEquals(50, getMessageCount(queueExpiry));
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(EXPIRY);
    session.start();
    // Consume half of the messages to make sure all the messages are paging (on the second try)
    for (int i = 0; i < numberOfMessages / 2; i++) {
        ClientMessage msg = cons.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    session.commit();
    cons.close();
    for (int rep = 0; rep < 6; rep++) {
        cons = session.createConsumer(EXPIRY);
        session.start();
        log.info("Trying " + rep);
        for (int i = 0; i < numberOfMessages / 2; i++) {
            ClientMessage message = cons.receive(5000);
            assertNotNull(message);
            if (i % 10 == 0) {
                System.out.println("Received " + i);
            }
            for (int location = 0; location < messageSize; location++) {
                assertEquals(getSamplebyte(location), message.getBodyBuffer().readByte());
            }
            message.acknowledge();
        }
        session.rollback();
        cons.close();
        session.close();
        sf.close();
        if (rep == 0) {
            // restart the server at the first try
            server.stop();
            server.start();
        }
        sf = createSessionFactory(locator);
        session = sf.createSession(false, false);
        session.start();
    }
    cons = session.createConsumer(EXPIRY);
    session.start();
    assertNull(cons.receiveImmediate());
    cons.close();
    session.close();
    sf.close();
    for (int rep = 0; rep < 2; rep++) {
        sf = createSessionFactory(locator);
        session = sf.createSession(false, false);
        cons = session.createConsumer(DLQ);
        session.start();
        for (int i = 0; i < numberOfMessages / 2; i++) {
            ClientMessage message = cons.receive(5000);
            assertNotNull(message);
            if (i % 10 == 0) {
                System.out.println("Received " + i);
            }
            for (int location = 0; location < messageSize; location++) {
                assertEquals(getSamplebyte(location), message.getBodyBuffer().readByte());
            }
            message.acknowledge();
        }
        if (rep == 0) {
            session.rollback();
            session.close();
            sf.close();
            server.stop();
            server.start();
        }
    }
    session.commit();
    assertNull(cons.receiveImmediate());
    session.close();
    sf.close();
    locator.close();
    validateNoFilesOnLargeDir();
}

91. InterruptedLargeMessageTest#testSendPreparedXA()

View license
@Test
public void testSendPreparedXA() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, createDefaultConfig(isNetty()), 10000, 20000, new HashMap<String, AddressSettings>());
    server.getConfiguration().getIncomingInterceptorClassNames().add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(true, false, false);
    Xid xid1 = newXID();
    Xid xid2 = newXID();
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    session.start(xid1, XAResource.TMNOFLAGS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        clientFile.putIntProperty("txid", 1);
        producer.send(clientFile);
    }
    session.end(xid1, XAResource.TMSUCCESS);
    session.prepare(xid1);
    session.start(xid2, XAResource.TMNOFLAGS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        clientFile.putIntProperty("txid", 2);
        clientFile.putIntProperty("i", i);
        producer.send(clientFile);
    }
    session.end(xid2, XAResource.TMSUCCESS);
    session.prepare(xid2);
    session.close();
    sf.close();
    server.stop(false);
    server.start();
    for (int start = 0; start < 2; start++) {
        System.out.println("Start " + start);
        sf = createSessionFactory(locator);
        if (start == 0) {
            session = sf.createSession(true, false, false);
            session.commit(xid1, false);
            session.close();
        }
        session = sf.createSession(false, false, false);
        ClientConsumer cons1 = session.createConsumer(ADDRESS);
        session.start();
        for (int i = 0; i < 10; i++) {
            log.info("I = " + i);
            ClientMessage msg = cons1.receive(5000);
            Assert.assertNotNull(msg);
            Assert.assertEquals(1, msg.getIntProperty("txid").intValue());
            msg.acknowledge();
        }
        if (start == 1) {
            session.commit();
        } else {
            session.rollback();
        }
        session.close();
        sf.close();
        server.stop();
        server.start();
    }
    server.stop();
    validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), 10);
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(true, false, false);
    session.rollback(xid2);
    sf.close();
    server.stop();
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}

92. BridgeFailoverTest#internalTestFailoverOnBridge()

View license
public void internalTestFailoverOnBridge(int retriesSameNode) throws Exception {
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration();
    String ORIGINAL_QUEUE = "noCluster.originalQueue";
    String TARGET_QUEUE = "noCluster.targetQueue";
    bridgeConfiguration.setHA(true);
    List<String> connectors = new ArrayList<>();
    connectors.add("target-4");
    connectors.add("backup-4");
    bridgeConfiguration.setName("Bridge-for-test");
    bridgeConfiguration.setStaticConnectors(connectors);
    bridgeConfiguration.setQueueName(ORIGINAL_QUEUE);
    bridgeConfiguration.setForwardingAddress(TARGET_QUEUE);
    bridgeConfiguration.setRetryInterval(100);
    bridgeConfiguration.setConfirmationWindowSize(1);
    bridgeConfiguration.setReconnectAttempts(-1);
    bridgeConfiguration.setReconnectAttemptsOnSameNode(retriesSameNode);
    bridgeConfiguration.setHA(true);
    servers[2].getConfiguration().getBridgeConfigurations().add(bridgeConfiguration);
    for (ActiveMQServer server : servers) {
        server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(ORIGINAL_QUEUE).setName(ORIGINAL_QUEUE));
        server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(TARGET_QUEUE).setName(TARGET_QUEUE));
    }
    startServers();
    BridgeImpl bridge = (BridgeImpl) servers[2].getClusterManager().getBridges().get("Bridge-for-test");
    assertNotNull(bridge);
    long timeout = System.currentTimeMillis() + 5000;
    while (bridge.getTargetNodeFromTopology() == null && timeout > System.currentTimeMillis()) {
        Thread.sleep(100);
    }
    assertNotNull(bridge.getTargetNodeFromTopology());
    // The server where the bridge source is configured at
    ServerLocator locatorProducer = createLocator(false, 2);
    ClientSessionFactory factory = addSessionFactory(locatorProducer.createSessionFactory());
    ClientSession session = addClientSession(factory.createSession(false, false));
    ClientProducer producer = addClientProducer(session.createProducer(ORIGINAL_QUEUE));
    for (int i = 0; i < 100; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("i", i);
        producer.send(msg);
    }
    session.commit();
    ServerLocator locatorConsumer = createLocator(false, 4);
    ClientSessionFactory factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
    ClientSession sessionConsumer = addClientSession(factoryConsumer.createSession(false, false));
    ClientConsumer consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
    sessionConsumer.start();
    for (int i = 0; i < 100; i++) {
        ClientMessage message = consumer.receive(10000);
        assertNotNull(message);
        message.acknowledge();
    }
    // We rollback as we will receive them again
    sessionConsumer.rollback();
    factoryConsumer.close();
    sessionConsumer.close();
    crashAndWaitForFailure(servers[4], locatorConsumer);
    locatorConsumer.close();
    assertTrue("Backup server didn't activate.", backupServers[4].waitForActivation(5, TimeUnit.SECONDS));
    for (int i = 100; i < 200; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("i", i);
        producer.send(msg);
    }
    session.commit();
    locatorConsumer = createLocator(false, 9);
    factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
    sessionConsumer = addClientSession(factoryConsumer.createSession());
    consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
    sessionConsumer.start();
    for (int i = 0; i < 200; i++) {
        ClientMessage message = consumer.receive(10000);
        assertNotNull(message);
        message.acknowledge();
    }
    sessionConsumer.commit();
}

93. PersistentDivertTest#doTestPersistentDivertRestartBeforeConsume()

View license
public void doTestPersistentDivertRestartBeforeConsume(final boolean largeMessage) throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress1 = "forwardAddress1";
    final String forwardAddress2 = "forwardAddress2";
    final String forwardAddress3 = "forwardAddress3";
    DivertConfiguration divertConf1 = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress1);
    DivertConfiguration divertConf2 = new DivertConfiguration().setName("divert2").setRoutingName("divert2").setAddress(testAddress).setForwardingAddress(forwardAddress2);
    DivertConfiguration divertConf3 = new DivertConfiguration().setName("divert3").setRoutingName("divert3").setAddress(testAddress).setForwardingAddress(forwardAddress3);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf1).addDivertConfiguration(divertConf2).addDivertConfiguration(divertConf3);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config));
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(true, true, 0);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    final SimpleString queueName3 = new SimpleString("queue3");
    final SimpleString queueName4 = new SimpleString("queue4");
    session.createQueue(new SimpleString(forwardAddress1), queueName1, null, true);
    session.createQueue(new SimpleString(forwardAddress2), queueName2, null, true);
    session.createQueue(new SimpleString(forwardAddress3), queueName3, null, true);
    session.createQueue(new SimpleString(testAddress), queueName4, null, true);
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty(propKey, i);
        if (largeMessage) {
            message.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(minLargeMessageSize));
        }
        producer.send(message);
    }
    session.close();
    sf.close();
    server.stop();
    waitForServerToStop(server);
    server.start();
    ServerLocator locator2 = createInVMNonHALocator().setBlockOnDurableSend(true);
    sf = createSessionFactory(locator2);
    session = sf.createSession(false, true, true);
    session.start();
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    ClientConsumer consumer3 = session.createConsumer(queueName3);
    ClientConsumer consumer4 = session.createConsumer(queueName4);
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(5000);
        Assert.assertNotNull(message);
        if (largeMessage) {
            checkLargeMessage(message);
        }
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer2.receive(5000);
        Assert.assertNotNull(message);
        if (largeMessage) {
            checkLargeMessage(message);
        }
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer2.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer3.receive(5000);
        Assert.assertNotNull(message);
        if (largeMessage) {
            checkLargeMessage(message);
        }
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer3.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer4.receive(5000);
        Assert.assertNotNull(message);
        if (largeMessage) {
            checkLargeMessage(message);
        }
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer4.receiveImmediate());
    session.close();
    sf.close();
    server.stop();
    waitForServerToStop(server);
    server.start();
    ServerLocator locator3 = createInVMNonHALocator().setBlockOnDurableSend(true);
    sf = createSessionFactory(locator3);
    session = sf.createSession(false, true, true);
    consumer1 = session.createConsumer(queueName1);
    consumer2 = session.createConsumer(queueName2);
    consumer3 = session.createConsumer(queueName3);
    consumer4 = session.createConsumer(queueName4);
    Assert.assertNull(consumer1.receiveImmediate());
    Assert.assertNull(consumer2.receiveImmediate());
    Assert.assertNull(consumer3.receiveImmediate());
    Assert.assertNull(consumer4.receiveImmediate());
}

94. ActiveMQServerControlTest#testCommitPreparedTransactions()

View license
@Test
public void testCommitPreparedTransactions() throws Exception {
    SimpleString recQueue = new SimpleString("BasicXaTestqRec");
    SimpleString sendQueue = new SimpleString("BasicXaTestqSend");
    byte[] globalTransactionId = UUIDGenerator.getInstance().generateStringUUID().getBytes();
    Xid xid = new XidImpl("xa1".getBytes(), 1, globalTransactionId);
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, globalTransactionId);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession clientSession = csf.createSession(true, false, false);
    clientSession.createQueue(recQueue, recQueue, null, true);
    clientSession.createQueue(sendQueue, sendQueue, null, true);
    ClientMessage m1 = createTextMessage(clientSession, "");
    m1.putStringProperty("m1", "m1");
    ClientProducer clientProducer = clientSession.createProducer(recQueue);
    clientProducer.send(m1);
    locator.close();
    ServerLocator receiveLocator = createInVMNonHALocator();
    ClientSessionFactory receiveCsf = createSessionFactory(receiveLocator);
    ClientSession receiveClientSession = receiveCsf.createSession(true, false, false);
    ClientConsumer consumer = receiveClientSession.createConsumer(recQueue);
    ServerLocator sendLocator = createInVMNonHALocator();
    ClientSessionFactory sendCsf = createSessionFactory(sendLocator);
    ClientSession sendClientSession = sendCsf.createSession(true, false, false);
    ClientProducer producer = sendClientSession.createProducer(sendQueue);
    receiveClientSession.start(xid, XAResource.TMNOFLAGS);
    receiveClientSession.start();
    sendClientSession.start(xid2, XAResource.TMNOFLAGS);
    ClientMessage m = consumer.receive(5000);
    assertNotNull(m);
    producer.send(m);
    receiveClientSession.end(xid, XAResource.TMSUCCESS);
    sendClientSession.end(xid2, XAResource.TMSUCCESS);
    receiveClientSession.prepare(xid);
    sendClientSession.prepare(xid2);
    ActiveMQServerControl serverControl = createManagementControl();
    sendLocator.close();
    receiveLocator.close();
    boolean success = serverControl.commitPreparedTransaction(XidImpl.toBase64String(xid));
    success = serverControl.commitPreparedTransaction(XidImpl.toBase64String(xid));
    System.out.println("ActiveMQServerControlTest.testCommitPreparedTransactions");
}

95. ScheduledMessageTest#testPendingACKOnPrepared()

View license
@Test
public void testPendingACKOnPrepared() throws Exception {
    int NUMBER_OF_MESSAGES = 100;
    ClientSessionFactory sessionFactory = createSessionFactory(locator);
    ClientSession session = sessionFactory.createSession(true, false, false);
    session.createQueue(atestq, atestq, null, true);
    ClientProducer producer = session.createProducer(atestq);
    long scheduled = System.currentTimeMillis() + 1000;
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("value", i);
        msg.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, scheduled);
        producer.send(msg);
    }
    session.close();
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        Xid xid = newXID();
        session = sessionFactory.createSession(true, false, false);
        ClientConsumer consumer = session.createConsumer(atestq);
        session.start();
        session.start(xid, XAResource.TMNOFLAGS);
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
        session.end(xid, XAResource.TMSUCCESS);
        session.prepare(xid);
        session.close();
    }
    sessionFactory.close();
    locator.close();
    server.stop();
    startServer();
    sessionFactory = createSessionFactory(locator);
    session = sessionFactory.createSession(false, false);
    ClientConsumer consumer = session.createConsumer(atestq);
    session.start();
    assertNull(consumer.receive(1000));
    session.close();
    sessionFactory.close();
}

96. MessageServiceManager#start()

View license
public void start() throws Exception {
    if (configuration == null || configSet == false) {
        if (configResourcePath == null) {
            configuration = new MessageServiceConfiguration();
        } else {
            URL url = getClass().getClassLoader().getResource(configResourcePath);
            if (url == null) {
                // The URL is outside of the classloader. Trying a pure url now
                url = new URL(configResourcePath);
            }
            JAXBContext jaxb = JAXBContext.newInstance(MessageServiceConfiguration.class);
            Reader reader = new InputStreamReader(url.openStream());
            String xml = XMLUtil.readerToString(reader);
            xml = XMLUtil.replaceSystemProps(xml);
            configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
        }
    }
    if (threadPool == null)
        threadPool = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    timeoutTaskInterval = configuration.getTimeoutTaskInterval();
    timeoutTask = new TimeoutTask(timeoutTaskInterval);
    threadPool.execute(timeoutTask);
    DestinationSettings defaultSettings = new DestinationSettings();
    defaultSettings.setConsumerSessionTimeoutSeconds(configuration.getConsumerSessionTimeoutSeconds());
    defaultSettings.setDuplicatesAllowed(configuration.isDupsOk());
    defaultSettings.setDurableSend(configuration.isDefaultDurableSend());
    HashMap<String, Object> transportConfig = new HashMap<>();
    transportConfig.put(TransportConstants.SERVER_ID_PROP_NAME, configuration.getInVmId());
    ServerLocator consumerLocator = new ServerLocatorImpl(false, new TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
    ActiveMQRestLogger.LOGGER.debug("Created ServerLocator: " + consumerLocator);
    if (configuration.getConsumerWindowSize() != -1) {
        consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
    }
    ClientSessionFactory consumerSessionFactory = consumerLocator.createSessionFactory();
    ActiveMQRestLogger.LOGGER.debug("Created ClientSessionFactory: " + consumerSessionFactory);
    ServerLocator defaultLocator = new ServerLocatorImpl(false, new TransportConfiguration(InVMConnectorFactory.class.getName(), transportConfig));
    ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();
    LinkStrategy linkStrategy = new LinkHeaderLinkStrategy();
    if (configuration.isUseLinkHeaders()) {
        linkStrategy = new LinkHeaderLinkStrategy();
    } else {
        linkStrategy = new CustomHeaderLinkStrategy();
    }
    queueManager.setServerLocator(defaultLocator);
    queueManager.setSessionFactory(sessionFactory);
    queueManager.setTimeoutTask(timeoutTask);
    queueManager.setConsumerServerLocator(consumerLocator);
    queueManager.setConsumerSessionFactory(consumerSessionFactory);
    queueManager.setDefaultSettings(defaultSettings);
    queueManager.setPushStoreFile(configuration.getQueuePushStoreDirectory());
    queueManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
    queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
    queueManager.setLinkStrategy(linkStrategy);
    queueManager.setRegistry(registry);
    topicManager.setServerLocator(defaultLocator);
    topicManager.setSessionFactory(sessionFactory);
    topicManager.setTimeoutTask(timeoutTask);
    topicManager.setConsumerServerLocator(consumerLocator);
    topicManager.setConsumerSessionFactory(consumerSessionFactory);
    topicManager.setDefaultSettings(defaultSettings);
    topicManager.setPushStoreFile(configuration.getTopicPushStoreDirectory());
    topicManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
    queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
    topicManager.setLinkStrategy(linkStrategy);
    topicManager.setRegistry(registry);
    queueManager.start();
    topicManager.start();
}

97. HornetQProtocolTest#createCoreClientSession()

View license
private ClientSession createCoreClientSession() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("host", "localhost");
    map.put("port", 61616);
    ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), map));
    ClientSessionFactory sf = serverLocator.createSessionFactory();
    return sf.createSession();
}

98. CommitRollbackTest#testAsyncConsumerRollback()

View license
@Test
public void testAsyncConsumerRollback() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    final ClientSession session = cf.createSession(false, true, false);
    sendSession.createQueue(addressA, queueA, false);
    ClientProducer cp = sendSession.createProducer(addressA);
    ClientConsumer cc = session.createConsumer(queueA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(sendSession.createMessage(false));
    }
    CountDownLatch latch = new CountDownLatch(numMessages);
    session.start();
    cc.setMessageHandler(new ackHandler(session, latch));
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(numMessages, q.getDeliveringCount());
    Assert.assertEquals(numMessages, getMessageCount(q));
    session.stop();
    session.rollback();
    Assert.assertEquals(0, q.getDeliveringCount());
    Assert.assertEquals(numMessages, getMessageCount(q));
    latch = new CountDownLatch(numMessages);
    cc.setMessageHandler(new ackHandler(session, latch));
    session.start();
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    sendSession.close();
    session.close();
    cf.close();
}

99. ConsumerFilterTest#testLinkedListOrder()

View license
@Test
public void testLinkedListOrder() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession();
    session.start();
    ClientProducer producer = session.createProducer("foo");
    ClientConsumer redConsumer = session.createConsumer("foo", "color='red'");
    ClientConsumer anyConsumer = session.createConsumer("foo");
    sendMessage(session, producer, "any", "msg1");
    sendMessage(session, producer, "any", "msg2");
    sendMessage(session, producer, "any", "msg3");
    sendMessage(session, producer, "red", "msgRed4");
    sendMessage(session, producer, "red", "msgRed5");
    readConsumer("anyConsumer", anyConsumer);
    readConsumer("anyConsumer", anyConsumer);
    log.info("### closing consumer ###");
    anyConsumer.close();
    readConsumer("redConsumer", redConsumer);
    readConsumer("redConsumer", redConsumer);
    log.info("### recreating consumer ###");
    anyConsumer = session.createConsumer("foo");
    session.start();
    readConsumer("anyConsumer", anyConsumer);
    session.close();
    sf.close();
    locator.close();
}

100. ConsumerTest#testConsumeWithNoConsumerFlowControl()

Project: activemq-artemis
Source File: ConsumerTest.java
View license
// https://jira.jboss.org/browse/HORNETQ-410
@Test
public void testConsumeWithNoConsumerFlowControl() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    locator.setConsumerWindowSize(-1);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(QUEUE, QUEUE, null, false);
    session.start();
    ClientProducer producer = session.createProducer(QUEUE);
    final int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = createTextMessage(session, "m" + i);
        producer.send(message);
    }
    ClientConsumer consumer = session.createConsumer(QUEUE);
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer.receive(10000);
        assertNotNull(message);
        message.acknowledge();
    }
    session.close();
    sf.close();
    locator.close();
}