use of org.apache.activemq.broker.region.AbstractRegion in project activemq-artemis by apache.
the class ThreeBrokerTempDestDemandSubscriptionCleanupTest method testSubscriptionsCleanedUpAfterConnectionClose.
/**
* This test is slightly different from the above. We don't explicitly close the consumer down
* (which we did in the previous test to force the RemoveInfo to be sent). Here we just close
* the connection which should still clean up the subscriptions and temp destinations on the
* networked brokers.
*
* @throws Exception
*/
public void testSubscriptionsCleanedUpAfterConnectionClose() throws Exception {
final BrokerItem brokerA = brokers.get(BROKER_A);
for (int i = 0; i < NUM_ITER; i++) {
Connection conn = null;
try {
conn = brokerA.createConnection();
conn.start();
final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = sess.createQueue(ECHO_QUEUE_NAME);
MessageProducer producer = sess.createProducer(destination);
LOG.info("Starting iter: " + i);
Destination replyTo = sess.createTemporaryQueue();
MessageConsumer responseConsumer = sess.createConsumer(replyTo);
Message message = sess.createTextMessage("Iteration: " + i);
message.setJMSReplyTo(replyTo);
producer.send(message);
TextMessage response = (TextMessage) responseConsumer.receive(CONSUME_TIMEOUT);
assertNotNull("We should have gotten a response, but didn't for iter: " + i, response);
assertEquals("We got the wrong response from the echo service", "Iteration: " + i, response.getText());
// so closing the connection without closing the consumer first will leak subscriptions
// in a nob?
// responseConsumer.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
// for the real test... we should not have any subscriptions left on broker C for the temp dests
BrokerItem brokerC = brokers.get(BROKER_C);
RegionBroker regionBroker = (RegionBroker) brokerC.broker.getRegionBroker();
final AbstractRegion region = (AbstractRegion) regionBroker.getTempQueueRegion();
assertTrue("There were no lingering temp-queue destinations", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("Lingering temps: " + region.getSubscriptions().size());
return 0 == region.getSubscriptions().size();
}
}));
}
use of org.apache.activemq.broker.region.AbstractRegion in project activemq-artemis by apache.
the class ThreeBrokerTempDestDemandSubscriptionCleanupTest method testSubscriptionsCleanedUpRace.
/**
* So we network three brokers together, and send a message with request-reply semantics.
* The message goes to an echo service listening on broker C. We send a message on a queue
* to broker A which gets demand forwarded to broker C. the echo service will respond to the
* temp destination listed in the JMSReplyTo header. that will get demand forwarded back to
* broker A. When the consumer of the temp dest on broker A closes, that subscription should
* be removed on broker A. advisories firing from broker A to broker B should remove that
* subscription on broker B. advisories firing from broker B to broker C should remove that
* subscription on broker C.
*
* @throws Exception
*/
public void testSubscriptionsCleanedUpRace() throws Exception {
final BrokerItem brokerA = brokers.get(BROKER_A);
Runnable tester = new Runnable() {
@Override
public void run() {
for (int i = 0; i < NUM_ITER; i++) {
Connection conn = null;
try {
conn = brokerA.createConnection();
conn.start();
final Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = sess.createQueue(ECHO_QUEUE_NAME);
MessageProducer producer = sess.createProducer(destination);
LOG.info("Starting iter: " + i);
Destination replyTo = sess.createTemporaryQueue();
MessageConsumer responseConsumer = sess.createConsumer(replyTo);
Message message = sess.createTextMessage("Iteration: " + i);
message.setJMSReplyTo(replyTo);
producer.send(message);
TextMessage response = (TextMessage) responseConsumer.receive(CONSUME_TIMEOUT);
assertNotNull("We should have gotten a response, but didn't for iter: " + i, response);
assertEquals("We got the wrong response from the echo service", "Iteration: " + i, response.getText());
// so we close the consumer so that an actual RemoveInfo command gets propagated through the
// network
responseConsumer.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}
};
ExecutorService threadService = Executors.newFixedThreadPool(2);
threadService.submit(tester);
threadService.submit(tester);
threadService.shutdown();
assertTrue("executor done on time", threadService.awaitTermination(30L, TimeUnit.SECONDS));
// for the real test... we should not have any subscriptions left on broker C for the temp dests
BrokerItem brokerC = brokers.get(BROKER_C);
RegionBroker regionBroker = (RegionBroker) brokerC.broker.getRegionBroker();
final AbstractRegion region = (AbstractRegion) regionBroker.getTempQueueRegion();
assertTrue("There were no lingering temp-queue destinations", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("Lingering temps: " + region.getSubscriptions().size());
return 0 == region.getSubscriptions().size();
}
}));
}
Aggregations