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