Search in sources :

Example 1 with Broker

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

the class RedeliveryPluginTest method testInstallPluginValidation.

public void testInstallPluginValidation() throws Exception {
    RedeliveryPolicyMap redeliveryPolicyMap = new RedeliveryPolicyMap();
    RedeliveryPolicy defaultEntry = new RedeliveryPolicy();
    defaultEntry.setInitialRedeliveryDelay(500);
    redeliveryPolicyMap.setDefaultEntry(defaultEntry);
    underTest.setRedeliveryPolicyMap(redeliveryPolicyMap);
    final BrokerService brokerService = new BrokerService();
    brokerService.setSchedulerSupport(false);
    Broker broker = new ErrorBroker("hi") {

        @Override
        public BrokerService getBrokerService() {
            return brokerService;
        }
    };
    try {
        underTest.installPlugin(broker);
        fail("expect exception on no scheduler support");
    } catch (Exception expected) {
        LOG.info("expected: " + expected);
    }
    brokerService.setSchedulerSupport(true);
    try {
        underTest.installPlugin(broker);
        fail("expect exception on small initial delay");
    } catch (Exception expected) {
        LOG.info("expected: " + expected);
    }
    defaultEntry.setInitialRedeliveryDelay(5000);
    defaultEntry.setRedeliveryDelay(500);
    brokerService.setSchedulerSupport(true);
    try {
        underTest.installPlugin(broker);
        fail("expect exception on small redelivery delay");
    } catch (Exception expected) {
        LOG.info("expected: " + expected);
    }
}
Also used : Broker(org.apache.activemq.broker.Broker) ErrorBroker(org.apache.activemq.broker.ErrorBroker) ErrorBroker(org.apache.activemq.broker.ErrorBroker) RedeliveryPolicy(org.apache.activemq.RedeliveryPolicy) RedeliveryPolicyMap(org.apache.activemq.broker.region.policy.RedeliveryPolicyMap) BrokerService(org.apache.activemq.broker.BrokerService)

Example 2 with Broker

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

the class ThreeBrokerQueueNetworkTest method testNoDuplicateQueueSubsHasLowestPriority.

public void testNoDuplicateQueueSubsHasLowestPriority() throws Exception {
    boolean suppressQueueDuplicateSubscriptions = true;
    boolean decreaseNetworkConsumerPriority = true;
    bridgeAllBrokers("default", 3, suppressQueueDuplicateSubscriptions, decreaseNetworkConsumerPriority);
    // Setup destination
    final Destination dest = createDestination("TEST.FOO", false);
    // delay the advisory messages so that one can percolate fully (cyclically) before the other
    BrokerItem brokerB = brokers.get("BrokerA");
    brokerB.broker.setPlugins(new BrokerPlugin[] { new BrokerPlugin() {

        @Override
        public Broker installPlugin(Broker broker) throws Exception {
            return new BrokerFilter(broker) {

                final AtomicInteger count = new AtomicInteger();

                @Override
                public void preProcessDispatch(MessageDispatch messageDispatch) {
                    if (messageDispatch.getDestination().getPhysicalName().contains("ActiveMQ.Advisory.Consumer")) {
                        // lets delay the first advisory
                        if (count.getAndIncrement() == 0) {
                            LOG.info("Sleeping on first advisory: " + messageDispatch);
                            try {
                                Thread.sleep(2000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    super.postProcessDispatch(messageDispatch);
                }
            };
        }
    } });
    startAllBrokers();
    waitForBridgeFormation();
    // Setup consumers
    String brokerName = "BrokerA";
    createConsumer(brokerName, dest);
    // wait for advisories
    Thread.sleep(5000);
    // verify there is one consumer on each broker, no cycles
    Collection<BrokerItem> brokerList = brokers.values();
    for (Iterator<BrokerItem> i = brokerList.iterator(); i.hasNext(); ) {
        BrokerService broker = i.next().broker;
        verifyConsumerCount(broker, 1, dest);
        if (!brokerName.equals(broker.getBrokerName())) {
            verifyConsumePriority(broker, ConsumerInfo.NETWORK_CONSUMER_PRIORITY, dest);
        }
    }
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) Broker(org.apache.activemq.broker.Broker) RegionBroker(org.apache.activemq.broker.region.RegionBroker) BrokerPlugin(org.apache.activemq.broker.BrokerPlugin) BrokerFilter(org.apache.activemq.broker.BrokerFilter) MessageDispatch(org.apache.activemq.command.MessageDispatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BrokerService(org.apache.activemq.broker.BrokerService)

Example 3 with Broker

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

the class RegionBrokerProxy method newRegionBroker.

public static RegionBroker newRegionBroker(ArtemisBrokerWrapper broker) {
    Broker brokerProxy = null;
    try {
        brokerProxy = new RegionBrokerProxy(broker);
        RegionBroker regionBroker = Mockito.mock(RegionBroker.class, delegatesTo(brokerProxy));
        return regionBroker;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Broker(org.apache.activemq.broker.Broker) RegionBroker(org.apache.activemq.broker.region.RegionBroker) RegionBroker(org.apache.activemq.broker.region.RegionBroker)

Aggregations

Broker (org.apache.activemq.broker.Broker)3 BrokerService (org.apache.activemq.broker.BrokerService)2 RegionBroker (org.apache.activemq.broker.region.RegionBroker)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Destination (javax.jms.Destination)1 RedeliveryPolicy (org.apache.activemq.RedeliveryPolicy)1 BrokerFilter (org.apache.activemq.broker.BrokerFilter)1 BrokerPlugin (org.apache.activemq.broker.BrokerPlugin)1 ErrorBroker (org.apache.activemq.broker.ErrorBroker)1 RedeliveryPolicyMap (org.apache.activemq.broker.region.policy.RedeliveryPolicyMap)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 MessageDispatch (org.apache.activemq.command.MessageDispatch)1