use of org.apache.activemq.broker.region.RegionBroker 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.RegionBroker 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();
}
}));
}
use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.
the class ThreeBrokerQueueNetworkTest method verifyConsumePriority.
private void verifyConsumePriority(BrokerService broker, byte expectedPriority, Destination dest) throws Exception {
RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
for (Subscription consumer : internalQueue.getConsumers()) {
assertEquals("consumer on " + broker.getBrokerName() + " matches priority: " + internalQueue, expectedPriority, consumer.getConsumerInfo().getPriority());
}
}
use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.
the class QueueMemoryFullMultiBrokersTest method testQueueNetworkWithConsumerFull.
public void testQueueNetworkWithConsumerFull() throws Exception {
bridgeAllBrokers();
startAllBrokers();
Destination dest = createDestination("TEST.FOO", false);
sendMessages("Broker1", dest, 50);
CountDownLatch latch = new CountDownLatch(MESSAGE_COUNT);
createConsumer("Broker2", dest, latch);
assertConsumersConnect("Broker1", dest, 1, 30000);
sendMessages("Broker1", dest, MESSAGE_COUNT - 50);
// Wait for messages to be delivered
assertTrue("Missing " + latch.getCount() + " messages", latch.await(45, TimeUnit.SECONDS));
// verify stats, all messages acked
BrokerService broker1 = brokers.get("Broker1").broker;
RegionBroker regionBroker = (RegionBroker) broker1.getRegionBroker();
// give the acks a chance to flow
Thread.sleep(2000);
Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
assertTrue("All messages are consumed and acked from source:" + internalQueue, internalQueue.getMessages().isEmpty());
assertEquals("messages source:" + internalQueue, 0, internalQueue.getDestinationStatistics().getMessages().getCount());
assertEquals("inflight source:" + internalQueue, 0, internalQueue.getDestinationStatistics().getInflight().getCount());
}
use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.
the class NetworkOfTwentyBrokersTest method verifyPeerBrokerInfo.
private void verifyPeerBrokerInfo(BrokerItem brokerItem, final int max) throws Exception {
final BrokerService broker = brokerItem.broker;
final RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("verify infos " + broker.getBrokerName() + ", len: " + regionBroker.getPeerBrokerInfos().length);
return max == regionBroker.getPeerBrokerInfos().length;
}
}, 120 * 1000);
LOG.info("verify infos " + broker.getBrokerName() + ", len: " + regionBroker.getPeerBrokerInfos().length);
for (BrokerInfo info : regionBroker.getPeerBrokerInfos()) {
LOG.info(info.getBrokerName());
}
assertEquals(broker.getBrokerName(), max, regionBroker.getPeerBrokerInfos().length);
}
Aggregations