Search in sources :

Example 41 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class BMFailoverTest method testFailoverOnCommit.

@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "commit", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)") })
public void testFailoverOnCommit() throws Exception {
    serverToStop = liveServer;
    locator = getServerLocator().setFailoverOnInitialConnection(true);
    createSessionFactory();
    ClientSession session = createSessionAndQueue();
    ClientProducer producer = addClientProducer(session.createProducer(FailoverTestBase.ADDRESS));
    sendMessages(session, producer, 10);
    try {
        session.commit();
        fail("should have thrown an exception");
    } catch (ActiveMQTransactionOutcomeUnknownException e) {
    // pass
    }
    sendMessages(session, producer, 10);
    session.commit();
    Queue bindable = (Queue) backupServer.getServer().getPostOffice().getBinding(FailoverTestBase.ADDRESS).getBindable();
    assertEquals(10, getMessageCount(bindable));
}
Also used : ActiveMQTransactionOutcomeUnknownException(org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 42 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class BMFailoverTest method testFailoverOnReceiveCommit.

@Test
@BMRules(rules = { @BMRule(name = "trace clientsessionimpl commit", targetClass = "org.apache.activemq.artemis.core.client.impl.ClientSessionImpl", targetMethod = "commit", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.BMFailoverTest.serverToStop.getServer().stop(true)") })
public void testFailoverOnReceiveCommit() throws Exception {
    serverToStop = liveServer;
    locator = getServerLocator().setFailoverOnInitialConnection(true);
    createSessionFactory();
    ClientSession session = createSessionAndQueue();
    ClientSession sendSession = createSession(sf, true, true);
    ClientProducer producer = addClientProducer(sendSession.createProducer(FailoverTestBase.ADDRESS));
    sendMessages(sendSession, producer, 10);
    ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        ClientMessage m = consumer.receive(500);
        assertNotNull(m);
        m.acknowledge();
    }
    try {
        session.commit();
        fail("should have thrown an exception");
    } catch (ActiveMQTransactionOutcomeUnknownException e) {
    // pass
    } catch (ActiveMQTransactionRolledBackException e1) {
    // pass
    }
    Queue bindable = (Queue) backupServer.getServer().getPostOffice().getBinding(FailoverTestBase.ADDRESS).getBindable();
    assertEquals(10, getMessageCount(bindable));
}
Also used : ActiveMQTransactionOutcomeUnknownException(org.apache.activemq.artemis.api.core.ActiveMQTransactionOutcomeUnknownException) ActiveMQTransactionRolledBackException(org.apache.activemq.artemis.api.core.ActiveMQTransactionRolledBackException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 43 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class BindingsImplTest method internalTest.

private void internalTest(final boolean route) throws Exception {
    final FakeBinding fake = new FakeBinding(new SimpleString("a"));
    final Bindings bind = new BindingsImpl(null, null, null);
    bind.addBinding(fake);
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                bind.removeBinding(fake);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    Queue queue = new FakeQueue(new SimpleString("a"));
    t.start();
    for (int i = 0; i < 100; i++) {
        if (route) {
            bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction()));
        } else {
            bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction()));
        }
    }
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 44 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class QueueManagerImpl method doIt.

private void doIt() {
    Queue queue = server.locateQueue(queueName);
    // the queue may already have been deleted and this is a result of that
    if (queue == null) {
        if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
            ActiveMQServerLogger.LOGGER.debug("pno queue to delete \"" + queueName + ".\"");
        }
        return;
    }
    SimpleString address = queue.getAddress();
    AddressSettings settings = server.getAddressSettingsRepository().getMatch(address.toString());
    long consumerCount = queue.getConsumerCount();
    long messageCount = queue.getMessageCount();
    if (queue.isAutoCreated() && settings.isAutoDeleteQueues() && queue.getMessageCount() == 0 && queue.getConsumerCount() == 0) {
        if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
            ActiveMQServerLogger.LOGGER.debug("deleting " + (queue.isAutoCreated() ? "auto-created " : "") + "queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteQueues = " + settings.isAutoDeleteQueues());
        }
        try {
            server.destroyQueue(queueName, null, true, false);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.errorRemovingAutoCreatedQueue(e, queueName);
        }
    } else if (queue.isPurgeOnNoConsumers()) {
        if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
            ActiveMQServerLogger.LOGGER.debug("purging queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount);
        }
        try {
            queue.deleteMatchingReferences(QueueImpl.DEFAULT_FLUSH_LIMIT, null, AckReason.KILLED);
        } catch (Exception e) {
            ActiveMQServerLogger.LOGGER.failedToPurgeQueue(e, queueName);
        }
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 45 with Queue

use of org.apache.activemq.artemis.core.server.Queue in project activemq-artemis by apache.

the class PostOfficeJournalLoader method generateMapsOnPendingCount.

/**
 * This generates a map for use on the recalculation and recovery of pending maps after reloading it
 *
 * @param queues
 * @param pendingNonTXPageCounter
 * @param txRecoverCounter
 * @return
 * @throws Exception
 */
private Map<SimpleString, Map<Long, Map<Long, List<PageCountPending>>>> generateMapsOnPendingCount(Map<Long, Queue> queues, List<PageCountPending> pendingNonTXPageCounter, Transaction txRecoverCounter) throws Exception {
    Map<SimpleString, Map<Long, Map<Long, List<PageCountPending>>>> perAddressMap = new HashMap<>();
    for (PageCountPending pgCount : pendingNonTXPageCounter) {
        long queueID = pgCount.getQueueID();
        long pageID = pgCount.getPageID();
        // We first figure what Queue is based on the queue id
        Queue queue = queues.get(queueID);
        if (queue == null) {
            logger.debug("removing pending page counter id = " + pgCount.getID() + " as queueID=" + pgCount.getID() + " no longer exists");
            // this means the queue doesn't exist any longer, we will remove it from the storage
            storageManager.deletePendingPageCounter(txRecoverCounter.getID(), pgCount.getID());
            txRecoverCounter.setContainsPersistent();
            continue;
        }
        // Level 1 on the structure, per address
        SimpleString address = queue.getAddress();
        Map<Long, Map<Long, List<PageCountPending>>> perPageMap = perAddressMap.get(address);
        if (perPageMap == null) {
            perPageMap = new HashMap<>();
            perAddressMap.put(address, perPageMap);
        }
        Map<Long, List<PageCountPending>> perQueueMap = perPageMap.get(pageID);
        if (perQueueMap == null) {
            perQueueMap = new HashMap<>();
            perPageMap.put(pageID, perQueueMap);
        }
        List<PageCountPending> pendingCounters = perQueueMap.get(queueID);
        if (pendingCounters == null) {
            pendingCounters = new LinkedList<>();
            perQueueMap.put(queueID, pendingCounters);
        }
        pendingCounters.add(pgCount);
        perQueueMap.put(queueID, pendingCounters);
    }
    return perAddressMap;
}
Also used : PageCountPending(org.apache.activemq.artemis.core.persistence.impl.PageCountPending) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AtomicLong(java.util.concurrent.atomic.AtomicLong) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Queue(org.apache.activemq.artemis.core.server.Queue)

Aggregations

Queue (org.apache.activemq.artemis.core.server.Queue)275 Test (org.junit.Test)193 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)128 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)89 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)85 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)75 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)70 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)70 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)70 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)64 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)59 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)56 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)49 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)47 Session (javax.jms.Session)36 Connection (javax.jms.Connection)32 Configuration (org.apache.activemq.artemis.core.config.Configuration)31 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)30 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)27 TextMessage (javax.jms.TextMessage)25