Search in sources :

Example 1 with RegionBroker

use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.

the class TempDestLoadTest method testLoadTempAdvisoryQueues.

public void testLoadTempAdvisoryQueues() throws Exception {
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        TemporaryQueue tempQueue = session.createTemporaryQueue();
        MessageConsumer consumer = session.createConsumer(tempQueue);
        MessageProducer producer = session.createProducer(tempQueue);
        consumer.close();
        producer.close();
        tempQueue.delete();
    }
    AdvisoryBroker ab = (AdvisoryBroker) broker.getBroker().getAdaptor(AdvisoryBroker.class);
    assertTrue(ab.getAdvisoryDestinations().size() == 0);
    assertTrue(ab.getAdvisoryConsumers().size() == 0);
    assertTrue(ab.getAdvisoryProducers().size() == 0);
    RegionBroker rb = (RegionBroker) broker.getBroker().getAdaptor(RegionBroker.class);
    for (Destination dest : rb.getDestinationMap().values()) {
        LOG.debug("Destination: {}", dest);
    }
    // there should be at least 2 destinations - advisories -
    // 1 for the connection + 1 generic ones
    assertTrue("Should be at least 2 destinations", rb.getDestinationMap().size() > 2);
}
Also used : Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) RegionBroker(org.apache.activemq.broker.region.RegionBroker) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer)

Example 2 with RegionBroker

use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.

the class TempDestLoadTest method testLoadTempAdvisoryTopics.

public void testLoadTempAdvisoryTopics() throws Exception {
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        TemporaryTopic tempTopic = session.createTemporaryTopic();
        MessageConsumer consumer = session.createConsumer(tempTopic);
        MessageProducer producer = session.createProducer(tempTopic);
        consumer.close();
        producer.close();
        tempTopic.delete();
    }
    AdvisoryBroker ab = (AdvisoryBroker) broker.getBroker().getAdaptor(AdvisoryBroker.class);
    assertTrue(ab.getAdvisoryDestinations().size() == 0);
    assertTrue(ab.getAdvisoryConsumers().size() == 0);
    assertTrue(ab.getAdvisoryProducers().size() == 0);
    RegionBroker rb = (RegionBroker) broker.getBroker().getAdaptor(RegionBroker.class);
    for (Destination dest : rb.getDestinationMap().values()) {
        LOG.debug("Destination: {}", dest);
    }
    // there should be at least 2 destinations - advisories -
    // 1 for the connection + 1 generic ones
    assertTrue("Should be at least 2 destinations", rb.getDestinationMap().size() > 2);
}
Also used : Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) RegionBroker(org.apache.activemq.broker.region.RegionBroker) MessageProducer(javax.jms.MessageProducer) TemporaryTopic(javax.jms.TemporaryTopic)

Example 3 with RegionBroker

use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.

the class ThreeBrokerQueueNetworkTest method verifyConsumerCount.

private void verifyConsumerCount(BrokerService broker, int count, final Destination dest) throws Exception {
    final RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
    waitFor(new Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return !regionBroker.getDestinations(ActiveMQDestination.transform(dest)).isEmpty();
        }
    });
    Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
    LOG.info("Verify: consumer count on " + broker.getBrokerName() + " matches:" + count + ", val:" + internalQueue.getConsumers().size());
    assertEquals("consumer count on " + broker.getBrokerName() + " matches for q: " + internalQueue, count, internalQueue.getConsumers().size());
}
Also used : RegionBroker(org.apache.activemq.broker.region.RegionBroker) Queue(org.apache.activemq.broker.region.Queue)

Example 4 with RegionBroker

use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.

the class ThreeBrokerQueueNetworkTest method logConsumerCount.

private void logConsumerCount(BrokerService broker, int count, final Destination dest) throws Exception {
    final RegionBroker regionBroker = (RegionBroker) broker.getRegionBroker();
    waitFor(new Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return !regionBroker.getDestinations(ActiveMQDestination.transform(dest)).isEmpty();
        }
    });
    Queue internalQueue = (Queue) regionBroker.getDestinations(ActiveMQDestination.transform(dest)).iterator().next();
    LOG.info("Verify: consumer count on " + broker.getBrokerName() + " matches:" + count + ", val:" + internalQueue.getConsumers().size());
}
Also used : RegionBroker(org.apache.activemq.broker.region.RegionBroker) Queue(org.apache.activemq.broker.region.Queue)

Example 5 with RegionBroker

use of org.apache.activemq.broker.region.RegionBroker in project activemq-artemis by apache.

the class RequestReplyNoAdvisoryNetworkTest method doTestNonAdvisoryNetworkRequestReply.

public void doTestNonAdvisoryNetworkRequestReply() throws Exception {
    waitForBridgeFormation(a, 1, 0);
    waitForBridgeFormation(b, 1, 0);
    ActiveMQConnectionFactory sendFactory = createConnectionFactory(a);
    ActiveMQConnection sendConnection = createConnection(sendFactory);
    ActiveMQSession sendSession = (ActiveMQSession) sendConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sendSession.createProducer(sendQ);
    ActiveMQTempQueue realReplyQ = (ActiveMQTempQueue) sendSession.createTemporaryQueue();
    TextMessage message = sendSession.createTextMessage("1");
    message.setJMSReplyTo(realReplyQ);
    producer.send(message);
    LOG.info("request sent");
    // responder
    ActiveMQConnectionFactory consumerFactory = createConnectionFactory(b);
    ActiveMQConnection consumerConnection = createConnection(consumerFactory);
    ActiveMQSession consumerSession = (ActiveMQSession) consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(sendQ);
    TextMessage received = (TextMessage) consumer.receive(receiveTimeout);
    assertNotNull("got request from sender ok", received);
    LOG.info("got request, sending reply");
    MessageProducer consumerProducer = consumerSession.createProducer(received.getJMSReplyTo());
    consumerProducer.send(consumerSession.createTextMessage("got " + received.getText()));
    // temp dest on reply broker tied to this connection, setOptimizedDispatch=true ensures
    // message gets delivered before destination is removed
    consumerConnection.close();
    // reply consumer
    MessageConsumer replyConsumer = sendSession.createConsumer(realReplyQ);
    TextMessage reply = (TextMessage) replyConsumer.receive(receiveTimeout);
    assertNotNull("expected reply message", reply);
    assertEquals("text is as expected", "got 1", reply.getText());
    sendConnection.close();
    LOG.info("checking for dangling temp destinations");
    // ensure all temp dests get cleaned up on all brokers
    for (BrokerService brokerService : brokers) {
        final RegionBroker regionBroker = (RegionBroker) brokerService.getRegionBroker();
        assertTrue("all temps are gone on " + regionBroker.getBrokerName(), Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                Map<?, ?> tempTopics = regionBroker.getTempTopicRegion().getDestinationMap();
                LOG.info("temp topics on " + regionBroker.getBrokerName() + ", " + tempTopics);
                Map<?, ?> tempQ = regionBroker.getTempQueueRegion().getDestinationMap();
                LOG.info("temp queues on " + regionBroker.getBrokerName() + ", " + tempQ);
                return tempQ.isEmpty() && tempTopics.isEmpty();
            }
        }));
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ActiveMQSession(org.apache.activemq.ActiveMQSession) RegionBroker(org.apache.activemq.broker.region.RegionBroker) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) MessageProducer(javax.jms.MessageProducer) BrokerService(org.apache.activemq.broker.BrokerService) ActiveMQTempQueue(org.apache.activemq.command.ActiveMQTempQueue) TextMessage(javax.jms.TextMessage)

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