Here are the examples of the java api class org.apache.activemq.ActiveMQConnectionFactory taken from open source projects.
1. NetworkLoadTest#createConnection()
Project: activemq-artemis
File: NetworkLoadTest.java
File: NetworkLoadTest.java
protected Connection createConnection(int brokerId) throws JMSException { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:" + (60000 + brokerId)); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setCopyMessageOnSend(false); connectionFactory.setUseCompression(false); connectionFactory.setDispatchAsync(true); connectionFactory.setUseAsyncSend(false); connectionFactory.setOptimizeAcknowledge(false); connectionFactory.setWatchTopicAdvisories(false); ActiveMQPrefetchPolicy qPrefetchPolicy = new ActiveMQPrefetchPolicy(); qPrefetchPolicy.setQueuePrefetch(100); qPrefetchPolicy.setTopicPrefetch(1000); connectionFactory.setPrefetchPolicy(qPrefetchPolicy); connectionFactory.setAlwaysSyncSend(true); return connectionFactory.createConnection(); }
2. NetworkBrokerDetachTest#createConnectionFactory()
Project: activemq-artemis
File: NetworkBrokerDetachTest.java
File: NetworkBrokerDetachTest.java
protected ConnectionFactory createConnectionFactory(final BrokerService broker) throws Exception { String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setCopyMessageOnSend(false); connectionFactory.setUseCompression(false); connectionFactory.setDispatchAsync(false); connectionFactory.setUseAsyncSend(false); connectionFactory.setOptimizeAcknowledge(false); connectionFactory.setWatchTopicAdvisories(true); ActiveMQPrefetchPolicy qPrefetchPolicy = new ActiveMQPrefetchPolicy(); qPrefetchPolicy.setQueuePrefetch(100); qPrefetchPolicy.setTopicPrefetch(1000); connectionFactory.setPrefetchPolicy(qPrefetchPolicy); connectionFactory.setAlwaysSyncSend(true); return connectionFactory; }
3. CamelJmsTestHelper#createConnectionFactory()
Project: camel
File: CamelJmsTestHelper.java
File: CamelJmsTestHelper.java
public static ConnectionFactory createConnectionFactory(String options) { // using a unique broker name improves testing when running the entire test suite in the same JVM int id = counter.incrementAndGet(); String url = "vm://test-broker-" + id + "?broker.persistent=false&broker.useJmx=false"; if (options != null) { url = url + "&" + options; } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); // optimize AMQ to be as fast as possible so unit testing is quicker connectionFactory.setCopyMessageOnSend(false); connectionFactory.setOptimizeAcknowledge(true); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setTrustAllPackages(true); // When using asyncSend, producers will not be guaranteed to send in the order we // have in the tests (which may be confusing for queues) so we need this set to false. // Another way of guaranteeing order is to use persistent messages or transactions. connectionFactory.setUseAsyncSend(false); connectionFactory.setAlwaysSessionAsync(false); // use a pooled connection factory PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory); pooled.setMaxConnections(8); return pooled; }
4. CamelJmsTestHelper#createConnectionFactory()
Project: camel
File: CamelJmsTestHelper.java
File: CamelJmsTestHelper.java
public static ConnectionFactory createConnectionFactory(String options, Integer maximumRedeliveries) { // using a unique broker name improves testing when running the entire test suite in the same JVM int id = counter.incrementAndGet(); String url = "vm://test-broker-" + id + "?broker.persistent=false&broker.useJmx=false"; if (options != null) { url = url + "&" + options; } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); // optimize AMQ to be as fast as possible so unit testing is quicker connectionFactory.setCopyMessageOnSend(false); connectionFactory.setOptimizeAcknowledge(true); connectionFactory.setOptimizedMessageDispatch(true); // When using asyncSend, producers will not be guaranteed to send in the order we // have in the tests (which may be confusing for queues) so we need this set to false. // Another way of guaranteeing order is to use persistent messages or transactions. connectionFactory.setUseAsyncSend(false); connectionFactory.setAlwaysSessionAsync(false); if (maximumRedeliveries != null) { connectionFactory.getRedeliveryPolicy().setMaximumRedeliveries(maximumRedeliveries); } connectionFactory.setTrustAllPackages(true); return connectionFactory; }
5. CamelJmsTestHelper#createConnectionFactory()
Project: camel
File: CamelJmsTestHelper.java
File: CamelJmsTestHelper.java
public static ConnectionFactory createConnectionFactory(String options) { // using a unique broker name improves testing when running the entire test suite in the same JVM int id = counter.incrementAndGet(); String url = "vm://test-broker-" + id + "?broker.persistent=false&broker.useJmx=false"; if (options != null) { url = url + "&" + options; } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); // optimize AMQ to be as fast as possible so unit testing is quicker connectionFactory.setCopyMessageOnSend(false); connectionFactory.setOptimizeAcknowledge(true); connectionFactory.setOptimizedMessageDispatch(true); // When using asyncSend, producers will not be guaranteed to send in the order we // have in the tests (which may be confusing for queues) so we need this set to false. // Another way of guaranteeing order is to use persistent messages or transactions. connectionFactory.setUseAsyncSend(false); connectionFactory.setAlwaysSessionAsync(false); // use a pooled connection factory PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory); pooled.setMaxConnections(8); return pooled; }
6. CamelJmsTestHelper#createPersistentConnectionFactory()
Project: camel
File: CamelJmsTestHelper.java
File: CamelJmsTestHelper.java
public static ConnectionFactory createPersistentConnectionFactory(String options) { // using a unique broker name improves testing when running the entire test suite in the same JVM int id = counter.incrementAndGet(); // use an unique data directory in target String dir = "target/activemq-data-" + id; // remove dir so its empty on startup FileUtil.removeDir(new File(dir)); String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir; if (options != null) { url = url + "&" + options; } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); // optimize AMQ to be as fast as possible so unit testing is quicker connectionFactory.setCopyMessageOnSend(false); connectionFactory.setOptimizeAcknowledge(true); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setAlwaysSessionAsync(false); connectionFactory.setTrustAllPackages(true); return connectionFactory; }
7. BusConnection#createFactory()
Project: freedomotic
File: BusConnection.java
File: BusConnection.java
private ActiveMQConnectionFactory createFactory() { // connect to the embedded broker defined above String P2P_BROKER_URL = config.getStringProperty("BROKER_PROTOCOL", Info.MESSAGING.BROKER_DEFAULT_PROTOCOL) + "://" + config.getStringProperty("P2P_CLUSTER_NAME", Info.MESSAGING.BROKER_DEFAULT_CLUSTER_NAME) + "/" + Info.MESSAGING.BROKER_DEFAULT_UUID; LOG.info("P2P Connection on " + P2P_BROKER_URL); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(P2P_BROKER_URL); // tuned for performances // http://activemq.apache.org/performance-tuning.html factory.setUseAsyncSend(true); factory.setAlwaysSessionAsync(true); factory.setObjectMessageSerializationDefered(true); factory.setCopyMessageOnSend(false); return factory; }
8. CompressionOverNetworkTest#doSetUp()
Project: activemq-artemis
File: CompressionOverNetworkTest.java
File: CompressionOverNetworkTest.java
protected void doSetUp(boolean deleteAllMessages) throws Exception { localBroker = createLocalBroker(); localBroker.setDeleteAllMessagesOnStartup(deleteAllMessages); localBroker.start(); localBroker.waitUntilStarted(); remoteBroker = createRemoteBroker(); remoteBroker.setDeleteAllMessagesOnStartup(deleteAllMessages); remoteBroker.start(); remoteBroker.waitUntilStarted(); URI localURI = localBroker.getVmConnectorURI(); ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(localURI); fac.setAlwaysSyncSend(true); fac.setDispatchAsync(false); localConnection = fac.createConnection(); localConnection.setClientID("clientId"); localConnection.start(); URI remoteURI = remoteBroker.getVmConnectorURI(); fac = new ActiveMQConnectionFactory(remoteURI); remoteConnection = fac.createConnection(); remoteConnection.setClientID("clientId"); remoteConnection.start(); included = new ActiveMQTopic("include.test.bar"); localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
9. MessageCompressionTest#testObjectMessageCompression()
Project: activemq-artemis
File: MessageCompressionTest.java
File: MessageCompressionTest.java
public void testObjectMessageCompression() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(true); sendTestObjectMessage(factory, TEXT); ActiveMQObjectMessage objectMessage = receiveTestObjectMessage(factory); int compressedSize = objectMessage.getContent().getLength(); assertTrue(objectMessage.isCompressed()); Object objectVal = objectMessage.getObject(); assertEquals(TEXT, objectVal); factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(false); sendTestObjectMessage(factory, TEXT); objectMessage = receiveTestObjectMessage(factory); int unCompressedSize = objectMessage.getContent().getLength(); assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize); }
10. MessageCompressionTest#testBytesMessageCompression()
Project: activemq-artemis
File: MessageCompressionTest.java
File: MessageCompressionTest.java
public void testBytesMessageCompression() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(true); sendTestBytesMessage(factory, TEXT); ActiveMQBytesMessage message = receiveTestBytesMessage(factory); int compressedSize = message.getContent().getLength(); byte[] bytes = new byte[TEXT.getBytes(StandardCharsets.UTF_8).length]; message.readBytes(bytes); assertTrue(message.readBytes(new byte[255]) == -1); String rcvString = new String(bytes, StandardCharsets.UTF_8); assertEquals(TEXT, rcvString); assertTrue(message.isCompressed()); factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(false); sendTestBytesMessage(factory, TEXT); message = receiveTestBytesMessage(factory); int unCompressedSize = message.getContent().getLength(); assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize); }
11. MessageCompressionTest#testTextMessageCompression()
Project: activemq-artemis
File: MessageCompressionTest.java
File: MessageCompressionTest.java
public void testTextMessageCompression() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(true); sendTestMessage(factory, TEXT); ActiveMQTextMessage message = receiveTestMessage(factory); int compressedSize = message.getContent().getLength(); factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(false); sendTestMessage(factory, TEXT); message = receiveTestMessage(factory); int unCompressedSize = message.getContent().getLength(); assertEquals(TEXT, message.getText()); assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize); }
12. TwoBrokerQueueClientsReconnectTest#setUp()
Project: activemq-artemis
File: TwoBrokerQueueClientsReconnectTest.java
File: TwoBrokerQueueClientsReconnectTest.java
@Override public void setUp() throws Exception { super.setAutoFail(true); super.setUp(); createBroker(new URI("broker:(tcp://localhost:61616)/BrokerA?persistent=false&useJmx=true")); createBroker(new URI("broker:(tcp://localhost:61617)/BrokerB?persistent=false&useJmx=true")); // Configure broker connection factory ActiveMQConnectionFactory factoryA; ActiveMQConnectionFactory factoryB; factoryA = (ActiveMQConnectionFactory) getConnectionFactory("BrokerA"); factoryB = (ActiveMQConnectionFactory) getConnectionFactory("BrokerB"); // Set prefetch policy ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy(); policy.setAll(PREFETCH_COUNT); factoryA.setPrefetchPolicy(policy); factoryB.setPrefetchPolicy(policy); msgsClient1 = 0; msgsClient2 = 0; }
13. NetworkRestartTest#doSetUp()
Project: activemq-artemis
File: NetworkRestartTest.java
File: NetworkRestartTest.java
protected void doSetUp() throws Exception { remoteBroker = createRemoteBroker(); remoteBroker.start(); remoteBroker.waitUntilStarted(); localBroker = createLocalBroker(); localBroker.start(); localBroker.waitUntilStarted(); String localURI = "tcp://localhost:61616"; String remoteURI = "tcp://localhost:61617"; ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(localURI); localConnection = fac.createConnection(); localConnection.setClientID("local"); localConnection.start(); fac = new ActiveMQConnectionFactory(remoteURI); fac.setWatchTopicAdvisories(false); remoteConnection = fac.createConnection(); remoteConnection.setClientID("remote"); remoteConnection.start(); localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
14. MessageQueueTest#createConnection()
Project: communote-server
File: MessageQueueTest.java
File: MessageQueueTest.java
/** * Method to setup the message queue. * * @param url * Url the connector should connect to. * @param messageQueueLogin * Login of the MQ user. * @param messageQueuePassword * Password of the MQ user. * @throws Exception * exception. */ private void createConnection(String url, String messageQueueLogin, String messageQueuePassword) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url); factory.setClientID(new Date() + ""); if (messageQueueLogin != null && messageQueueLogin.trim().length() > 0 && messageQueuePassword != null && messageQueuePassword.trim().length() > 0) { connection = factory.createConnection(messageQueueLogin, messageQueuePassword); } else { connection = factory.createConnection(); } connection.start(); }
15. JmsTransactionEndpointTest#createCamelContext()
Project: camel-cookbook-examples
File: JmsTransactionEndpointTest.java
File: JmsTransactionEndpointTest.java
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(broker.getTcpConnectorUri()); registry.put("connectionFactory", connectionFactory); CamelContext camelContext = new DefaultCamelContext(registry); ActiveMQComponent activeMQComponent = new ActiveMQComponent(); activeMQComponent.setConnectionFactory(connectionFactory); camelContext.addComponent("jms", activeMQComponent); return camelContext; }
16. SjmsBatchEndpointTest#createCamelContext()
Project: camel
File: SjmsBatchEndpointTest.java
File: SjmsBatchEndpointTest.java
@Override protected CamelContext createCamelContext() throws Exception { SimpleRegistry registry = new SimpleRegistry(); registry.put("aggStrategy", AggregationStrategies.groupedExchange()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); connectionFactory.setBrokerURL(broker.getTcpConnectorUri()); SjmsComponent sjmsComponent = new SjmsComponent(); sjmsComponent.setConnectionFactory(connectionFactory); SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent(); sjmsBatchComponent.setConnectionFactory(connectionFactory); CamelContext context = new DefaultCamelContext(registry); context.addComponent("sjms-batch", sjmsBatchComponent); context.addComponent("sjms", sjmsComponent); return context; }
17. ActiveMQMessageGenerator#setupConnection()
Project: apex-malhar
File: ActiveMQMessageGenerator.java
File: ActiveMQMessageGenerator.java
/** * Setup connection, producer, consumer so on. * * @throws JMSException */ public void setupConnection() throws JMSException { // Create connection ActiveMQConnectionFactory connectionFactory; connectionFactory = new ActiveMQConnectionFactory(user, password, url); connection = connectionFactory.createConnection(); connection.start(); // Create session session = connection.createSession(transacted, ackMode); // Create destination destination = topic ? session.createTopic(subject) : session.createQueue(subject); // Create producer producer = session.createProducer(destination); }
18. ActiveMQMessageListener#setupConnection()
Project: apex-malhar
File: ActiveMQMessageListener.java
File: ActiveMQMessageListener.java
public void setupConnection() throws JMSException { // Create connection ActiveMQConnectionFactory connectionFactory; connectionFactory = new ActiveMQConnectionFactory(user, password, url); connection = connectionFactory.createConnection(); connection.start(); // Create session session = connection.createSession(transacted, ackMode); // Create destination destination = topic ? session.createTopic(subject) : session.createQueue(subject); // Create consumer consumer = (durable && topic) ? session.createDurableSubscriber((Topic) destination, consumerName) : session.createConsumer(destination); consumer.setMessageListener(this); }
19. SimpleOpenWireTest#testProducerFlowControl()
Project: activemq-artemis
File: SimpleOpenWireTest.java
File: SimpleOpenWireTest.java
@Test public void testProducerFlowControl() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlString); factory.setProducerWindowSize(1024 * 64); Connection connection = factory.createConnection(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); producer.send(session.createTextMessage("test")); connection.close(); }
20. TopicSubscriptionZeroPrefetchTest#setUp()
Project: activemq-artemis
File: TopicSubscriptionZeroPrefetchTest.java
File: TopicSubscriptionZeroPrefetchTest.java
@Before public void setUp() throws Exception { brokerService = createBroker(); ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost"); activeMQConnectionFactory.setWatchTopicAdvisories(true); connection = activeMQConnectionFactory.createConnection(); connection.setClientID("ClientID-1"); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = new ActiveMQTopic(TOPIC_NAME); producer = session.createProducer(destination); connection.start(); }
21. TopicSubscriptionSlowConsumerTest#setUp()
Project: activemq-artemis
File: TopicSubscriptionSlowConsumerTest.java
File: TopicSubscriptionSlowConsumerTest.java
@Override public void setUp() throws Exception { brokerService = createBroker(); ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost"); activeMQConnectionFactory.setWatchTopicAdvisories(true); connection = activeMQConnectionFactory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = new ActiveMQTopic(TOPIC_NAME); producer = session.createProducer(destination); connection.start(); }
22. MessageListenerDeadLetterTest#createConnectionFactory()
Project: activemq-artemis
File: MessageListenerDeadLetterTest.java
File: MessageListenerDeadLetterTest.java
@Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { ActiveMQConnectionFactory answer = super.createConnectionFactory(); RedeliveryPolicy policy = new RedeliveryPolicy(); policy.setMaximumRedeliveries(3); policy.setBackOffMultiplier((short) 1); policy.setRedeliveryDelay(0); policy.setInitialRedeliveryDelay(0); policy.setUseExponentialBackOff(false); answer.setRedeliveryPolicy(policy); return answer; }
23. BrokerXmlConfigTest#createConnectionFactory()
Project: activemq-artemis
File: BrokerXmlConfigTest.java
File: BrokerXmlConfigTest.java
@Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { // START SNIPPET: bean // configure the connection factory using // normal Java Bean property methods ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); // configure the embedded broker using an XML config file // which is either a URL or a resource on the classpath // TODO ... //connectionFactory.setBrokerXmlConfig("file:src/sample-conf/default.xml"); // you only need to configure the broker URL if you wish to change the // default connection mechanism, which in this test case we do connectionFactory.setBrokerURL("vm://localhost"); // END SNIPPET: bean return connectionFactory; }
24. JmsAutoConfigurationTests#testActiveMQOverriddenPoolAndRemoteServer()
Project: spring-boot
File: JmsAutoConfigurationTests.java
File: JmsAutoConfigurationTests.java
@Test public void testActiveMQOverriddenPoolAndRemoteServer() { load(TestConfiguration.class, "spring.activemq.pool.enabled:true", "spring.activemq.brokerUrl:tcp://remote-host:10000"); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class); assertThat(jmsTemplate).isNotNull(); assertThat(pool).isNotNull(); assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory()); ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory(); assertThat(factory.getBrokerURL()).isEqualTo("tcp://remote-host:10000"); }
25. JmsAutoConfigurationTests#testActiveMQOverriddenPoolAndStandalone()
Project: spring-boot
File: JmsAutoConfigurationTests.java
File: JmsAutoConfigurationTests.java
@Test public void testActiveMQOverriddenPoolAndStandalone() { load(TestConfiguration.class, "spring.activemq.pool.enabled:true", "spring.activemq.inMemory:false"); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class); assertThat(jmsTemplate).isNotNull(); assertThat(pool).isNotNull(); assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory()); ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory(); assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_NETWORK_URL); }
26. JmsAutoConfigurationTests#testActiveMQOverriddenPool()
Project: spring-boot
File: JmsAutoConfigurationTests.java
File: JmsAutoConfigurationTests.java
@Test public void testActiveMQOverriddenPool() { load(TestConfiguration.class, "spring.activemq.pool.enabled:true"); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); PooledConnectionFactory pool = this.context.getBean(PooledConnectionFactory.class); assertThat(jmsTemplate).isNotNull(); assertThat(pool).isNotNull(); assertThat(pool).isEqualTo(jmsTemplate.getConnectionFactory()); ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) pool.getConnectionFactory(); assertThat(factory.getBrokerURL()).isEqualTo(ACTIVEMQ_EMBEDDED_URL); }
27. JmsAutoConfigurationTests#testActiveMQOverriddenRemoteHost()
Project: spring-boot
File: JmsAutoConfigurationTests.java
File: JmsAutoConfigurationTests.java
@Test public void testActiveMQOverriddenRemoteHost() { load(TestConfiguration.class, "spring.activemq.brokerUrl:tcp://remote-host:10000"); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class); assertThat(jmsTemplate).isNotNull(); assertThat(connectionFactory).isNotNull(); assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory()); assertThat(((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL()).isEqualTo("tcp://remote-host:10000"); }
28. JmsAutoConfigurationTests#testActiveMQOverriddenStandalone()
Project: spring-boot
File: JmsAutoConfigurationTests.java
File: JmsAutoConfigurationTests.java
@Test public void testActiveMQOverriddenStandalone() { load(TestConfiguration.class, "spring.activemq.inMemory:false"); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class); assertThat(jmsTemplate).isNotNull(); assertThat(connectionFactory).isNotNull(); assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory()); assertThat(((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL()).isEqualTo(ACTIVEMQ_NETWORK_URL); }
29. JmsAutoConfigurationTests#testDefaultJmsConfiguration()
Project: spring-boot
File: JmsAutoConfigurationTests.java
File: JmsAutoConfigurationTests.java
@Test public void testDefaultJmsConfiguration() { load(TestConfiguration.class); ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); JmsMessagingTemplate messagingTemplate = this.context.getBean(JmsMessagingTemplate.class); assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory()); assertThat(messagingTemplate.getJmsTemplate()).isEqualTo(jmsTemplate); assertThat(((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL()).isEqualTo(ACTIVEMQ_EMBEDDED_URL); assertThat(this.context.containsBean("jmsListenerContainerFactory")).isTrue(); }
30. IgniteJmsStreamerTest#beforeTest()
Project: ignite
File: IgniteJmsStreamerTest.java
File: IgniteJmsStreamerTest.java
@Before @SuppressWarnings("unchecked") public void beforeTest() throws Exception { grid().<Integer, String>getOrCreateCache(defaultCacheConfiguration()); broker = new BrokerService(); broker.setDeleteAllMessagesOnStartup(true); broker.setPersistent(false); broker.setPersistenceAdapter(null); broker.setPersistenceFactory(null); PolicyMap policyMap = new PolicyMap(); PolicyEntry policy = new PolicyEntry(); policy.setQueuePrefetch(1); broker.setDestinationPolicy(policyMap); broker.getDestinationPolicy().setDefaultEntry(policy); broker.setSchedulerSupport(false); broker.start(true); connectionFactory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI()); }
31. TransactedTopicProducerTest#createCamelContext()
Project: camel
File: TransactedTopicProducerTest.java
File: TransactedTopicProducerTest.java
/* * @see org.apache.camel.test.junit4.CamelTestSupport#createCamelContext() * @return * @throws Exception */ @Override protected CamelContext createCamelContext() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false"); ConnectionFactoryResource connectionResource = new ConnectionFactoryResource(); connectionResource.setConnectionFactory(connectionFactory); connectionResource.setClientId("test-connection-1"); CamelContext camelContext = super.createCamelContext(); SjmsComponent component = new SjmsComponent(); component.setConnectionResource(connectionResource); component.setConnectionCount(1); camelContext.addComponent("sjms", component); return camelContext; }
32. TransactedConsumerSupport#createCamelContext()
Project: camel
File: TransactedConsumerSupport.java
File: TransactedConsumerSupport.java
@Override protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(getBrokerUri()); // use low redelivery delay to speed connectionFactory.getRedeliveryPolicy().setInitialRedeliveryDelay(100); connectionFactory.getRedeliveryPolicy().setRedeliveryDelay(100); connectionFactory.getRedeliveryPolicy().setUseCollisionAvoidance(false); connectionFactory.getRedeliveryPolicy().setUseExponentialBackOff(false); SjmsComponent component = new SjmsComponent(); component.setConnectionFactory(connectionFactory); camelContext.addComponent("sjms", component); return camelContext; }
33. JmsTestSupport#createCamelContext()
Project: camel
File: JmsTestSupport.java
File: JmsTestSupport.java
/* * @see org.apache.camel.test.junit4.CamelTestSupport#createCamelContext() * @return * @throws Exception */ @Override protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUri); connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); SjmsComponent component = new SjmsComponent(); component.setConnectionCount(1); component.setConnectionFactory(connectionFactory); camelContext.addComponent("sjms", component); return camelContext; }
34. InOnlyTopicDurableConsumerTest#createCamelContext()
Project: camel
File: InOnlyTopicDurableConsumerTest.java
File: InOnlyTopicDurableConsumerTest.java
/* * @see org.apache.camel.test.junit4.CamelTestSupport#createCamelContext() * * @return * @throws Exception */ @Override protected CamelContext createCamelContext() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URI); ConnectionFactoryResource connectionResource = new ConnectionFactoryResource(); connectionResource.setConnectionFactory(connectionFactory); connectionResource.setClientId(CONNECTION_ID); CamelContext camelContext = super.createCamelContext(); SjmsComponent component = new SjmsComponent(); component.setConnectionResource(connectionResource); component.setConnectionCount(1); camelContext.addComponent("sjms", component); return camelContext; }
35. AsyncConsumerInOutTest#createCamelContext()
Project: camel
File: AsyncConsumerInOutTest.java
File: AsyncConsumerInOutTest.java
protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); camelContext.addComponent("async", new MyAsyncComponent()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false"); SjmsComponent component = new SjmsComponent(); component.setConnectionFactory(connectionFactory); camelContext.addComponent("sjms", component); return camelContext; }
36. AsyncConsumerFalseTest#createCamelContext()
Project: camel
File: AsyncConsumerFalseTest.java
File: AsyncConsumerFalseTest.java
protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); camelContext.addComponent("async", new MyAsyncComponent()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false"); SjmsComponent component = new SjmsComponent(); component.setConnectionFactory(connectionFactory); camelContext.addComponent("sjms", component); return camelContext; }
37. TestBrokerService#createAndStartBroker()
Project: c2mon
File: TestBrokerService.java
File: TestBrokerService.java
/** * Creates and starts the broker. Also sets the following system * properties for use in tests: * * jms.broker.url * jms.client.user * jms.client.password * * @throws Exception if problem starting the broker */ public static void createAndStartBroker() throws Exception { broker = new BrokerService(); broker.setPersistent(false); broker.setUseShutdownHook(false); broker.setUseJmx(false); broker.start(); c = new ActiveMQConnectionFactory(); c.setObjectMessageSerializationDefered(true); c.setBrokerURL("vm://localhost"); c.setCopyMessageOnSend(false); //reset the system properties so the connection is made to this broker System.setProperty("c2mon.client.jms.url", "vm://localhost"); System.setProperty("c2mon.client.jms.user", ""); System.setProperty("c2mon.client.jms.password", ""); }
38. JMSObjectInputOperatorTest#produceMsg()
Project: apex-malhar
File: JMSObjectInputOperatorTest.java
File: JMSObjectInputOperatorTest.java
private void produceMsg() throws Exception { // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); // Create a Connection testMeta.connection = connectionFactory.createConnection(); testMeta.connection.start(); // Create a Session testMeta.session = testMeta.connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = testMeta.session.createQueue("TEST.FOO"); // Create a MessageProducer from the Session to the Topic or Queue testMeta.producer = testMeta.session.createProducer(destination); testMeta.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); }
39. ConnectorXBeanConfigTest#testForceBrokerRestart()
Project: activemq-artemis
File: ConnectorXBeanConfigTest.java
File: ConnectorXBeanConfigTest.java
public void testForceBrokerRestart() throws Exception { brokerService.stop(); brokerService.waitUntilStopped(); // force restart brokerService.start(true); brokerService.waitUntilStarted(); LOG.info("try and connect to restarted broker"); //send and receive a message from a restarted broker ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61636"); Connection conn = factory.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Destination dest = new ActiveMQQueue("test"); MessageConsumer consumer = sess.createConsumer(dest); MessageProducer producer = sess.createProducer(dest); producer.send(sess.createTextMessage("test")); TextMessage msg = (TextMessage) consumer.receive(1000); assertEquals("test", msg.getText()); }
40. TopicDurableConnectStatsTest#createConnectionFactory()
Project: activemq-artemis
File: TopicDurableConnectStatsTest.java
File: TopicDurableConnectStatsTest.java
@Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { connectionFactory = new ActiveMQConnectionFactory("vm://" + getName(true)); ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); prefetchPolicy.setAll(10); connectionFactory.setPrefetchPolicy(prefetchPolicy); connectionFactory.setWatchTopicAdvisories(false); return connectionFactory; }
41. QueueBrowsingTest#startBroker()
Project: activemq-artemis
File: QueueBrowsingTest.java
File: QueueBrowsingTest.java
@Before public void startBroker() throws Exception { broker = createBroker(); TransportConnector connector = broker.addConnector("tcp://0.0.0.0:0"); broker.deleteAllMessages(); broker.start(); broker.waitUntilStarted(); PolicyEntry policy = new PolicyEntry(); policy.setMaxPageSize(maxPageSize); broker.setDestinationPolicy(new PolicyMap()); broker.getDestinationPolicy().setDefaultEntry(policy); connectUri = connector.getConnectUri(); factory = new ActiveMQConnectionFactory(connectUri); }
42. QueueBrowsingLimitTest#startBroker()
Project: activemq-artemis
File: QueueBrowsingLimitTest.java
File: QueueBrowsingLimitTest.java
@Before public void startBroker() throws Exception { broker = createBroker(); TransportConnector connector = broker.addConnector("tcp://0.0.0.0:0"); broker.deleteAllMessages(); broker.start(); broker.waitUntilStarted(); PolicyEntry policy = new PolicyEntry(); policy.setMaxBrowsePageSize(browserLimit); broker.setDestinationPolicy(new PolicyMap()); broker.getDestinationPolicy().setDefaultEntry(policy); connectUri = connector.getConnectUri(); factory = new ActiveMQConnectionFactory(connectUri); }
43. NonBlockingConsumerRedeliveryTest#startBroker()
Project: activemq-artemis
File: NonBlockingConsumerRedeliveryTest.java
File: NonBlockingConsumerRedeliveryTest.java
@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); }
44. JMXRemoveQueueThenSendIgnoredTest#setUp()
Project: activemq-artemis
File: JMXRemoveQueueThenSendIgnoredTest.java
File: JMXRemoveQueueThenSendIgnoredTest.java
@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(); }
45. DurableSubscriptionHangTestCase#collectMessagesFromDurableSubscriptionForOneMinute()
Project: activemq-artemis
File: DurableSubscriptionHangTestCase.java
File: DurableSubscriptionHangTestCase.java
private Message collectMessagesFromDurableSubscriptionForOneMinute() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName); TopicConnection connection = connectionFactory.createTopicConnection(); connection.setClientID(clientID); TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = topicSession.createTopic(topicName); connection.start(); TopicSubscriber subscriber = topicSession.createDurableSubscriber(topic, durableSubName); LOG.info("About to receive messages"); Message message = subscriber.receive(120000); subscriber.close(); connection.close(); LOG.info("collectMessagesFromDurableSubscriptionForOneMinute done"); return message; }
46. DurableSubscriptionHangTestCase#registerDurableSubscription()
Project: activemq-artemis
File: DurableSubscriptionHangTestCase.java
File: DurableSubscriptionHangTestCase.java
private void registerDurableSubscription() throws JMSException { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName); TopicConnection connection = connectionFactory.createTopicConnection(); connection.setClientID(clientID); TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = topicSession.createTopic(topicName); TopicSubscriber durableSubscriber = topicSession.createDurableSubscriber(topic, durableSubName); connection.start(); durableSubscriber.close(); connection.close(); LOG.info("Durable Sub Registered"); }
47. DurableSubscriptionHangTestCase#produceExpiredAndOneNonExpiredMessages()
Project: activemq-artemis
File: DurableSubscriptionHangTestCase.java
File: DurableSubscriptionHangTestCase.java
private void produceExpiredAndOneNonExpiredMessages() throws JMSException { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName); TopicConnection connection = connectionFactory.createTopicConnection(); TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); producer.setTimeToLive(TimeUnit.SECONDS.toMillis(1)); for (int i = 0; i < 40000; i++) { sendRandomMessage(session, producer); } producer.setTimeToLive(TimeUnit.DAYS.toMillis(1)); sendRandomMessage(session, producer); connection.close(); LOG.info("produceExpiredAndOneNonExpiredMessages done"); }
48. DispatchMultipleConsumersTest#startConsumers()
Project: activemq-artemis
File: DispatchMultipleConsumersTest.java
File: DispatchMultipleConsumersTest.java
private void startConsumers() { ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory(userName, password, brokerURL); Connection conn; try { conn = connFactory.createConnection(); conn.start(); for (int i = 0; i < consumerCount; i++) { new ConsumerThread(conn, "ConsumerThread" + i); } } catch (JMSException e) { logger.error("Failed to start consumers", e); } }
49. ConsumeUncompressedCompressedMessageTest#setUp()
Project: activemq-artemis
File: ConsumeUncompressedCompressedMessageTest.java
File: ConsumeUncompressedCompressedMessageTest.java
@Before public void setUp() throws Exception { broker = createBroker(); broker.start(); broker.waitUntilStarted(); factory = new ActiveMQConnectionFactory(tcpUri); factory.setUseCompression(true); connection = (ActiveMQConnection) factory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue("CompressionTestQueue"); }
50. NIOSSLLoadTest#setUp()
Project: activemq-artemis
File: NIOSSLLoadTest.java
File: NIOSSLLoadTest.java
@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(); }
51. NIOSSLBasicTest#basicSendReceive()
Project: activemq-artemis
File: NIOSSLBasicTest.java
File: NIOSSLBasicTest.java
public void basicSendReceive(String uri) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri); Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); String body = "hello world!"; Queue destination = session.createQueue("TEST"); MessageProducer producer = session.createProducer(destination); producer.send(session.createTextMessage(body)); MessageConsumer consumer = session.createConsumer(destination); Message received = consumer.receive(2000); TestCase.assertEquals(body, ((TextMessage) received).getText()); }
52. FanoutTest#assertMessagesReceived()
Project: activemq-artemis
File: FanoutTest.java
File: FanoutTest.java
protected void assertMessagesReceived(String brokerURL) throws Exception { ActiveMQConnectionFactory consumerFactory = new ActiveMQConnectionFactory(brokerURL); Connection consumerConnection = consumerFactory.createConnection(); consumerConnection.start(); Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = consumerSession.createConsumer(consumerSession.createQueue("TEST")); MessageIdList listener = new MessageIdList(); consumer.setMessageListener(listener); listener.waitForMessagesToArrive(messageCount); listener.assertMessagesReceived(messageCount); consumer.close(); consumerSession.close(); consumerConnection.close(); }
53. FailoverTransactionTest#testFailoverProducerCloseBeforeTransactionFailWhenDisabled()
Project: activemq-artemis
File: FailoverTransactionTest.java
File: FailoverTransactionTest.java
@Test public void testFailoverProducerCloseBeforeTransactionFailWhenDisabled() throws Exception { LOG.info(this + " running test testFailoverProducerCloseBeforeTransactionFailWhenDisabled"); startCleanBroker(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")?trackTransactionProducers=false"); configureConnectionFactory(cf); Connection connection = cf.createConnection(); connection.start(); Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(QUEUE_NAME); MessageConsumer consumer = session.createConsumer(destination); produceMessage(session, destination); // restart to force failover and connection state recovery before the commit broker.stop(); startBroker(); session.commit(); // without tracking producers, message will not be replayed on recovery Assert.assertNull("we got the message", consumer.receive(5000)); session.commit(); connection.close(); }
54. FailoverTransactionTest#testFailoverProducerCloseBeforeTransaction()
Project: activemq-artemis
File: FailoverTransactionTest.java
File: FailoverTransactionTest.java
@Test public void testFailoverProducerCloseBeforeTransaction() throws Exception { LOG.info(this + " running test testFailoverProducerCloseBeforeTransaction"); startCleanBroker(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")"); configureConnectionFactory(cf); Connection connection = cf.createConnection(); connection.start(); Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(QUEUE_NAME); MessageConsumer consumer = session.createConsumer(destination); produceMessage(session, destination); // restart to force failover and connection state recovery before the commit broker.stop(); startBroker(); session.commit(); Assert.assertNotNull("we got the message", consumer.receive(20000)); session.commit(); connection.close(); }
55. FailoverTimeoutTest#testUpdateUris()
Project: activemq-artemis
File: FailoverTimeoutTest.java
File: FailoverTimeoutTest.java
@Test public void testUpdateUris() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri + ")?useExponentialBackOff=false"); ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); try { connection.start(); FailoverTransport failoverTransport = connection.getTransport().narrow(FailoverTransport.class); URI[] bunchOfUnknownAndOneKnown = new URI[] { new URI("tcp://unknownHost:" + tcpUri.getPort()), new URI("tcp://unknownHost2:" + tcpUri.getPort()), new URI("tcp://localhost:2222") }; failoverTransport.add(false, bunchOfUnknownAndOneKnown); } finally { if (connection != null) { connection.close(); } } }
56. FailoverRandomTest#testRandomConnections()
Project: activemq-artemis
File: FailoverRandomTest.java
File: FailoverRandomTest.java
@Test public void testRandomConnections() throws Exception { String failoverUrl = "failover:(" + newURI(0) + "," + newURI(1) + ")"; ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(failoverUrl); ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); connection.start(); final String brokerName1 = connection.getBrokerName(); Assert.assertNotNull(brokerName1); connection.close(); String brokerName2 = brokerName1; int attempts = 40; while (brokerName1.equals(brokerName2) && attempts-- > 0) { connection = (ActiveMQConnection) cf.createConnection(); connection.start(); brokerName2 = connection.getBrokerName(); Assert.assertNotNull(brokerName2); connection.close(); } Assert.assertTrue(brokerName1 + "!=" + brokerName2, !brokerName1.equals(brokerName2)); }
57. FailoverClusterTestSupport#createClients()
Project: activemq-artemis
File: FailoverClusterTestSupport.java
File: FailoverClusterTestSupport.java
@SuppressWarnings("unused") protected void createClients(int numOfClients) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(clientUrl); for (int i = 0; i < numOfClients; i++) { ActiveMQConnection c = (ActiveMQConnection) factory.createConnection(); c.start(); Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); connections.add(c); } }
58. FailoverClusterTest#createClients()
Project: activemq-artemis
File: FailoverClusterTest.java
File: FailoverClusterTest.java
protected void createClients() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(clientUrl); for (int i = 0; i < NUMBER; i++) { System.out.println("*****create connection using url: " + clientUrl); ActiveMQConnection c = (ActiveMQConnection) factory.createConnection(); System.out.println("got connection, starting it ..."); c.start(); System.out.println("******Started"); Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); MessageConsumer consumer = s.createConsumer(queue); connections.add(c); } }
59. AMQ1925Test#setUp()
Project: activemq-artemis
File: AMQ1925Test.java
File: AMQ1925Test.java
@Before public void setUp() throws Exception { exception = null; bs = createNewServer(); bs.start(); //auto created queue can't survive a restart, so we need this bs.getJMSServerManager().createQueue(false, QUEUE_NAME, null, true, QUEUE_NAME); tcpUri = new URI(newURI(0)); cf = new ActiveMQConnectionFactory("failover://(" + tcpUri + ")"); sendMessagesToQueue(); }
60. DiscoveryUriTest#testConnect()
Project: activemq-artemis
File: DiscoveryUriTest.java
File: DiscoveryUriTest.java
public void testConnect() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("discovery:(multicast://default?group=test)?reconnectDelay=1000&maxReconnectAttempts=30&useExponentialBackOff=false"); Connection conn = factory.createConnection(); conn.start(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = sess.createProducer(sess.createQueue("test")); producer.send(sess.createTextMessage("test")); MessageConsumer consumer = sess.createConsumer(sess.createQueue("test")); Message msg = consumer.receive(1000); assertNotNull(msg); }
61. LDAPSecurityTest#testTempDestinations()
Project: activemq-artemis
File: LDAPSecurityTest.java
File: LDAPSecurityTest.java
@Test public void testTempDestinations() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createTemporaryQueue(); MessageProducer producer = sess.createProducer(queue); MessageConsumer consumer = sess.createConsumer(queue); producer.send(sess.createTextMessage("test")); Message msg = consumer.receive(1000); assertNotNull(msg); }
62. LDAPSecurityTest#testCompositeSendDenied()
Project: activemq-artemis
File: LDAPSecurityTest.java
File: LDAPSecurityTest.java
@Test public void testCompositeSendDenied() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createQueue("TEST.FOO,ADMIN.FOO"); try { MessageProducer producer = sess.createProducer(queue); producer.send(sess.createTextMessage("test")); fail("expect auth exception"); } catch (JMSException expected) { } }
63. LDAPSecurityTest#testSendDenied()
Project: activemq-artemis
File: LDAPSecurityTest.java
File: LDAPSecurityTest.java
@Test public void testSendDenied() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createQueue("ADMIN.FOO"); try { MessageProducer producer = sess.createProducer(queue); producer.send(sess.createTextMessage("test")); fail("expect auth exception"); } catch (JMSException expected) { } }
64. LDAPSecurityTest#testSendTopic()
Project: activemq-artemis
File: LDAPSecurityTest.java
File: LDAPSecurityTest.java
@Test public void testSendTopic() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Destination topic = sess.createTopic("TEST.BAR"); MessageProducer producer = sess.createProducer(topic); MessageConsumer consumer = sess.createConsumer(topic); producer.send(sess.createTextMessage("test")); Message msg = consumer.receive(1000); assertNotNull(msg); }
65. LDAPSecurityTest#testSendReceive()
Project: activemq-artemis
File: LDAPSecurityTest.java
File: LDAPSecurityTest.java
@Test public void testSendReceive() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Destination queue = sess.createQueue("TEST.FOO"); MessageProducer producer = sess.createProducer(queue); MessageConsumer consumer = sess.createConsumer(queue); producer.send(sess.createTextMessage("test")); Message msg = consumer.receive(1000); assertNotNull(msg); }
66. LDAPAuthenticationTest#testWildcard()
Project: activemq-artemis
File: LDAPAuthenticationTest.java
File: LDAPAuthenticationTest.java
@Test public void testWildcard() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createQueueConnection("*", "sunflower"); try { conn.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (Exception e) { e.printStackTrace(); return; } fail("Should have failed connecting"); }
67. CachedLDAPSecurityLegacyTest#testTempDestinations()
Project: activemq-artemis
File: CachedLDAPSecurityLegacyTest.java
File: CachedLDAPSecurityLegacyTest.java
@Test public void testTempDestinations() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createTemporaryQueue(); MessageProducer producer = sess.createProducer(queue); MessageConsumer consumer = sess.createConsumer(queue); producer.send(sess.createTextMessage("test")); Message msg = consumer.receive(1000); assertNotNull(msg); }
68. CachedLDAPSecurityLegacyTest#testCompositeSendDenied()
Project: activemq-artemis
File: CachedLDAPSecurityLegacyTest.java
File: CachedLDAPSecurityLegacyTest.java
@Test public void testCompositeSendDenied() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createQueue("TEST.FOO,ADMIN.FOO"); try { sess.createProducer(queue); fail("expect auth exception"); } catch (JMSException expected) { } }
69. CachedLDAPSecurityLegacyTest#testSendDenied()
Project: activemq-artemis
File: CachedLDAPSecurityLegacyTest.java
File: CachedLDAPSecurityLegacyTest.java
@Test public void testSendDenied() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createQueue("ADMIN.FOO"); try { sess.createProducer(queue); fail("expect auth exception"); } catch (JMSException expected) { } }
70. CachedLDAPSecurityLegacyTest#testSendReceive()
Project: activemq-artemis
File: CachedLDAPSecurityLegacyTest.java
File: CachedLDAPSecurityLegacyTest.java
@Test public void testSendReceive() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); Connection conn = factory.createQueueConnection("jdoe", "sunflower"); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start(); Queue queue = sess.createQueue("TEST.FOO"); MessageProducer producer = sess.createProducer(queue); MessageConsumer consumer = sess.createConsumer(queue); producer.send(sess.createTextMessage("test")); Message msg = consumer.receive(1000); assertNotNull(msg); }
71. InactiveQueueTest#setUp()
Project: activemq-artemis
File: InactiveQueueTest.java
File: InactiveQueueTest.java
@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); }
72. InactiveDurableTopicTest#setUp()
Project: activemq-artemis
File: InactiveDurableTopicTest.java
File: InactiveDurableTopicTest.java
@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); }
73. TopicBridgeSpringTest#setUp()
Project: activemq-artemis
File: TopicBridgeSpringTest.java
File: TopicBridgeSpringTest.java
@Override protected void setUp() throws Exception { super.setUp(); context = createApplicationContext(); ActiveMQConnectionFactory fac = (ActiveMQConnectionFactory) context.getBean("localFactory"); localConnection = fac.createTopicConnection(); localConnection.start(); requestServerSession = localConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic theTopic = requestServerSession.createTopic(getClass().getName()); requestServerConsumer = requestServerSession.createConsumer(theTopic); requestServerConsumer.setMessageListener(this); requestServerProducer = requestServerSession.createProducer(null); fac = (ActiveMQConnectionFactory) context.getBean("remoteFactory"); remoteConnection = fac.createTopicConnection(); remoteConnection.start(); TopicSession session = remoteConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); requestor = new TopicRequestor(session, theTopic); }
74. InitialContextTest#testConnectionFactoryPolicyConfig()
Project: activemq-artemis
File: InitialContextTest.java
File: InitialContextTest.java
public void testConnectionFactoryPolicyConfig() throws Exception { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); properties.put(Context.PROVIDER_URL, "tcp://localhost:65432"); properties.put("prefetchPolicy.queuePrefetch", "777"); properties.put("redeliveryPolicy.maximumRedeliveries", "15"); properties.put("redeliveryPolicy.backOffMultiplier", "32"); InitialContext context = new InitialContext(properties); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory"); assertTrue("Should have created a ConnectionFactory", connectionFactory != null); assertEquals(777, connectionFactory.getPrefetchPolicy().getQueuePrefetch()); assertEquals(15, connectionFactory.getRedeliveryPolicy().getMaximumRedeliveries()); assertEquals(32d, connectionFactory.getRedeliveryPolicy().getBackOffMultiplier()); }
75. InitialContextTest#testUsingStandardJNDIKeys()
Project: activemq-artemis
File: InitialContextTest.java
File: InitialContextTest.java
public void testUsingStandardJNDIKeys() throws Exception { Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); String expected = "tcp://localhost:65432"; properties.put(Context.PROVIDER_URL, expected); InitialContext context = new InitialContext(properties); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory"); assertTrue("Should have created a ConnectionFactory", connectionFactory != null); assertEquals("the brokerURL should match", expected, connectionFactory.getBrokerURL()); }
76. ConfigUsingDestinationOptions#testValidSelectorConfig()
Project: activemq-artemis
File: ConfigUsingDestinationOptions.java
File: ConfigUsingDestinationOptions.java
public void testValidSelectorConfig() throws JMSException { ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test=1"); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost"); Connection conn = factory.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQMessageConsumer cons; // JMS selector should be priority cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test=2"); assertEquals("test=2", cons.getMessageSelector()); // Test setting using JMS destinations cons = (ActiveMQMessageConsumer) sess.createConsumer(queue); assertEquals("test=1", cons.getMessageSelector()); }
77. BrokerXmlConfigFromJNDITest#createConnectionFactory()
Project: activemq-artemis
File: BrokerXmlConfigFromJNDITest.java
File: BrokerXmlConfigFromJNDITest.java
@Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { assertBaseDirectoryContainsSpaces(); // we could put these properties into a jndi.properties // on the classpath instead Hashtable<String, String> properties = new Hashtable<>(); properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"); // configure the embedded broker using an XML config file // which is either a URL or a resource on the classpath File f = new File(System.getProperty("basedir", "."), "/src/test/resources/activemq.xml"); properties.put(Context.PROVIDER_URL, "vm://localhost?brokerConfig=xbean:" + f.toURI()); InitialContext context = new InitialContext(properties); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory"); // END SNIPPET: example return connectionFactory; }
78. BrokerPropertiesTest#testVmBrokerPropertiesFile()
Project: activemq-artemis
File: BrokerPropertiesTest.java
File: BrokerPropertiesTest.java
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(); }
79. SchedulerDBVersionTest#testCreateStore()
Project: activemq-artemis
File: SchedulerDBVersionTest.java
File: SchedulerDBVersionTest.java
@Ignore("Used only when a new version of the store needs to archive it's test data.") @Test public void testCreateStore() throws Exception { JobSchedulerStoreImpl scheduler = new JobSchedulerStoreImpl(); File dir = new File("src/test/resources/org/apache/activemq/store/schedulerDB/legacy"); IOHelper.deleteFile(dir); scheduler.setDirectory(dir); scheduler.setJournalMaxFileLength(1024 * 1024); broker = createBroker(scheduler); broker.start(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost"); Connection connection = cf.createConnection(); connection.start(); scheduleRepeating(connection); connection.close(); broker.stop(); }
80. KahaDBSchedulerMissingJournalLogsTest#fillUpSomeLogFiles()
Project: activemq-artemis
File: KahaDBSchedulerMissingJournalLogsTest.java
File: KahaDBSchedulerMissingJournalLogsTest.java
private void fillUpSomeLogFiles() throws Exception { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost"); Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("test.queue"); MessageProducer producer = session.createProducer(queue); connection.start(); while (true) { scheduleRepeating(session, producer); if (schedulerStore.getJournal().getFileMap().size() == NUM_LOGS) { break; } } connection.close(); }
81. QueuePurgeTest#setUp()
Project: activemq-artemis
File: QueuePurgeTest.java
File: QueuePurgeTest.java
@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(); }
82. QueueSubscriptionTest#doMultipleClientsTest()
Project: activemq-artemis
File: QueueSubscriptionTest.java
File: QueueSubscriptionTest.java
public void doMultipleClientsTest() throws Exception { // Create destination final ActiveMQDestination dest = createDestination(); // Create consumers ActiveMQConnectionFactory consumerFactory = (ActiveMQConnectionFactory) createConnectionFactory(); consumerFactory.getPrefetchPolicy().setAll(prefetchCount); startConsumers(consumerFactory, dest); startProducers(dest, messageCount); // Wait for messages to be received. Make it proportional to the // messages delivered. int totalMessageCount = messageCount * producerCount; if (dest.isTopic()) { totalMessageCount *= consumerCount; } waitForAllMessagesToBeReceived(totalMessageCount); }
83. ObjectFactoryTest#testConnectionFactory()
Project: activemq-artemis
File: ObjectFactoryTest.java
File: ObjectFactoryTest.java
public void testConnectionFactory() throws Exception { // Create sample connection factory ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); factory.setDispatchAsync(true); factory.setBrokerURL("vm://test"); factory.setClientID("test"); factory.setCopyMessageOnSend(false); factory.setDisableTimeStampsByDefault(true); factory.setObjectMessageSerializationDefered(true); factory.setOptimizedMessageDispatch(false); factory.setPassword("pass"); factory.setUseAsyncSend(true); factory.setUseCompression(true); factory.setUseRetroactiveConsumer(true); factory.setUserName("user"); factory.getPrefetchPolicy().setQueuePrefetch(777); factory.getRedeliveryPolicy().setMaximumRedeliveries(15); factory.getRedeliveryPolicy().setBackOffMultiplier((short) 32); // Create reference Reference ref = JNDIReferenceFactory.createReference(factory.getClass().getName(), factory); // Get object created based on reference ActiveMQConnectionFactory temp; JNDIReferenceFactory refFactory = new JNDIReferenceFactory(); temp = (ActiveMQConnectionFactory) refFactory.getObjectInstance(ref, null, null, null); // Check settings assertEquals(factory.isDispatchAsync(), temp.isDispatchAsync()); assertEquals(factory.getBrokerURL(), temp.getBrokerURL()); assertEquals(factory.getClientID(), temp.getClientID()); assertEquals(factory.isCopyMessageOnSend(), temp.isCopyMessageOnSend()); assertEquals(factory.isDisableTimeStampsByDefault(), temp.isDisableTimeStampsByDefault()); assertEquals(factory.isObjectMessageSerializationDefered(), temp.isObjectMessageSerializationDefered()); assertEquals(factory.isOptimizedMessageDispatch(), temp.isOptimizedMessageDispatch()); assertEquals(factory.getPassword(), temp.getPassword()); assertEquals(factory.isUseAsyncSend(), temp.isUseAsyncSend()); assertEquals(factory.isUseCompression(), temp.isUseCompression()); assertEquals(factory.isUseRetroactiveConsumer(), temp.isUseRetroactiveConsumer()); assertEquals(factory.getUserName(), temp.getUserName()); assertEquals(factory.getPrefetchPolicy().getQueuePrefetch(), temp.getPrefetchPolicy().getQueuePrefetch()); assertEquals(factory.getRedeliveryPolicy().getMaximumRedeliveries(), temp.getRedeliveryPolicy().getMaximumRedeliveries()); assertEquals(factory.getRedeliveryPolicy().getBackOffMultiplier(), temp.getRedeliveryPolicy().getBackOffMultiplier()); }
84. CamelJmsTestHelper#createPersistentConnectionFactory()
Project: camel
File: CamelJmsTestHelper.java
File: CamelJmsTestHelper.java
public static ConnectionFactory createPersistentConnectionFactory(String options) { // using a unique broker name improves testing when running the entire test suite in the same JVM int id = counter.incrementAndGet(); // use an unique data directory in target String dir = "target/activemq-data-" + id; // remove dir so its empty on startup FileUtil.removeDir(new File(dir)); String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir; if (options != null) { url = url + "&" + options; } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); // optimize AMQ to be as fast as possible so unit testing is quicker connectionFactory.setCopyMessageOnSend(false); connectionFactory.setOptimizeAcknowledge(true); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setUseAsyncSend(true); connectionFactory.setAlwaysSessionAsync(false); connectionFactory.setTrustAllPackages(true); // use a pooled connection factory PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory); pooled.setMaxConnections(8); return pooled; }
85. FailoverStaticNetworkTest#createConnectionFactory()
Project: activemq-artemis
File: FailoverStaticNetworkTest.java
File: FailoverStaticNetworkTest.java
protected ConnectionFactory createConnectionFactory(final BrokerService broker) throws Exception { String url = broker.getTransportConnectors().get(0).getServer().getConnectURI().toString(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setDispatchAsync(false); connectionFactory.setUseAsyncSend(false); connectionFactory.setOptimizeAcknowledge(false); connectionFactory.setAlwaysSyncSend(true); return connectionFactory; }
86. CamelJmsTestHelper#createPersistentConnectionFactory()
Project: camel
File: CamelJmsTestHelper.java
File: CamelJmsTestHelper.java
public static ConnectionFactory createPersistentConnectionFactory(String options) { // using a unique broker name improves testing when running the entire test suite in the same JVM int id = counter.incrementAndGet(); // use an unique data directory in target String dir = "target/activemq-data-" + id; // remove dir so its empty on startup FileUtil.removeDir(new File(dir)); String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir; if (options != null) { url = url + "&" + options; } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url); // optimize AMQ to be as fast as possible so unit testing is quicker connectionFactory.setCopyMessageOnSend(false); connectionFactory.setOptimizeAcknowledge(true); connectionFactory.setOptimizedMessageDispatch(true); connectionFactory.setUseAsyncSend(true); connectionFactory.setAlwaysSessionAsync(false); // use a pooled connection factory PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory); pooled.setMaxConnections(8); return pooled; }
87. StartAndStopBrokerTest#testStartupShutdown()
Project: activemq-artemis
File: StartAndStopBrokerTest.java
File: StartAndStopBrokerTest.java
public void testStartupShutdown() throws Exception { // This systemproperty is used if we dont want to // have persistence messages as a default System.setProperty("activemq.persistenceAdapter", "org.apache.activemq.store.vm.VMPersistenceAdapter"); // configuration of container and all protocolls BrokerService broker = createBroker(); // start a client ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:9100"); factory.createConnection(); // stop activemq broker broker.stop(); // start activemq broker again broker = createBroker(); // start a client again factory = new ActiveMQConnectionFactory("tcp://localhost:9100"); factory.createConnection(); // stop activemq broker broker.stop(); }
88. SimpleNetworkTest#doSetUp()
Project: activemq-artemis
File: SimpleNetworkTest.java
File: SimpleNetworkTest.java
protected void doSetUp(boolean deleteAllMessages) throws Exception { remoteBroker = createRemoteBroker(); remoteBroker.setDeleteAllMessagesOnStartup(deleteAllMessages); remoteBroker.start(); remoteBroker.waitUntilStarted(); localBroker = createLocalBroker(); localBroker.setDeleteAllMessagesOnStartup(deleteAllMessages); localBroker.start(); localBroker.waitUntilStarted(); URI localURI = localBroker.getVmConnectorURI(); ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(localURI); fac.setAlwaysSyncSend(true); fac.setDispatchAsync(false); localConnection = fac.createConnection(); localConnection.setClientID("clientId"); localConnection.start(); URI remoteURI = remoteBroker.getVmConnectorURI(); fac = new ActiveMQConnectionFactory(remoteURI); remoteConnection = fac.createConnection(); remoteConnection.setClientID("clientId"); remoteConnection.start(); included = new ActiveMQTopic("include.test.bar"); excluded = new ActiveMQTopic("exclude.test.bar"); localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); }
89. MessageCompressionTest#testStreamMessageCompression()
Project: activemq-artemis
File: MessageCompressionTest.java
File: MessageCompressionTest.java
public void testStreamMessageCompression() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(true); sendTestStreamMessage(factory, TEXT); ActiveMQStreamMessage streamMessage = receiveTestStreamMessage(factory); int compressedSize = streamMessage.getContent().getLength(); assertTrue(streamMessage.isCompressed()); boolean booleanVal = streamMessage.readBoolean(); assertTrue(booleanVal); byte byteVal = streamMessage.readByte(); assertEquals((byte) 10, byteVal); byte[] originVal = TEXT.getBytes(); byte[] bytesVal = new byte[originVal.length]; streamMessage.readBytes(bytesVal); for (int i = 0; i < bytesVal.length; i++) { assertTrue(bytesVal[i] == originVal[i]); } char charVal = streamMessage.readChar(); assertEquals('A', charVal); double doubleVal = streamMessage.readDouble(); assertEquals(55.3D, doubleVal, 0.1D); float floatVal = streamMessage.readFloat(); assertEquals(79.1F, floatVal, 0.1F); int intVal = streamMessage.readInt(); assertEquals(37, intVal); long longVal = streamMessage.readLong(); assertEquals(56652L, longVal); Object objectVal = streamMessage.readObject(); Object origVal = new String("VVVV"); assertTrue(objectVal.equals(origVal)); short shortVal = streamMessage.readShort(); assertEquals((short) 333, shortVal); String strVal = streamMessage.readString(); assertEquals(TEXT, strVal); factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(false); sendTestStreamMessage(factory, TEXT); streamMessage = receiveTestStreamMessage(factory); int unCompressedSize = streamMessage.getContent().getLength(); System.out.println("compressedSize: " + compressedSize + " un: " + unCompressedSize); assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize); }
90. MessageCompressionTest#testMapMessageCompression()
Project: activemq-artemis
File: MessageCompressionTest.java
File: MessageCompressionTest.java
public void testMapMessageCompression() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(true); sendTestMapMessage(factory, TEXT); ActiveMQMapMessage mapMessage = receiveTestMapMessage(factory); int compressedSize = mapMessage.getContent().getLength(); assertTrue(mapMessage.isCompressed()); boolean booleanVal = mapMessage.getBoolean("boolean-type"); assertTrue(booleanVal); byte byteVal = mapMessage.getByte("byte-type"); assertEquals((byte) 10, byteVal); byte[] bytesVal = mapMessage.getBytes("bytes-type"); byte[] originVal = TEXT.getBytes(); assertEquals(originVal.length, bytesVal.length); for (int i = 0; i < bytesVal.length; i++) { assertTrue(bytesVal[i] == originVal[i]); } char charVal = mapMessage.getChar("char-type"); assertEquals('A', charVal); double doubleVal = mapMessage.getDouble("double-type"); assertEquals(55.3D, doubleVal, 0.1D); float floatVal = mapMessage.getFloat("float-type"); assertEquals(79.1F, floatVal, 0.1F); int intVal = mapMessage.getInt("int-type"); assertEquals(37, intVal); long longVal = mapMessage.getLong("long-type"); assertEquals(56652L, longVal); Object objectVal = mapMessage.getObject("object-type"); Object origVal = new String("VVVV"); assertTrue(objectVal.equals(origVal)); short shortVal = mapMessage.getShort("short-type"); assertEquals((short) 333, shortVal); String strVal = mapMessage.getString("string-type"); assertEquals(TEXT, strVal); factory = new ActiveMQConnectionFactory(connectionUri); factory.setUseCompression(false); sendTestMapMessage(factory, TEXT); mapMessage = receiveTestMapMessage(factory); int unCompressedSize = mapMessage.getContent().getLength(); assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'", compressedSize < unCompressedSize); }
91. ConnectorXBeanConfigTest#testBrokerWontStop()
Project: activemq-artemis
File: ConnectorXBeanConfigTest.java
File: ConnectorXBeanConfigTest.java
public void testBrokerWontStop() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?async=false"); factory.setDispatchAsync(false); factory.setAlwaysSessionAsync(false); Connection conn = factory.createConnection(); final Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE); conn.start(); final Destination dest = new ActiveMQQueue("TEST"); final CountDownLatch stop = new CountDownLatch(1); final CountDownLatch sendSecond = new CountDownLatch(1); final CountDownLatch shutdown = new CountDownLatch(1); final CountDownLatch test = new CountDownLatch(1); ActiveMQConnectionFactory testFactory = new ActiveMQConnectionFactory("vm://localhost?async=false"); Connection testConn = testFactory.createConnection(); testConn.start(); Destination testDestination = sess.createQueue("NEW"); Session testSess = testConn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer testProducer = testSess.createProducer(testDestination); final Thread consumerThread = new Thread() { @Override public void run() { try { MessageProducer producer = sess.createProducer(dest); producer.send(sess.createTextMessage("msg1")); MessageConsumer consumer = sess.createConsumer(dest); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { // send a message that will block Thread.sleep(2000); sendSecond.countDown(); // try to stop the broker Thread.sleep(5000); stop.countDown(); // run the test Thread.sleep(5000); test.countDown(); shutdown.await(); } catch (InterruptedException ie) { } } }); } catch (Exception e) { e.printStackTrace(); } } }; consumerThread.start(); final Thread producerThread = new Thread() { @Override public void run() { try { sendSecond.await(); MessageProducer producer = sess.createProducer(dest); producer.send(sess.createTextMessage("msg2")); } catch (Exception e) { e.printStackTrace(); } } }; producerThread.start(); final Thread stopThread = new Thread() { @Override public void run() { try { stop.await(); brokerService.stop(); } catch (Exception e) { e.printStackTrace(); } } }; stopThread.start(); test.await(); try { testSess.createConsumer(testDestination); fail("Should have failed creating a consumer!"); } catch (Exception e) { e.printStackTrace(); } try { testProducer.send(testSess.createTextMessage("msg3")); fail("Should have failed sending a message!"); } catch (Exception e) { e.printStackTrace(); } shutdown.countDown(); }
92. TopicProducerFlowControlTest#testTopicProducerFlowControl()
Project: activemq-artemis
File: TopicProducerFlowControlTest.java
File: TopicProducerFlowControlTest.java
public void testTopicProducerFlowControl() throws Exception { // Create the connection factory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); connectionFactory.setAlwaysSyncSend(true); connectionFactory.setProducerWindowSize(1024); ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); prefetchPolicy.setAll(5000); connectionFactory.setPrefetchPolicy(prefetchPolicy); // Start the test destination listener Connection c = connectionFactory.createConnection(); c.start(); Session listenerSession = c.createSession(false, 1); Destination destination = createDestination(listenerSession); listenerSession.createConsumer(destination).setMessageListener(new TopicProducerFlowControlTest()); final AtomicInteger blockedCounter = new AtomicInteger(0); listenerSession.createConsumer(new ActiveMQTopic(AdvisorySupport.FULL_TOPIC_PREFIX + ">")).setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { LOG.info("Got full advisory, blockedCounter: " + blockedCounter.get()); blockedCounter.incrementAndGet(); } }); // Start producing the test messages final Session session = connectionFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageProducer producer = session.createProducer(destination); Thread producingThread = new Thread("Producing Thread") { @Override public void run() { try { for (long i = 0; i < numMessagesToSend; i++) { producer.send(session.createTextMessage("test")); long count = produced.incrementAndGet(); if (count % 10000 == 0) { LOG.info("Produced " + count + " messages"); } } } catch (Throwable ex) { ex.printStackTrace(); } finally { try { producer.close(); session.close(); } catch (Exception e) { } } } }; producingThread.start(); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return consumed.get() == numMessagesToSend; } }, // give it plenty of time before failing 5 * 60 * 1000); assertEquals("Didn't produce all messages", numMessagesToSend, produced.get()); assertEquals("Didn't consume all messages", numMessagesToSend, consumed.get()); assertTrue("Producer got blocked", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return blockedCounter.get() > 0; } }, 5 * 1000)); }
93. TrackerConfig#jmsConnectionFactory()
Project: biking2
File: TrackerConfig.java
File: TrackerConfig.java
@Bean public ConnectionFactory jmsConnectionFactory() { final ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("vm://localhost"); activeMQConnectionFactory.setUserName(properties.getUsername()); activeMQConnectionFactory.setPassword(properties.getPassword()); return new PooledConnectionFactory(activeMQConnectionFactory); }
94. ProducerFlowControlSendFailTest#testPublisherRecoverAfterBlockWithSyncSend()
Project: activemq-artemis
File: ProducerFlowControlSendFailTest.java
File: ProducerFlowControlSendFailTest.java
@Test public void testPublisherRecoverAfterBlockWithSyncSend() throws Exception { ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) getConnectionFactory(); factory.setExceptionListener(null); factory.setUseAsyncSend(false); this.flowControlConnection = (ActiveMQConnection) factory.createConnection(); this.flowControlConnection.start(); final Session session = this.flowControlConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE); final MessageProducer producer = session.createProducer(queueA); final AtomicBoolean keepGoing = new AtomicBoolean(true); final AtomicInteger exceptionCount = new AtomicInteger(0); Thread thread = new Thread("Filler") { @Override public void run() { while (keepGoing.get()) { try { producer.send(session.createTextMessage("Test message")); } catch (JMSException arg0) { if (arg0 instanceof ResourceAllocationException) { gotResourceException.set(true); exceptionCount.incrementAndGet(); } } } } }; thread.start(); waitForBlockedOrResourceLimit(new AtomicBoolean(false)); // resourceException on second message, resumption if we // can receive 10 MessageConsumer consumer = session.createConsumer(queueA); TextMessage msg; for (int idx = 0; idx < 10; ++idx) { msg = (TextMessage) consumer.receive(1000); if (msg != null) { msg.acknowledge(); } } assertTrue("we were blocked at least 5 times", 5 < exceptionCount.get()); keepGoing.set(false); }
95. MessageListenerRedeliveryTest#createRetryConnection()
Project: activemq-artemis
File: MessageListenerRedeliveryTest.java
File: MessageListenerRedeliveryTest.java
protected Connection createRetryConnection() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlString); factory.setRedeliveryPolicy(getRedeliveryPolicy()); return factory.createConnection(); }
96. RequestReplyTempDestRemovalAdvisoryRaceTest#testTempDestRace()
Project: activemq-artemis
File: RequestReplyTempDestRemovalAdvisoryRaceTest.java
File: RequestReplyTempDestRemovalAdvisoryRaceTest.java
public void testTempDestRace() throws Exception { // non duplex bridgeBrokers(BROKER_A, BROKER_B, false, 3); bridgeBrokers(BROKER_B, BROKER_A, false, 3); bridgeBrokers(BROKER_B, BROKER_C, false, 3); bridgeBrokers(BROKER_C, BROKER_B, false, 3); startAllBrokers(); waitForBridgeFormation(1); HashSet<NetworkBridge> bridgesStart = new HashSet<>(); for (NetworkConnector networkConnector : networkConnectors) { bridgesStart.addAll(networkConnector.activeBridges()); } slowDownAdvisoryDispatch(); noConsumerAdvisory(); forwardFailureAdvisory(); // set up respondents ExecutorService respondentThreadPool = Executors.newFixedThreadPool(50); BrokerItem brokerA = brokers.get(BROKER_A); ActiveMQConnectionFactory brokerAFactory = new ActiveMQConnectionFactory(brokerA.broker.getTransportConnectorByScheme("tcp").getName() + "?jms.watchTopicAdvisories=false"); brokerAFactory.setAlwaysSyncSend(true); for (int i = 0; i < NUM_RESPONDENTS; i++) { respondentThreadPool.execute(new EchoRespondent(brokerAFactory)); } // fire off sends ExecutorService senderThreadPool = Executors.newCachedThreadPool(); BrokerItem brokerC = brokers.get(BROKER_C); ActiveMQConnectionFactory brokerCFactory = new ActiveMQConnectionFactory(brokerC.broker.getTransportConnectorByScheme("tcp").getName() + "?jms.watchTopicAdvisories=false"); for (int i = 0; i < NUM_SENDS; i++) { senderThreadPool.execute(new MessageSender(brokerCFactory)); } senderThreadPool.shutdown(); senderThreadPool.awaitTermination(30, TimeUnit.SECONDS); TimeUnit.SECONDS.sleep(10); LOG.info("shutting down"); shutdown.compareAndSet(false, true); HashSet<NetworkBridge> bridgesEnd = new HashSet<>(); for (NetworkConnector networkConnector : networkConnectors) { bridgesEnd.addAll(networkConnector.activeBridges()); } assertEquals("no new bridges created", bridgesStart, bridgesEnd); // validate success or error or dlq LOG.info("received: " + responseReceived.get() + ", respondent error: " + respondentSendError.get() + ", noConsumerCount: " + sendsWithNoConsumers.get() + ", forwardFailures: " + forwardFailures.get()); assertEquals("success or error", NUM_SENDS, respondentSendError.get() + forwardFailures.get() + responseReceived.get() + sendsWithNoConsumers.get()); }
97. RequestReplyTempDestRemovalAdvisoryRaceTest#testTempDestRaceDuplex()
Project: activemq-artemis
File: RequestReplyTempDestRemovalAdvisoryRaceTest.java
File: RequestReplyTempDestRemovalAdvisoryRaceTest.java
public void testTempDestRaceDuplex() throws Exception { // duplex useDuplex = true; bridgeBrokers(BROKER_A, BROKER_B, false, 3); bridgeBrokers(BROKER_B, BROKER_C, false, 3); startAllBrokers(); waitForBridgeFormation(1); HashSet<NetworkBridge> bridgesStart = new HashSet<>(); for (NetworkConnector networkConnector : networkConnectors) { bridgesStart.addAll(networkConnector.activeBridges()); } LOG.info("Bridges start:" + bridgesStart); slowDownAdvisoryDispatch(); noConsumerAdvisory(); forwardFailureAdvisory(); // set up respondents ExecutorService respondentThreadPool = Executors.newFixedThreadPool(50); BrokerItem brokerA = brokers.get(BROKER_A); ActiveMQConnectionFactory brokerAFactory = new ActiveMQConnectionFactory(brokerA.broker.getTransportConnectorByScheme("tcp").getName() + "?jms.watchTopicAdvisories=false"); brokerAFactory.setAlwaysSyncSend(true); for (int i = 0; i < NUM_RESPONDENTS; i++) { respondentThreadPool.execute(new EchoRespondent(brokerAFactory)); } // fire off sends ExecutorService senderThreadPool = Executors.newCachedThreadPool(); BrokerItem brokerC = brokers.get(BROKER_C); ActiveMQConnectionFactory brokerCFactory = new ActiveMQConnectionFactory(brokerC.broker.getTransportConnectorByScheme("tcp").getName() + "?jms.watchTopicAdvisories=false"); for (int i = 0; i < NUM_SENDS; i++) { senderThreadPool.execute(new MessageSender(brokerCFactory)); } senderThreadPool.shutdown(); senderThreadPool.awaitTermination(30, TimeUnit.SECONDS); TimeUnit.SECONDS.sleep(15); LOG.info("shutting down"); shutdown.compareAndSet(false, true); HashSet<NetworkBridge> bridgesEnd = new HashSet<>(); for (NetworkConnector networkConnector : networkConnectors) { bridgesEnd.addAll(networkConnector.activeBridges()); } LOG.info("Bridges end:" + bridgesEnd); assertEquals("no new bridges created", bridgesStart, bridgesEnd); // validate success or error of dlq LOG.info("received: " + responseReceived.get() + ", respondent error: " + respondentSendError.get() + ", noConsumerCount: " + sendsWithNoConsumers.get() + ", forwardFailures: " + forwardFailures.get()); assertEquals("success or error", NUM_SENDS, respondentSendError.get() + forwardFailures.get() + responseReceived.get() + sendsWithNoConsumers.get()); }
98. RequestReplyNoAdvisoryNetworkTest#createConnectionFactory()
Project: activemq-artemis
File: RequestReplyNoAdvisoryNetworkTest.java
File: RequestReplyNoAdvisoryNetworkTest.java
private ActiveMQConnectionFactory createConnectionFactory(BrokerService brokerService) throws Exception { String target = brokerService.getTransportConnectors().get(0).getPublishableConnectString(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(target); factory.setWatchTopicAdvisories(false); factory.setConnectionIDPrefix(connectionIdMarker + brokerService.getBrokerName()); return factory; }
99. ConcurrentProducerQueueConsumerTest#createConnectionFactory()
Project: activemq-artemis
File: ConcurrentProducerQueueConsumerTest.java
File: ConcurrentProducerQueueConsumerTest.java
@Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString()); ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); prefetchPolicy.setAll(1); factory.setPrefetchPolicy(prefetchPolicy); factory.setDispatchAsync(true); return factory; }
100. ConcurrentProducerDurableConsumerTest#createConnectionFactory()
Project: activemq-artemis
File: ConcurrentProducerDurableConsumerTest.java
File: ConcurrentProducerDurableConsumerTest.java
@Override protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString()); ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); prefetchPolicy.setAll(1); factory.setPrefetchPolicy(prefetchPolicy); factory.setDispatchAsync(true); return factory; }