use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ResourceAdapterTest method testResourceAdapterSetupNoOverrideDiscovery.
@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();
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ResourceAdapterTest method testMaskPasswordENC.
@Test
public void testMaskPasswordENC() throws Exception {
ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();
qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
ActiveMQRATestBase.MyBootstrapContext ctx = new ActiveMQRATestBase.MyBootstrapContext();
DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
String mask = codec.encode("helloworld");
qResourceAdapter.setPassword(PasswordMaskingUtil.wrap(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 = codec.encode("mdbpassword");
spec.setPassword(PasswordMaskingUtil.wrap(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);
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueInLocalTX.
@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();
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerXATest method testXACommitWhenStopping.
@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);
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerXATest method testXARollback.
@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();
}
Aggregations