Here are the examples of the java api class org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory taken from open source projects.
1. JMSServerManagerImpl#internalCreateCFPOJO()
Project: activemq-artemis
File: JMSServerManagerImpl.java
File: JMSServerManagerImpl.java
/** * @param cfConfig * @return * @throws ActiveMQException */ protected ActiveMQConnectionFactory internalCreateCFPOJO(final ConnectionFactoryConfiguration cfConfig) throws ActiveMQException { ActiveMQConnectionFactory cf; if (cfConfig.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration groupConfig = server.getConfiguration().getDiscoveryGroupConfigurations().get(cfConfig.getDiscoveryGroupName()); if (groupConfig == null) { throw ActiveMQJMSServerBundle.BUNDLE.discoveryGroupDoesntExist(cfConfig.getDiscoveryGroupName()); } if (cfConfig.isHA()) { cf = ActiveMQJMSClient.createConnectionFactoryWithHA(groupConfig, cfConfig.getFactoryType()); } else { cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfig, cfConfig.getFactoryType()); } } else { if (cfConfig.getConnectorNames() == null || cfConfig.getConnectorNames().size() == 0) { throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameOnCF(); } TransportConfiguration[] configs = new TransportConfiguration[cfConfig.getConnectorNames().size()]; int count = 0; for (String name : cfConfig.getConnectorNames()) { TransportConfiguration connector = server.getConfiguration().getConnectorConfigurations().get(name); if (connector == null) { throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameConfiguredOnCF(name); } correctInvalidNettyConnectorHost(connector); configs[count++] = connector; } if (cfConfig.isHA()) { cf = ActiveMQJMSClient.createConnectionFactoryWithHA(cfConfig.getFactoryType(), configs); } else { cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(cfConfig.getFactoryType(), configs); } } cf.setClientID(cfConfig.getClientID()); cf.setClientFailureCheckPeriod(cfConfig.getClientFailureCheckPeriod()); cf.setConnectionTTL(cfConfig.getConnectionTTL()); cf.setCallTimeout(cfConfig.getCallTimeout()); cf.setCallFailoverTimeout(cfConfig.getCallFailoverTimeout()); cf.setCacheLargeMessagesClient(cfConfig.isCacheLargeMessagesClient()); cf.setMinLargeMessageSize(cfConfig.getMinLargeMessageSize()); cf.setConsumerWindowSize(cfConfig.getConsumerWindowSize()); cf.setConsumerMaxRate(cfConfig.getConsumerMaxRate()); cf.setConfirmationWindowSize(cfConfig.getConfirmationWindowSize()); cf.setProducerWindowSize(cfConfig.getProducerWindowSize()); cf.setProducerMaxRate(cfConfig.getProducerMaxRate()); cf.setBlockOnAcknowledge(cfConfig.isBlockOnAcknowledge()); cf.setBlockOnDurableSend(cfConfig.isBlockOnDurableSend()); cf.setBlockOnNonDurableSend(cfConfig.isBlockOnNonDurableSend()); cf.setAutoGroup(cfConfig.isAutoGroup()); cf.setPreAcknowledge(cfConfig.isPreAcknowledge()); cf.setConnectionLoadBalancingPolicyClassName(cfConfig.getLoadBalancingPolicyClassName()); cf.setTransactionBatchSize(cfConfig.getTransactionBatchSize()); cf.setDupsOKBatchSize(cfConfig.getDupsOKBatchSize()); cf.setUseGlobalPools(cfConfig.isUseGlobalPools()); cf.setScheduledThreadPoolMaxSize(cfConfig.getScheduledThreadPoolMaxSize()); cf.setThreadPoolMaxSize(cfConfig.getThreadPoolMaxSize()); cf.setRetryInterval(cfConfig.getRetryInterval()); cf.setRetryIntervalMultiplier(cfConfig.getRetryIntervalMultiplier()); cf.setMaxRetryInterval(cfConfig.getMaxRetryInterval()); cf.setReconnectAttempts(cfConfig.getReconnectAttempts()); cf.setFailoverOnInitialConnection(cfConfig.isFailoverOnInitialConnection()); cf.setCompressLargeMessage(cfConfig.isCompressLargeMessages()); cf.setGroupID(cfConfig.getGroupID()); cf.setProtocolManagerFactoryStr(cfConfig.getProtocolManagerFactoryStr()); return cf; }
2. StompTestBase#setUpAfterServer()
Project: activemq-artemis
File: StompTestBase.java
File: StompTestBase.java
protected void setUpAfterServer(boolean jmsCompressLarge) throws Exception { connectionFactory = createConnectionFactory(); ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) connectionFactory; activeMQConnectionFactory.setCompressLargeMessage(jmsCompressLarge); createBootstrap(); connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.createQueue(getQueueName()); topic = session.createTopic(getTopicName()); }
3. JMSReconnectTest#testNoReconnectCloseAfterFailToReconnectWithTempQueue()
Project: activemq-artemis
File: JMSReconnectTest.java
File: JMSReconnectTest.java
//If server is shutdown, and then connection is closed, after a temp queue has been created, the close should complete normally @Test public void testNoReconnectCloseAfterFailToReconnectWithTempQueue() throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcf.setReconnectAttempts(0); Connection conn = jbcf.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); sess.createTemporaryQueue(); Thread.sleep(2000); this.server.stop(); this.server.start(); sess.close(); conn.close(); }
4. ActiveMQConnectionFactoryTest#testGettersAndSetters()
Project: activemq-artemis
File: ActiveMQConnectionFactoryTest.java
File: ActiveMQConnectionFactoryTest.java
@Test public void testGettersAndSetters() { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); long clientFailureCheckPeriod = RandomUtil.randomPositiveLong(); long connectionTTL = RandomUtil.randomPositiveLong(); long callTimeout = RandomUtil.randomPositiveLong(); int minLargeMessageSize = RandomUtil.randomPositiveInt(); int consumerWindowSize = RandomUtil.randomPositiveInt(); int consumerMaxRate = RandomUtil.randomPositiveInt(); int confirmationWindowSize = RandomUtil.randomPositiveInt(); int producerMaxRate = RandomUtil.randomPositiveInt(); boolean blockOnAcknowledge = RandomUtil.randomBoolean(); boolean blockOnDurableSend = RandomUtil.randomBoolean(); boolean blockOnNonDurableSend = RandomUtil.randomBoolean(); boolean autoGroup = RandomUtil.randomBoolean(); boolean preAcknowledge = RandomUtil.randomBoolean(); String loadBalancingPolicyClassName = RandomUtil.randomString(); boolean useGlobalPools = RandomUtil.randomBoolean(); int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt(); int threadPoolMaxSize = RandomUtil.randomPositiveInt(); long retryInterval = RandomUtil.randomPositiveLong(); double retryIntervalMultiplier = RandomUtil.randomDouble(); int reconnectAttempts = RandomUtil.randomPositiveInt(); cf.setClientFailureCheckPeriod(clientFailureCheckPeriod); cf.setConnectionTTL(connectionTTL); cf.setCallTimeout(callTimeout); cf.setMinLargeMessageSize(minLargeMessageSize); cf.setConsumerWindowSize(consumerWindowSize); cf.setConsumerMaxRate(consumerMaxRate); cf.setConfirmationWindowSize(confirmationWindowSize); cf.setProducerMaxRate(producerMaxRate); cf.setBlockOnAcknowledge(blockOnAcknowledge); cf.setBlockOnDurableSend(blockOnDurableSend); cf.setBlockOnNonDurableSend(blockOnNonDurableSend); cf.setAutoGroup(autoGroup); cf.setPreAcknowledge(preAcknowledge); cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName); cf.setUseGlobalPools(useGlobalPools); cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize); cf.setThreadPoolMaxSize(threadPoolMaxSize); cf.setRetryInterval(retryInterval); cf.setRetryIntervalMultiplier(retryIntervalMultiplier); cf.setReconnectAttempts(reconnectAttempts); Assert.assertEquals(clientFailureCheckPeriod, cf.getClientFailureCheckPeriod()); Assert.assertEquals(connectionTTL, cf.getConnectionTTL()); Assert.assertEquals(callTimeout, cf.getCallTimeout()); Assert.assertEquals(minLargeMessageSize, cf.getMinLargeMessageSize()); Assert.assertEquals(consumerWindowSize, cf.getConsumerWindowSize()); Assert.assertEquals(consumerMaxRate, cf.getConsumerMaxRate()); Assert.assertEquals(confirmationWindowSize, cf.getConfirmationWindowSize()); Assert.assertEquals(producerMaxRate, cf.getProducerMaxRate()); Assert.assertEquals(blockOnAcknowledge, cf.isBlockOnAcknowledge()); Assert.assertEquals(blockOnDurableSend, cf.isBlockOnDurableSend()); Assert.assertEquals(blockOnNonDurableSend, cf.isBlockOnNonDurableSend()); Assert.assertEquals(autoGroup, cf.isAutoGroup()); Assert.assertEquals(preAcknowledge, cf.isPreAcknowledge()); Assert.assertEquals(loadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName()); Assert.assertEquals(useGlobalPools, cf.isUseGlobalPools()); Assert.assertEquals(scheduledThreadPoolMaxSize, cf.getScheduledThreadPoolMaxSize()); Assert.assertEquals(threadPoolMaxSize, cf.getThreadPoolMaxSize()); Assert.assertEquals(retryInterval, cf.getRetryInterval()); Assert.assertEquals(retryIntervalMultiplier, cf.getRetryIntervalMultiplier(), 0.0001); Assert.assertEquals(reconnectAttempts, cf.getReconnectAttempts()); cf.close(); }
5. ActiveMQConnectionFactoryTest#testStaticConnectorLiveConstructor()
Project: activemq-artemis
File: ActiveMQConnectionFactoryTest.java
File: ActiveMQConnectionFactoryTest.java
@Test public void testStaticConnectorLiveConstructor() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); assertFactoryParams(cf, new TransportConfiguration[] { liveTC }, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); cf.close(); conn.close(); }
6. HornetQProtocolManagerTest#testLegacy()
Project: activemq-artemis
File: HornetQProtocolManagerTest.java
File: HornetQProtocolManagerTest.java
@Test public void testLegacy() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?protocolManagerFactoryStr=" + HornetQClientProtocolManagerFactory.class.getName()); connectionFactory.createConnection().close(); ActiveMQConnectionFactory connectionFactory2 = new ActiveMQConnectionFactory("tcp://localhost:61617"); connectionFactory2.createConnection().close(); RecoveryManager manager = new RecoveryManager(); manager.register(connectionFactory, null, null, new ConcurrentHashMap<String, String>()); manager.register(connectionFactory2, null, null, new ConcurrentHashMap<String, String>()); for (XARecoveryConfig resource : manager.getResources()) { ServerLocator locator = resource.createServerLocator(); ClientSessionFactory factory = locator.createSessionFactory(); ClientSession session = factory.createSession(); session.close(); factory.close(); locator.close(); } }
7. ConnectionFactoryURITest#testJGroupsPropertiesURI()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testJGroupsPropertiesURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); JGroupsPropertiesBroadcastEndpointFactory endpointFactory = new JGroupsPropertiesBroadcastEndpointFactory().setChannelName("channel-name").setProperties("param=val,param2-val2"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory broadcastEndpointFactory = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(broadcastEndpointFactory); Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); Assert.assertEquals(dgc.getName(), "foo"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); Assert.assertEquals(dgc.getRefreshTimeout(), 12345); JGroupsPropertiesBroadcastEndpointFactory propertiesBroadcastEndpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; Assert.assertEquals(propertiesBroadcastEndpointFactory.getProperties(), "param=val,param2-val2"); Assert.assertEquals(propertiesBroadcastEndpointFactory.getChannelName(), "channel-name"); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
8. ConnectionFactoryURITest#testJGroupsFileURI()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testJGroupsFileURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(befc); Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory); Assert.assertEquals(dgc.getName(), "foo"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678); Assert.assertEquals(dgc.getRefreshTimeout(), 12345); JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc; Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml"); Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name"); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
9. ConnectionFactoryURITest#testTCPURI()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testTCPURI() throws Exception { TransportConfiguration tc = new TransportConfiguration(NettyConnectorFactory.class.getName()); HashMap<String, Object> params = new HashMap<>(); params.put("host", "localhost1"); params.put("port", 61617); TransportConfiguration tc2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params); HashMap<String, Object> params2 = new HashMap<>(); params2.put("host", "localhost2"); params2.put("port", 61618); TransportConfiguration tc3 = new TransportConfiguration(NettyConnectorFactory.class.getName(), params2); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, tc, tc2, tc3); URI tcp = parser.createSchema("tcp", connectionFactoryWithHA); ActiveMQConnectionFactory factory = parser.newObject(tcp, null); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
10. ConnectionFactoryURITest#testWeirdEncodingsOnIP()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testWeirdEncodingsOnIP() throws Exception { // This is to make things worse. Having & and = on the property shouldn't break it final String BROKEN_PROPERTY = "e80::56ee:75ff:fe53:e6a7%25enp0s25&host=[fe80::56ee:75ff:fe53:e6a7]#"; Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, BROKEN_PROPERTY); TransportConfiguration configuration = new TransportConfiguration(NettyConnector.class.getName(), params); ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, configuration); URI uri = factory.toURI(); ActiveMQConnectionFactory newFactory = ActiveMQJMSClient.createConnectionFactory(uri.toString(), "somefactory"); TransportConfiguration[] initialConnectors = ((ServerLocatorImpl) newFactory.getServerLocator()).getInitialConnectors(); Assert.assertEquals(1, initialConnectors.length); Assert.assertEquals(BROKEN_PROPERTY, initialConnectors[0].getParams().get(TransportConstants.LOCAL_ADDRESS_PROP_NAME).toString()); }
11. ResourceAdapterTest#testCreateConnectionFactoryOverrideDiscovery()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testCreateConnectionFactoryOverrideDiscovery() throws Exception { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(InVMConnectorFactory.class.getName()); ConnectionFactoryProperties connectionFactoryProperties = new ConnectionFactoryProperties(); connectionFactoryProperties.setDiscoveryAddress("myhost"); connectionFactoryProperties.setDiscoveryPort(5678); connectionFactoryProperties.setDiscoveryLocalBindAddress("newAddress"); ActiveMQConnectionFactory factory = ra.getConnectionFactory(connectionFactoryProperties); ActiveMQConnectionFactory defaultFactory = ra.getDefaultActiveMQConnectionFactory(); Assert.assertNotSame(factory, defaultFactory); DiscoveryGroupConfiguration dc = factory.getServerLocator().getDiscoveryGroupConfiguration(); UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory(); Assert.assertEquals(udpDg.getLocalBindAddress(), "newAddress"); Assert.assertEquals(udpDg.getGroupAddress(), "myhost"); Assert.assertEquals(udpDg.getGroupPort(), 5678); }
12. ResourceAdapterTest#testCreateConnectionFactoryOverrideConnector()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testCreateConnectionFactoryOverrideConnector() throws Exception { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(InVMConnectorFactory.class.getName()); ConnectionFactoryProperties connectionFactoryProperties = new ConnectionFactoryProperties(); ArrayList<String> value = new ArrayList<>(); value.add(NettyConnectorFactory.class.getName()); connectionFactoryProperties.setParsedConnectorClassNames(value); ActiveMQConnectionFactory factory = ra.getConnectionFactory(connectionFactoryProperties); ActiveMQConnectionFactory defaultFactory = ra.getDefaultActiveMQConnectionFactory(); Assert.assertNotSame(factory, defaultFactory); }
13. ArtemisAutoConfigurationTests#embeddedConnectionFactoryByDefault()
Project: spring-boot
File: ArtemisAutoConfigurationTests.java
File: ArtemisAutoConfigurationTests.java
@Test public void embeddedConnectionFactoryByDefault() { // No mode is specified load(EmptyConfiguration.class); assertThat(this.context.getBeansOfType(EmbeddedJMS.class)).hasSize(1); org.apache.activemq.artemis.core.config.Configuration configuration = this.context.getBean(org.apache.activemq.artemis.core.config.Configuration.class); assertThat(configuration.isPersistenceEnabled()).isFalse(); assertThat(configuration.isSecurityEnabled()).isFalse(); ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class); assertInVmConnectionFactory(connectionFactory); }
14. ArtemisAutoConfigurationTests#embeddedConnectionFactory()
Project: spring-boot
File: ArtemisAutoConfigurationTests.java
File: ArtemisAutoConfigurationTests.java
@Test public void embeddedConnectionFactory() { load(EmptyConfiguration.class, "spring.artemis.mode:embedded"); ArtemisProperties properties = this.context.getBean(ArtemisProperties.class); assertThat(properties.getMode()).isEqualTo(ArtemisMode.EMBEDDED); assertThat(this.context.getBeansOfType(EmbeddedJMS.class)).hasSize(1); org.apache.activemq.artemis.core.config.Configuration configuration = this.context.getBean(org.apache.activemq.artemis.core.config.Configuration.class); assertThat(configuration.isPersistenceEnabled()).isFalse(); assertThat(configuration.isSecurityEnabled()).isFalse(); ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class); assertInVmConnectionFactory(connectionFactory); }
15. ArtemisAutoConfigurationTests#nativeConnectionFactoryCredentials()
Project: spring-boot
File: ArtemisAutoConfigurationTests.java
File: ArtemisAutoConfigurationTests.java
@Test public void nativeConnectionFactoryCredentials() { load(EmptyConfiguration.class, "spring.artemis.mode:native", "spring.artemis.user:user", "spring.artemis.password:secret"); JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class); ActiveMQConnectionFactory connectionFactory = this.context.getBean(ActiveMQConnectionFactory.class); assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory()); assertNettyConnectionFactory(connectionFactory, "localhost", 61616); assertThat(connectionFactory.getUser()).isEqualTo("user"); assertThat(connectionFactory.getPassword()).isEqualTo("secret"); }
16. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectorsOverride()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testCreateConnectionFactoryMultipleConnectorsOverride() { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY); ConnectionFactoryProperties overrideProperties = new ConnectionFactoryProperties(); ArrayList<String> value = new ArrayList<>(); value.add(INVM_CONNECTOR_FACTORY); value.add(NETTY_CONNECTOR_FACTORY); value.add(INVM_CONNECTOR_FACTORY); overrideProperties.setParsedConnectorClassNames(value); ActiveMQConnectionFactory factory = ra.getConnectionFactory(overrideProperties); TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations(); assertNotNull(configurations); assertEquals(3, configurations.length); assertEquals(INVM_CONNECTOR_FACTORY, configurations[0].getFactoryClassName()); assertEquals(1, configurations[0].getParams().size()); assertEquals(NETTY_CONNECTOR_FACTORY, configurations[1].getFactoryClassName()); assertEquals(2, configurations[1].getParams().size()); assertEquals(INVM_CONNECTOR_FACTORY, configurations[2].getFactoryClassName()); assertEquals(1, configurations[2].getParams().size()); }
17. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectorsAndParams()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testCreateConnectionFactoryMultipleConnectorsAndParams() { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY); ra.setConnectionParameters("host=host1;port=61616, serverid=0, host=host2;port=61617"); ActiveMQConnectionFactory factory = ra.getConnectionFactory(new ConnectionFactoryProperties()); TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations(); assertNotNull(configurations); assertEquals(3, configurations.length); assertEquals(NETTY_CONNECTOR_FACTORY, configurations[0].getFactoryClassName()); assertEquals(2, configurations[0].getParams().size()); assertEquals("host1", configurations[0].getParams().get("host")); assertEquals("61616", configurations[0].getParams().get("port")); assertEquals(INVM_CONNECTOR_FACTORY, configurations[1].getFactoryClassName()); assertEquals(1, configurations[1].getParams().size()); assertEquals("0", configurations[1].getParams().get("serverid")); assertEquals(NETTY_CONNECTOR_FACTORY, configurations[2].getFactoryClassName()); assertEquals(2, configurations[2].getParams().size()); assertEquals("host2", configurations[2].getParams().get("host")); assertEquals("61617", configurations[2].getParams().get("port")); }
18. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectors()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testCreateConnectionFactoryMultipleConnectors() { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(NETTY_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY + "," + NETTY_CONNECTOR_FACTORY); ActiveMQConnectionFactory factory = ra.getConnectionFactory(new ConnectionFactoryProperties()); TransportConfiguration[] configurations = factory.getServerLocator().getStaticTransportConfigurations(); assertNotNull(configurations); assertEquals(3, configurations.length); assertEquals(NETTY_CONNECTOR_FACTORY, configurations[0].getFactoryClassName()); assertEquals(2, configurations[0].getParams().size()); assertEquals(INVM_CONNECTOR_FACTORY, configurations[1].getFactoryClassName()); assertEquals(1, configurations[1].getParams().size()); assertEquals(NETTY_CONNECTOR_FACTORY, configurations[2].getFactoryClassName()); assertEquals(2, configurations[2].getParams().size()); }
19. ResourceAdapterTest#testResourceAdapterSetupReconnectAttemptsOverride()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupReconnectAttemptsOverride() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); spec.setReconnectAttempts(100); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertEquals(100, fac.getReconnectAttempts()); qResourceAdapter.stop(); assertTrue(spec.isHasBeenUpdated()); }
20. ResourceAdapterTest#testResourceAdapterSetupReconnectAttemptDefault()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupReconnectAttemptDefault() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertEquals(-1, fac.getReconnectAttempts()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
21. ResourceAdapterTest#testResourceAdapterSetupNoReconnectAttemptsOverride()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupNoReconnectAttemptsOverride() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); qResourceAdapter.setReconnectAttempts(100); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertEquals(100, fac.getReconnectAttempts()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
22. ResourceAdapterTest#testResourceAdapterSetupHAOverride()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupHAOverride() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); spec.setHA(true); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertTrue(fac.isHA()); qResourceAdapter.stop(); assertTrue(spec.isHasBeenUpdated()); }
23. ResourceAdapterTest#testResourceAdapterSetupNoHADefault()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupNoHADefault() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertFalse(fac.isHA()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
24. ResourceAdapterTest#testResourceAdapterSetupNoHAOverride()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupNoHAOverride() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY); qResourceAdapter.setConnectionParameters("server-id=0"); qResourceAdapter.setHA(true); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); assertTrue(fac.isHA()); qResourceAdapter.stop(); assertFalse(spec.isHasBeenUpdated()); }
25. ResourceAdapterTest#testResourceAdapterSetupNoOverrideDiscovery()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupNoOverrideDiscovery() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setDiscoveryAddress("231.6.6.6"); qResourceAdapter.setDiscoveryPort(1234); qResourceAdapter.setDiscoveryRefreshTimeout(1L); qResourceAdapter.setDiscoveryInitialWaitTimeout(1L); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); DiscoveryGroupConfiguration dc = fac.getServerLocator().getDiscoveryGroupConfiguration(); UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory(); assertEquals(udpDg.getGroupAddress(), "231.6.6.6"); assertEquals(udpDg.getGroupPort(), 1234); assertEquals(dc.getRefreshTimeout(), 1L); assertEquals(dc.getDiscoveryInitialWaitTimeout(), 1L); qResourceAdapter.stop(); }
26. SimpleJNDIClientTest#testRemoteCFWithUDPWithTransportConfig()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testRemoteCFWithUDPWithTransportConfig() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); props.put("connectionFactory.myConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort() + "?" + TransportConstants.LOCAL_ADDRESS_PROP_NAME + "=Server1&" + TransportConstants.LOCAL_PORT_PROP_NAME + "=1198&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); UDPBroadcastEndpointFactory udpBroadcastEndpointFactory = (UDPBroadcastEndpointFactory) discoveryGroupConfiguration.getBroadcastEndpointFactory(); //these 2 are transient so are ignored Assert.assertNotEquals("Server1", udpBroadcastEndpointFactory.getLocalBindAddress()); Assert.assertNotEquals(1198, udpBroadcastEndpointFactory.getLocalBindPort()); Assert.assertEquals(getUDPDiscoveryAddress(), udpBroadcastEndpointFactory.getGroupAddress()); Assert.assertEquals(getUDPDiscoveryPort(), udpBroadcastEndpointFactory.getGroupPort()); }
27. SimpleJNDIClientTest#testRemoteCFWithJgroupsWithTransportConfigNullProps()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testRemoteCFWithJgroupsWithTransportConfigNullProps() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); props.put("connectionFactory.ConnectionFactory", "jgroups://testChannelName?" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); BroadcastEndpointFactory broadcastEndpointFactory = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); JGroupsPropertiesBroadcastEndpointFactory endpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; Assert.assertEquals(endpointFactory.getProperties(), null); Assert.assertEquals(endpointFactory.getChannelName(), "testChannelName"); }
28. SimpleJNDIClientTest#testRemoteCFWithJgroupsWithTransportConfigProps()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testRemoteCFWithJgroupsWithTransportConfigProps() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName()); props.put("connectionFactory.ConnectionFactory", "jgroups://testChannelName?properties=param=value&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("ConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); BroadcastEndpointFactory broadcastEndpointFactory = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); Assert.assertTrue(broadcastEndpointFactory instanceof JGroupsPropertiesBroadcastEndpointFactory); JGroupsPropertiesBroadcastEndpointFactory endpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) broadcastEndpointFactory; Assert.assertEquals(endpointFactory.getProperties(), "param=value"); Assert.assertEquals(endpointFactory.getChannelName(), "testChannelName"); }
29. SimpleJNDIClientTest#testRemoteCFWithJgroupsWithTransportConfigFile()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testRemoteCFWithJgroupsWithTransportConfigFile() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory.class.getCanonicalName()); props.put("connectionFactory.myConnectionFactory", "jgroups://testChannelName?file=test-jgroups-file_ping.xml&" + ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" + ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration(); Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout()); Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout()); BroadcastEndpoint broadcastEndpoint = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint(); Assert.assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpoint); broadcastEndpoint.close(false); }
30. InvalidConnectorTest#testInvalidConnector()
Project: activemq-artemis
File: InvalidConnectorTest.java
File: InvalidConnectorTest.java
@Test public void testInvalidConnector() throws Exception { Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.HOST_PROP_NAME, "0.0.0.0"); List<TransportConfiguration> connectorConfigs = new ArrayList<>(); connectorConfigs.add(new TransportConfiguration(NETTY_CONNECTOR_FACTORY, params)); int retryInterval = 1000; double retryIntervalMultiplier = 1.0; int reconnectAttempts = -1; int callTimeout = 30000; jmsServer.createConnectionFactory("invalid-cf", false, JMSFactoryType.CF, registerConnectors(server, connectorConfigs), null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, callTimeout, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, retryInterval, retryIntervalMultiplier, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, reconnectAttempts, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, "/invalid-cf"); ActiveMQConnectionFactory invalidCf = (ActiveMQConnectionFactory) namingContext.lookup("/invalid-cf"); TransportConfiguration[] tcs = invalidCf.getServerLocator().getStaticTransportConfigurations(); TransportConfiguration tc = tcs[0]; assertNotSame(tc.getParams().get(TransportConstants.HOST_PROP_NAME), "0.0.0.0"); assertEquals(tc.getParams().get(TransportConstants.HOST_PROP_NAME), InetAddress.getLocalHost().getHostName()); }
31. ConnectionFactoryWithJGroupsSerializationTest#testSerialization()
Project: activemq-artemis
File: ConnectionFactoryWithJGroupsSerializationTest.java
File: ConnectionFactoryWithJGroupsSerializationTest.java
// Public -------------------------------------------------------- //HORNETQ-1389 //Here we deploy two Connection Factories with JGroups discovery groups. //The first one uses a runtime JChannel object, which is the case before the fix. //The second one uses the raw jgroups config string, which is the case after fix. //So the first one will get serialization exception in the test //while the second will not. @Test public void testSerialization() throws Exception { jmsCf1 = (ActiveMQConnectionFactory) namingContext.lookup("/ConnectionFactory1"); jmsCf2 = (ActiveMQConnectionFactory) namingContext.lookup("/ConnectionFactory2"); try { serialize(jmsCf1); } catch (java.io.NotSerializableException e) { } //now cf2 should be OK byte[] x = serialize(jmsCf2); ActiveMQConnectionFactory jmsCf2Copy = deserialize(x, ActiveMQConnectionFactory.class); assertNotNull(jmsCf2Copy); BroadcastEndpointFactory broadcastEndpoint = jmsCf2Copy.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory(); assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpointFactory); }
32. ConnectionFactorySerializationTest#testConnectionFactoryStatic1()
Project: activemq-artemis
File: ConnectionFactorySerializationTest.java
File: ConnectionFactorySerializationTest.java
@Test public void testConnectionFactoryStatic1() throws Exception { createStaticFactory(true); cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); // apparently looking up the connection factory with the org.apache.activemq.artemis.jms.tests.tools.container.InVMInitialContextFactory // is not enough to actually serialize it so we serialize it manually byte[] x = serialize(cf); ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); checkEquals(cf, y); Assert.assertEquals(cf.isHA(), y.isHA()); TransportConfiguration[] staticConnectors = y.getStaticConnectors(); Assert.assertEquals(staticConnectors.length, 2); TransportConfiguration tc0 = cf.getStaticConnectors()[0]; TransportConfiguration y0 = y.getStaticConnectors()[0]; Map<String, Object> ctParams = tc0.getParams(); Map<String, Object> y0Params = y0.getParams(); Assert.assertEquals(ctParams.size(), y0Params.size()); for (String key : y0Params.keySet()) { Assert.assertEquals(ctParams.get(key), y0Params.get(key)); } }
33. ConnectionFactorySerializationTest#testConnectionFactoryJgroupsProperties()
Project: activemq-artemis
File: ConnectionFactorySerializationTest.java
File: ConnectionFactorySerializationTest.java
@Test public void testConnectionFactoryJgroupsProperties() throws Exception { createDiscoveryFactoryJGroupsProperties(); cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); // apparently looking up the connection factory with the org.apache.activemq.artemis.jms.tests.tools.container.InVMInitialContextFactory // is not enough to actually serialize it so we serialize it manually byte[] x = serialize(cf); ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); checkEquals(cf, y); DiscoveryGroupConfiguration dgc = y.getDiscoveryGroupConfiguration(); Assert.assertEquals(dgc.getName(), "dg1"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5000); Assert.assertEquals(dgc.getRefreshTimeout(), 5000); Assert.assertTrue(dgc.getBroadcastEndpointFactory() instanceof JGroupsPropertiesBroadcastEndpointFactory); JGroupsPropertiesBroadcastEndpointFactory befc = (JGroupsPropertiesBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); Assert.assertEquals("myChannel", befc.getChannelName()); Assert.assertEquals("param=1,param2=2", befc.getProperties()); }
34. ConnectionFactorySerializationTest#testConnectionFactoryJgroupsFile()
Project: activemq-artemis
File: ConnectionFactorySerializationTest.java
File: ConnectionFactorySerializationTest.java
@Test public void testConnectionFactoryJgroupsFile() throws Exception { createDiscoveryFactoryJGroupsFile(); cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); // apparently looking up the connection factory with the org.apache.activemq.artemis.jms.tests.tools.container.InVMInitialContextFactory // is not enough to actually serialize it so we serialize it manually byte[] x = serialize(cf); ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); checkEquals(cf, y); DiscoveryGroupConfiguration dgc = y.getDiscoveryGroupConfiguration(); Assert.assertEquals(dgc.getName(), "dg1"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5000); Assert.assertEquals(dgc.getRefreshTimeout(), 5000); Assert.assertTrue(dgc.getBroadcastEndpointFactory() instanceof JGroupsFileBroadcastEndpointFactory); JGroupsFileBroadcastEndpointFactory befc = (JGroupsFileBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); Assert.assertEquals("myChannel", befc.getChannelName()); Assert.assertEquals("/META-INF/myfile.xml", befc.getFile()); }
35. ConnectionFactorySerializationTest#testConnectionFactoryUDP()
Project: activemq-artemis
File: ConnectionFactorySerializationTest.java
File: ConnectionFactorySerializationTest.java
// Public -------------------------------------------------------- @Test public void testConnectionFactoryUDP() throws Exception { createDiscoveryFactoryUDP(); cf = (ActiveMQConnectionFactory) namingContext.lookup("/MyConnectionFactory"); // apparently looking up the connection factory with the org.apache.activemq.artemis.jms.tests.tools.container.InVMInitialContextFactory // is not enough to actually serialize it so we serialize it manually byte[] x = serialize(cf); ActiveMQConnectionFactory y = deserialize(x, ActiveMQConnectionFactory.class); checkEquals(cf, y); DiscoveryGroupConfiguration dgc = y.getDiscoveryGroupConfiguration(); Assert.assertEquals(dgc.getName(), "dg1"); Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5000); Assert.assertEquals(dgc.getRefreshTimeout(), 5000); Assert.assertTrue(dgc.getBroadcastEndpointFactory() instanceof UDPBroadcastEndpointFactory); UDPBroadcastEndpointFactory befc = (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory(); Assert.assertEquals(Integer.parseInt(System.getProperty("org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory.localBindPort", "-1")), befc.getLocalBindPort()); Assert.assertEquals(System.getProperty("org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory.localBindAddress"), befc.getLocalBindAddress()); Assert.assertEquals(1234, befc.getGroupPort()); Assert.assertEquals("1.2.3.4", befc.getGroupAddress()); }
36. ActiveMQConnectionFactoryTest#testStaticConnectorListConstructor()
Project: activemq-artemis
File: ActiveMQConnectionFactoryTest.java
File: ActiveMQConnectionFactoryTest.java
@Test public void testStaticConnectorListConstructor() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); assertFactoryParams(cf, new TransportConfiguration[] { liveTC }, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); conn.close(); }
37. ActiveMQConnectionFactoryTest#testDiscoveryConstructor()
Project: activemq-artemis
File: ActiveMQConnectionFactoryTest.java
File: ActiveMQConnectionFactoryTest.java
@Test public void testDiscoveryConstructor() throws Exception { DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration().setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort)); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF); assertFactoryParams(cf, null, groupConfiguration, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); conn.close(); }
38. ActiveMQConnectionFactoryTest#testDefaultConstructorAndSetConnectorPairs()
Project: activemq-artemis
File: ActiveMQConnectionFactoryTest.java
File: ActiveMQConnectionFactoryTest.java
@Test public void testDefaultConstructorAndSetConnectorPairs() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); assertFactoryParams(cf, new TransportConfiguration[] { liveTC }, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); conn.close(); }
39. ActiveMQConnectionFactoryTest#testDefaultConstructor()
Project: activemq-artemis
File: ActiveMQConnectionFactoryTest.java
File: ActiveMQConnectionFactoryTest.java
@Test public void testDefaultConstructor() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF); assertFactoryParams(cf, null, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = null; try { conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Assert.fail("Should throw exception"); } catch (JMSException e) { } if (conn != null) { conn.close(); } ActiveMQConnectionFactoryTest.log.info("Got here"); testSettersThrowException(cf); }
40. JMSContextExample#main()
Project: activemq-artemis
File: JMSContextExample.java
File: JMSContextExample.java
public static void main(final String[] args) throws Exception { // Instantiate the queue Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Using closeable interface try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); JMSContext jmsContext = cf.createContext()) { // Create a message producer, note that we can chain all this into one statement jmsContext.createProducer().setDeliveryMode(DeliveryMode.PERSISTENT).send(queue, "this is a string"); // Create a Consumer and receive the payload of the message direct. String payLoad = jmsContext.createConsumer(queue).receiveBody(String.class); System.out.println("payLoad = " + payLoad); } }
41. JMSAutoCloseableExample#main()
Project: activemq-artemis
File: JMSAutoCloseableExample.java
File: JMSAutoCloseableExample.java
public static void main(final String[] args) throws Exception { // Step 2. Perfom a lookup on the queue Queue queue = ActiveMQJMSClient.createQueue("exampleQueue"); // Step 4.Create a JMS Context using the try-with-resources statement try (// Even though ConnectionFactory is not closeable it would be nice to close an ActiveMQConnectionFactory ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(); JMSContext jmsContext = cf.createContext()) { // Step 5. create a jms producer JMSProducer jmsProducer = jmsContext.createProducer(); // Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception jmsProducer.send(queue, "A Message from JMS2!"); System.out.println("Received:" + jmsContext.createConsumer(queue).receiveBody(String.class)); } }
42. ActiveMQResourceAdapter#getConnectionFactory()
Project: activemq-artemis
File: ActiveMQResourceAdapter.java
File: ActiveMQResourceAdapter.java
public synchronized ActiveMQConnectionFactory getConnectionFactory(final ConnectionFactoryProperties overrideProperties) { ActiveMQConnectionFactory cf; boolean known = false; if (!knownConnectionFactories.keySet().contains(overrideProperties)) { cf = newConnectionFactory(overrideProperties); knownConnectionFactories.put(overrideProperties, new Pair<>(cf, new AtomicInteger(1))); } else { Pair<ActiveMQConnectionFactory, AtomicInteger> pair = knownConnectionFactories.get(overrideProperties); cf = pair.getA(); pair.getB().incrementAndGet(); known = true; } if (known && cf.getServerLocator().isClosed()) { knownConnectionFactories.remove(overrideProperties); cf = newConnectionFactory(overrideProperties); knownConnectionFactories.put(overrideProperties, new Pair<>(cf, new AtomicInteger(1))); } return cf; }
43. JMSServerManagerImpl#internalCreateCF()
Project: activemq-artemis
File: JMSServerManagerImpl.java
File: JMSServerManagerImpl.java
/** * @param cfConfig * @throws Exception */ private ActiveMQConnectionFactory internalCreateCF(final ConnectionFactoryConfiguration cfConfig) throws Exception { checkInitialised(); ActiveMQConnectionFactory cf = connectionFactories.get(cfConfig.getName()); if (cf == null) { cf = internalCreateCFPOJO(cfConfig); } connectionFactories.put(cfConfig.getName(), cf); jmsManagementService.registerConnectionFactory(cfConfig.getName(), cfConfig, cf); return cf; }
44. JMSServerManagerImpl#recreateCF()
Project: activemq-artemis
File: JMSServerManagerImpl.java
File: JMSServerManagerImpl.java
@Override public synchronized ActiveMQConnectionFactory recreateCF(String name, ConnectionFactoryConfiguration cf) throws Exception { List<String> bindings = connectionFactoryBindings.get(name); if (bindings == null) { throw ActiveMQJMSServerBundle.BUNDLE.cfDoesntExist(name); } String[] usedBindings = bindings.toArray(new String[bindings.size()]); ActiveMQConnectionFactory realCF = internalCreateCFPOJO(cf); if (cf.isPersisted()) { storage.storeConnectionFactory(new PersistedConnectionFactory(cf)); storage.addBindings(PersistedType.ConnectionFactory, cf.getName(), usedBindings); } for (String bindingsElement : usedBindings) { this.bindToBindings(bindingsElement, realCF); } return realCF; }
45. JMSServerManagerImpl#createConnectionFactory()
Project: activemq-artemis
File: JMSServerManagerImpl.java
File: JMSServerManagerImpl.java
@Override public synchronized void createConnectionFactory(final String name, final boolean ha, final JMSFactoryType cfType, final String discoveryGroupName, final String... registryBindings) throws Exception { checkInitialised(); ActiveMQConnectionFactory cf = connectionFactories.get(name); if (cf == null) { ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfigurationImpl().setName(name).setHA(ha).setBindings(registryBindings).setDiscoveryGroupName(discoveryGroupName); createConnectionFactory(true, configuration, registryBindings); } }
46. JMSServerManagerImpl#createConnectionFactory()
Project: activemq-artemis
File: JMSServerManagerImpl.java
File: JMSServerManagerImpl.java
@Override public synchronized void createConnectionFactory(final String name, final boolean ha, final JMSFactoryType cfType, final List<String> connectorNames, String... registryBindings) throws Exception { checkInitialised(); ActiveMQConnectionFactory cf = connectionFactories.get(name); if (cf == null) { ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfigurationImpl().setName(name).setHA(ha).setConnectorNames(connectorNames).setFactoryType(cfType); createConnectionFactory(true, configuration, registryBindings); } }
47. JMSServerManagerImpl#addConnectionFactoryToBindingRegistry()
Project: activemq-artemis
File: JMSServerManagerImpl.java
File: JMSServerManagerImpl.java
@Override public boolean addConnectionFactoryToBindingRegistry(final String name, final String registryBinding) throws Exception { checkInitialised(); checkBindings(registryBinding); ActiveMQConnectionFactory factory = connectionFactories.get(name); if (factory == null) { throw new IllegalArgumentException("Factory does not exist"); } if (registry.lookup(registryBinding) != null) { throw ActiveMQJMSServerBundle.BUNDLE.cfBindingsExists(name); } boolean added = bindToBindings(registryBinding, factory); if (added) { addToBindings(connectionFactoryBindings, name, registryBinding); storage.addBindings(PersistedType.ConnectionFactory, name, registryBinding); } return added; }
48. ConnectionFactoryURITest#testTCPAllNettyConnectorPropertiesMultiple()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testTCPAllNettyConnectorPropertiesMultiple() throws Exception { Map<String, Object> props = new HashMap<>(); Set<String> allowableConnectorKeys = TransportConstants.ALLOWABLE_CONNECTOR_KEYS; StringBuilder sb = new StringBuilder(); //localhost1:61617,localhost2:61618,localhost3:61619)&ha=true"); sb.append("(tcp://localhost0:61616?"); populateConnectorParams(props, allowableConnectorKeys, sb); Map<String, Object> props2 = new HashMap<>(); sb.append(",tcp://localhost1:61617?"); populateConnectorParams(props2, allowableConnectorKeys, sb); Map<String, Object> props3 = new HashMap<>(); sb.append(",tcp://localhost2:61618?"); populateConnectorParams(props3, allowableConnectorKeys, sb); sb.append(")?ha=true&clientID=myID"); ActiveMQConnectionFactory factory = parser.newObject(parser.expandURI((sb.toString())), null); TransportConfiguration[] staticConnectors = factory.getStaticConnectors(); Assert.assertEquals(3, staticConnectors.length); checkTC(props, staticConnectors[0], 0); checkTC(props2, staticConnectors[1], 1); checkTC(props3, staticConnectors[2], 2); }
49. ConnectionFactoryURITest#testTCPAllNettyConnectorProperties()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testTCPAllNettyConnectorProperties() throws Exception { Map<String, Object> props = new HashMap<>(); Set<String> allowableConnectorKeys = TransportConstants.ALLOWABLE_CONNECTOR_KEYS; StringBuilder sb = new StringBuilder(); sb.append("tcp://localhost:3030?ha=true"); populateConnectorParams(props, allowableConnectorKeys, sb); ActiveMQConnectionFactory factory = parser.newObject(new URI(sb.toString()), null); Map<String, Object> params = factory.getStaticConnectors()[0].getParams(); Assert.assertEquals(params.get("host"), "localhost"); Assert.assertEquals(params.get("port"), "3030"); for (Map.Entry<String, Object> entry : params.entrySet()) { if (!entry.getKey().equals("host") && !entry.getKey().equals("port")) { Assert.assertEquals(entry.getValue(), props.get(entry.getKey())); } } }
50. UDPSchema#internalNewObject()
Project: activemq-artemis
File: UDPSchema.java
File: UDPSchema.java
@Override public ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); DiscoveryGroupConfiguration dgc = UDPServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, getHost(uri), getPort(uri), name); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dgc, options.getFactoryTypeEnum()); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, options.getFactoryTypeEnum()); } return BeanSupport.setData(uri, factory, query); }
51. TCPSchema#internalNewObject()
Project: activemq-artemis
File: TCPSchema.java
File: TCPSchema.java
@Override protected ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); List<TransportConfiguration> configurations = TCPTransportConfigurationSchema.getTransportConfigurations(uri, query, TransportConstants.ALLOWABLE_CONNECTOR_KEYS, name, NettyConnectorFactory.class.getName()); TransportConfiguration[] tcs = new TransportConfiguration[configurations.size()]; configurations.toArray(tcs); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(options.getFactoryTypeEnum(), tcs); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), tcs); } return BeanSupport.setData(uri, factory, query); }
52. JGroupsSchema#internalNewObject()
Project: activemq-artemis
File: JGroupsSchema.java
File: JGroupsSchema.java
@Override public ActiveMQConnectionFactory internalNewObject(URI uri, Map<String, String> query, String name) throws Exception { JMSConnectionOptions options = newConectionOptions(uri, query); DiscoveryGroupConfiguration dcConfig = JGroupsServerLocatorSchema.getDiscoveryGroupConfiguration(uri, query, name); ActiveMQConnectionFactory factory; if (options.isHa()) { factory = ActiveMQJMSClient.createConnectionFactoryWithHA(dcConfig, options.getFactoryTypeEnum()); } else { factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dcConfig, options.getFactoryTypeEnum()); } return BeanSupport.setData(uri, factory, query); }
53. ActiveMQJMSClient#createConnectionFactoryWithoutHA()
Project: activemq-artemis
File: ActiveMQJMSClient.java
File: ActiveMQJMSClient.java
/** * Create an ActiveMQConnectionFactory which creates session factories using a static list of * transportConfigurations. * <p> * The ActiveMQConnectionFactory is not updated automatically as the cluster topology changes, and * no HA backup information is propagated to the client * * @param jmsFactoryType * @param transportConfigurations * @return the ActiveMQConnectionFactory */ public static ActiveMQConnectionFactory createConnectionFactoryWithoutHA(JMSFactoryType jmsFactoryType, final TransportConfiguration... transportConfigurations) { ActiveMQConnectionFactory factory = null; if (jmsFactoryType.equals(JMSFactoryType.CF)) { factory = new ActiveMQJMSConnectionFactory(false, transportConfigurations); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) { factory = new ActiveMQQueueConnectionFactory(false, transportConfigurations); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) { factory = new ActiveMQTopicConnectionFactory(false, transportConfigurations); } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) { factory = new ActiveMQXAConnectionFactory(false, transportConfigurations); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) { factory = new ActiveMQXAQueueConnectionFactory(false, transportConfigurations); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) { factory = new ActiveMQXATopicConnectionFactory(false, transportConfigurations); } return factory; }
54. ActiveMQJMSClient#createConnectionFactoryWithHA()
Project: activemq-artemis
File: ActiveMQJMSClient.java
File: ActiveMQJMSClient.java
/** * Create an ActiveMQConnectionFactory which will receive cluster topology updates from the cluster * as servers leave or join and new backups are appointed or removed. * <p> * The initial list of servers supplied in this method is simply to make an initial connection to * the cluster, once that connection is made, up to date cluster topology information is * downloaded and automatically updated whenever the cluster topology changes. If the topology * includes backup servers that information is also propagated to the client so that it can know * which server to failover onto in case of live server failure. * * @param jmsFactoryType * @param initialServers The initial set of servers used to make a connection to the cluster. * Each one is tried in turn until a successful connection is made. Once a connection * is made, the cluster topology is downloaded and the rest of the list is ignored. * @return the ActiveMQConnectionFactory */ public static ActiveMQConnectionFactory createConnectionFactoryWithHA(JMSFactoryType jmsFactoryType, final TransportConfiguration... initialServers) { ActiveMQConnectionFactory factory = null; if (jmsFactoryType.equals(JMSFactoryType.CF)) { factory = new ActiveMQJMSConnectionFactory(true, initialServers); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) { factory = new ActiveMQQueueConnectionFactory(true, initialServers); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) { factory = new ActiveMQTopicConnectionFactory(true, initialServers); } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) { factory = new ActiveMQXAConnectionFactory(true, initialServers); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) { factory = new ActiveMQXAQueueConnectionFactory(true, initialServers); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) { factory = new ActiveMQXATopicConnectionFactory(true, initialServers); } return factory; }
55. ActiveMQJMSClient#createConnectionFactoryWithoutHA()
Project: activemq-artemis
File: ActiveMQJMSClient.java
File: ActiveMQJMSClient.java
/** * Create an ActiveMQConnectionFactory which creates session factories from a set of live servers, no HA backup information is propagated to the client * * The UDP address and port are used to listen for live servers in the cluster * * @param groupConfiguration * @param jmsFactoryType * @return the ActiveMQConnectionFactory */ public static ActiveMQConnectionFactory createConnectionFactoryWithoutHA(final DiscoveryGroupConfiguration groupConfiguration, JMSFactoryType jmsFactoryType) { ActiveMQConnectionFactory factory = null; if (jmsFactoryType.equals(JMSFactoryType.CF)) { factory = new ActiveMQJMSConnectionFactory(false, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) { factory = new ActiveMQQueueConnectionFactory(false, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) { factory = new ActiveMQTopicConnectionFactory(false, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) { factory = new ActiveMQXAConnectionFactory(false, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) { factory = new ActiveMQXAQueueConnectionFactory(false, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) { factory = new ActiveMQXATopicConnectionFactory(false, groupConfiguration); } return factory; }
56. ActiveMQJMSClient#createConnectionFactoryWithHA()
Project: activemq-artemis
File: ActiveMQJMSClient.java
File: ActiveMQJMSClient.java
/** * Creates an ActiveMQConnectionFactory that receives cluster topology updates from the cluster as * servers leave or join and new backups are appointed or removed. * <p> * The discoveryAddress and discoveryPort parameters in this method are used to listen for UDP * broadcasts which contain connection information for members of the cluster. The broadcasted * connection information is simply used to make an initial connection to the cluster, once that * connection is made, up to date cluster topology information is downloaded and automatically * updated whenever the cluster topology changes. If the topology includes backup servers that * information is also propagated to the client so that it can know which server to failover onto * in case of live server failure. * * @param groupConfiguration * @param jmsFactoryType * @return the ActiveMQConnectionFactory */ public static ActiveMQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration, JMSFactoryType jmsFactoryType) { ActiveMQConnectionFactory factory = null; if (jmsFactoryType.equals(JMSFactoryType.CF)) { factory = new ActiveMQJMSConnectionFactory(true, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_CF)) { factory = new ActiveMQQueueConnectionFactory(true, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_CF)) { factory = new ActiveMQTopicConnectionFactory(true, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.XA_CF)) { factory = new ActiveMQXAConnectionFactory(true, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.QUEUE_XA_CF)) { factory = new ActiveMQXAQueueConnectionFactory(true, groupConfiguration); } else if (jmsFactoryType.equals(JMSFactoryType.TOPIC_XA_CF)) { factory = new ActiveMQXATopicConnectionFactory(true, groupConfiguration); } return factory; }
57. JMSFailoverTest#testManualFailover()
Project: activemq-artemis
File: JMSFailoverTest.java
File: JMSFailoverTest.java
@Test public void testManualFailover() throws Exception { ActiveMQConnectionFactory jbcfLive = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcfLive.setBlockOnNonDurableSend(true); jbcfLive.setBlockOnDurableSend(true); ActiveMQConnectionFactory jbcfBackup = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams)); jbcfBackup.setBlockOnNonDurableSend(true); jbcfBackup.setBlockOnDurableSend(true); jbcfBackup.setInitialConnectAttempts(-1); jbcfBackup.setReconnectAttempts(-1); Connection connLive = jbcfLive.createConnection(); MyExceptionListener listener = new MyExceptionListener(); connLive.setExceptionListener(listener); Session sessLive = connLive.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSessionLive = ((ActiveMQSession) sessLive).getCoreSession(); RemotingConnection coreConnLive = ((ClientSessionInternal) coreSessionLive).getConnection(); SimpleString jmsQueueName = new SimpleString(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue"); coreSessionLive.createQueue(jmsQueueName, jmsQueueName, null, true); Queue queue = sessLive.createQueue("myqueue"); final int numMessages = 1000; MessageProducer producerLive = sessLive.createProducer(queue); for (int i = 0; i < numMessages; i++) { TextMessage tm = sessLive.createTextMessage("message" + i); producerLive.send(tm); } // Note we block on P send to make sure all messages get to server before failover JMSUtil.crash(liveServer, coreSessionLive); connLive.close(); // Now recreate on backup Connection connBackup = jbcfBackup.createConnection(); Session sessBackup = connBackup.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumerBackup = sessBackup.createConsumer(queue); connBackup.start(); for (int i = 0; i < numMessages; i++) { TextMessage tm = (TextMessage) consumerBackup.receive(1000); Assert.assertNotNull(tm); Assert.assertEquals("message" + i, tm.getText()); } TextMessage tm = (TextMessage) consumerBackup.receiveNoWait(); Assert.assertNull(tm); connBackup.close(); }
58. JMSFailoverListenerTest#testManualFailover()
Project: activemq-artemis
File: JMSFailoverListenerTest.java
File: JMSFailoverListenerTest.java
@Test public void testManualFailover() throws Exception { ActiveMQConnectionFactory jbcfLive = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcfLive.setBlockOnNonDurableSend(true); jbcfLive.setBlockOnDurableSend(true); ActiveMQConnectionFactory jbcfBackup = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams)); jbcfBackup.setBlockOnNonDurableSend(true); jbcfBackup.setBlockOnDurableSend(true); jbcfBackup.setInitialConnectAttempts(-1); jbcfBackup.setReconnectAttempts(-1); ActiveMQConnection connLive = (ActiveMQConnection) jbcfLive.createConnection(); MyFailoverListener listener = new MyFailoverListener(); connLive.setFailoverListener(listener); Session sessLive = connLive.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSessionLive = ((ActiveMQSession) sessLive).getCoreSession(); SimpleString jmsQueueName = new SimpleString(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue"); coreSessionLive.createQueue(jmsQueueName, jmsQueueName, null, true); Queue queue = sessLive.createQueue("myqueue"); final int numMessages = 1000; MessageProducer producerLive = sessLive.createProducer(queue); for (int i = 0; i < numMessages; i++) { TextMessage tm = sessLive.createTextMessage("message" + i); producerLive.send(tm); } // Note we block on P send to make sure all messages get to server before failover JMSUtil.crash(liveServer, coreSessionLive); Assert.assertEquals(FailoverEventType.FAILURE_DETECTED, listener.get(0)); connLive.close(); // Now recreate on backup Connection connBackup = jbcfBackup.createConnection(); Session sessBackup = connBackup.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumerBackup = sessBackup.createConsumer(queue); connBackup.start(); for (int i = 0; i < numMessages; i++) { TextMessage tm = (TextMessage) consumerBackup.receive(1000); Assert.assertNotNull(tm); Assert.assertEquals("message" + i, tm.getText()); } TextMessage tm = (TextMessage) consumerBackup.receiveNoWait(); Assert.assertEquals(FailoverEventType.FAILOVER_FAILED, listener.get(1)); Assert.assertEquals("Expected 2 FailoverEvents to be triggered", 2, listener.size()); Assert.assertNull(tm); connBackup.close(); }
59. JMSReconnectTest#testReconnectOrReattachSameNode()
Project: activemq-artemis
File: JMSReconnectTest.java
File: JMSReconnectTest.java
private void testReconnectOrReattachSameNode(boolean reattach) throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); jbcf.setReconnectAttempts(-1); if (reattach) { jbcf.setConfirmationWindowSize(1024 * 1024); } // Note we set consumer window size to a value so we can verify that consumer credit re-sending // works properly on failover // The value is small enough that credits will have to be resent several time final int numMessages = 10; final int bodySize = 1000; jbcf.setConsumerWindowSize(numMessages * bodySize / 10); Connection conn = jbcf.createConnection(); MyExceptionListener listener = new MyExceptionListener(); conn.setExceptionListener(listener); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); RemotingConnection coreConn = ((ClientSessionInternal) coreSession).getConnection(); SimpleString jmsQueueName = new SimpleString(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue"); coreSession.createQueue(jmsQueueName, jmsQueueName, null, true); Queue queue = sess.createQueue("myqueue"); MessageProducer producer = sess.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); MessageConsumer consumer = sess.createConsumer(queue); byte[] body = RandomUtil.randomBytes(bodySize); for (int i = 0; i < numMessages; i++) { BytesMessage bm = sess.createBytesMessage(); bm.writeBytes(body); producer.send(bm); } conn.start(); Thread.sleep(2000); ActiveMQException me = new ActiveMQNotConnectedException(); coreConn.fail(me); for (int i = 0; i < numMessages; i++) { BytesMessage bm = (BytesMessage) consumer.receive(1000); Assert.assertNotNull(bm); Assert.assertEquals(body.length, bm.getBodyLength()); } TextMessage tm = (TextMessage) consumer.receiveNoWait(); Assert.assertNull(tm); conn.close(); Assert.assertNotNull(listener.e); Assert.assertTrue(me == listener.e.getCause()); }
60. JMSFailoverTest#testSendReceiveLargeMessages()
Project: activemq-artemis
File: JMSFailoverTest.java
File: JMSFailoverTest.java
@Test public void testSendReceiveLargeMessages() throws Exception { SimpleString QUEUE = new SimpleString("jms.queue.somequeue"); ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc, backuptc); jbcf.setReconnectAttempts(-1); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); jbcf.setMinLargeMessageSize(1024); //jbcf.setConsumerWindowSize(0); //jbcf.setMinLargeMessageSize(1024); final CountDownLatch flagAlign = new CountDownLatch(1); final CountDownLatch waitToKill = new CountDownLatch(1); final AtomicBoolean killed = new AtomicBoolean(false); jbcf.getServerLocator().addIncomingInterceptor(new Interceptor() { int count = 0; @Override public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException { if (packet instanceof SessionReceiveContinuationMessage) { if (count++ == 300 && !killed.get()) { System.out.println("sending countDown on latch waitToKill"); killed.set(true); waitToKill.countDown(); } } return true; } }); Connection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); Session sess = conn.createSession(true, Session.SESSION_TRANSACTED); final ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); // The thread that will fail the server Thread spoilerThread = new Thread() { @Override public void run() { flagAlign.countDown(); // a large timeout just to help in case of debugging try { waitToKill.await(120, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); } try { System.out.println("Killing server..."); JMSUtil.crash(liveServer, coreSession); } catch (Exception e) { e.printStackTrace(); } } }; coreSession.createQueue(QUEUE, QUEUE, true); Queue queue = sess.createQueue("somequeue"); MessageProducer producer = sess.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); for (int i = 0; i < 100; i++) { TextMessage message = sess.createTextMessage(new String(new byte[10 * 1024])); producer.send(message); if (i % 10 == 0) { sess.commit(); } } sess.commit(); conn.start(); spoilerThread.start(); assertTrue(flagAlign.await(10, TimeUnit.SECONDS)); MessageConsumer consumer = sess.createConsumer(queue); // this test is not meant to validate transactionality during Failover as that would require XA and recovery for (int i = 0; i < 90; i++) { TextMessage message = null; int retryNrs = 0; do { retryNrs++; try { message = (TextMessage) consumer.receive(5000); assertNotNull(message); break; } catch (JMSException e) { new Exception("Exception on receive message", e).printStackTrace(); } } while (retryNrs < 10); assertNotNull(message); try { sess.commit(); } catch (Exception e) { new Exception("Exception during commit", e); sess.rollback(); } } conn.close(); spoilerThread.join(); }
61. JMSFailoverTest#testAutomaticFailover()
Project: activemq-artemis
File: JMSFailoverTest.java
File: JMSFailoverTest.java
@Test public void testAutomaticFailover() throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); // Note we set consumer window size to a value so we can verify that consumer credit re-sending // works properly on failover // The value is small enough that credits will have to be resent several time final int numMessages = 10; final int bodySize = 1000; jbcf.setConsumerWindowSize(numMessages * bodySize / 10); Connection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); MyExceptionListener listener = new MyExceptionListener(); conn.setExceptionListener(listener); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); SimpleString jmsQueueName = new SimpleString(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue"); coreSession.createQueue(jmsQueueName, jmsQueueName, null, true); Queue queue = sess.createQueue("myqueue"); MessageProducer producer = sess.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); MessageConsumer consumer = sess.createConsumer(queue); byte[] body = RandomUtil.randomBytes(bodySize); for (int i = 0; i < numMessages; i++) { BytesMessage bm = sess.createBytesMessage(); bm.writeBytes(body); producer.send(bm); } conn.start(); JMSFailoverTest.log.info("sent messages and started connection"); Thread.sleep(2000); JMSUtil.crash(liveServer, ((ActiveMQSession) sess).getCoreSession()); for (int i = 0; i < numMessages; i++) { JMSFailoverTest.log.info("got message " + i); BytesMessage bm = (BytesMessage) consumer.receive(1000); Assert.assertNotNull(bm); Assert.assertEquals(body.length, bm.getBodyLength()); } TextMessage tm = (TextMessage) consumer.receiveNoWait(); Assert.assertNull(tm); conn.close(); }
62. JMSFailoverListenerTest#testAutomaticFailover()
Project: activemq-artemis
File: JMSFailoverListenerTest.java
File: JMSFailoverListenerTest.java
// Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- @Test public void testAutomaticFailover() throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); // Note we set consumer window size to a value so we can verify that consumer credit re-sending // works properly on failover // The value is small enough that credits will have to be resent several time final int numMessages = 10; final int bodySize = 1000; jbcf.setConsumerWindowSize(numMessages * bodySize / 10); ActiveMQConnection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); MyFailoverListener listener = new MyFailoverListener(); conn.setFailoverListener(listener); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); SimpleString jmsQueueName = new SimpleString(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX + "myqueue"); coreSession.createQueue(jmsQueueName, jmsQueueName, null, true); Queue queue = sess.createQueue("myqueue"); MessageProducer producer = sess.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); MessageConsumer consumer = sess.createConsumer(queue); byte[] body = RandomUtil.randomBytes(bodySize); for (int i = 0; i < numMessages; i++) { BytesMessage bm = sess.createBytesMessage(); bm.writeBytes(body); producer.send(bm); } conn.start(); JMSFailoverListenerTest.log.info("sent messages and started connection"); Thread.sleep(2000); JMSUtil.crash(liveServer, ((ActiveMQSession) sess).getCoreSession()); Assert.assertEquals(FailoverEventType.FAILURE_DETECTED, listener.get(0)); for (int i = 0; i < numMessages; i++) { JMSFailoverListenerTest.log.info("got message " + i); BytesMessage bm = (BytesMessage) consumer.receive(1000); Assert.assertNotNull(bm); Assert.assertEquals(body.length, bm.getBodyLength()); } TextMessage tm = (TextMessage) consumer.receiveNoWait(); Assert.assertNull(tm); Assert.assertEquals(FailoverEventType.FAILOVER_COMPLETED, listener.get(1)); conn.close(); Assert.assertEquals("Expected 2 FailoverEvents to be triggered", 2, listener.size()); }
63. JMSQueueControlTest#createConnection()
Project: activemq-artemis
File: JMSQueueControlTest.java
File: JMSQueueControlTest.java
// Private ------------------------------------------------------- private Connection createConnection() throws JMSException { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(InVMConnectorFactory.class.getName())); cf.setBlockOnDurableSend(true); return cf.createConnection(); }
64. JMSServerStartStopTest#testStopStart1()
Project: activemq-artemis
File: JMSServerStartStopTest.java
File: JMSServerStartStopTest.java
@Test public void testStopStart1() throws Exception { final int numMessages = 5; for (int j = 0; j < numMessages; j++) { JMSServerStartStopTest.log.info("Iteration " + j); jmsServer.start(); ActiveMQConnectionFactory jbcf = createConnectionFactory(); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); Connection conn = jbcf.createConnection(); try { Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = sess.createQueue("myJMSQueue"); MessageProducer producer = sess.createProducer(queue); TextMessage tm = sess.createTextMessage("message" + j); producer.send(tm); } finally { conn.close(); jbcf.close(); jmsServer.stop(); } } jmsServer.start(); jbcf = createConnectionFactory(); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); conn = jbcf.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = sess.createQueue("myJMSQueue"); MessageConsumer consumer = sess.createConsumer(queue); conn.start(); for (int i = 0; i < numMessages; i++) { TextMessage tm = (TextMessage) consumer.receive(10000); Assert.assertNotNull("not null", tm); Assert.assertEquals("message" + i, tm.getText()); } conn.close(); jbcf.close(); }
65. GroupingTest#testGroupingRollbackOnClose()
Project: activemq-artemis
File: GroupingTest.java
File: GroupingTest.java
@Test public void testGroupingRollbackOnClose() throws Exception { ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF(); fact.setConsumerWindowSize(1000); fact.setTransactionBatchSize(0); Connection connection = fact.createConnection(); RemotingConnection rc = server.getRemotingService().getConnections().iterator().next(); Connection connection2 = fact.createConnection(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED); MessageProducer producer = session.createProducer(queue); MessageConsumer consumer1 = session.createConsumer(queue); MessageConsumer consumer2 = session2.createConsumer(queue); connection.start(); connection2.start(); String jmsxgroupID = null; for (int j = 0; j < 100; j++) { TextMessage message = session.createTextMessage(); message.setText("Message" + j); setProperty(message); producer.send(message); String prop = message.getStringProperty("JMSXGroupID"); assertNotNull(prop); if (jmsxgroupID != null) { assertEquals(jmsxgroupID, prop); } else { jmsxgroupID = prop; } } session.commit(); //consume 5 msgs from 1st first consumer for (int j = 0; j < 1; j++) { TextMessage tm = (TextMessage) consumer1.receive(10000); assertNotNull(tm); assertEquals("Message" + j, tm.getText()); assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID); } Thread.sleep(2000); //session.rollback(); //session.close(); //consume all msgs from 2nd first consumer // ClientSession amqs = ((ActiveMQSession) session).getCoreSession(); // ((DelegatingSession) amqs).getChannel().close(); rc.fail(new ActiveMQNotConnectedException()); for (int j = 0; j < 10; j++) { TextMessage tm = (TextMessage) consumer2.receive(10000); assertNotNull(tm); long text = ((ActiveMQTextMessage) tm).getCoreMessage().getMessageID(); System.out.println(tm.getJMSMessageID() + " text = " + text); //assertEquals("Message" + j, text); assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID); } connection.close(); connection2.close(); }
66. ConcurrentDeliveryCancelTest#testConcurrentCancels()
Project: activemq-artemis
File: ConcurrentDeliveryCancelTest.java
File: ConcurrentDeliveryCancelTest.java
@Test @BMRules(rules = { @BMRule(name = "enterCancel-holdThere", targetClass = "org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl", targetMethod = "close", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ConcurrentDeliveryCancelTest.enterCancel();") }) public void testConcurrentCancels() throws Exception { System.out.println(server.getConfiguration().getJournalLocation().toString()); server.getAddressSettingsRepository().clear(); AddressSettings settings = new AddressSettings(); settings.setMaxDeliveryAttempts(-1); server.getAddressSettingsRepository().addMatch("#", settings); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("tcp://localhost:61616", "test"); cf.setReconnectAttempts(0); cf.setRetryInterval(10); System.out.println("....."); for (ServerSession srvSess : server.getSessions()) { System.out.println(srvSess); } String queueName = RandomUtil.randomString(); Queue queue = createQueue(queueName); int numberOfMessages = 10000; { Connection connection = cf.createConnection(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); MessageProducer producer = session.createProducer(queue); for (int i = 0; i < numberOfMessages; i++) { TextMessage msg = session.createTextMessage("message " + i); msg.setIntProperty("i", i); producer.send(msg); } session.commit(); connection.close(); } for (int i = 0; i < 100; i++) { XAConnectionFactory xacf = ActiveMQJMSClient.createConnectionFactory("tcp://localhost:61616", "test"); final XAConnection connection = xacf.createXAConnection(); final XASession theSession = connection.createXASession(); ((ActiveMQSession) theSession).getCoreSession().addMetaData("theSession", "true"); connection.start(); final MessageConsumer consumer = theSession.createConsumer(queue); XidImpl xid = newXID(); theSession.getXAResource().start(xid, XAResource.TMNOFLAGS); // I'm setting a small timeout just because I'm lazy to call end myself theSession.getXAResource().setTransactionTimeout(1); for (int msg = 0; msg < 11; msg++) { Assert.assertNotNull(consumer.receiveNoWait()); } System.out.println("....."); final List<ServerSession> serverSessions = new LinkedList<>(); // We will force now the failure simultaneously from several places for (ServerSession srvSess : server.getSessions()) { if (srvSess.getMetaData("theSession") != null) { System.out.println(srvSess); serverSessions.add(srvSess); } } // from Transactional reaper resetLatches(2); List<Thread> threads = new LinkedList<>(); threads.add(new Thread("ConsumerCloser") { @Override public void run() { try { System.out.println(Thread.currentThread().getName() + " closing consumer"); consumer.close(); System.out.println(Thread.currentThread().getName() + " closed consumer"); } catch (Exception e) { e.printStackTrace(); } } }); threads.add(new Thread("SessionCloser") { @Override public void run() { for (ServerSession sess : serverSessions) { System.out.println("Thread " + Thread.currentThread().getName() + " starting"); try { // A session.close could sneak in through failover or some other scenarios. // a call to RemotingConnection.fail wasn't replicating the issue. // I needed to call Session.close() directly to replicate what was happening in production sess.close(true); } catch (Exception e) { e.printStackTrace(); } System.out.println("Thread " + Thread.currentThread().getName() + " done"); } } }); for (Thread t : threads) { t.start(); } Assert.assertTrue(latchEnter.await(10, TimeUnit.MINUTES)); latchFlag.countDown(); for (Thread t : threads) { t.join(5000); Assert.assertFalse(t.isAlive()); } connection.close(); } Connection connection = cf.createConnection(); try { connection.setClientID("myID"); // I am too lazy to call end on all the transactions Thread.sleep(5000); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(queue); HashMap<Integer, AtomicInteger> mapCount = new HashMap<>(); while (true) { TextMessage message = (TextMessage) consumer.receiveNoWait(); if (message == null) { break; } Integer value = message.getIntProperty("i"); AtomicInteger count = mapCount.get(value); if (count == null) { count = new AtomicInteger(0); mapCount.put(message.getIntProperty("i"), count); } count.incrementAndGet(); } boolean failed = false; for (int i = 0; i < numberOfMessages; i++) { AtomicInteger count = mapCount.get(i); if (count == null) { System.out.println("Message " + i + " not received"); failed = true; } else if (count.get() > 1) { System.out.println("Message " + i + " received " + count.get() + " times"); failed = true; } } Assert.assertFalse("test failed, look at the system.out of the test for more information", failed); } finally { connection.close(); } }
67. ActiveMQResourceAdapter#createRecoveryActiveMQConnectionFactory()
Project: activemq-artemis
File: ActiveMQResourceAdapter.java
File: ActiveMQResourceAdapter.java
public ActiveMQConnectionFactory createRecoveryActiveMQConnectionFactory(final ConnectionFactoryProperties overrideProperties) { ActiveMQConnectionFactory cf; List<String> connectorClassName = overrideProperties.getParsedConnectorClassNames() != null ? overrideProperties.getParsedConnectorClassNames() : raProperties.getParsedConnectorClassNames(); String discoveryAddress = overrideProperties.getDiscoveryAddress() != null ? overrideProperties.getDiscoveryAddress() : getDiscoveryAddress(); String jgroupsFileName = overrideProperties.getJgroupsFile() != null ? overrideProperties.getJgroupsFile() : getJgroupsFile(); String jgroupsChannel = overrideProperties.getJgroupsChannelName() != null ? overrideProperties.getJgroupsChannelName() : getJgroupsChannelName(); if (connectorClassName == null) { BroadcastEndpointFactory endpointFactory = null; if (discoveryAddress != null) { Integer discoveryPort = overrideProperties.getDiscoveryPort() != null ? overrideProperties.getDiscoveryPort() : getDiscoveryPort(); if (discoveryPort == null) { discoveryPort = ActiveMQClient.DEFAULT_DISCOVERY_PORT; } String localBindAddress = overrideProperties.getDiscoveryLocalBindAddress() != null ? overrideProperties.getDiscoveryLocalBindAddress() : raProperties.getDiscoveryLocalBindAddress(); endpointFactory = new UDPBroadcastEndpointFactory().setGroupAddress(discoveryAddress).setGroupPort(discoveryPort).setLocalBindAddress(localBindAddress).setLocalBindPort(-1); } else if (jgroupsFileName != null) { endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName(jgroupsChannel).setFile(jgroupsFileName); } else { String jgroupsLocatorClass = raProperties.getJgroupsChannelLocatorClass(); if (jgroupsLocatorClass != null) { String jgroupsChannelRefName = raProperties.getJgroupsChannelRefName(); JChannel jchannel = ActiveMQRaUtils.locateJGroupsChannel(jgroupsLocatorClass, jgroupsChannelRefName); endpointFactory = new ChannelBroadcastEndpointFactory(jchannel, jgroupsChannel); } if (endpointFactory == null) { throw new IllegalArgumentException("must provide either TransportType or DiscoveryGroupAddress and DiscoveryGroupPort for ResourceAdapter Connection Factory"); } } Long refreshTimeout = overrideProperties.getDiscoveryRefreshTimeout() != null ? overrideProperties.getDiscoveryRefreshTimeout() : raProperties.getDiscoveryRefreshTimeout(); if (refreshTimeout == null) { refreshTimeout = ActiveMQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT; } Long initialTimeout = overrideProperties.getDiscoveryInitialWaitTimeout() != null ? overrideProperties.getDiscoveryInitialWaitTimeout() : raProperties.getDiscoveryInitialWaitTimeout(); if (initialTimeout == null) { initialTimeout = ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT; } DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration().setRefreshTimeout(refreshTimeout).setDiscoveryInitialWaitTimeout(initialTimeout).setBroadcastEndpointFactory(endpointFactory); groupConfiguration.setRefreshTimeout(refreshTimeout); if (ActiveMQRALogger.LOGGER.isDebugEnabled()) { ActiveMQRALogger.LOGGER.debug("Creating Recovery Connection Factory on the resource adapter for discovery=" + groupConfiguration); } cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.XA_CF); } else { TransportConfiguration[] transportConfigurations = new TransportConfiguration[connectorClassName.size()]; List<Map<String, Object>> connectionParams; if (overrideProperties.getParsedConnectorClassNames() != null) { connectionParams = overrideProperties.getParsedConnectionParameters(); } else { connectionParams = raProperties.getParsedConnectionParameters(); } for (int i = 0; i < connectorClassName.size(); i++) { TransportConfiguration tc; if (connectionParams == null || i >= connectionParams.size()) { tc = new TransportConfiguration(connectorClassName.get(i)); ActiveMQRALogger.LOGGER.debug("No connector params provided using default"); } else { tc = new TransportConfiguration(connectorClassName.get(i), connectionParams.get(i)); } transportConfigurations[i] = tc; } if (ActiveMQRALogger.LOGGER.isDebugEnabled()) { ActiveMQRALogger.LOGGER.debug("Creating Recovery Connection Factory on the resource adapter for transport=" + Arrays.toString(transportConfigurations)); } cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, transportConfigurations); } setParams(cf, overrideProperties); //now make sure we are HA in any way cf.setReconnectAttempts(0); cf.setInitialConnectAttempts(0); return cf; }
68. ResourceAdapterTest#test2DefaultConnectionFactorySame()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void test2DefaultConnectionFactorySame() throws Exception { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(InVMConnectorFactory.class.getName()); ActiveMQConnectionFactory factory = ra.getDefaultActiveMQConnectionFactory(); ActiveMQConnectionFactory factory2 = ra.getDefaultActiveMQConnectionFactory(); Assert.assertEquals(factory, factory2); }
69. JMSServerControlTest#testDestroyQueueWithConsumersNetty()
Project: activemq-artemis
File: JMSServerControlTest.java
File: JMSServerControlTest.java
@Test public void testDestroyQueueWithConsumersNetty() throws Exception { String queueJNDIBinding = RandomUtil.randomString(); String queueName = RandomUtil.randomString(); ActiveMQTestBase.checkNoBinding(context, queueJNDIBinding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); JMSServerControl control = createManagementControl(); control.createQueue(queueName, queueJNDIBinding); ActiveMQTestBase.checkBinding(context, queueJNDIBinding); checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(false, new TransportConfiguration(ActiveMQTestBase.NETTY_CONNECTOR_FACTORY)); cf.setReconnectAttempts(-1); ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create a consumer will create a Core queue bound to the topic address MessageConsumer cons = session.createConsumer(ActiveMQJMSClient.createQueue(queueName)); control.destroyQueue(queueName, true); ActiveMQTestBase.checkNoBinding(context, queueJNDIBinding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName)); Assert.assertNull(fakeJMSStorageManager.destinationMap.get(queueName)); long timeout = System.currentTimeMillis() + 1000; while (timeout > System.currentTimeMillis() && !((ActiveMQMessageConsumer) cons).isClosed()) { Thread.sleep(1); } Assert.assertTrue(((ActiveMQMessageConsumer) cons).isClosed()); try { cons.receive(5000); Assert.fail("should throw exception"); } catch (javax.jms.IllegalStateException e) { Assert.assertTrue(e.getCause() instanceof ActiveMQObjectClosedException); } } finally { if (connection != null) { connection.close(); } } }
70. LargeMessageOverBridgeTest#testSendLargeForBridge()
Project: activemq-artemis
File: LargeMessageOverBridgeTest.java
File: LargeMessageOverBridgeTest.java
/** * The message won't be large to the client while it will be considered large through the bridge * * @throws Exception */ @Test public void testSendLargeForBridge() throws Exception { createQueue("Q1"); Queue queue = (Queue) context1.lookup("queue/Q1"); ActiveMQConnectionFactory cf1 = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, generateInVMParams(1))); cf1.setMinLargeMessageSize(200 * 1024); Connection conn1 = cf1.createConnection(); Session session1 = conn1.createSession(true, Session.SESSION_TRANSACTED); MessageProducer prod1 = session1.createProducer(queue); Connection conn2 = cf2.createConnection(); Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons2 = session2.createConsumer(queue); conn2.start(); byte[] bytes = new byte[150 * 1024]; for (int i = 0; i < bytes.length; i++) { bytes[i] = getSamplebyte(i); } for (int i = 0; i < 10; i++) { BytesMessage msg = session1.createBytesMessage(); msg.writeBytes(bytes); prod1.send(msg); } session1.commit(); for (int i = 0; i < 5; i++) { BytesMessage msg2 = (BytesMessage) cons2.receive(5000); assertNotNull(msg2); msg2.acknowledge(); for (int j = 0; j < bytes.length; j++) { assertEquals("Position " + i, msg2.readByte(), bytes[j]); } } conn1.close(); conn2.close(); }
71. JMSReconnectTest#testNoReconnectCloseAfterFailToReconnectWithTopicConsumer()
Project: activemq-artemis
File: JMSReconnectTest.java
File: JMSReconnectTest.java
//If the server is shutdown after a non durable sub is created, then close on the connection should proceed normally @Test public void testNoReconnectCloseAfterFailToReconnectWithTopicConsumer() throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcf.setReconnectAttempts(0); Connection conn = jbcf.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); coreSession.createQueue(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX + "mytopic", "blahblah", null, false); Topic topic = ActiveMQJMSClient.createTopic("mytopic"); //Create a non durable subscriber sess.createConsumer(topic); Thread.sleep(2000); this.server.stop(); this.server.start(); sess.close(); conn.close(); }
72. JMSReconnectTest#testReconnectSameNodeServerRestartedWithNonDurableSubOrTempQueue()
Project: activemq-artemis
File: JMSReconnectTest.java
File: JMSReconnectTest.java
//Test that non durable JMS sub gets recreated in auto reconnect private void testReconnectSameNodeServerRestartedWithNonDurableSubOrTempQueue(final boolean nonDurableSub) throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcf.setReconnectAttempts(-1); Connection conn = jbcf.createConnection(); MyExceptionListener listener = new MyExceptionListener(); conn.setExceptionListener(listener); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); Destination dest; if (nonDurableSub) { coreSession.createQueue(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX + "mytopic", "blahblah", null, false); dest = ActiveMQJMSClient.createTopic("mytopic"); } else { dest = sess.createTemporaryQueue(); } MessageProducer producer = sess.createProducer(dest); //Create a non durable subscriber MessageConsumer consumer = sess.createConsumer(dest); this.server.stop(); this.server.start(); //Allow client some time to reconnect Thread.sleep(3000); final int numMessages = 100; byte[] body = RandomUtil.randomBytes(1000); for (int i = 0; i < numMessages; i++) { BytesMessage bm = sess.createBytesMessage(); bm.writeBytes(body); producer.send(bm); } conn.start(); for (int i = 0; i < numMessages; i++) { BytesMessage bm = (BytesMessage) consumer.receive(1000); Assert.assertNotNull(bm); Assert.assertEquals(body.length, bm.getBodyLength()); } TextMessage tm = (TextMessage) consumer.receiveNoWait(); Assert.assertNull(tm); conn.close(); Assert.assertNotNull(listener.e); }
73. JMSFailoverTest#testCreateTopic()
Project: activemq-artemis
File: JMSFailoverTest.java
File: JMSFailoverTest.java
@Test public void testCreateTopic() throws Exception { liveJMSServer.createTopic(true, "topic", "/topic/t1"); assertNotNull(ctx1.lookup("//topic/t1")); ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); Connection conn = null; try { conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); JMSUtil.crash(liveServer, coreSession); assertNotNull(ctx2.lookup("/topic/t1")); } finally { if (conn != null) { conn.close(); } } }
74. JMSFailoverTest#testCreateQueue()
Project: activemq-artemis
File: JMSFailoverTest.java
File: JMSFailoverTest.java
// Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- @Test public void testCreateQueue() throws Exception { liveJMSServer.createQueue(true, "queue1", null, true, "/queue/queue1"); assertNotNull(ctx1.lookup("/queue/queue1")); ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc); jbcf.setReconnectAttempts(-1); Connection conn = null; try { conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession(); JMSUtil.crash(liveServer, coreSession); assertNotNull(ctx2.lookup("/queue/queue1")); } finally { if (conn != null) { conn.close(); } } }
75. ConnectionTest#testThroughNewConnectionFactory()
Project: activemq-artemis
File: ConnectionTest.java
File: ConnectionTest.java
@Test public void testThroughNewConnectionFactory() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://0"); testThroughNewConnectionFactory(connectionFactory); // Run it again with a cloned through serialization CF, simulating JNDI lookups connectionFactory = serialClone(connectionFactory); testThroughNewConnectionFactory(connectionFactory); connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?&blockOnNonDurableSend=true&" + "retryIntervalMultiplier=1.0&maxRetryInterval=2000&producerMaxRate=-1&" + "blockOnDurableSend=true&connectionTTL=60000&compressLargeMessage=false&reconnectAttempts=0&" + "cacheLargeMessagesClient=false&scheduledThreadPoolMaxSize=5&useGlobalPools=true&" + "callFailoverTimeout=-1&initialConnectAttempts=1&clientFailureCheckPeriod=30000&" + "blockOnAcknowledge=true&consumerWindowSize=1048576&minLargeMessageSize=102400&" + "autoGroup=false&threadPoolMaxSize=-1&confirmationWindowSize=-1&" + "transactionBatchSize=1048576&callTimeout=30000&preAcknowledge=false&" + "connectionLoadBalancingPolicyClassName=org.apache.activemq.artemis.api.core.client.loadbalance." + "RoundRobinConnectionLoadBalancingPolicy&dupsOKBatchSize=1048576&initialMessagePacketSize=1500&" + "consumerMaxRate=-1&retryInterval=2000&failoverOnInitialConnection=false&producerWindowSize=65536&" + "port=61616&host=localhost#"); testThroughNewConnectionFactory(connectionFactory); // Run it again with a cloned through serialization CF, simulating JNDI lookups connectionFactory = serialClone(connectionFactory); testThroughNewConnectionFactory(connectionFactory); }
76. InterceptorTest#testInterceptorOnURI()
Project: activemq-artemis
File: InterceptorTest.java
File: InterceptorTest.java
@Test public void testInterceptorOnURI() throws Exception { locator.close(); server.createQueue(JMS_QUEUE, JMS_QUEUE, null, true, false); String uri = "tcp://localhost:61616?incomingInterceptorList=" + Incoming.class.getCanonicalName() + "&outgoingInterceptorList=" + Outgoing.class.getName(); System.out.println(uri); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri); // Serialize stuff to make sure the interceptors are on the URI ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.close(); objectOutputStream.writeObject(factory); ByteArrayInputStream input = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); ObjectInputStream objectInputStream = new ObjectInputStream(input); factory = (ActiveMQConnectionFactory) objectInputStream.readObject(); Connection connection = factory.createConnection(); Session session = connection.createSession(); MessageProducer producer = session.createProducer(session.createQueue(QUEUE.toString())); producer.send(session.createTextMessage("HelloMessage")); connection.start(); MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE.toString())); TextMessage msg = (TextMessage) consumer.receive(5000); Assert.assertNotNull(msg); Assert.assertEquals("HelloMessage", msg.getText()); Assert.assertEquals("was here", msg.getStringProperty("Incoming")); Assert.assertEquals("sending", msg.getStringProperty("Outgoing")); connection.close(); factory.close(); }
77. HornetQProtocolManagerTest#testLegacy2()
Project: activemq-artemis
File: HornetQProtocolManagerTest.java
File: HornetQProtocolManagerTest.java
/** This test will use an ArtemisConnectionFactory with clientProtocolManager=*/ @Test public void testLegacy2() throws Exception { ConnectionFactoryConfiguration configuration = new ConnectionFactoryConfigurationImpl(); configuration.setConnectorNames("legacy"); configuration.setName("legacy"); configuration.setProtocolManagerFactoryStr(HornetQClientProtocolManagerFactory.class.getName()); embeddedJMS.getJMSServerManager().createConnectionFactory(false, configuration, "legacy"); Queue queue = (Queue) embeddedJMS.lookup("testQueue"); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) embeddedJMS.lookup("legacy"); Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue); TextMessage message = session.createTextMessage("Test"); for (int i = 0; i < 5; i++) { message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "duplicate"); producer.send(message); } connection.start(); MessageConsumer consumer = session.createConsumer(queue); TextMessage messageRec = (TextMessage) consumer.receive(5000); Assert.assertNotNull(messageRec); Assert.assertEquals("Test", messageRec.getText()); Assert.assertNull(consumer.receiveNoWait()); connection.close(); connectionFactory.close(); }
78. ConnectionFactoryURITest#testJGroupsAllProperties()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testJGroupsAllProperties() throws Exception { StringBuilder sb = new StringBuilder(); sb.append("jgroups://?file=param=value;param=value&channelName=channelName&ha=true"); BeanUtilsBean bean = new BeanUtilsBean(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); populate(sb, bean, factory); ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString()), null); checkEquals(bean, factory, factory2); }
79. ConnectionFactoryURITest#testUDPURI()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testUDPURI() throws Exception { DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration(); UDPBroadcastEndpointFactory endpoint = new UDPBroadcastEndpointFactory(); endpoint.setGroupPort(3333).setGroupAddress("wahey").setLocalBindPort(555).setLocalBindAddress("uhuh"); discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpoint); ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF); URI tcp = parser.createSchema("udp", connectionFactoryWithHA); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(tcp.toString()); DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration(); Assert.assertNotNull(dgc); BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory(); Assert.assertNotNull(befc); Assert.assertTrue(befc instanceof UDPBroadcastEndpointFactory); UDPBroadcastEndpointFactory ubgc = (UDPBroadcastEndpointFactory) befc; Assert.assertEquals("wahey", ubgc.getGroupAddress()); Assert.assertEquals(3333, ubgc.getGroupPort()); //these 2 are transient // These will take the System.properties used on the testsuite, // for that reason we take them as != instead of checking for null Assert.assertNotEquals("uhuh", ubgc.getLocalBindAddress()); Assert.assertNotEquals(555, ubgc.getLocalBindPort()); Assert.assertEquals("foo", dgc.getName()); Assert.assertEquals(5678, dgc.getDiscoveryInitialWaitTimeout()); Assert.assertEquals(12345, dgc.getRefreshTimeout()); BeanUtilsBean bean = new BeanUtilsBean(); checkEquals(bean, connectionFactoryWithHA, factory); }
80. ConnectionFactoryURITest#testUDPAllProperties()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testUDPAllProperties() throws Exception { StringBuilder sb = new StringBuilder(); sb.append("udp://localhost:3030?ha=true"); BeanUtilsBean bean = new BeanUtilsBean(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); populate(sb, bean, factory); ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString()), null); checkEquals(bean, factory, factory2); }
81. ConnectionFactoryURITest#testTCPAllProperties()
Project: activemq-artemis
File: ConnectionFactoryURITest.java
File: ConnectionFactoryURITest.java
@Test public void testTCPAllProperties() throws Exception { StringBuilder sb = new StringBuilder(); sb.append("tcp://localhost:3030?ha=true"); BeanUtilsBean bean = new BeanUtilsBean(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(true, (TransportConfiguration) null); populate(sb, bean, factory); ActiveMQConnectionFactory factory2 = parser.newObject(new URI(sb.toString()), null); checkEquals(bean, factory, factory2); }
82. ResourceAdapterTest#testCreateConnectionFactoryNoOverrides()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testCreateConnectionFactoryNoOverrides() throws Exception { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(InVMConnectorFactory.class.getName()); ActiveMQConnectionFactory factory = ra.getConnectionFactory(new ConnectionFactoryProperties()); Assert.assertEquals(factory.getCallTimeout(), ActiveMQClient.DEFAULT_CALL_TIMEOUT); Assert.assertEquals(factory.getClientFailureCheckPeriod(), ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD); Assert.assertEquals(factory.getClientID(), null); Assert.assertEquals(factory.getConnectionLoadBalancingPolicyClassName(), ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME); Assert.assertEquals(factory.getConnectionTTL(), ActiveMQClient.DEFAULT_CONNECTION_TTL); Assert.assertEquals(factory.getConsumerMaxRate(), ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE); Assert.assertEquals(factory.getConsumerWindowSize(), ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE); Assert.assertEquals(factory.getDupsOKBatchSize(), ActiveMQClient.DEFAULT_ACK_BATCH_SIZE); Assert.assertEquals(factory.getMinLargeMessageSize(), ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE); Assert.assertEquals(factory.getProducerMaxRate(), ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE); Assert.assertEquals(factory.getConfirmationWindowSize(), ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE); // by default, reconnect attempts is set to -1 Assert.assertEquals(-1, factory.getReconnectAttempts()); Assert.assertEquals(factory.getRetryInterval(), ActiveMQClient.DEFAULT_RETRY_INTERVAL); Assert.assertEquals(factory.getRetryIntervalMultiplier(), ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, 0.000001); Assert.assertEquals(factory.getScheduledThreadPoolMaxSize(), ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE); Assert.assertEquals(factory.getThreadPoolMaxSize(), ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE); Assert.assertEquals(factory.getTransactionBatchSize(), ActiveMQClient.DEFAULT_ACK_BATCH_SIZE); Assert.assertEquals(factory.isAutoGroup(), ActiveMQClient.DEFAULT_AUTO_GROUP); Assert.assertEquals(factory.isBlockOnAcknowledge(), ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE); Assert.assertEquals(factory.isBlockOnNonDurableSend(), ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND); Assert.assertEquals(factory.isBlockOnDurableSend(), ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND); Assert.assertEquals(factory.isPreAcknowledge(), ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE); Assert.assertEquals(factory.isUseGlobalPools(), ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS); }
83. ResourceAdapterTest#testDefaultConnectionFactory()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
// Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- // Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- @Test public void testDefaultConnectionFactory() throws Exception { ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); ra.setConnectorClassName(InVMConnectorFactory.class.getName()); ActiveMQConnectionFactory factory = ra.getDefaultActiveMQConnectionFactory(); Assert.assertEquals(factory.getCallTimeout(), ActiveMQClient.DEFAULT_CALL_TIMEOUT); Assert.assertEquals(factory.getClientFailureCheckPeriod(), ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD); Assert.assertEquals(factory.getClientID(), null); Assert.assertEquals(factory.getConnectionLoadBalancingPolicyClassName(), ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME); Assert.assertEquals(factory.getConnectionTTL(), ActiveMQClient.DEFAULT_CONNECTION_TTL); Assert.assertEquals(factory.getConsumerMaxRate(), ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE); Assert.assertEquals(factory.getConsumerWindowSize(), ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE); Assert.assertEquals(factory.getDupsOKBatchSize(), ActiveMQClient.DEFAULT_ACK_BATCH_SIZE); Assert.assertEquals(factory.getMinLargeMessageSize(), ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE); Assert.assertEquals(factory.getProducerMaxRate(), ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE); Assert.assertEquals(factory.getConfirmationWindowSize(), ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE); // by default, reconnect attempts is set to -1 Assert.assertEquals(-1, factory.getReconnectAttempts()); Assert.assertEquals(factory.getRetryInterval(), ActiveMQClient.DEFAULT_RETRY_INTERVAL); Assert.assertEquals(factory.getRetryIntervalMultiplier(), ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, 0.00001); Assert.assertEquals(factory.getScheduledThreadPoolMaxSize(), ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE); Assert.assertEquals(factory.getThreadPoolMaxSize(), ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE); Assert.assertEquals(factory.getTransactionBatchSize(), ActiveMQClient.DEFAULT_ACK_BATCH_SIZE); Assert.assertEquals(factory.isAutoGroup(), ActiveMQClient.DEFAULT_AUTO_GROUP); Assert.assertEquals(factory.isBlockOnAcknowledge(), ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE); Assert.assertEquals(factory.isBlockOnNonDurableSend(), ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND); Assert.assertEquals(factory.isBlockOnDurableSend(), ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND); Assert.assertEquals(factory.isPreAcknowledge(), ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE); Assert.assertEquals(factory.isUseGlobalPools(), ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS); }
84. SendReceiveMultiThreadTest#testMultipleWrites()
Project: activemq-artemis
File: SendReceiveMultiThreadTest.java
File: SendReceiveMultiThreadTest.java
@Test public void testMultipleWrites() throws Exception { deleteDirectory(new File(DIRECTORY)); ActiveMQServer server = createServer(true); server.getConfiguration().setJournalFileSize(10 * 1024 * 1024); server.getConfiguration().setJournalMinFiles(2); server.getConfiguration().setJournalCompactMinFiles(ActiveMQDefaultConfiguration.getDefaultJournalCompactMinFiles()); server.getConfiguration().setJournalCompactPercentage(ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage()); server.getConfiguration().setJournalType(JournalType.ASYNCIO); server.getConfiguration().addAcceptorConfiguration("core", DefaultConnectionProperties.DEFAULT_BROKER_BIND_URL); server.getConfiguration().setJournalDirectory(DIRECTORY + "/journal"); server.getConfiguration().setBindingsDirectory(DIRECTORY + "/bindings"); server.getConfiguration().setPagingDirectory(DIRECTORY + "/paging"); server.getConfiguration().setLargeMessagesDirectory(DIRECTORY + "/largemessage"); server.getConfiguration().setJournalMaxIO_AIO(200); // TODO Setup Acceptors server.start(); Queue queue = server.createQueue(SimpleString.toSimpleString("jms.queue.performanceQueue"), SimpleString.toSimpleString("jms.queue.performanceQueue"), null, true, false); Queue queue2 = server.createQueue(SimpleString.toSimpleString("jms.queue.stationaryQueue"), SimpleString.toSimpleString("jms.queue.stationaryQueue"), null, true, false); MyThread[] threads = new MyThread[NUMBER_OF_THREADS]; ConsumerThread[] cthreads = new ConsumerThread[NUMBER_OF_THREADS]; final CountDownLatch alignFlag = new CountDownLatch(NUMBER_OF_THREADS); final CountDownLatch startFlag = new CountDownLatch(1); final CountDownLatch finishFlag = new CountDownLatch(NUMBER_OF_THREADS); cf = new ActiveMQConnectionFactory(); Thread slowSending = new Thread() { @Override public void run() { Connection conn = null; try { conn = cf.createConnection(); Session session = conn.createSession(true, Session.SESSION_TRANSACTED); MessageProducer producer = session.createProducer(ActiveMQJMSClient.createQueue("stationaryQueue")); conn.start(); MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue("stationaryQueue")); while (true) { for (int i = 0; i < 10; i++) { System.out.println("stationed message"); producer.send(session.createTextMessage("stationed")); session.commit(); Thread.sleep(1000); } for (int i = 0; i < 10; i++) { consumer.receive(5000); session.commit(); System.out.println("Receiving stationed"); Thread.sleep(1000); } } } catch (Exception e) { e.printStackTrace(); } finally { try { conn.close(); } catch (Exception ignored) { } } } }; slowSending.start(); destination = ActiveMQJMSClient.createQueue("performanceQueue"); for (int i = 0; i < threads.length; i++) { threads[i] = new MyThread("sender::" + i, NUMBER_OF_MESSAGES, alignFlag, startFlag, finishFlag); cthreads[i] = new ConsumerThread(NUMBER_OF_MESSAGES); } for (ConsumerThread t : cthreads) { t.start(); } for (MyThread t : threads) { t.start(); } Assert.assertEquals(NUMBER_OF_THREADS, queue.getConsumerCount()); alignFlag.await(); long startTime = System.currentTimeMillis(); startFlag.countDown(); // I'm using a countDown to avoid measuring time spent on thread context from join. // i.e. i want to measure as soon as the loops are done finishFlag.await(); long endtime = System.currentTimeMillis(); receivedLatch.await(); long endTimeConsuming = System.currentTimeMillis(); for (ConsumerThread t : cthreads) { t.join(); Assert.assertEquals(0, t.errors); } for (MyThread t : threads) { t.join(); Assert.assertEquals(0, t.errors.get()); } slowSending.interrupt(); slowSending.join(); server.stop(); System.out.println("Time on sending:: " + (endtime - startTime)); System.out.println("Time on consuming:: " + (endTimeConsuming - startTime)); }
85. ConnectionFactoryTest#testFactoryTypes()
Project: activemq-artemis
File: ConnectionFactoryTest.java
File: ConnectionFactoryTest.java
@Test public void testFactoryTypes() throws Exception { deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory"); deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE"); deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE_XA_FALSE", "/CF_QUEUE_XA_FALSE"); deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE"); deployConnectionFactory(0, JMSFactoryType.CF, "CF_XA_FALSE", "/CF_XA_FALSE"); deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE"); deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC"); deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE"); deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC", "/CF_GENERIC"); deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_GENERIC_XA_TRUE", "/CF_GENERIC_XA_TRUE"); deployConnectionFactory(0, JMSFactoryType.CF, "CF_GENERIC_XA_FALSE", "/CF_GENERIC_XA_FALSE"); deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC_XA_FALSE", "/CF_TOPIC_XA_FALSE"); ActiveMQConnectionFactory factory = null; factory = (ActiveMQConnectionFactory) ic.lookup("/ConnectionFactory"); Assert.assertTrue(factory instanceof ConnectionFactory); assertNTypes(factory, 4); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_TRUE"); Assert.assertTrue(factory instanceof XAConnectionFactory); assertNTypes(factory, 6); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_XA_FALSE"); Assert.assertTrue(factory instanceof ConnectionFactory); assertNTypes(factory, 4); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC"); Assert.assertTrue(factory instanceof ConnectionFactory); assertNTypes(factory, 4); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_TRUE"); Assert.assertTrue(factory instanceof XAConnectionFactory); assertNTypes(factory, 6); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_GENERIC_XA_FALSE"); Assert.assertTrue(factory instanceof ConnectionFactory); assertNTypes(factory, 4); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE"); Assert.assertTrue(factory instanceof QueueConnectionFactory); assertNTypes(factory, 3); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE"); Assert.assertTrue(factory instanceof XAQueueConnectionFactory); assertNTypes(factory, 4); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_QUEUE_XA_FALSE"); Assert.assertTrue(factory instanceof QueueConnectionFactory); assertNTypes(factory, 3); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC"); Assert.assertTrue(factory instanceof TopicConnectionFactory); assertNTypes(factory, 3); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE"); Assert.assertTrue(factory instanceof XATopicConnectionFactory); assertNTypes(factory, 4); factory = (ActiveMQConnectionFactory) ic.lookup("/CF_TOPIC_XA_FALSE"); Assert.assertTrue(factory instanceof TopicConnectionFactory); assertNTypes(factory, 3); undeployConnectionFactory("ConnectionFactory"); undeployConnectionFactory("CF_QUEUE_XA_TRUE"); undeployConnectionFactory("CF_QUEUE_XA_FALSE"); undeployConnectionFactory("CF_XA_TRUE"); undeployConnectionFactory("CF_XA_FALSE"); undeployConnectionFactory("CF_QUEUE"); undeployConnectionFactory("CF_TOPIC"); undeployConnectionFactory("CF_TOPIC_XA_TRUE"); undeployConnectionFactory("CF_GENERIC"); undeployConnectionFactory("CF_GENERIC_XA_TRUE"); undeployConnectionFactory("CF_GENERIC_XA_FALSE"); undeployConnectionFactory("CF_TOPIC_XA_FALSE"); }
86. BrowserTest#testBrowse2()
Project: activemq-artemis
File: BrowserTest.java
File: BrowserTest.java
@Test public void testBrowse2() throws Exception { conn = getConnectionFactory().createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(queue1); ActiveMQConnectionFactory cf1 = (ActiveMQConnectionFactory) getConnectionFactory(); ClientSession coreSession = cf1.getServerLocator().createSessionFactory().createSession(true, true); coreSession.start(); ClientConsumer browser = coreSession.createConsumer("jms.queue.Queue1", true); conn.start(); Message m = session.createMessage(); m.setIntProperty("cnt", 0); producer.send(m); Assert.assertNotNull(browser.receiveImmediate()); coreSession.close(); drainDestination(getConnectionFactory(), queue1); }
87. ResourceAdapterTest#testResourceAdapterSetupOverrideDiscovery()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
@Test public void testResourceAdapterSetupOverrideDiscovery() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter(); qResourceAdapter.setDiscoveryAddress("231.7.7.7"); ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext(); qResourceAdapter.start(ctx); ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); spec.setResourceAdapter(qResourceAdapter); spec.setUseJNDI(false); spec.setDestinationType("javax.jms.Queue"); spec.setDestination(MDBQUEUE); spec.setSetupAttempts(0); spec.setDiscoveryAddress("231.6.6.6"); spec.setDiscoveryPort(1234); spec.setDiscoveryInitialWaitTimeout(1L); spec.setDiscoveryRefreshTimeout(1L); ActiveMQConnectionFactory fac = qResourceAdapter.getConnectionFactory(spec); DiscoveryGroupConfiguration dc = fac.getServerLocator().getDiscoveryGroupConfiguration(); UDPBroadcastEndpointFactory udpDg = (UDPBroadcastEndpointFactory) dc.getBroadcastEndpointFactory(); assertEquals(udpDg.getGroupAddress(), "231.6.6.6"); assertEquals(udpDg.getGroupPort(), 1234); assertEquals(dc.getRefreshTimeout(), 1L); assertEquals(dc.getDiscoveryInitialWaitTimeout(), 1L); qResourceAdapter.stop(); }
88. ResourceAdapterTest#testResourceAdapterSetup()
Project: activemq-artemis
File: ResourceAdapterTest.java
File: ResourceAdapterTest.java
// https://issues.jboss.org/browse/JBPAPP-5790 @Test public void testResourceAdapterSetup() throws Exception { ActiveMQResourceAdapter adapter = new ActiveMQResourceAdapter(); adapter.setDiscoveryAddress("231.1.1.1"); ActiveMQConnectionFactory factory = adapter.getDefaultActiveMQConnectionFactory(); long initWait = factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(); long refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout(); int port = ((UDPBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory()).getGroupPort(); // defaults assertEquals(10000L, refresh); assertEquals(10000L, initWait); assertEquals(9876, port); adapter = new ActiveMQResourceAdapter(); adapter.setDiscoveryAddress("231.1.1.1"); adapter.setDiscoveryPort(9876); adapter.setDiscoveryRefreshTimeout(1234L); factory = adapter.getDefaultActiveMQConnectionFactory(); initWait = factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(); refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout(); // override refresh timeout assertEquals(1234L, refresh); assertEquals(10000L, initWait); adapter = new ActiveMQResourceAdapter(); adapter.setDiscoveryAddress("231.1.1.1"); adapter.setDiscoveryPort(9876); adapter.setDiscoveryInitialWaitTimeout(9999L); factory = adapter.getDefaultActiveMQConnectionFactory(); initWait = factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(); refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout(); // override initial wait assertEquals(10000L, refresh); assertEquals(9999L, initWait); adapter = new ActiveMQResourceAdapter(); adapter.setDiscoveryAddress("231.1.1.1"); adapter.setDiscoveryPort(9876); adapter.setDiscoveryInitialWaitTimeout(9999L); factory = adapter.getDefaultActiveMQConnectionFactory(); initWait = factory.getDiscoveryGroupConfiguration().getDiscoveryInitialWaitTimeout(); refresh = factory.getDiscoveryGroupConfiguration().getRefreshTimeout(); // override initial wait assertEquals(10000L, refresh); assertEquals(9999L, initWait); }
89. SimpleJNDIClientTest#testRemoteCFWithJGroups()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testRemoteCFWithJGroups() throws Exception { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "jgroups://mychannelid?file=test-jgroups-file_ping.xml"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); connectionFactory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint().close(false); }
90. SimpleJNDIClientTest#testRemoteCFWithTCPandHA()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testRemoteCFWithTCPandHA() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?ha=true"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); Assert.assertEquals(true, cf.isHA()); }
91. SimpleJNDIClientTest#testTopicXACF()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testTopicXACF() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "vm://0?type=TOPIC_XA_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); Assert.assertEquals(JMSFactoryType.TOPIC_XA_CF.intValue(), connectionFactory.getFactoryType()); }
92. SimpleJNDIClientTest#testTopicCF()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testTopicCF() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "vm://0?type=TOPIC_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); Assert.assertEquals(JMSFactoryType.TOPIC_CF.intValue(), connectionFactory.getFactoryType()); }
93. SimpleJNDIClientTest#testQueueXACF()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testQueueXACF() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "vm://0?type=QUEUE_XA_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); Assert.assertEquals(JMSFactoryType.QUEUE_XA_CF.intValue(), connectionFactory.getFactoryType()); }
94. SimpleJNDIClientTest#testQueueCF()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testQueueCF() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "vm://0?type=QUEUE_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); Assert.assertEquals(JMSFactoryType.QUEUE_CF.intValue(), connectionFactory.getFactoryType()); }
95. SimpleJNDIClientTest#testXACF()
Project: activemq-artemis
File: SimpleJNDIClientTest.java
File: SimpleJNDIClientTest.java
@Test public void testXACF() throws NamingException, JMSException { Hashtable<String, String> props = new Hashtable<>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"); props.put("connectionFactory.myConnectionFactory", "vm://0?type=XA_CF"); Context ctx = new InitialContext(props); ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory"); Assert.assertEquals(JMSFactoryType.XA_CF.intValue(), connectionFactory.getFactoryType()); }
96. TopicControlUsingJMSTest#setUp()
Project: activemq-artemis
File: TopicControlUsingJMSTest.java
File: TopicControlUsingJMSTest.java
// Package protected --------------------------------------------- // Protected ----------------------------------------------------- @Override @Before public void setUp() throws Exception { super.setUp(); Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true); server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, false)); server.start(); serverManager = new JMSServerManagerImpl(server); serverManager.start(); serverManager.setRegistry(new JndiBindingRegistry(new InVMNamingContext())); serverManager.activated(); clientID = RandomUtil.randomString(); subscriptionName = RandomUtil.randomString(); String topicName = RandomUtil.randomString(); serverManager.createTopic(false, topicName, topicBinding); topic = (ActiveMQTopic) ActiveMQJMSClient.createTopic(topicName); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); connection = cf.createQueueConnection(); session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); ActiveMQQueue managementQueue = (ActiveMQQueue) ActiveMQJMSClient.createQueue("activemq.management"); proxy = new JMSMessagingProxy(session, managementQueue, ResourceNames.JMS_TOPIC + topic.getTopicName()); }
97. JMSServerControlUsingJMSTest#setUp()
Project: activemq-artemis
File: JMSServerControlUsingJMSTest.java
File: JMSServerControlUsingJMSTest.java
@Override @Before public void setUp() throws Exception { super.setUp(); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(InVMConnectorFactory.class.getName())); connection = cf.createQueueConnection(); session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); }
98. JMSServerControlTest#testRemoteClientIDConnection()
Project: activemq-artemis
File: JMSServerControlTest.java
File: JMSServerControlTest.java
@Test public void testRemoteClientIDConnection() throws Exception { JMSServerControl control = createManagementControl(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())); Connection connection = cf.createConnection(); connection.setClientID("someID"); Connection connection2 = cf.createConnection(); boolean failed = false; try { connection2.setClientID("someID"); } catch (JMSException e) { failed = true; } Assert.assertTrue(failed); System.out.println(control.closeConnectionWithClientID("someID")); connection2.setClientID("someID"); failed = false; Connection connection3 = cf.createConnection(); try { connection3.setClientID("someID"); } catch (JMSException e) { failed = true; } Assert.assertTrue(failed); }
99. JMSServerControlTest#testListAllConsumers()
Project: activemq-artemis
File: JMSServerControlTest.java
File: JMSServerControlTest.java
@Test public void testListAllConsumers() throws Exception { String topicJNDIBinding = RandomUtil.randomString(); String topicName = RandomUtil.randomString(); ActiveMQTestBase.checkNoBinding(context, topicJNDIBinding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName)); JMSServerControl control = createManagementControl(); control.createTopic(topicName, topicJNDIBinding); checkResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName)); Topic topic = (Topic) context.lookup(topicJNDIBinding); Assert.assertNotNull(topic); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(false, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create a consumer will create a Core queue bound to the topic address MessageConsumer cons = session.createConsumer(topic); JSONArray jsonArray = new JSONArray(control.listAllConsumersAsJSON()); Assert.assertEquals(1 + getNumberOfConsumers(), jsonArray.length()); cons.close(); jsonArray = new JSONArray(control.listAllConsumersAsJSON()); Assert.assertEquals(getNumberOfConsumers(), jsonArray.length()); String topicAddress = ActiveMQDestination.createTopicAddressFromName(topicName).toString(); AddressControl addressControl = (AddressControl) server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + topicAddress); Assert.assertNotNull(addressControl); Assert.assertTrue(addressControl.getQueueNames().length > 0); connection.close(); control.destroyTopic(topicName); Assert.assertNull(server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + topicAddress)); ActiveMQTestBase.checkNoBinding(context, topicJNDIBinding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName)); Assert.assertNull(fakeJMSStorageManager.destinationMap.get(topicName)); }
100. JMSServerControlTest#testDestroyTopic()
Project: activemq-artemis
File: JMSServerControlTest.java
File: JMSServerControlTest.java
@Test public void testDestroyTopic() throws Exception { String topicJNDIBinding = RandomUtil.randomString(); String topicName = RandomUtil.randomString(); ActiveMQTestBase.checkNoBinding(context, topicJNDIBinding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName)); JMSServerControl control = createManagementControl(); control.createTopic(topicName, topicJNDIBinding); checkResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName)); Topic topic = (Topic) context.lookup(topicJNDIBinding); Assert.assertNotNull(topic); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())); Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // create a consumer will create a Core queue bound to the topic address session.createConsumer(topic); String topicAddress = ActiveMQDestination.createTopicAddressFromName(topicName).toString(); AddressControl addressControl = (AddressControl) server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + topicAddress); Assert.assertNotNull(addressControl); Assert.assertTrue(addressControl.getQueueNames().length > 0); connection.close(); control.destroyTopic(topicName); Assert.assertNull(server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + topicAddress)); ActiveMQTestBase.checkNoBinding(context, topicJNDIBinding); checkNoResource(ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(topicName)); Assert.assertNull(fakeJMSStorageManager.destinationMap.get(topicName)); }