use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQActivationTest method testValidateJNDIParameters.
// 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"));
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerSecurityTest method testSimpleMessageReceivedOnQueueWithSecuritySucceeds.
@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, 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();
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testBadDestinationType.
@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());
}
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueManyMessagesAndInterruptTimeout.
@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();
}
use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.
the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueue.
@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();
}
Aggregations