Search in sources :

Example 6 with ClientSessionFactoryImpl

use of org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl in project activemq-artemis by apache.

the class OrphanedConsumerTest method internalTestOrphanedConsumers.

/**
 * @param useManagement true = it will use a management operation to make the connection failure, false through ping
 * @throws Exception
 */
private void internalTestOrphanedConsumers(boolean useManagement) throws Exception {
    final int NUMBER_OF_MESSAGES = 2;
    server = createServer(true, true);
    server.start();
    staticServer = server;
    // We are not interested on consumer-window-size on this test
    // We want that every message is delivered
    // as we asserting for number of consumers available and round-robin on delivery
    locator.setConsumerWindowSize(-1).setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(true).setConnectionTTL(1000).setClientFailureCheckPeriod(100).setReconnectAttempts(0);
    ClientSessionFactoryImpl sf = (ClientSessionFactoryImpl) createSessionFactory(locator);
    ClientSession session = sf.createSession(true, true, 0);
    session.createQueue("queue", "queue1", true);
    session.createQueue("queue", "queue2", true);
    ClientProducer prod = session.createProducer("queue");
    ClientConsumer consumer = session.createConsumer("queue1");
    ClientConsumer consumer2 = session.createConsumer("queue2");
    Queue queue1 = server.locateQueue(new SimpleString("queue1"));
    Queue queue2 = server.locateQueue(new SimpleString("queue2"));
    session.start();
    if (!useManagement) {
        sf.stopPingingAfterOne();
        for (long timeout = System.currentTimeMillis() + 6000; timeout > System.currentTimeMillis() && server.getConnectionCount() != 0; ) {
            Thread.sleep(100);
        }
        // an extra second to avoid races of something closing the session while we are asserting it
        Thread.sleep(1000);
    } else {
        server.getActiveMQServerControl().closeConnectionsForAddress("127.0.0.1");
    }
    if (verification != null) {
        throw verification;
    }
    assertEquals(0, queue1.getConsumerCount());
    assertEquals(0, queue2.getConsumerCount());
    setConditionActive(false);
    locator = internalCreateNonHALocator(true).setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).setBlockOnAcknowledge(true).setReconnectAttempts(0).setConsumerWindowSize(-1);
    sf = (ClientSessionFactoryImpl) locator.createSessionFactory();
    session = sf.createSession(true, true, 0);
    session.start();
    prod = session.createProducer("queue");
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("i", i);
        prod.send(message);
    }
    consumer = session.createConsumer("queue1");
    consumer2 = session.createConsumer("queue2");
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        assertNotNull(consumer.receive(5000));
        assertNotNull(consumer2.receive(5000));
    }
    session.close();
}
Also used : ClientSessionFactoryImpl(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue)

Aggregations

ClientSessionFactoryImpl (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)5 Test (org.junit.Test)5 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 RemotingConnectionImpl (org.apache.activemq.artemis.core.protocol.core.impl.RemotingConnectionImpl)2 NettyConnection (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 SessionFailureListener (org.apache.activemq.artemis.api.core.client.SessionFailureListener)1 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)1 CoreRemotingConnection (org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection)1 CloseListener (org.apache.activemq.artemis.core.remoting.CloseListener)1 NettyConnector (org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector)1