org.apache.activemq.artemis.ra.ActiveMQResourceAdapter

Here are the examples of the java api class org.apache.activemq.artemis.ra.ActiveMQResourceAdapter taken from open source projects.

1. ActiveMQClusteredTest#testShutdownOnPartialConnect()

View license
/*
   * the second server has no queue so this tests for partial initialisation
   * */
@Test
public void testShutdownOnPartialConnect() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.setHA(true);
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setSetupAttempts(0);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setHA(true);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY + "," + INVM_CONNECTOR_FACTORY);
    qResourceAdapter.setConnectionParameters("server-id=0, server-id=1");
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    //make sure thet activation didn't start, i.e. no MDB consumers
    assertEquals(((Queue) server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE).getBindable()).getConsumerCount(), 0);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

2. ResourceAdapterTest#testDefaultConnectionFactoryOverrides()

View license
@Test
public void testDefaultConnectionFactoryOverrides() throws Exception {
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ra.setConnectorClassName(InVMConnectorFactory.class.getName());
    ra.setAutoGroup(!ActiveMQClient.DEFAULT_AUTO_GROUP);
    ra.setBlockOnAcknowledge(!ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE);
    ra.setBlockOnNonDurableSend(!ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND);
    ra.setBlockOnDurableSend(!ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND);
    ra.setCallTimeout(1L);
    ra.setClientFailureCheckPeriod(2L);
    ra.setClientID("myid");
    ra.setConnectionLoadBalancingPolicyClassName("mlbcn");
    ra.setConnectionTTL(3L);
    ra.setConsumerMaxRate(4);
    ra.setConsumerWindowSize(5);
    ra.setDiscoveryInitialWaitTimeout(6L);
    ra.setDiscoveryRefreshTimeout(7L);
    ra.setDupsOKBatchSize(8);
    ra.setMinLargeMessageSize(10);
    ra.setPreAcknowledge(!ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE);
    ra.setProducerMaxRate(11);
    ra.setConfirmationWindowSize(12);
    ra.setReconnectAttempts(13);
    ra.setRetryInterval(14L);
    ra.setRetryIntervalMultiplier(15d);
    ra.setScheduledThreadPoolMaxSize(16);
    ra.setThreadPoolMaxSize(17);
    ra.setTransactionBatchSize(18);
    ra.setUseGlobalPools(!ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS);
    ActiveMQConnectionFactory factory = ra.getDefaultActiveMQConnectionFactory();
    Assert.assertEquals(factory.getCallTimeout(), 1);
    Assert.assertEquals(factory.getClientFailureCheckPeriod(), 2);
    Assert.assertEquals(factory.getClientID(), "myid");
    Assert.assertEquals(factory.getConnectionLoadBalancingPolicyClassName(), "mlbcn");
    Assert.assertEquals(factory.getConnectionTTL(), 3);
    Assert.assertEquals(factory.getConsumerMaxRate(), 4);
    Assert.assertEquals(factory.getConsumerWindowSize(), 5);
    Assert.assertEquals(factory.getDupsOKBatchSize(), 8);
    Assert.assertEquals(factory.getMinLargeMessageSize(), 10);
    Assert.assertEquals(factory.getProducerMaxRate(), 11);
    Assert.assertEquals(factory.getConfirmationWindowSize(), 12);
    Assert.assertEquals(factory.getReconnectAttempts(), 13);
    Assert.assertEquals(factory.getRetryInterval(), 14);
    Assert.assertEquals(factory.getRetryIntervalMultiplier(), 15d, 0.00001);
    Assert.assertEquals(factory.getScheduledThreadPoolMaxSize(), 16);
    Assert.assertEquals(factory.getThreadPoolMaxSize(), 17);
    Assert.assertEquals(factory.getTransactionBatchSize(), 18);
    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);
}

3. ResourceAdapterTest#testResourceAdapterSetupNoOverrideDiscovery()

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

4. ResourceAdapterTest#testResourceAdapterSetupOverrideNoCFParams()

View license
@Test
public void testResourceAdapterSetupOverrideNoCFParams() 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);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertFalse(spec.isHasBeenUpdated());
    assertTrue(endpoint.released);
}

5. ResourceAdapterTest#testStartStop()

View license
@Test
public void testStartStop() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    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);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertTrue(endpoint.released);
}

6. ActiveMQMessageHandlerTest#testMaxSessions()

View license
@Test
public void testMaxSessions() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setMaxSession(1);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 1);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

7. ActiveMQMessageHandlerTest#testEndpointDeactivated()

View license
@Test
public void testEndpointDeactivated() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 0);
    assertTrue(endpoint.released);
    qResourceAdapter.stop();
}

8. ResourceAdapterTest#testResourceAdapterSetupOverrideCFParams()

View license
// https://issues.jboss.org/browse/JBPAPP-5836
@Test
public void testResourceAdapterSetupOverrideCFParams() 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);
    // now override the connector class
    spec.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    spec.setConnectionParameters("port=61616");
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(new CountDownLatch(1));
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    //make sure 2 recovery resources, one is default, one is in activation.
    assertEquals(2, qResourceAdapter.getRecoveryManager().getResources().size());
    qResourceAdapter.stop();
    assertTrue(endpoint.released);
}

9. ResourceAdapterTest#testResourceAdapterSetupNoHAOverride()

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

10. ActiveMQMessageHandlerSecurityTest#testSimpleMessageReceivedOnQueueWithSecurityFails()

View license
@Test
public void testSimpleMessageReceivedOnQueueWithSecurityFails() throws Exception {
    SecurityConfiguration emptyConfiguration = new SecurityConfiguration();
    ((ActiveMQJAASSecurityManager) server.getSecurityManager()).setConfiguration(emptyConfiguration);
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setUser("dodgyuser");
    spec.setPassword("dodgypassword");
    spec.setSetupAttempts(0);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(0, ((LocalQueueBinding) binding).getQueue().getConsumerCount());
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

11. ResourceAdapterTest#testResourceAdapterSetupNoReconnectAttemptsOverride()

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

12. ResourceAdapterTest#testResourceAdapterSetupReconnectAttemptsOverride()

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

13. ResourceAdapterTest#testResourceAdapterSetupNoHADefault()

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

14. ResourceAdapterTest#testResourceAdapterSetupHAOverride()

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

15. ResourceAdapterTest#testResourceAdapterSetupReconnectAttemptDefault()

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

16. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectorsAndParams()

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

17. ActiveMQMessageHandlerTest#testInvalidAckMode()

View license
@Test
public void testInvalidAckMode() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    try {
        spec.setAcknowledgeMode("CLIENT_ACKNOWLEDGE");
        fail("should throw exception");
    } catch (java.lang.IllegalArgumentException e) {
    }
    qResourceAdapter.stop();
}

18. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectorsOverride()

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

19. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectors()

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

20. ResourceAdapterTest#testCreateConnectionFactoryOverrideDiscovery()

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

21. ResourceAdapterTest#testCreateConnectionFactoryOverrideConnector()

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

22. ActiveMQActivationTest#testValidateJNDIParameters()

View license
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testValidateJNDIParameters() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setJndiParams("a=b;c=d;url=a1,a2,a3");
    assertEquals("b", spec.getParsedJndiParams().get("a"));
    assertEquals("d", spec.getParsedJndiParams().get("c"));
    assertEquals("a1,a2,a3", spec.getParsedJndiParams().get("url"));
}

23. ResourceAdapterTest#testSetters2()

View license
@Test
public void testSetters2() throws Exception {
    Boolean b = Boolean.FALSE;
    Long l = (long) 2000;
    Integer i = 2000;
    Double d = (double) 2000;
    String className = "testConnector2";
    String backupConn = "testBackupConnector2";
    String testConfig = "key2=val2";
    String testid = "testid2";
    String testBalancer = "testBalancer2";
    String testParams = "key=val2";
    String testaddress = "testaddress2";
    String loadbalancer = "loadbalancer2";
    String testpass = "testpass2";
    String testuser = "testuser2";
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    testParams(b, l, i, d, className, backupConn, testConfig, testid, testBalancer, testParams, testaddress, testpass, testuser, qResourceAdapter);
}

24. ResourceAdapterTest#testSetters()

View license
@Test
public void testSetters() throws Exception {
    Boolean b = Boolean.TRUE;
    Long l = (long) 1000;
    Integer i = 1000;
    Double d = (double) 1000;
    String className = "testConnector";
    String backupConn = "testBackupConnector";
    String testConfig = "key=val";
    String testid = "testid";
    String testBalancer = "testBalancer";
    String testParams = "key=val";
    String testaddress = "testaddress";
    String loadbalancer = "loadbalancer";
    String testpass = "testpass";
    String testuser = "testuser";
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    testParams(b, l, i, d, className, backupConn, testConfig, testid, testBalancer, testParams, testaddress, testpass, testuser, qResourceAdapter);
}

25. ResourceAdapterTest#testCreateConnectionFactoryThrowsException()

View license
@Test
public void testCreateConnectionFactoryThrowsException() throws Exception {
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ConnectionFactoryProperties connectionFactoryProperties = new ConnectionFactoryProperties();
    try {
        ra.getConnectionFactory(connectionFactoryProperties);
        Assert.fail("should throw exception");
    } catch (IllegalArgumentException e) {
    }
}

26. OutgoingConnectionTestJTA#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    useDummyTransactionManager();
    super.setUp();
    ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("testuser", "testpassword");
    ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest");
    ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest");
    ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("testuser", "arole");
    ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "arole");
    Role role = new Role("arole", true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    resourceAdapter = new ActiveMQResourceAdapter();
    resourceAdapter.setEntries("[\"java://jmsXA\"]");
    resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
}

27. OutgoingConnectionTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    securityManager.getConfiguration().addRole("testuser", "arole");
    securityManager.getConfiguration().addRole("guest", "arole");
    Role role = new Role("arole", true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    resourceAdapter = new ActiveMQResourceAdapter();
    resourceAdapter.setEntries("[\"java://jmsXA\"]");
    resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
}

28. JMSContextTest#setUp()

View license
@Override
@Before
public void setUp() throws Exception {
    useDummyTransactionManager();
    super.setUp();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    securityManager.getConfiguration().addRole("testuser", "arole");
    securityManager.getConfiguration().addRole("guest", "arole");
    Role role = new Role("arole", true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    resourceAdapter = new ActiveMQResourceAdapter();
    resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
}

29. ResourceAdapterTest#testResourceAdapterSetup()

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

30. ResourceAdapterTest#testMaskPassword2()

View license
@Test
public void testMaskPassword2() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    qResourceAdapter.setUseMaskedPassword(true);
    qResourceAdapter.setPasswordCodec(DefaultSensitiveStringCodec.class.getName() + ";key=anotherkey");
    DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
    Map<String, String> prop = new HashMap<>();
    prop.put("key", "anotherkey");
    codec.init(prop);
    String mask = (String) codec.encode("helloworld");
    qResourceAdapter.setPassword(mask);
    qResourceAdapter.start(ctx);
    assertEquals("helloworld", qResourceAdapter.getPassword());
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    mask = (String) codec.encode("mdbpassword");
    spec.setPassword(mask);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    assertEquals("mdbpassword", spec.getPassword());
    qResourceAdapter.stop();
    assertTrue(endpoint.released);
}

31. ActiveMQMessageHandlerTest#testSelectorNotChangedWithTopic()

View license
@Test
public void testSelectorNotChangedWithTopic() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    spec.setMessageSelector("foo='bar'");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    message.putStringProperty("foo", "bar");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("2");
    message.putStringProperty("foo", "bar");
    clientProducer.send(message);
    latch = new CountDownLatch(1);
    endpoint = new DummyMessageEndpoint(latch);
    endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "2");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

32. ResourceAdapterTest#testMaskPassword()

View license
@Test
public void testMaskPassword() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
    DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
    String mask = (String) codec.encode("helloworld");
    qResourceAdapter.setUseMaskedPassword(true);
    qResourceAdapter.setPassword(mask);
    qResourceAdapter.start(ctx);
    assertEquals("helloworld", qResourceAdapter.getPassword());
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    mask = (String) codec.encode("mdbpassword");
    spec.setPassword(mask);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    assertEquals("mdbpassword", spec.getPassword());
    qResourceAdapter.stop();
    assertTrue(endpoint.released);
}

33. ActiveMQMessageHandlerTest#testServerShutdownAndReconnect()

View license
@Test
public void testServerShutdownAndReconnect() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    qResourceAdapter.setReconnectAttempts(-1);
    qResourceAdapter.setCallTimeout(500L);
    qResourceAdapter.setRetryInterval(500L);
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    // This is just to register a listener
    final CountDownLatch failedLatch = new CountDownLatch(1);
    ClientSessionFactoryInternal factoryListener = (ClientSessionFactoryInternal) qResourceAdapter.getDefaultActiveMQConnectionFactory().getServerLocator().createSessionFactory();
    factoryListener.addFailureListener(new SessionFailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
        }

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(exception, failedOver);
        }

        @Override
        public void beforeReconnect(ActiveMQException exception) {
            failedLatch.countDown();
        }
    });
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    server.stop();
    assertTrue(failedLatch.await(5, TimeUnit.SECONDS));
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

34. ActiveMQMessageHandlerTest#testSelectorChangedWithTopic()

View license
@Test
public void testSelectorChangedWithTopic() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    spec.setMessageSelector("foo='bar'");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    message.putStringProperty("foo", "bar");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("2");
    message.putStringProperty("foo", "bar");
    clientProducer.send(message);
    latch = new CountDownLatch(1);
    endpoint = new DummyMessageEndpoint(latch);
    //change the selector forcing the queue to be recreated
    spec.setMessageSelector("foo='abar'");
    endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("3");
    message.putStringProperty("foo", "abar");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "3");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

35. ActiveMQMessageHandlerTest#testDurableSubscription()

View license
@Test
public void testDurableSubscription() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("2");
    clientProducer.send(message);
    latch = new CountDownLatch(1);
    endpoint = new DummyMessageEndpoint(latch);
    endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "2");
    latch = new CountDownLatch(1);
    endpoint.reset(latch);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("3");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "3");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

36. ActiveMQMessageHandlerTest#testNonDurableSubscription()

View license
@Test
public void testNonDurableSubscription() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("2");
    clientProducer.send(message);
    latch = new CountDownLatch(1);
    endpoint = new DummyMessageEndpoint(latch);
    endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("3");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "3");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

37. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueueInLocalTX()

View license
@Test
public void testSimpleMessageReceivedOnQueueInLocalTX() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    qResourceAdapter.setUseLocalTx(true);
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    ExceptionDummyMessageEndpoint endpoint = new ExceptionDummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNull(endpoint.lastMessage);
    latch = new CountDownLatch(1);
    endpoint.reset(latch);
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

38. ActiveMQMessageHandlerXATest#testXARollback()

View license
@Test
public void testXARollback() throws Exception {
    setupDLQ(10);
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setMaxSession(1);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpoint endpoint = new XADummyEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    latch = new CountDownLatch(1);
    endpoint.reset(latch);
    endpoint.rollback();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

39. ActiveMQMessageHandlerTest#testSharedSubscription()

View license
@Test
public void testSharedSubscription() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    ActiveMQActivationSpec spec2 = new ActiveMQActivationSpec();
    spec2.setResourceAdapter(qResourceAdapter);
    spec2.setUseJNDI(false);
    spec2.setDestinationType("javax.jms.Topic");
    spec2.setDestination("mdbTopic");
    spec2.setSubscriptionDurability("Durable");
    spec2.setSubscriptionName("durable-mdb");
    spec2.setClientID("id-1");
    spec2.setSetupAttempts(1);
    spec2.setShareSubscriptions(true);
    spec2.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    CountDownLatch latch2 = new CountDownLatch(5);
    DummyMessageEndpoint endpoint2 = new DummyMessageEndpoint(latch2);
    DummyMessageEndpointFactory endpointFactory2 = new DummyMessageEndpointFactory(endpoint2, false);
    qResourceAdapter.endpointActivation(endpointFactory2, spec2);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    for (int i = 0; i < 10; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("" + i);
        clientProducer.send(message);
    }
    session.commit();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertTrue(latch2.await(5, TimeUnit.SECONDS));
    assertNotNull(endpoint.lastMessage);
    assertNotNull(endpoint2.lastMessage);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.endpointDeactivation(endpointFactory2, spec2);
    qResourceAdapter.stop();
}

40. ActiveMQMessageHandlerSecurityTest#testSimpleMessageReceivedOnQueueWithSecuritySucceeds()

View license
@Test
public void testSimpleMessageReceivedOnQueueWithSecuritySucceeds() throws Exception {
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addRole("testuser", "arole");
    Role role = new Role("arole", false, true, false, false, false, false, false);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setUser("testuser");
    spec.setPassword("testpassword");
    spec.setSetupAttempts(0);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

41. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueueManyMessagesAndInterruptTimeout()

View license
@Test
public void testSimpleMessageReceivedOnQueueManyMessagesAndInterruptTimeout() throws Exception {
    final int SIZE = 14;
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setCallTimeout(500L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(SIZE);
    CountDownLatch latchDone = new CountDownLatch(SIZE);
    MultipleEndpoints endpoint = new MultipleEndpoints(latch, latchDone, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    for (int i = 0; i < SIZE; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("teststring" + i);
        clientProducer.send(message);
    }
    session.close();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    latchDone.await(5, TimeUnit.SECONDS);
    assertEquals(SIZE, endpoint.messages.intValue());
    //half onmessage interrupted
    assertEquals(SIZE / 2, endpoint.interrupted.intValue());
    qResourceAdapter.stop();
}

42. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueueManyMessagesAndInterrupt()

View license
@Test
public void testSimpleMessageReceivedOnQueueManyMessagesAndInterrupt() throws Exception {
    final int SIZE = 14;
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(SIZE);
    CountDownLatch latchDone = new CountDownLatch(SIZE);
    MultipleEndpoints endpoint = new MultipleEndpoints(latch, latchDone, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    for (int i = 0; i < SIZE; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("teststring" + i);
        clientProducer.send(message);
    }
    session.close();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    latchDone.await(5, TimeUnit.SECONDS);
    assertEquals(SIZE, endpoint.messages.intValue());
    assertEquals(0, endpoint.interrupted.intValue());
    qResourceAdapter.stop();
}

43. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueueManyMessages()

View license
@Test
public void testSimpleMessageReceivedOnQueueManyMessages() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(15);
    MultipleEndpoints endpoint = new MultipleEndpoints(latch, null, false);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    for (int i = 0; i < 15; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("teststring" + i);
        clientProducer.send(message);
    }
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

44. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueue()

View license
@Test
public void testSimpleMessageReceivedOnQueue() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

45. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueueTwoPhase()

View license
@Test
@BMRules(rules = { @BMRule(name = "interrupt", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "xaEnd", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ActiveMQMessageHandlerTest.interrupt();") })
public void testSimpleMessageReceivedOnQueueTwoPhase() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    resourceAdapter = qResourceAdapter;
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setMaxSession(1);
    spec.setCallTimeout(1000L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpoint endpoint = new XADummyEndpoint(latch, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    Binding binding = server.getPostOffice().getBinding(SimpleString.toSimpleString(MDBQUEUEPREFIXED));
    assertEquals(1, getMessageCount(((Queue) binding.getBindable())));
    server.stop();
    server.start();
    ClientSessionFactory factory = locator.createSessionFactory();
    session = factory.createSession(true, true);
    session.start();
    ClientConsumer consumer = session.createConsumer(MDBQUEUEPREFIXED);
    assertNotNull(consumer.receive(5000));
    session.close();
}

46. ActiveMQClusteredTest#testRebalanceInternal()

View license
public void testRebalanceInternal(int reconnectAttempts) throws Exception {
    final int CONSUMER_COUNT = 10;
    secondaryJmsServer.createQueue(true, MDBQUEUE, null, true, "/jms/" + MDBQUEUE);
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setRebalanceConnections(true);
    spec.setMaxSession(CONSUMER_COUNT);
    spec.setSetupAttempts(5);
    spec.setSetupInterval(200);
    spec.setReconnectAttempts(reconnectAttempts);
    // if this isn't true then the toplogy listener won't get nodeDown notifications
    spec.setHA(true);
    // if this isn't set then it may take a long time for tearDown to occur on the MDB connection
    spec.setCallTimeout(500L);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    Queue primaryQueue = server.locateQueue(MDBQUEUEPREFIXEDSIMPLE);
    Queue secondaryQueue = secondaryServer.locateQueue(MDBQUEUEPREFIXEDSIMPLE);
    assertTrue(primaryQueue.getConsumerCount() < CONSUMER_COUNT);
    assertTrue(secondaryQueue.getConsumerCount() < CONSUMER_COUNT);
    assertTrue(primaryQueue.getConsumerCount() + secondaryQueue.getConsumerCount() == CONSUMER_COUNT);
    ClientSession session = addClientSession(locator.createSessionFactory().createSession());
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("test");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "test");
    for (int i = 0; i < 10; i++) {
        secondaryServer.stop();
        long mark = System.currentTimeMillis();
        long timeout = 5000;
        while (primaryQueue.getConsumerCount() < CONSUMER_COUNT && (System.currentTimeMillis() - mark) < timeout) {
            Thread.sleep(100);
        }
        assertTrue(primaryQueue.getConsumerCount() == CONSUMER_COUNT);
        secondaryServer.start();
        waitForServerToStart(secondaryServer);
        secondaryQueue = secondaryServer.locateQueue(MDBQUEUEPREFIXEDSIMPLE);
        mark = System.currentTimeMillis();
        while (((primaryQueue.getConsumerCount() + secondaryQueue.getConsumerCount()) < (CONSUMER_COUNT) || primaryQueue.getConsumerCount() == CONSUMER_COUNT) && (System.currentTimeMillis() - mark) <= timeout) {
            Thread.sleep(100);
        }
        assertTrue(primaryQueue.getConsumerCount() < CONSUMER_COUNT);
        assertTrue(secondaryQueue.getConsumerCount() < CONSUMER_COUNT);
        assertTrue(primaryQueue.getConsumerCount() + secondaryQueue.getConsumerCount() == CONSUMER_COUNT);
    }
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

47. ActiveMQClusteredTest#testNonDurableInCluster()

View license
/**
    * https://bugzilla.redhat.com/show_bug.cgi?id=1029076
    * Look at the logs for this test, if you see exceptions it's an issue.
    *
    * @throws Exception
    */
@Test
public void testNonDurableInCluster() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSetupAttempts(5);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = addClientSession(locator.createSessionFactory().createSession());
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("test");
    clientProducer.send(message);
    ActiveMQActivation activation = lookupActivation(qResourceAdapter);
    SimpleString tempQueue = activation.getTopicTemporaryQueue();
    assertNotNull(server.locateQueue(tempQueue));
    assertNotNull(secondaryServer.locateQueue(tempQueue));
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "test");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertNull(server.locateQueue(tempQueue));
    assertNull(secondaryServer.locateQueue(tempQueue));
}

48. InterruptedMessageHandlerTest#testSimpleMessageReceivedOnQueueTwoPhaseFailPrepareByConnectionTimout()

View license
@Test
@BMRules(rules = { @BMRule(name = "throw ActiveMQException(CONNETION_TIMEOUT) during rollback", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "flushAcks", targetLocation = "AFTER INVOKE flushAcks", action = "org.apache.activemq.artemis.tests.extras.byteman.InterruptedMessageHandlerTest.throwActiveMQQExceptionConnectionTimeout();"), @BMRule(name = "check that outcome of XA transaction is TwoPhaseOutcome.FINISH_ERROR=8", targetClass = "com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord", targetMethod = "topLevelAbort", targetLocation = "AT EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.InterruptedMessageHandlerTest.assertTxOutComeIsOfStatusFinishedError($!);") })
public void testSimpleMessageReceivedOnQueueTwoPhaseFailPrepareByConnectionTimout() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    resourceAdapter = qResourceAdapter;
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setMaxSession(1);
    spec.setCallTimeout(1000L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpointWithDummyXAResourceFailEnd endpoint = new XADummyEndpointWithDummyXAResourceFailEnd(latch, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    server.stop();
    assertEquals("Two phase outcome must be of TwoPhaseOutcome.FINISH_ERROR.", TwoPhaseOutcome.FINISH_ERROR, txTwoPhaseOutCome.intValue());
}

49. ActiveMQMessageHandlerXATest#testXACommit()

View license
@Test
public void testXACommit() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpoint endpoint = new XADummyEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    endpoint.prepare();
    endpoint.commit();
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

50. ResourceAdapterTest#testRecoveryRegistrationOnFailure()

View license
@Test
public void testRecoveryRegistrationOnFailure() 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);
    // now override the connector class
    spec.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    spec.setSetupAttempts(2);
    // using a wrong port number
    spec.setConnectionParameters("port=6776");
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(new CountDownLatch(1));
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    assertEquals(1, qResourceAdapter.getRecoveryManager().getResources().size());
    qResourceAdapter.stop();
    assertFalse(endpoint.released);
}

51. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueueWithSelector()

View license
@Test
public void testSimpleMessageReceivedOnQueueWithSelector() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setMessageSelector("color='red'");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("blue");
    message.putStringProperty("color", "blue");
    clientProducer.send(message);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("red");
    message.putStringProperty("color", "red");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "red");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

52. ActiveMQMessageHandlerTest#testSimpleTopic()

View license
@Test
public void testSimpleTopic() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("test");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "test");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}

53. ResourceAdapterTest#testStartStopActivationManyTimes()

View license
@Test
public void testStartStopActivationManyTimes() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
    session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
    session.close();
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ra.setUserName("userGlobal");
    ra.setPassword("passwordGlobal");
    ra.start(new BootstrapContext());
    Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
    conn.close();
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(ra);
    spec.setUseJNDI(false);
    spec.setUser("user");
    spec.setPassword("password");
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("test");
    spec.setMinSession(1);
    spec.setMaxSession(15);
    ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
    ServerLocatorImpl serverLocator = (ServerLocatorImpl) ra.getDefaultActiveMQConnectionFactory().getServerLocator();
    Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources();
    for (int i = 0; i < 10; i++) {
        System.out.println(i);
        activation.start();
        assertEquals(1, resources.size());
        activation.stop();
    }
    ra.stop();
    assertEquals(0, resources.size());
    locator.close();
}

54. ActiveMQMessageHandlerTest#testSimpleMessageReceivedOnQueue()

View license
@Test
@BMRules(rules = { @BMRule(name = "interrupt", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "xaEnd", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ActiveMQMessageHandlerTest.interrupt();") })
public void testSimpleMessageReceivedOnQueue() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    resourceAdapter = qResourceAdapter;
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.setConnectorClassName(NETTY_CONNECTOR_FACTORY);
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setMaxSession(1);
    spec.setCallTimeout(1000L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpoint endpoint = new XADummyEndpoint(latch, false);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    Binding binding = server.getPostOffice().getBinding(SimpleString.toSimpleString(MDBQUEUEPREFIXED));
    assertEquals(1, getMessageCount(((Queue) binding.getBindable())));
    server.stop();
    server.start();
    ClientSessionFactory factory = locator.createSessionFactory();
    session = factory.createSession(true, true);
    session.start();
    ClientConsumer consumer = session.createConsumer(MDBQUEUEPREFIXED);
    assertNotNull(consumer.receive(5000));
    session.close();
}

55. ActiveMQMessageHandlerXATest#testXACommitInterruptsWhenStopping()

View license
@Test
public void testXACommitInterruptsWhenStopping() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setCallTimeout(500L);
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setMaxSession(1);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch beforeDeliveryLatch = new CountDownLatch(1);
    PausingXADummyEndpoint endpoint = new PausingXADummyEndpoint(latch, beforeDeliveryLatch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    ClientMessage message2 = session.createMessage(true);
    message2.getBodyBuffer().writeString("teststring2");
    clientProducer.send(message2);
    session.close();
    beforeDeliveryLatch.await(5, TimeUnit.SECONDS);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertTrue(endpoint.interrupted);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    long messageCount = getMessageCount((Queue) binding.getBindable());
    assertEquals(1, messageCount);
}

56. ActiveMQMessageHandlerXATest#testXACommitWhenStopping()

View license
@Test
public void testXACommitWhenStopping() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setMaxSession(1);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    CountDownLatch beforeDeliveryLatch = new CountDownLatch(1);
    PausingXADummyEndpoint endpoint = new PausingXADummyEndpoint(latch, beforeDeliveryLatch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    ClientMessage message2 = session.createMessage(true);
    message2.getBodyBuffer().writeString("teststring2");
    clientProducer.send(message2);
    session.close();
    beforeDeliveryLatch.await(5, TimeUnit.SECONDS);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
    assertFalse(endpoint.interrupted);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    long messageCount = getMessageCount((Queue) binding.getBindable());
    assertEquals(1, messageCount);
}

57. ActiveMQMessageHandlerTest#testNonDurableSubscriptionDeleteAfterCrash()

View license
//https://issues.jboss.org/browse/JBPAPP-8017
@Test
public void testNonDurableSubscriptionDeleteAfterCrash() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("1");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    ActiveMQActivation activation = lookupActivation(qResourceAdapter);
    SimpleString tempQueueName = activation.getTopicTemporaryQueue();
    QueueQuery query = session.queueQuery(tempQueueName);
    assertTrue(query.isExists());
    //this should be enough to simulate the crash
    qResourceAdapter.getDefaultActiveMQConnectionFactory().close();
    qResourceAdapter.stop();
    query = session.queueQuery(tempQueueName);
    assertFalse(query.isExists());
}

58. ResourceAdapterTest#testResourceAdapterSetupOverrideDiscovery()

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

59. ResourceAdapterTest#testValidateProperties()

View license
@Test
public void testValidateProperties() throws Exception {
    validateGettersAndSetters(new ActiveMQResourceAdapter(), "backupTransportConfiguration", "connectionParameters", "jndiParams");
    validateGettersAndSetters(new ActiveMQRAManagedConnectionFactory(), "connectionParameters", "sessionDefaultType", "backupConnectionParameters", "jndiParams");
    validateGettersAndSetters(new ActiveMQActivationSpec(), "connectionParameters", "acknowledgeMode", "subscriptionDurability", "jndiParams");
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setAcknowledgeMode("DUPS_OK_ACKNOWLEDGE");
    Assert.assertEquals("Dups-ok-acknowledge", spec.getAcknowledgeMode());
    spec.setSubscriptionDurability("Durable");
    Assert.assertEquals("Durable", spec.getSubscriptionDurability());
    spec.setSubscriptionDurability("NonDurable");
    Assert.assertEquals("NonDurable", spec.getSubscriptionDurability());
    spec = new ActiveMQActivationSpec();
    ActiveMQResourceAdapter adapter = new ActiveMQResourceAdapter();
    adapter.setUserName("us1");
    adapter.setPassword("ps1");
    adapter.setClientID("cl1");
    spec.setResourceAdapter(adapter);
    Assert.assertEquals("us1", spec.getUser());
    Assert.assertEquals("ps1", spec.getPassword());
    spec.setUser("us2");
    spec.setPassword("ps2");
    spec.setClientID("cl2");
    Assert.assertEquals("us2", spec.getUser());
    Assert.assertEquals("ps2", spec.getPassword());
    Assert.assertEquals("cl2", spec.getClientID());
}

60. ResourceAdapterTest#testCreateConnectionFactoryMultipleConnectorsOverrideAndParams()

View license
@Test
public void testCreateConnectionFactoryMultipleConnectorsOverrideAndParams() {
    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");
    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);
    ArrayList<Map<String, Object>> connectionParameters = new ArrayList<>();
    Map<String, Object> map1 = new HashMap<>();
    map1.put("serverid", "0");
    connectionParameters.add(map1);
    Map<String, Object> map2 = new HashMap<>();
    map2.put("host", "myhost");
    map2.put("port", "61616");
    connectionParameters.add(map2);
    Map<String, Object> map3 = new HashMap<>();
    map3.put("serverid", "1");
    connectionParameters.add(map3);
    overrideProperties.setParsedConnectionParameters(connectionParameters);
    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("0", configurations[0].getParams().get("serverid"));
    assertEquals(NETTY_CONNECTOR_FACTORY, configurations[1].getFactoryClassName());
    assertEquals(2, configurations[1].getParams().size());
    assertEquals("myhost", configurations[1].getParams().get("host"));
    assertEquals("61616", configurations[1].getParams().get("port"));
    assertEquals(INVM_CONNECTOR_FACTORY, configurations[2].getFactoryClassName());
    assertEquals(1, configurations[2].getParams().size());
    assertEquals("1", configurations[2].getParams().get("serverid"));
}

61. ActiveMQRATestBase#newResourceAdapter()

View license
protected ActiveMQResourceAdapter newResourceAdapter() {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    return qResourceAdapter;
}

62. ResourceAdapterTest#testCreateConnectionFactoryOverrides()

View license
@Test
public void testCreateConnectionFactoryOverrides() throws Exception {
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ra.setConnectorClassName(InVMConnectorFactory.class.getName());
    ConnectionFactoryProperties connectionFactoryProperties = new ConnectionFactoryProperties();
    connectionFactoryProperties.setAutoGroup(!ActiveMQClient.DEFAULT_AUTO_GROUP);
    connectionFactoryProperties.setBlockOnAcknowledge(!ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE);
    connectionFactoryProperties.setBlockOnNonDurableSend(!ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND);
    connectionFactoryProperties.setBlockOnDurableSend(!ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND);
    connectionFactoryProperties.setCallTimeout(1L);
    connectionFactoryProperties.setClientFailureCheckPeriod(2L);
    connectionFactoryProperties.setClientID("myid");
    connectionFactoryProperties.setConnectionLoadBalancingPolicyClassName("mlbcn");
    connectionFactoryProperties.setConnectionTTL(3L);
    connectionFactoryProperties.setConsumerMaxRate(4);
    connectionFactoryProperties.setConsumerWindowSize(5);
    connectionFactoryProperties.setDiscoveryInitialWaitTimeout(6L);
    connectionFactoryProperties.setDiscoveryRefreshTimeout(7L);
    connectionFactoryProperties.setDupsOKBatchSize(8);
    connectionFactoryProperties.setMinLargeMessageSize(10);
    connectionFactoryProperties.setPreAcknowledge(!ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE);
    connectionFactoryProperties.setProducerMaxRate(11);
    connectionFactoryProperties.setConfirmationWindowSize(12);
    connectionFactoryProperties.setReconnectAttempts(13);
    connectionFactoryProperties.setRetryInterval(14L);
    connectionFactoryProperties.setRetryIntervalMultiplier(15d);
    connectionFactoryProperties.setScheduledThreadPoolMaxSize(16);
    connectionFactoryProperties.setThreadPoolMaxSize(17);
    connectionFactoryProperties.setTransactionBatchSize(18);
    connectionFactoryProperties.setUseGlobalPools(!ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS);
    ActiveMQConnectionFactory factory = ra.getConnectionFactory(connectionFactoryProperties);
    Assert.assertEquals(factory.getCallTimeout(), 1);
    Assert.assertEquals(factory.getClientFailureCheckPeriod(), 2);
    Assert.assertEquals(factory.getClientID(), "myid");
    Assert.assertEquals(factory.getConnectionLoadBalancingPolicyClassName(), "mlbcn");
    Assert.assertEquals(factory.getConnectionTTL(), 3);
    Assert.assertEquals(factory.getConsumerMaxRate(), 4);
    Assert.assertEquals(factory.getConsumerWindowSize(), 5);
    Assert.assertEquals(factory.getDupsOKBatchSize(), 8);
    Assert.assertEquals(factory.getMinLargeMessageSize(), 10);
    Assert.assertEquals(factory.getProducerMaxRate(), 11);
    Assert.assertEquals(factory.getConfirmationWindowSize(), 12);
    Assert.assertEquals(factory.getReconnectAttempts(), 13);
    Assert.assertEquals(factory.getRetryInterval(), 14);
    Assert.assertEquals(factory.getRetryIntervalMultiplier(), 15d, 0.000001);
    Assert.assertEquals(factory.getScheduledThreadPoolMaxSize(), 16);
    Assert.assertEquals(factory.getThreadPoolMaxSize(), 17);
    Assert.assertEquals(factory.getTransactionBatchSize(), 18);
    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);
}

63. ResourceAdapterTest#testCreateConnectionFactoryNoOverrides()

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

64. ResourceAdapterTest#test2DefaultConnectionFactorySame()

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

65. ResourceAdapterTest#testDefaultConnectionFactory()

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

66. ActiveMQMessageHandlerTest#testBadDestinationType()

View license
@Test
public void testBadDestinationType() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("badDestinationType");
    spec.setDestination("mdbTopic");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    try {
        qResourceAdapter.endpointActivation(endpointFactory, spec);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof InvalidPropertyException);
        assertEquals("destinationType", ((InvalidPropertyException) e).getInvalidPropertyDescriptors()[0].getName());
    }
}

67. ActiveMQMessageHandlerTest#testNullSubscriptionName()

View license
@Test
public void testNullSubscriptionName() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setClientID("id-1");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    try {
        qResourceAdapter.endpointActivation(endpointFactory, spec);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof InvalidPropertyException);
        assertEquals("subscriptionName", ((InvalidPropertyException) e).getInvalidPropertyDescriptors()[0].getName());
    }
}

68. ActiveMQMessageHandlerTest#newResourceAdapter()

View license
/**
    * @return
    */
@Override
protected ActiveMQResourceAdapter newResourceAdapter() {
    ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    return qResourceAdapter;
}

69. ActiveMQClusteredTest#testOutboundLoadBalancing()

View license
@Test
public void testOutboundLoadBalancing() throws Exception {
    final int CONNECTION_COUNT = 100;
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    List<Session> sessions = new ArrayList<>();
    List<ActiveMQRAManagedConnection> managedConnections = new ArrayList<>();
    try {
        MyBootstrapContext ctx = new MyBootstrapContext();
        qResourceAdapter.start(ctx);
        ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
        ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
        mcf.setResourceAdapter(qResourceAdapter);
        ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
        QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
        Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        sessions.add(s);
        ActiveMQRAManagedConnection mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
        managedConnections.add(mc);
        ActiveMQConnectionFactory cf1 = mc.getConnectionFactory();
        long timeout = 10000;
        long now = System.currentTimeMillis();
        while (!((ServerLocatorImpl) cf1.getServerLocator()).isReceivedToplogy()) {
            Thread.sleep(50);
        }
        for (int i = 0; i < CONNECTION_COUNT; i++) {
            queueConnection = qraConnectionFactory.createQueueConnection();
            s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            sessions.add(s);
            mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
            managedConnections.add(mc);
        }
        assertTrue(server.getConnectionCount() >= (CONNECTION_COUNT / 2));
        assertTrue(secondaryServer.getConnectionCount() >= (CONNECTION_COUNT / 2));
    } finally {
        for (Session s : sessions) {
            s.close();
        }
        for (ActiveMQRAManagedConnection mc : managedConnections) {
            mc.destroy();
        }
    }
}

70. JMSServerControl2Test#testStartActivationOverrideListConnections()

View license
@Test
public void testStartActivationOverrideListConnections() throws Exception {
    ActiveMQActivation activation = null;
    ActiveMQResourceAdapter ra = null;
    try {
        startActiveMQServer(InVMAcceptorFactory.class.getName());
        ActiveMQJMSClient.createQueue("test");
        serverManager.createQueue(false, "test", null, true, "test");
        JMSServerControl control = createManagementControl();
        ra = new ActiveMQResourceAdapter();
        ra.setConnectorClassName("org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory");
        ra.setUserName("userGlobal");
        ra.setPassword("passwordGlobal");
        ra.start(new BootstrapContext());
        Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
        conn.close();
        ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
        spec.setResourceAdapter(ra);
        spec.setUseJNDI(false);
        spec.setClientID("my-client-id");
        spec.setUser("user");
        spec.setPassword("password");
        spec.setDestinationType("javax.jms.Queue");
        spec.setDestination("test");
        spec.setMinSession(1);
        spec.setMaxSession(1);
        activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
        activation.start();
        String cons = control.listConnectionsAsJSON();
        JMSConnectionInfo[] jmsConnectionInfos = JMSConnectionInfo.from(cons);
        assertEquals(1, jmsConnectionInfos.length);
        assertEquals("user", jmsConnectionInfos[0].getUsername());
        assertEquals("my-client-id", jmsConnectionInfos[0].getClientID());
    } finally {
        if (activation != null)
            activation.stop();
        if (ra != null)
            ra.stop();
        try {
            if (serverManager != null) {
                //serverManager.destroyQueue(queueName);
                serverManager.stop();
            }
        } catch (Throwable ignored) {
            ignored.printStackTrace();
        }
        if (server != null) {
            server.stop();
        }
    }
}

71. JMSServerControl2Test#testStartActivationListConnections()

View license
@Test
public void testStartActivationListConnections() throws Exception {
    ActiveMQActivation activation = null;
    ActiveMQResourceAdapter ra = null;
    try {
        startActiveMQServer(InVMAcceptorFactory.class.getName());
        ActiveMQJMSClient.createQueue("test");
        serverManager.createQueue(false, "test", null, true, "test");
        JMSServerControl control = createManagementControl();
        ra = new ActiveMQResourceAdapter();
        ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
        ra.setUserName("userGlobal");
        ra.setPassword("passwordGlobal");
        ra.start(new BootstrapContext());
        ra.setClientID("my-client-id");
        ra.setUserName("user");
        Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
        conn.close();
        ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
        spec.setResourceAdapter(ra);
        spec.setUseJNDI(false);
        spec.setPassword("password");
        spec.setDestinationType("javax.jms.Queue");
        spec.setDestination("test");
        spec.setMinSession(1);
        spec.setMaxSession(1);
        activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
        activation.start();
        String cons = control.listConnectionsAsJSON();
        JMSConnectionInfo[] jmsConnectionInfos = JMSConnectionInfo.from(cons);
        assertEquals(1, jmsConnectionInfos.length);
        assertEquals("user", jmsConnectionInfos[0].getUsername());
        assertEquals("my-client-id", jmsConnectionInfos[0].getClientID());
    } finally {
        if (activation != null)
            activation.stop();
        if (ra != null)
            ra.stop();
        try {
            if (serverManager != null) {
                //serverManager.destroyQueue(queueName);
                serverManager.stop();
            }
        } catch (Throwable ignored) {
            ignored.printStackTrace();
        }
        if (server != null) {
            server.stop();
        }
    }
}

72. ResourceAdapterTest#testForConnectionLeakDuringActivationWhenSessionCreationFails()

View license
@Test
public void testForConnectionLeakDuringActivationWhenSessionCreationFails() throws Exception {
    ActiveMQServer server = createServer(false);
    ActiveMQResourceAdapter ra = null;
    ActiveMQActivation activation = null;
    try {
        server.getConfiguration().setSecurityEnabled(true);
        server.start();
        ra = new ActiveMQResourceAdapter();
        ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
        ra.setUserName("badUser");
        ra.setPassword("badPassword");
        ra.start(new BootstrapContext());
        ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
        spec.setResourceAdapter(ra);
        spec.setUseJNDI(false);
        spec.setUser("user");
        spec.setPassword("password");
        spec.setDestinationType("javax.jms.Topic");
        spec.setDestination("test");
        spec.setMinSession(1);
        spec.setMaxSession(1);
        spec.setSetupAttempts(1);
        activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
        try {
            activation.start();
        } catch (Exception e) {
        }
        assertEquals(0, server.getRemotingService().getConnections().size());
    } finally {
        if (activation != null)
            activation.stop();
        if (ra != null)
            ra.stop();
        server.stop();
    }
}