Search in sources :

Example 16 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQTestBase method waitForBindings.

/**
 * @param server                the server where's being checked
 * @param address               the name of the address being checked
 * @param local                 if true we are looking for local bindings, false we are looking for remoting servers
 * @param expectedBindingCount  the expected number of counts
 * @param expectedConsumerCount the expected number of consumers
 * @param timeout               the timeout used on the check
 * @return
 * @throws Exception
 * @throws InterruptedException
 */
protected boolean waitForBindings(final ActiveMQServer server, final String address, final boolean local, final int expectedBindingCount, final int expectedConsumerCount, long timeout) throws Exception {
    final PostOffice po = server.getPostOffice();
    long start = System.currentTimeMillis();
    int bindingCount = 0;
    int totConsumers = 0;
    do {
        bindingCount = 0;
        totConsumers = 0;
        Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
        for (Binding binding : bindings.getBindings()) {
            if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
                QueueBinding qBinding = (QueueBinding) binding;
                bindingCount++;
                totConsumers += qBinding.consumerCount();
            }
        }
        if (bindingCount == expectedBindingCount && totConsumers == expectedConsumerCount) {
            return true;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < timeout);
    String msg = "Timed out waiting for bindings (bindingCount = " + bindingCount + " (expecting " + expectedBindingCount + ") " + ", totConsumers = " + totConsumers + " (expecting " + expectedConsumerCount + ")" + ")";
    log.error(msg);
    return false;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

Example 17 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQTestBase method getLocalQueueBindings.

private List<QueueBinding> getLocalQueueBindings(final PostOffice postOffice, final String address) throws Exception {
    ArrayList<QueueBinding> bindingsFound = new ArrayList<>();
    Bindings bindings = postOffice.getBindingsForAddress(new SimpleString(address));
    for (Binding binding : bindings.getBindings()) {
        if (binding instanceof LocalQueueBinding) {
            bindingsFound.add((QueueBinding) binding);
        }
    }
    return bindingsFound;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 18 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding 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 19 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testMaxSessions.

@Test
public void testMaxSessions() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setMaxSession(1);
    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);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 1);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 20 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testEndpointDeactivated.

@Test
public void testEndpointDeactivated() 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);
    Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 15);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 0);
    assertTrue(endpoint.released);
    qResourceAdapter.stop();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) 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

LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)22 Binding (org.apache.activemq.artemis.core.postoffice.Binding)19 Test (org.junit.Test)18 Queue (org.apache.activemq.artemis.core.server.Queue)14 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)8 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)8 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 PostOfficeImpl (org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)4 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3