Search in sources :

Example 11 with ActiveMQResourceAdapter

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

the class ActiveMQMessageHandlerSecurityTest method testSimpleMessageReceivedOnQueueWithSecurityFails.

@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();
}
Also used : LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with ActiveMQResourceAdapter

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

the class ActiveMQClusteredTest method testOutboundLoadBalancing.

@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();
        while (!((ServerLocatorImpl) cf1.getServerLocator()).isReceivedTopology()) {
            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();
        }
    }
}
Also used : ActiveMQRAConnectionManager(org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) ArrayList(java.util.ArrayList) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) QueueConnection(javax.jms.QueueConnection) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Session(javax.jms.Session) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) Test(org.junit.Test)

Example 13 with ActiveMQResourceAdapter

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

the class ActiveMQClusteredTest method testNonDurableInCluster.

/**
 * 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("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));
}
Also used : ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 14 with ActiveMQResourceAdapter

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

the class ActiveMQClusteredTest method testRebalanceInternal.

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(200L);
    spec.setReconnectAttempts(reconnectAttempts);
    // if this isn't true then the topology 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();
}
Also used : 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) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 15 with ActiveMQResourceAdapter

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

the class ActiveMQClusteredTest method testShutdownOnPartialConnect.

/*
   * 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 that activation didn't start, i.e. no MDB consumers
    assertEquals(((Queue) server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE).getBindable()).getConsumerCount(), 0);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

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