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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations