Search in sources :

Example 11 with RegionBroker

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();
        }
    }));
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) RegionBroker(org.apache.activemq.broker.region.RegionBroker) Connection(javax.jms.Connection) AbstractRegion(org.apache.activemq.broker.region.AbstractRegion) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 12 with RegionBroker

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();
        }
    }));
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) RegionBroker(org.apache.activemq.broker.region.RegionBroker) Connection(javax.jms.Connection) AbstractRegion(org.apache.activemq.broker.region.AbstractRegion) JMSException(javax.jms.JMSException) ExecutorService(java.util.concurrent.ExecutorService) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 13 with RegionBroker

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());
    }
}
Also used : RegionBroker(org.apache.activemq.broker.region.RegionBroker) Subscription(org.apache.activemq.broker.region.Subscription) Queue(org.apache.activemq.broker.region.Queue)

Example 14 with RegionBroker

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());
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) RegionBroker(org.apache.activemq.broker.region.RegionBroker) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerService(org.apache.activemq.broker.BrokerService) Queue(org.apache.activemq.broker.region.Queue)

Example 15 with RegionBroker

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);
}
Also used : RegionBroker(org.apache.activemq.broker.region.RegionBroker) Wait(org.apache.activemq.util.Wait) BrokerService(org.apache.activemq.broker.BrokerService) BrokerInfo(org.apache.activemq.command.BrokerInfo)

Aggregations

RegionBroker (org.apache.activemq.broker.region.RegionBroker)15 MessageConsumer (javax.jms.MessageConsumer)6 MessageProducer (javax.jms.MessageProducer)6 JMSException (javax.jms.JMSException)5 Destination (javax.jms.Destination)4 Queue (org.apache.activemq.broker.region.Queue)4 Message (javax.jms.Message)3 Session (javax.jms.Session)3 TextMessage (javax.jms.TextMessage)3 BrokerService (org.apache.activemq.broker.BrokerService)3 Destination (org.apache.activemq.broker.region.Destination)3 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Connection (javax.jms.Connection)2 TemporaryQueue (javax.jms.TemporaryQueue)2 AbstractRegion (org.apache.activemq.broker.region.AbstractRegion)2 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)2 Subscription (org.apache.activemq.broker.region.Subscription)2 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1