org.apache.activemq.broker.BrokerService

Here are the examples of the java api class org.apache.activemq.broker.BrokerService taken from open source projects.

1. ExpiredMessagesTest#createBroker()

View license
private BrokerService createBroker(boolean deleteAllMessages, long expireMessagesPeriod) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName("localhost");
    broker.setDestinations(new ActiveMQDestination[] { destination });
    broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
    PolicyEntry defaultPolicy = new PolicyEntry();
    if (useVMCursor) {
        defaultPolicy.setPendingQueuePolicy(new VMPendingQueueMessageStoragePolicy());
    }
    defaultPolicy.setExpireMessagesPeriod(expireMessagesPeriod);
    defaultPolicy.setMaxExpirePageSize(1200);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(defaultPolicy);
    broker.setDestinationPolicy(policyMap);
    broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
    broker.addConnector("tcp://localhost:0");
    broker.start();
    broker.waitUntilStarted();
    return broker;
}

2. RequestReplyNoAdvisoryNetworkTest#configureBroker()

View license
private BrokerService configureBroker(String brokerName) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName(brokerName);
    broker.setAdvisorySupport(false);
    broker.setPersistent(false);
    broker.setUseJmx(false);
    broker.setSchedulePeriodForDestinationPurge(1000);
    broker.setAllowTempAutoCreationOnSend(true);
    PolicyMap map = new PolicyMap();
    PolicyEntry tempReplyQPolicy = new PolicyEntry();
    tempReplyQPolicy.setOptimizedDispatch(true);
    tempReplyQPolicy.setGcInactiveDestinations(true);
    tempReplyQPolicy.setGcWithNetworkConsumers(true);
    tempReplyQPolicy.setInactiveTimeoutBeforeGC(1000);
    map.put(replyQWildcard, tempReplyQPolicy);
    broker.setDestinationPolicy(map);
    broker.addConnector("tcp://localhost:0");
    brokers.add(broker);
    return broker;
}

3. NetworkAsyncStartTest#testAsyncNetworkStartup()

View license
public void testAsyncNetworkStartup() throws Exception {
    BrokerService brokerA = brokers.get("BrokerA").broker;
    bridgeBroker(brokerA, brokerBUri);
    bridgeBroker(brokerA, brokerCUri);
    LOG.info("starting A, no blocking on failed network connectors");
    brokerA.start();
    LOG.info("starting C transport connector");
    BrokerService brokerC = brokers.get("BrokerC").broker;
    brokerC.addConnector(brokerCUri);
    brokerC.start();
    assertTrue("got bridge to C", waitForBridgeFormation(brokerA, 1, 1));
    LOG.info("Got bridge A->C");
    LOG.info("starting B transport connector");
    BrokerService brokerB = brokers.get("BrokerB").broker;
    brokerB.addConnector(brokerBUri);
    brokerB.start();
    assertTrue("got bridge to B", waitForBridgeFormation(brokerA, 1, 0));
    assertTrue("got bridge to B&C", waitForBridgeFormation(brokerA, 1, 1));
}

4. TopicSubscriptionSlowConsumerTest#createBroker()

View license
//helper method to create a broker with slow consumer advisory turned on
private BrokerService createBroker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName("localhost");
    broker.setUseJmx(true);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.addConnector("vm://localhost");
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setAdvisoryForSlowConsumers(true);
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
    broker.waitUntilStarted();
    return broker;
}

5. JobSchedulerTestSupport#createBroker()

View license
protected BrokerService createBroker(boolean delete) throws Exception {
    File schedulerDirectory = new File("target/scheduler");
    if (delete) {
        IOHelper.mkdirs(schedulerDirectory);
        IOHelper.deleteChildren(schedulerDirectory);
    }
    BrokerService answer = new BrokerService();
    answer.setPersistent(isPersistent());
    answer.setDeleteAllMessagesOnStartup(true);
    answer.setDataDirectory("target");
    answer.setSchedulerDirectoryFile(schedulerDirectory);
    answer.setSchedulerSupport(true);
    answer.setUseJmx(isUseJmx());
    return answer;
}

6. QueueOutboundBridgeReconnectTest#createFirstBroker()

View license
protected BrokerService createFirstBroker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName("broker1");
    broker.setPersistent(false);
    broker.setUseJmx(false);
    broker.addConnector("tcp://localhost:61616");
    broker.addConnector("vm://broker1");
    SimpleJmsQueueConnector jmsQueueConnector = new SimpleJmsQueueConnector();
    jmsQueueConnector.setOutboundQueueBridges(new OutboundQueueBridge[] { new OutboundQueueBridge("RECONNECT.TEST.QUEUE") });
    jmsQueueConnector.setOutboundQueueConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61617"));
    broker.setJmsBridgeConnectors(new JmsConnector[] { jmsQueueConnector });
    return broker;
}

7. TopicOutboundBridgeReconnectTest#createFirstBroker()

View license
protected BrokerService createFirstBroker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName("broker1");
    broker.setPersistent(false);
    broker.setUseJmx(false);
    broker.addConnector("tcp://localhost:61616");
    broker.addConnector("vm://broker1");
    SimpleJmsTopicConnector jmsTopicConnector = new SimpleJmsTopicConnector();
    jmsTopicConnector.setOutboundTopicBridges(new OutboundTopicBridge[] { new OutboundTopicBridge("RECONNECT.TEST.TOPIC") });
    jmsTopicConnector.setOutboundTopicConnectionFactory(new ActiveMQConnectionFactory("tcp://localhost:61617"));
    broker.setJmsBridgeConnectors(new JmsConnector[] { jmsTopicConnector });
    return broker;
}

8. SoWriteTimeoutTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    broker.setPersistent(true);
    broker.setDeleteAllMessagesOnStartup(true);
    KahaDBPersistenceAdapter adapter = new KahaDBPersistenceAdapter();
    adapter.setConcurrentStoreAndDispatchQueues(false);
    broker.setPersistenceAdapter(adapter);
    broker.addConnector("tcp://localhost:61616");
    broker.addConnector(brokerTransportScheme + "://localhost:0?wireFormat.maxInactivityDuration=0&transport.soWriteTimeout=1000&transport.sleep=1000");
    if ("nio".equals(brokerTransportScheme)) {
        broker.addConnector("stomp+" + brokerTransportScheme + "://localhost:0?transport.soWriteTimeout=1000&transport.sleep=1000&socketBufferSize=" + receiveBufferSize + "&trace=true");
    }
    return broker;
}

9. BacklogNetworkCrossTalkTest#createBroker()

View license
@Override
protected BrokerService createBroker(String brokerName) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setDeleteAllMessagesOnStartup(true);
    broker.setPersistent(true);
    broker.setUseJmx(false);
    broker.setBrokerName(brokerName);
    broker.addConnector(new URI(AUTO_ASSIGN_TRANSPORT));
    brokers.put(brokerName, new BrokerItem(broker));
    return broker;
}

10. VirtualTopicNetworkClusterReactivationTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    maxSetupTime = 1000;
    super.setAutoFail(true);
    super.setUp();
    final String options = "?persistent=true&useJmx=false&deleteAllMessagesOnStartup=true";
    BrokerService brokerServiceA = createBroker(new URI(String.format("broker:(%s)/%s%s", BROKER_A_TRANSPORT_URL, BROKER_A, options)));
    brokerServiceA.setDestinationPolicy(buildPolicyMap());
    brokerServiceA.setDestinations(new ActiveMQDestination[] { queue });
    BrokerService brokerServiceB = createBroker(new URI(String.format("broker:(%s)/%s%s", BROKER_B_TRANSPORT_URL, BROKER_B, options)));
    brokerServiceB.setDestinationPolicy(buildPolicyMap());
    brokerServiceB.setDestinations(new ActiveMQDestination[] { queue });
    // bridge brokers to each other statically (static: discovery)
    bridgeBrokers(BROKER_A, BROKER_B);
    bridgeBrokers(BROKER_B, BROKER_A);
    startAllBrokers();
}

11. ReconnectTest#createBroker()

Project: servicemix4-nmr
Source File: ReconnectTest.java
View license
@Override
protected Service createBroker(boolean deleteData) throws Exception {
    // For reconnection tests, we need a persistent broker
    File data = new File("target/activemq");
    if (deleteData) {
        deleteFile(data);
    }
    BrokerService broker = new BrokerService();
    broker.setPersistent(true);
    broker.setDataDirectoryFile(data);
    broker.setUseJmx(true);
    broker.addConnector("tcp://localhost:" + port);
    broker.start();
    return broker;
}

12. DestinationGCTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    broker.setDestinations(new ActiveMQDestination[] { queue });
    broker.setSchedulePeriodForDestinationPurge(1000);
    broker.setMaxPurgedDestinationsPerSweep(1);
    PolicyEntry entry = new PolicyEntry();
    entry.setGcInactiveDestinations(true);
    entry.setInactiveTimeoutBeforeGC(3000);
    PolicyMap map = new PolicyMap();
    map.setDefaultEntry(entry);
    broker.setDestinationPolicy(map);
    return broker;
}

13. JobSchedulerBrokerShutdownTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    File schedulerDirectory = new File("target/scheduler");
    IOHelper.mkdirs(schedulerDirectory);
    IOHelper.deleteChildren(schedulerDirectory);
    BrokerService broker = super.createBroker();
    broker.setSchedulerSupport(true);
    broker.setDataDirectory("target");
    broker.setSchedulerDirectoryFile(schedulerDirectory);
    broker.getSystemUsage().getStoreUsage().setLimit(1 * 512);
    broker.deleteAllMessages();
    return broker;
}

14. FailoverStaticNetworkTest#createBroker()

View license
private BrokerService createBroker(String listenPort, String dataDir) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setUseJmx(false);
    broker.getManagementContext().setCreateConnector(false);
    broker.setBrokerName("Broker_Shared");
    // lazy create transport connector on start completion
    TransportConnector connector = new TransportConnector();
    connector.setUri(new URI("tcp://localhost:" + listenPort));
    broker.addConnector(connector);
    broker.setDataDirectory(dataDir);
    return broker;
}

15. ProxyTestSupport#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setBrokerName("broker1");
    service.setPersistent(false);
    service.setUseJmx(false);
    connector = service.addConnector(getLocalURI());
    proxyConnector = new ProxyConnector();
    proxyConnector.setName("proxy");
    proxyConnector.setBind(new URI(getLocalProxyURI()));
    proxyConnector.setRemote(new URI("fanout:static://" + getRemoteURI()));
    service.addProxyConnector(proxyConnector);
    return service;
}

16. ProxyTestSupport#createRemoteBroker()

View license
protected BrokerService createRemoteBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setBrokerName("broker2");
    service.setPersistent(false);
    service.setUseJmx(false);
    remoteConnector = service.addConnector(getRemoteURI());
    remoteProxyConnector = new ProxyConnector();
    remoteProxyConnector.setName("remoteProxy");
    remoteProxyConnector.setBind(new URI(getRemoteProxyURI()));
    remoteProxyConnector.setRemote(new URI("fanout:static://" + getLocalURI()));
    service.addProxyConnector(remoteProxyConnector);
    return service;
}

17. ConcurrentProducerQueueConsumerTest#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService brokerService = new BrokerService();
    brokerService.setEnableStatistics(false);
    brokerService.addConnector("tcp://0.0.0.0:0");
    brokerService.setDeleteAllMessagesOnStartup(true);
    PolicyEntry policy = new PolicyEntry();
    policy.setPrioritizedMessages(true);
    policy.setMaxPageSize(500);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(policy);
    brokerService.setDestinationPolicy(policyMap);
    setDefaultPersistenceAdapter(brokerService);
    return brokerService;
}

18. MessageGroupReconnectDistributionTest#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setAdvisorySupport(false);
    service.setPersistent(false);
    service.setUseJmx(true);
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setUseConsumerPriority(consumerPriority);
    policy.setMessageGroupMapFactoryType("cached?cacheSize=" + (numConsumers - 1));
    policyMap.setDefaultEntry(policy);
    service.setDestinationPolicy(policyMap);
    connector = service.addConnector("tcp://localhost:0");
    return service;
}

19. OpenWireInteropTestSupport#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setUseJmx(true);
    TransportConnector connector = brokerService.addConnector("tcp://0.0.0.0:0?transport.trace=true&trace=true");
    connectionURI = connector.getPublishableConnectURI();
    LOG.debug("Using openwire port: {}", connectionURI);
    return brokerService;
}

20. JmsDiscoveryProviderTest#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService brokerService = new BrokerService();
    brokerService.setBrokerName("localhost");
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setUseJmx(false);
    TransportConnector connector = brokerService.addConnector("amqp://0.0.0.0:0");
    connector.setName("amqp");
    connector.setDiscoveryUri(new URI("multicast://default"));
    return brokerService;
}

21. AbstractClusterEndpointTest#createBroker()

View license
protected Service createBroker(boolean deleteData) throws Exception {
    File data = new File("target/activemq");
    if (deleteData) {
        deleteFile(data);
    }
    BrokerService broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(true);
    broker.addConnector("tcp://localhost:" + port);
    broker.start();
    return broker;
}

22. ActiveMQXAConnectionFactoryTest#testRollbackXaErrorCode()

View license
public void testRollbackXaErrorCode() throws Exception {
    String brokerName = "rollbackErrorCode";
    BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
    broker.start();
    broker.waitUntilStarted();
    ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
    XAConnection connection = (XAConnection) cf.createConnection();
    connection.start();
    XASession session = connection.createXASession();
    XAResource resource = session.getXAResource();
    Xid tid = createXid();
    try {
        resource.rollback(tid);
        fail("Expected xa exception on no tx");
    } catch (XAException expected) {
        LOG.info("got expected xa", expected);
        assertEquals("no tx", XAException.XAER_NOTA, expected.errorCode);
    }
    connection.close();
    broker.stop();
}

23. MessageAuthenticationTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService answer = new BrokerService();
    answer.setPersistent(false);
    answer.setMessageAuthorizationPolicy(new MessageAuthorizationPolicy() {

        @Override
        public boolean isAllowedToConsume(ConnectionContext context, Message message) {
            try {
                Object value = message.getProperty("myHeader");
                return "abc".equals(value);
            } catch (IOException e) {
                System.out.println("Caught: " + e);
                e.printStackTrace();
                return false;
            }
        }
    });
    answer.addConnector(bindAddress);
    return answer;
}

24. PerDestinationStoreLimitTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setDeleteAllMessagesOnStartup(true);
    service.setUseJmx(false);
    service.getSystemUsage().getStoreUsage().setLimit(200 * 1024);
    // allow destination to use 50% of store, leaving 50% for DLQ.
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setStoreUsageHighWaterMark(50);
    policyMap.put(queueDest, policy);
    policyMap.put(topicDest, policy);
    service.setDestinationPolicy(policyMap);
    connector = service.addConnector("tcp://localhost:0");
    return service;
}

25. ProducerFlowControlSendFailTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setPersistent(false);
    service.setUseJmx(false);
    // Setup a destination policy where it takes only 1 message at a time.
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setMemoryLimit(1);
    policy.setPendingSubscriberPolicy(new VMPendingSubscriberMessageStoragePolicy());
    policy.setPendingQueuePolicy(new VMPendingQueueMessageStoragePolicy());
    policy.setProducerFlowControl(true);
    policyMap.setDefaultEntry(policy);
    service.setDestinationPolicy(policyMap);
    service.getSystemUsage().setSendFailIfNoSpace(true);
    connector = service.addConnector("tcp://localhost:0");
    return service;
}

26. ProducerFlowControlTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setPersistent(false);
    service.setUseJmx(false);
    // Setup a destination policy where it takes only 1 message at a time.
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setMemoryLimit(1);
    policy.setPendingSubscriberPolicy(new VMPendingSubscriberMessageStoragePolicy());
    policy.setPendingQueuePolicy(new VMPendingQueueMessageStoragePolicy());
    policy.setProducerFlowControl(true);
    policyMap.setDefaultEntry(policy);
    service.setDestinationPolicy(policyMap);
    connector = service.addConnector("tcp://localhost:0");
    return service;
}

27. JobSchedulerStoreUsageTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    File schedulerDirectory = new File("target/scheduler");
    IOHelper.mkdirs(schedulerDirectory);
    IOHelper.deleteChildren(schedulerDirectory);
    BrokerService broker = super.createBroker();
    broker.setSchedulerSupport(true);
    broker.setSchedulerDirectoryFile(schedulerDirectory);
    broker.getSystemUsage().getJobSchedulerUsage().setLimit(7 * 1024);
    broker.deleteAllMessages();
    return broker;
}

28. AMQ2927Test#setUp()

Project: activemq-artemis
Source File: AMQ2927Test.java
View license
@Override
public void setUp() throws Exception {
    super.setAutoFail(true);
    super.setUp();
    BrokerService brokerA = createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?persistent=true&useJmx=false&deleteAllMessagesOnStartup=true"));
    brokerA.setBrokerId("BrokerA");
    BrokerService brokerB = createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=true&useJmx=false&deleteAllMessagesOnStartup=true"));
    brokerB.setBrokerId("BrokerB");
    NetworkConnector aTOb = bridgeBrokers(brokers.get("BrokerA").broker, brokers.get("BrokerB").broker, false, 2, true, true);
    aTOb.addStaticallyIncludedDestination(queue);
    NetworkConnector bTOa = bridgeBrokers(brokers.get("BrokerB").broker, brokers.get("BrokerA").broker, false, 2, true, true);
    bTOa.addStaticallyIncludedDestination(queue);
    startAllBrokers();
    waitForBridgeFormation();
}

29. MessageGroupDelayedTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setPersistent(false);
    service.setUseJmx(false);
    // Setup a destination policy where it takes only 1 message at a time.
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    log.info("testing with consumersBeforeDispatchStarts=" + consumersBeforeDispatchStarts + " and timeBeforeDispatchStarts=" + timeBeforeDispatchStarts);
    policy.setConsumersBeforeDispatchStarts(consumersBeforeDispatchStarts);
    policy.setTimeBeforeDispatchStarts(timeBeforeDispatchStarts);
    policyMap.setDefaultEntry(policy);
    service.setDestinationPolicy(policyMap);
    connector = service.addConnector("tcp://localhost:0");
    return service;
}

30. MessageGroupLateArrivalsTest#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService service = new BrokerService();
    service.setPersistent(false);
    service.setUseJmx(false);
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policy = new PolicyEntry();
    policy.setUseConsumerPriority(true);
    policyMap.setDefaultEntry(policy);
    service.setDestinationPolicy(policyMap);
    connector = service.addConnector("tcp://localhost:0");
    return service;
}

31. TrackerConfig#brokerService()

Project: biking2
Source File: TrackerConfig.java
View license
@Bean
public BrokerService brokerService() throws Exception {
    final BrokerService rv = BrokerFactory.createBroker(String.format("broker:(" + "vm://localhost," + "stomp://localhost:%d," + "mqtt+nio://%s:%d" + ")?persistent=false&useJmx=%s&useShutdownHook=true", properties.getStompPort(), properties.getHost(), properties.getMqttPort(), properties.isUseJMX()));
    final SimpleAuthenticationPlugin authenticationPlugin = new SimpleAuthenticationPlugin();
    authenticationPlugin.setAnonymousAccessAllowed(false);
    authenticationPlugin.setUsers(Arrays.asList(new AuthenticationUser(properties.getUsername(), properties.getPassword(), "")));
    rv.addShutdownHook(new SpringContextHook());
    rv.setPlugins(new BrokerPlugin[] { authenticationPlugin });
    rv.start();
    return rv;
}

32. DeadLetterTestSupport#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setPersistent(false);
    PolicyEntry policy = new PolicyEntry();
    DeadLetterStrategy defaultDeadLetterStrategy = policy.getDeadLetterStrategy();
    if (defaultDeadLetterStrategy != null) {
        defaultDeadLetterStrategy.setProcessNonPersistent(true);
    }
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

33. ExpiryHogTest#createBroker()

Project: activemq-artemis
Source File: ExpiryHogTest.java
View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService bs = new BrokerService();
    bs.setDeleteAllMessagesOnStartup(true);
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setExpireMessagesPeriod(5000);
    defaultEntry.setUseCache(false);
    policyMap.setDefaultEntry(defaultEntry);
    bs.setDestinationPolicy(policyMap);
    return bs;
}

34. SslContextNBrokerServiceTest#verifyCredentials()

View license
private boolean verifyCredentials(String name) throws Exception {
    boolean result = false;
    BrokerService broker = getBroker(name);
    assertNotNull(name, broker);
    broker.start();
    broker.waitUntilStarted();
    try {
        result = verifySslCredentials(broker);
    } finally {
        broker.stop();
    }
    return result;
}

35. MemoryLimitTest#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    BrokerService broker = new BrokerService();
    //1MB
    broker.getSystemUsage().getMemoryUsage().setLimit(1 * 1024 * 1024);
    broker.deleteAllMessages();
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry policyEntry = new PolicyEntry();
    policyEntry.setProducerFlowControl(false);
    policyMap.put(new ActiveMQQueue(">"), policyEntry);
    broker.setDestinationPolicy(policyMap);
    LOG.info("Starting broker with persistenceAdapterChoice " + persistenceAdapterChoice.toString());
    setPersistenceAdapter(broker, persistenceAdapterChoice);
    broker.getPersistenceAdapter().deleteAllMessages();
    return broker;
}

36. QpidJmsTestSupport#restartBroker()

Project: qpid-jms
Source File: QpidJmsTestSupport.java
View license
public BrokerService restartBroker(BrokerService brokerService) throws Exception {
    String name = brokerService.getBrokerName();
    Map<String, Integer> portMap = new HashMap<String, Integer>();
    for (TransportConnector connector : brokerService.getTransportConnectors()) {
        portMap.put(connector.getName(), connector.getPublishableConnectURI().getPort());
    }
    stopBroker(brokerService);
    BrokerService broker = createBroker(name, false, portMap);
    broker.start();
    broker.waitUntilStarted();
    return broker;
}

37. AbortSlowAckConsumer0Test#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    strategy = createSlowConsumerStrategy();
    underTest = strategy;
    policy.setSlowConsumerStrategy(strategy);
    policy.setQueuePrefetch(10);
    policy.setTopicPrefetch(10);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

38. AbortSlowAckConsumer1Test#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    AbortSlowAckConsumerStrategy strategy = new AbortSlowAckConsumerStrategy();
    strategy.setAbortConnection(abortConnection);
    strategy.setCheckPeriod(checkPeriod);
    strategy.setMaxSlowDuration(maxSlowDuration);
    strategy.setMaxTimeSinceLastAck(maxTimeSinceLastAck);
    policy.setSlowConsumerStrategy(strategy);
    policy.setQueuePrefetch(10);
    policy.setTopicPrefetch(10);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

39. AbortSlowAckConsumer2Test#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    AbortSlowAckConsumerStrategy strategy = new AbortSlowAckConsumerStrategy();
    strategy.setAbortConnection(abortConnection);
    strategy.setCheckPeriod(checkPeriod);
    strategy.setMaxSlowDuration(maxSlowDuration);
    strategy.setMaxTimeSinceLastAck(maxTimeSinceLastAck);
    policy.setSlowConsumerStrategy(strategy);
    policy.setQueuePrefetch(10);
    policy.setTopicPrefetch(10);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

40. AbortSlowConsumerBase#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    underTest.setAbortConnection(abortConnection);
    underTest.setCheckPeriod(checkPeriod);
    underTest.setMaxSlowDuration(maxSlowDuration);
    policy.setSlowConsumerStrategy(underTest);
    policy.setQueuePrefetch(10);
    policy.setTopicPrefetch(10);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

41. DiscardingDeadLetterPolicyTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    DeadLetterStrategy strategy = new DiscardingDeadLetterStrategy();
    strategy.setProcessNonPersistent(true);
    policy.setDeadLetterStrategy(strategy);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

42. IndividualDeadLetterTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    DeadLetterStrategy strategy = new IndividualDeadLetterStrategy();
    strategy.setProcessNonPersistent(true);
    policy.setDeadLetterStrategy(strategy);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

43. NoConsumerDeadLetterTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    policy.setSendAdvisoryIfNoConsumers(true);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

44. PerDurableConsumerDeadLetterTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    IndividualDeadLetterStrategy strategy = new IndividualDeadLetterStrategy();
    strategy.setProcessNonPersistent(true);
    strategy.setDestinationPerDurableSubscriber(true);
    policy.setDeadLetterStrategy(strategy);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

45. RoundRobinDispatchPolicyTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    policy.setDispatchPolicy(new RoundRobinDispatchPolicy());
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

46. SimpleDispatchPolicyTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    policy.setDispatchPolicy(new SimpleDispatchPolicy());
    policy.setSubscriptionRecoveryPolicy(new FixedCountSubscriptionRecoveryPolicy());
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

47. StrictOrderDispatchPolicyTest#createBroker()

View license
@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    PolicyEntry policy = new PolicyEntry();
    policy.setDispatchPolicy(new StrictOrderDispatchPolicy());
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    return broker;
}

48. SubscriptionAddRemoveQueueTest#setUp()

View license
@Override
public void setUp() throws Exception {
    BrokerService brokerService = new BrokerService();
    brokerService.start();
    DestinationStatistics parentStats = new DestinationStatistics();
    parentStats.setEnabled(true);
    TaskRunnerFactory taskFactory = new TaskRunnerFactory();
    MessageStore store = null;
    info.setDestination(destination);
    info.setPrefetchSize(100);
    producerBrokerExchange.setProducerState(producerState);
    producerBrokerExchange.setConnectionContext(context);
    queue = new Queue(brokerService, destination, store, parentStats, taskFactory);
    queue.initialize();
}

49. BrokerPropertiesTest#testVmBrokerPropertiesFile()

View license
public void testVmBrokerPropertiesFile() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?brokerConfig=properties:org/apache/activemq/config/broker.properties");
    Connection connection = factory.createConnection();
    BrokerService broker = BrokerRegistry.getInstance().lookup("Cheese");
    LOG.info("Found broker : " + broker);
    assertNotNull(broker);
    assertEquals("isUseJmx()", false, broker.isUseJmx());
    assertEquals("isPersistent()", false, broker.isPersistent());
    assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
    connection.close();
    broker.stop();
}

50. CompressionOverNetworkTest#createBroker()

View license
protected BrokerService createBroker(String uri) throws Exception {
    Resource resource = new ClassPathResource(uri);
    BrokerFactoryBean factory = new BrokerFactoryBean(resource);
    resource = new ClassPathResource(uri);
    factory = new BrokerFactoryBean(resource);
    factory.afterPropertiesSet();
    BrokerService result = factory.getBroker();
    for (NetworkConnector connector : result.getNetworkConnectors()) {
        connector.setUseCompression(true);
    }
    return result;
}

51. NetworkConnectionsTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    LOG.info("Setting up LocalBroker");
    localBroker = new BrokerService();
    localBroker.setBrokerName("LocalBroker");
    localBroker.setUseJmx(false);
    localBroker.setPersistent(false);
    localBroker.setTransportConnectorURIs(new String[] { LOCAL_BROKER_TRANSPORT_URI });
    localBroker.start();
    localBroker.waitUntilStarted();
    LOG.info("Setting up RemoteBroker");
    remoteBroker = new BrokerService();
    remoteBroker.setBrokerName("RemoteBroker");
    remoteBroker.setUseJmx(false);
    remoteBroker.setPersistent(false);
    remoteBroker.setTransportConnectorURIs(new String[] { REMOTE_BROKER_TRANSPORT_URI });
    remoteBroker.start();
    remoteBroker.waitUntilStarted();
}

52. AbstractTwoBrokerNetworkConnectorWildcardIncludedDestinationTestSupport#createAndConfigureBroker()

View license
private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    // make all topics virtual and consumers use the default prefix
    VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
    virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[] { new VirtualTopic() });
    DestinationInterceptor[] destinationInterceptors = new DestinationInterceptor[] { virtualDestinationInterceptor };
    broker.setDestinationInterceptors(destinationInterceptors);
    return broker;
}

53. RequestReplyNoAdvisoryNetworkTest#testNonAdvisoryNetworkRequestReplyWithPIM()

View license
public void testNonAdvisoryNetworkRequestReplyWithPIM() throws Exception {
    a = configureBroker("A");
    b = configureBroker("B");
    BrokerService hub = configureBroker("M");
    hub.setAllowTempAutoCreationOnSend(true);
    configureForPiggyInTheMiddle(bridge(a, hub));
    configureForPiggyInTheMiddle(bridge(b, hub));
    startBrokers();
    waitForBridgeFormation(hub, 2, 0);
    doTestNonAdvisoryNetworkRequestReply();
}

54. SingleBrokerVirtualDestinationsWithWildcardTest#createAndConfigureBroker()

View license
private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    // make all topics virtual and consumers use the default prefix
    VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
    virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[] { new VirtualTopic() });
    DestinationInterceptor[] destinationInterceptors = new DestinationInterceptor[] { virtualDestinationInterceptor };
    broker.setDestinationInterceptors(destinationInterceptors);
    return broker;
}

55. ThreeBrokerVirtualTopicNetworkTest#createAndConfigureBroker()

View license
private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    // make all topics virtual and consumers use the default prefix
    VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
    virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[] { new VirtualTopic() });
    DestinationInterceptor[] destinationInterceptors = new DestinationInterceptor[] { virtualDestinationInterceptor };
    broker.setDestinationInterceptors(destinationInterceptors);
    return broker;
}

56. TwoBrokerVirtualDestDinamicallyIncludedDestTest#createAndConfigureBroker()

View license
private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    // make all topics virtual and consumers use the default prefix
    VirtualDestinationInterceptor virtualDestinationInterceptor = new VirtualDestinationInterceptor();
    VirtualTopic vTopic = new VirtualTopic();
    vTopic.setLocal(true);
    virtualDestinationInterceptor.setVirtualDestinations(new VirtualDestination[] { vTopic });
    DestinationInterceptor[] destinationInterceptors = new DestinationInterceptor[] { virtualDestinationInterceptor };
    broker.setDestinationInterceptors(destinationInterceptors);
    return broker;
}

57. ActiveMQConnectionFactoryTest#testCreateTcpConnectionUsingKnownLocalPort()

View license
public void testCreateTcpConnectionUsingKnownLocalPort() throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.addConnector("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
    broker.start();
    // This should create the connection.
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61610/localhost:51610");
    connection = (ActiveMQConnection) cf.createConnection();
    assertNotNull(connection);
    connection.close();
    broker.stop();
}

58. ActiveMQConnectionFactoryTest#assertCreateConnection()

View license
protected void assertCreateConnection(String uri) throws Exception {
    // Start up a broker with a tcp connector.
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    TransportConnector connector = broker.addConnector(uri);
    broker.start();
    URI temp = new URI(uri);
    // URI connectURI = connector.getServer().getConnectURI();
    // TODO this sometimes fails when using the actual local host name
    URI currentURI = new URI(connector.getPublishableConnectString());
    // sometimes the actual host name doesn't work in this test case
    // e.g. on OS X so lets use the original details but just use the actual
    // port
    URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), temp.getPath(), temp.getQuery(), temp.getFragment());
    LOG.info("connection URI is: " + connectURI);
    // This should create the connection.
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI);
    connection = (ActiveMQConnection) cf.createConnection();
    assertNotNull(connection);
}

59. ActiveMQXAConnectionFactoryTest#assertTransactionGoneFromConnection()

View license
private void assertTransactionGoneFromConnection(String brokerName, String clientId, ConnectionId connectionId, Xid tid) throws Exception {
    BrokerService broker = BrokerRegistry.getInstance().lookup(brokerName);
    CopyOnWriteArrayList<TransportConnection> connections = broker.getTransportConnectors().get(0).getConnections();
    for (TransportConnection connection : connections) {
        if (connection.getConnectionId().equals(clientId)) {
            try {
                connection.processPrepareTransaction(new TransactionInfo(connectionId, new XATransactionId(tid), TransactionInfo.PREPARE));
                fail("did not get expected excepton on missing transaction, it must be still there in error!");
            } catch (IllegalStateException expectedOnNoTransaction) {
            }
        }
    }
}

60. JDBCQueueMasterSlaveTest#createMaster()

View license
@Override
protected void createMaster() throws Exception {
    master = new BrokerService();
    master.setBrokerName("master");
    master.addConnector(MASTER_URL);
    master.setUseJmx(false);
    master.setPersistent(true);
    master.setDeleteAllMessagesOnStartup(true);
    JDBCPersistenceAdapter persistenceAdapter = new JDBCPersistenceAdapter();
    persistenceAdapter.setDataSource(getExistingDataSource());
    configureJdbcPersistenceAdapter(persistenceAdapter);
    master.setPersistenceAdapter(persistenceAdapter);
    configureBroker(master);
    master.start();
}

61. kahaDbJdbcLeaseQueueMasterSlaveTest#createMaster()

View license
@Override
protected void createMaster() throws Exception {
    master = new BrokerService();
    master.setBrokerName("master");
    master.addConnector(MASTER_URL);
    master.setUseJmx(false);
    master.setPersistent(true);
    master.setDeleteAllMessagesOnStartup(true);
    KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) master.getPersistenceAdapter();
    LeaseDatabaseLocker leaseDatabaseLocker = new LeaseDatabaseLocker();
    leaseDatabaseLocker.setCreateTablesOnStartup(true);
    leaseDatabaseLocker.setDataSource(getExistingDataSource());
    leaseDatabaseLocker.setStatements(new Statements());
    kahaDBPersistenceAdapter.setLocker(leaseDatabaseLocker);
    configureLocker(kahaDBPersistenceAdapter);
    configureBroker(master);
    master.start();
}

62. mKahaDbQueueMasterSlaveTest#createMaster()

View license
@Override
protected void createMaster() throws Exception {
    master = new BrokerService();
    master.setBrokerName("master");
    master.addConnector(MASTER_URL);
    master.setUseJmx(false);
    master.setPersistent(true);
    master.setDeleteAllMessagesOnStartup(true);
    MultiKahaDBPersistenceAdapter mKahaDB = new MultiKahaDBPersistenceAdapter();
    List<FilteredKahaDBPersistenceAdapter> adapters = new LinkedList<>();
    FilteredKahaDBPersistenceAdapter defaultEntry = new FilteredKahaDBPersistenceAdapter();
    defaultEntry.setPersistenceAdapter(new KahaDBPersistenceAdapter());
    defaultEntry.setPerDestination(true);
    adapters.add(defaultEntry);
    mKahaDB.setFilteredPersistenceAdapters(adapters);
    master.setPersistenceAdapter(mKahaDB);
    master.start();
}

63. QueueMasterSlaveTestSupport#tearDown()

View license
@Override
protected void tearDown() throws Exception {
    super.tearDown();
    master.stop();
    master.waitUntilStopped();
    slaveStarted.await(60, TimeUnit.SECONDS);
    BrokerService brokerService = slave.get();
    if (brokerService != null) {
        brokerService.stop();
    }
    master.stop();
}

64. SpringPartitionBrokerTest#testCreatePartitionBroker()

View license
public void testCreatePartitionBroker() throws Exception {
    BrokerService broker = BrokerFactory.createBroker("xbean:activemq-partition.xml");
    assertEquals(1, broker.getPlugins().length);
    PartitionBrokerPlugin plugin = (PartitionBrokerPlugin) broker.getPlugins()[0];
    Partitioning config = plugin.getConfig();
    assertEquals(2, config.getBrokers().size());
    Object o;
    String json = "{\n" + "  \"by_client_id\":{\n" + "    \"client1\":{\"ids\":[\"broker1\"]},\n" + "    \"client2\":{\"ids\":[\"broker1\",\"broker2\"]}\n" + "  },\n" + "  \"brokers\":{\n" + "    \"broker1\":\"tcp://localhost:61616\",\n" + "    \"broker2\":\"tcp://localhost:61616\"\n" + "  }\n" + "}";
    Partitioning expected = Partitioning.MAPPER.readValue(json, Partitioning.class);
    assertEquals(expected.toString(), config.toString());
}

65. MessageGroupConfigTest#doTestGroupConfiguration()

View license
public MessageGroupMap doTestGroupConfiguration(String type, Class classType) throws Exception {
    broker = new BrokerService();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMessageGroupMapFactoryType(type);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
    super.topic = false;
    ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
    Queue brokerDestination = (Queue) broker.getDestination(destination);
    assertNotNull(brokerDestination);
    MessageGroupMap messageGroupMap = brokerDestination.getMessageGroupOwners();
    assertNotNull(messageGroupMap);
    assertTrue(messageGroupMap.getClass().isAssignableFrom(classType));
    return messageGroupMap;
}

66. QueueOptimizedDispatchExceptionTest#setUp()

View license
@Before
public void setUp() throws Exception {
    // Setup and start the broker
    broker = new BrokerService();
    broker.setBrokerName(brokerName);
    broker.setPersistent(false);
    broker.setSchedulerSupport(false);
    broker.setUseJmx(false);
    broker.setUseShutdownHook(false);
    broker.addConnector(brokerUrl);
    // Start the broker
    broker.start();
    broker.waitUntilStarted();
}

67. QueuePurgeTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    // 10 mins
    setMaxTestTime(10 * 60 * 1000);
    setAutoFail(true);
    super.setUp();
    broker = new BrokerService();
    File testDataDir = new File("target/activemq-data/QueuePurgeTest");
    broker.setDataDirectoryFile(testDataDir);
    broker.setUseJmx(true);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.getSystemUsage().getMemoryUsage().setLimit(1024L * 1024 * 64);
    KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
    persistenceAdapter.setDirectory(new File(testDataDir, "kahadb"));
    broker.setPersistenceAdapter(persistenceAdapter);
    broker.addConnector("tcp://localhost:0");
    broker.start();
    factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri().toString());
    connection = factory.createConnection();
    connection.start();
}

68. LostScheduledMessagesTest#startBroker()

View license
private void startBroker() throws Exception {
    broker = new BrokerService();
    broker.setSchedulerSupport(true);
    broker.setPersistent(true);
    broker.setDeleteAllMessagesOnStartup(false);
    broker.setDataDirectory("target");
    broker.setSchedulerDirectoryFile(schedulerDirectory);
    broker.setDataDirectoryFile(messageDirectory);
    broker.setUseJmx(false);
    broker.addConnector("vm://localhost");
    broker.start();
}

69. ConfigTest#testJournalConfig()

Project: activemq-artemis
Source File: ConfigTest.java
View license
/*
    * This tests creating a journal persistence adapter using xbeans-spring
    */
@Test
public void testJournalConfig() throws Exception {
    File journalFile = new File(JOURNAL_ROOT + "testJournalConfig/journal");
    recursiveDelete(journalFile);
    BrokerService broker;
    broker = createBroker(new FileSystemResource(CONF_ROOT + "journal-example.xml"));
    try {
        assertEquals("Broker Config Error (brokerName)", "brokerJournalConfigTest", broker.getBrokerName());
        PersistenceAdapter adapter = broker.getPersistenceAdapter();
        assertTrue("Should have created a journal persistence adapter", adapter instanceof JournalPersistenceAdapter);
        assertTrue("Should have created a journal directory at " + journalFile.getAbsolutePath(), journalFile.exists());
        LOG.info("Success");
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}

70. ConfigTest#testXmlConfigHelper()

Project: activemq-artemis
Source File: ConfigTest.java
View license
@Test
public void testXmlConfigHelper() throws Exception {
    BrokerService broker;
    broker = createBroker(new FileSystemResource(CONF_ROOT + "memory-example.xml"));
    try {
        assertEquals("Broker Config Error (brokerName)", "brokerMemoryConfigTest", broker.getBrokerName());
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
    broker = createBroker("org/apache/activemq/config/config.xml");
    try {
        assertEquals("Broker Config Error (brokerName)", "brokerXmlConfigHelper", broker.getBrokerName());
    } finally {
        if (broker != null) {
            broker.stop();
        }
    }
}

71. ConfigTest#createBroker()

Project: activemq-artemis
Source File: ConfigTest.java
View license
protected BrokerService createBroker(Resource resource) throws Exception {
    BrokerFactoryBean factory = new BrokerFactoryBean(resource);
    factory.afterPropertiesSet();
    BrokerService broker = factory.getBroker();
    assertTrue("Should have a broker!", broker != null);
    return broker;
}

72. JDBCConfigTest#createBroker()

View license
protected BrokerService createBroker(Resource resource) throws Exception {
    BrokerFactoryBean factory = new BrokerFactoryBean(resource);
    factory.afterPropertiesSet();
    BrokerService broker = factory.getBroker();
    assertTrue("Should have a broker!", broker != null);
    return broker;
}

73. BrokerNetworkWithStuckMessagesTest#waitForBridgeFormation()

View license
protected void waitForBridgeFormation() throws Exception {
    for (final BrokerService broker : brokers.values()) {
        if (!broker.getNetworkConnectors().isEmpty()) {
            // Max wait here is 30 secs
            Wait.waitFor(new Wait.Condition() {

                @Override
                public boolean isSatisified() throws Exception {
                    return !broker.getNetworkConnectors().get(0).activeBridges().isEmpty();
                }
            });
        }
    }
}

74. BrokerNetworkWithStuckMessagesTest#createBroker()

View license
protected BrokerService createBroker() throws Exception {
    localBroker = new BrokerService();
    localBroker.setBrokerName("localhost");
    localBroker.setUseJmx(true);
    localBroker.setPersistenceAdapter(null);
    localBroker.setPersistent(false);
    connector = createConnector();
    localBroker.addConnector(connector);
    configureBroker(localBroker);
    localBroker.start();
    localBroker.waitUntilStarted();
    localBroker.getManagementContext().setConnectorPort(2221);
    brokers.put(localBroker.getBrokerName(), localBroker);
    return localBroker;
}

75. BrokerNetworkWithStuckMessagesTest#createRemoteBroker()

View license
protected BrokerService createRemoteBroker() throws Exception {
    remoteBroker = new BrokerService();
    remoteBroker.setBrokerName("remotehost");
    remoteBroker.setUseJmx(true);
    remoteBroker.setPersistenceAdapter(null);
    remoteBroker.setPersistent(false);
    remoteConnector = createRemoteConnector();
    remoteBroker.addConnector(remoteConnector);
    configureBroker(remoteBroker);
    remoteBroker.start();
    remoteBroker.waitUntilStarted();
    remoteBroker.getManagementContext().setConnectorPort(2222);
    brokers.put(remoteBroker.getBrokerName(), remoteBroker);
    return remoteBroker;
}

76. BrokerNetworkWithStuckMessagesTest#createSecondRemoteBroker()

View license
protected BrokerService createSecondRemoteBroker() throws Exception {
    secondRemoteBroker = new BrokerService();
    secondRemoteBroker.setBrokerName("secondRemotehost");
    secondRemoteBroker.setUseJmx(false);
    secondRemoteBroker.setPersistenceAdapter(null);
    secondRemoteBroker.setPersistent(false);
    secondRemoteConnector = createSecondRemoteConnector();
    secondRemoteBroker.addConnector(secondRemoteConnector);
    configureBroker(secondRemoteBroker);
    secondRemoteBroker.start();
    secondRemoteBroker.waitUntilStarted();
    brokers.put(secondRemoteBroker.getBrokerName(), secondRemoteBroker);
    return secondRemoteBroker;
}

77. CheckDuplicateMessagesOnDuplexTest#createLocalBroker()

View license
private void createLocalBroker() throws Exception {
    localBroker = new BrokerService();
    localBroker.setBrokerName("LOCAL");
    localBroker.setUseJmx(true);
    localBroker.setSchedulePeriodForDestinationPurge(5000);
    ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector(false);
    localBroker.setManagementContext(managementContext);
    PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/local");
    localBroker.setPersistenceAdapter(persistenceAdapter);
    List<TransportConnector> transportConnectors = new ArrayList<>();
    DebugTransportFactory tf = new DebugTransportFactory();
    TransportServer transport = tf.doBind(URI.create("nio://127.0.0.1:23539"));
    TransportConnector transportConnector = new TransportConnector(transport);
    transportConnector.setName("tc");
    transportConnector.setAuditNetworkProducers(true);
    transportConnectors.add(transportConnector);
    localBroker.setTransportConnectors(transportConnectors);
}

78. CheckDuplicateMessagesOnDuplexTest#createRemoteBroker()

View license
private void createRemoteBroker() throws Exception {
    remoteBroker = new BrokerService();
    remoteBroker.setBrokerName("REMOTE");
    remoteBroker.setUseJmx(true);
    remoteBroker.setSchedulePeriodForDestinationPurge(5000);
    ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector(false);
    remoteBroker.setManagementContext(managementContext);
    PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/remote");
    remoteBroker.setPersistenceAdapter(persistenceAdapter);
    List<NetworkConnector> networkConnectors = new ArrayList<>();
    DiscoveryNetworkConnector networkConnector = new DiscoveryNetworkConnector();
    networkConnector.setName("to local");
    // set maxInactivityDuration to 0, otherwise the broker restarts while you are in the debugger
    networkConnector.setUri(URI.create("static://(tcp://127.0.0.1:23539?wireFormat.maxInactivityDuration=0)"));
    networkConnector.setDuplex(true);
    //networkConnector.setNetworkTTL(5);
    //networkConnector.setDynamicOnly(true);
    networkConnector.setAlwaysSyncSend(true);
    networkConnector.setDecreaseNetworkConsumerPriority(false);
    networkConnector.setPrefetchSize(1);
    networkConnector.setCheckDuplicateMessagesOnDuplex(true);
    networkConnectors.add(networkConnector);
    remoteBroker.setNetworkConnectors(networkConnectors);
}

79. InactiveDurableTopicTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    broker = new BrokerService();
    //broker.setPersistenceAdapter(new KahaPersistenceAdapter());
    /*
         * JournalPersistenceAdapterFactory factory = new
         * JournalPersistenceAdapterFactory();
         * factory.setDataDirectoryFile(broker.getDataDirectory());
         * factory.setTaskRunnerFactory(broker.getTaskRunnerFactory());
         * factory.setUseJournal(false); broker.setPersistenceFactory(factory);
         */
    broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
    broker.start();
    connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
    /*
         * Doesn't matter if you enable or disable these, so just leaving them
         * out for this test case connectionFactory.setAlwaysSessionAsync(true);
         * connectionFactory.setAsyncDispatch(true);
         */
    connectionFactory.setUseAsyncSend(true);
}

80. InactiveQueueTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    broker = new BrokerService();
    // broker.setPersistenceAdapter(new KahaPersistenceAdapter(new File
    // ("TEST_STUFD")));
    /*
         * JournalPersistenceAdapterFactory factory = new
         * JournalPersistenceAdapterFactory();
         * factory.setDataDirectoryFile(broker.getDataDirectory());
         * factory.setTaskRunnerFactory(broker.getTaskRunnerFactory());
         * factory.setUseJournal(false); broker.setPersistenceFactory(factory);
         */
    broker.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
    broker.start();
    connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_URL);
    /*
         * Doesn't matter if you enable or disable these, so just leaving them
         * out for this test case connectionFactory.setAlwaysSessionAsync(true);
         * connectionFactory.setAsyncDispatch(true);
         */
    connectionFactory.setUseAsyncSend(true);
}

81. AMQ4889Test#createBroker()

Project: activemq-artemis
Source File: AMQ4889Test.java
View license
protected BrokerService createBroker() throws Exception {
    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    ArrayList<BrokerPlugin> plugins = new ArrayList<>();
    BrokerPlugin authenticationPlugin = configureAuthentication();
    plugins.add(authenticationPlugin);
    BrokerPlugin[] array = new BrokerPlugin[plugins.size()];
    brokerService.setPlugins(plugins.toArray(array));
    transportConnector = brokerService.addConnector(LOCAL_URI);
    proxyConnector = new ProxyConnector();
    proxyConnector.setName("proxy");
    proxyConnector.setBind(new URI(PROXY_URI));
    proxyConnector.setRemote(new URI(LOCAL_URI));
    brokerService.addProxyConnector(proxyConnector);
    brokerService.start();
    brokerService.waitUntilStarted();
    return brokerService;
}

82. ProxyFailoverTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    startRemoteBroker(true);
    proxyBroker = new BrokerService();
    ProxyConnector connector = new ProxyConnector();
    connector.setBind(new URI("tcp://localhost:51618"));
    connector.setProxyToLocalBroker(false);
    connector.setRemote(new URI("failover:(tcp://localhost:61616)"));
    proxyBroker.addProxyConnector(connector);
    proxyBroker.setPersistent(false);
    proxyBroker.setUseJmx(false);
    proxyBroker.start();
    proxyBroker.waitUntilStarted();
}

83. FailoverClusterTestSupport#destroyBrokerCluster()

View license
protected void destroyBrokerCluster() throws JMSException, Exception {
    for (BrokerService b : brokers.values()) {
        try {
            b.stop();
            b.waitUntilStopped();
        } catch (Exception e) {
            logger.info("Error while stopping broker[" + b.getBrokerName() + "] continuing...");
        }
    }
    brokers.clear();
}

84. NIOSSLLoadTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
    System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
    System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
    System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
    System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
    System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setUseJmx(false);
    TransportConnector connector = broker.addConnector("nio+ssl://localhost:0?transport.needClientAuth=true&transport.enabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
    broker.start();
    broker.waitUntilStarted();
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("nio+ssl://localhost:" + connector.getConnectUri().getPort());
    connection = factory.createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    connection.start();
}

85. SslContextNBrokerServiceTest#getBroker()

View license
private BrokerService getBroker(String name) {
    BrokerService result = null;
    Iterator<BrokerService> iterator = beansOfType.values().iterator();
    while (iterator.hasNext()) {
        BrokerService candidate = iterator.next();
        if (candidate.getBrokerName().equals(name)) {
            result = candidate;
            break;
        }
    }
    return result;
}

86. AdvisoryTopicCleanUpTest#createBroker()

View license
private void createBroker() throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.setUseJmx(true);
    connectionUri = broker.addConnector("tcp://localhost:0").getPublishableConnectString();
    PolicyEntry policy = new PolicyEntry();
    policy.setAdvisoryForFastProducers(true);
    policy.setAdvisoryForConsumed(true);
    policy.setAdvisoryForDelivery(true);
    policy.setAdvisoryForDiscardingMessages(true);
    policy.setAdvisoryForSlowConsumers(true);
    policy.setAdvisoryWhenFull(true);
    policy.setProducerFlowControl(false);
    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);
    broker.setDestinationPolicy(pMap);
    broker.start();
}

87. DiscriminatingConsumerLoadTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    broker = new BrokerService();
    broker.setPersistent(false);
    // workaround is to ensure sufficient dispatch buffer for the destination
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultPolicy = new PolicyEntry();
    defaultPolicy.setMaxPageSize(testSize);
    policyMap.setDefaultEntry(defaultPolicy);
    broker.setDestinationPolicy(policyMap);
    broker.start();
    super.setUp();
    this.producerConnection = this.createConnection();
    this.consumerConnection = this.createConnection();
}

88. DispatchMultipleConsumersTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    broker = new BrokerService();
    broker.setPersistent(true);
    broker.setUseJmx(true);
    broker.deleteAllMessages();
    broker.addConnector("tcp://localhost:0");
    broker.start();
    broker.waitUntilStarted();
    dest = new ActiveMQQueue(destinationName);
    resetCounters();
    brokerURL = broker.getTransportConnectors().get(0).getPublishableConnectString();
}

89. DurableSubscriberNonPersistentMessageTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    broker = new BrokerService();
    TransportConnector transportConnector = broker.addConnector("tcp://localhost:0");
    KahaDBStore store = new KahaDBStore();
    store.setDirectory(new File("data"));
    broker.setPersistenceAdapter(store);
    broker.start();
    brokerURL = "failover:(" + transportConnector.getPublishableConnectString() + ")";
    consumerBrokerURL = brokerURL + "?jms.prefetchPolicy.all=100";
    mbeanServer = ManagementFactory.getPlatformMBeanServer();
}

90. DurableSubscriptionHangTestCase#startBroker()

View license
@Before
public void startBroker() throws Exception {
    brokerService = new BrokerService();
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setBrokerName(brokerName);
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setExpireMessagesPeriod(5000);
    policyMap.setDefaultEntry(defaultEntry);
    brokerService.setDestinationPolicy(policyMap);
    brokerService.start();
}

91. DurableSubscriptionSelectorTest#startBroker()

View license
private void startBroker(boolean deleteMessages) throws Exception {
    broker = new BrokerService();
    broker.setBrokerName("test-broker");
    if (deleteMessages) {
        broker.setDeleteAllMessagesOnStartup(true);
    }
    setDefaultPersistenceAdapter(broker);
    /* use maxPageSize policy in place of always pulling from the broker in maxRows chunks
        if (broker.getPersistenceAdapter() instanceof JDBCPersistenceAdapter) {
            ((JDBCPersistenceAdapter)broker.getPersistenceAdapter()).setMaxRows(5000);
        }*/
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMaxPageSize(5000);
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
}

92. JdbcDurableSubDupTest#startBroker()

View license
@Before
public void startBroker() throws Exception {
    exceptions.clear();
    for (int i = 0; i < MAX_MESSAGES; i++) {
        dupChecker[i] = 0;
    }
    broker = new BrokerService();
    broker.setAdvisorySupport(false);
    broker.setPersistenceAdapter(new JDBCPersistenceAdapter());
    PolicyEntry policyEntry = new PolicyEntry();
    policyEntry.setMaxAuditDepth(3000);
    policyEntry.setMaxPageSize(150);
    policyEntry.setPrioritizedMessages(true);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(policyEntry);
    broker.setDestinationPolicy(policyMap);
    broker.addConnector("tcp://localhost:0");
    broker.setDeleteAllMessagesOnStartup(true);
    broker.start();
    broker.waitUntilStarted();
    url = broker.getTransportConnectors().get(0).getConnectUri().toString() + "?" + urlOptions;
}

93. JMXRemoveQueueThenSendIgnoredTest#setUp()

View license
@Before
public void setUp() throws Exception {
    brokerService = new BrokerService();
    brokerService.setBrokerName("dev");
    brokerService.setPersistent(false);
    brokerService.setUseJmx(true);
    brokerService.addConnector("tcp://localhost:0");
    brokerService.start();
    final String brokerUri = brokerService.getTransportConnectors().get(0).getPublishableConnectString();
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerUri);
    connection = activeMQConnectionFactory.createQueueConnection();
    session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
    queue = session.createQueue("myqueue");
    producer = session.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    connection.start();
}

94. NetworkOfTwentyBrokersTest#verifyPeerBrokerInfo()

View license
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);
}

95. NonBlockingConsumerRedeliveryTest#startBroker()

View license
@Before
public void startBroker() throws Exception {
    broker = new BrokerService();
    broker.setDeleteAllMessagesOnStartup(true);
    broker.setPersistent(false);
    broker.setUseJmx(false);
    broker.addConnector("tcp://0.0.0.0:0");
    broker.start();
    broker.waitUntilStarted();
    connectionUri = broker.getTransportConnectors().get(0).getPublishableConnectString();
    connectionFactory = new ActiveMQConnectionFactory(connectionUri);
    connectionFactory.setNonBlockingRedelivery(true);
    RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay(TimeUnit.SECONDS.toMillis(2));
    policy.setBackOffMultiplier(-1);
    policy.setRedeliveryDelay(TimeUnit.SECONDS.toMillis(2));
    policy.setMaximumRedeliveryDelay(-1);
    policy.setUseExponentialBackOff(false);
    policy.setMaximumRedeliveries(-1);
}

96. QueueMemoryFullMultiBrokersTest#setUp()

View license
@Override
public void setUp() throws Exception {
    super.setAutoFail(true);
    super.setUp();
    messageSize = 1024;
    // Setup n brokers
    for (int i = 1; i <= BROKER_COUNT; i++) {
        createBroker(new URI("broker:()/Broker" + i + "?persistent=false&useJmx=false"));
    }
    BrokerService broker2 = brokers.get("Broker2").broker;
    applyMemoryLimitPolicy(broker2);
}

97. StartAndStopBrokerTest#createBroker()

View license
protected BrokerService createBroker() throws JMSException {
    BrokerService broker = null;
    try {
        broker = BrokerFactory.createBroker(new URI("broker://()/localhost"));
        broker.setBrokerName("DefaultBroker");
        broker.addConnector("tcp://localhost:9100");
        broker.setUseShutdownHook(false);
        broker.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return broker;
}

98. TwoBrokerQueueSendReceiveTest#testReceiveOnXConsumersNoLeak()

View license
public void testReceiveOnXConsumersNoLeak() throws Exception {
    consumer.close();
    sendMessages();
    for (int i = 0; i < data.length; i++) {
        consumer = createConsumer();
        onMessage(consumer.receive(10000));
        consumer.close();
    }
    waitForMessagesToBeDelivered();
    assertEquals("Got all messages", data.length, messages.size());
    BrokerService broker = brokers.get("receiver");
    final DemandForwardingBridgeSupport bridge = (DemandForwardingBridgeSupport) broker.getNetworkConnectors().get(0).activeBridges().toArray()[0];
    assertTrue("No extra, size:" + bridge.getLocalSubscriptionMap().size(), Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("local subs map size = " + bridge.getLocalSubscriptionMap().size());
            return 0 == bridge.getLocalSubscriptionMap().size();
        }
    }));
}

99. MqttBrokerPublisher#startBroker()

View license
public static void startBroker() throws Exception {
    LOG.info("Starting broker...");
    broker = new BrokerService();
    broker.addConnector("mqtt://localhost:1883");
    broker.setDataDirectory("target");
    broker.start();
    LOG.info("MQTT broker started");
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            try {
                LOG.info("Shutting down MQTT broker...");
                broker.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

100. JMSTestBase#startJMSService()

Project: apex-malhar
Source File: JMSTestBase.java
View license
/**
   * Start JMS broker from the Testcase.
   *
   * @throws Exception
   */
private void startJMSService() throws Exception {
    broker = new BrokerService();
    String brokerName = "ActiveMQOutputOperator-broker";
    broker.setBrokerName(brokerName);
    broker.getPersistenceAdapter().setDirectory(new File("target/activemq-data/" + broker.getBrokerName() + '/' + org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter.class.getSimpleName()).getAbsoluteFile());
    broker.addConnector("tcp://localhost:61617?broker.persistent=false");
    // 1GB
    broker.getSystemUsage().getStoreUsage().setLimit(1024 * 1024 * 1024);
    // 100MB
    broker.getSystemUsage().getTempUsage().setLimit(100 * 1024 * 1024);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.start();
}