Search in sources :

Example 6 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ResourceAdapterTest method testDefaultConnectionFactory.

// 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);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) Test(org.junit.Test)

Example 7 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ResourceAdapterTest method testCreateConnectionFactoryOverrideConnector.

@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);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactoryProperties(org.apache.activemq.artemis.ra.ConnectionFactoryProperties) NettyConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory) ArrayList(java.util.ArrayList) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) Test(org.junit.Test)

Example 8 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ResourceAdapterTest method testCreateConnectionFactoryOverrideDiscovery.

@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);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactoryProperties(org.apache.activemq.artemis.ra.ConnectionFactoryProperties) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) UDPBroadcastEndpointFactory(org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory) Test(org.junit.Test)

Example 9 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueue.

@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();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 10 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueTwoPhase.

@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();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Aggregations

ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)81 Test (org.junit.Test)72 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)54 CountDownLatch (java.util.concurrent.CountDownLatch)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)28 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)24 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)24 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)24 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)14 ConnectionFactoryProperties (org.apache.activemq.artemis.ra.ConnectionFactoryProperties)10 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)9 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)8 Binding (org.apache.activemq.artemis.core.postoffice.Binding)7 HashSet (java.util.HashSet)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Role (org.apache.activemq.artemis.core.security.Role)5 ActiveMQActivation (org.apache.activemq.artemis.ra.inflow.ActiveMQActivation)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)4 Session (javax.jms.Session)4