Search in sources :

Example 6 with ConnectionContext

use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.

the class LargeQueueSparseDeleteTest method testMoveMessages.

/**
 * The test queue is filled with QUEUE_SIZE test messages, each with a
 * numeric id property beginning at 0. Once the queue is filled, the last
 * message (id = QUEUE_SIZE-1) is moved to another queue. The test succeeds
 * if the move completes within TEST_TIMEOUT milliseconds.
 *
 * @throws Exception
 */
public void testMoveMessages() throws Exception {
    final int QUEUE_SIZE = 30000;
    final String MOVE_TO_DESTINATION_NAME = getDestinationString() + ".dest";
    final long TEST_TIMEOUT = 20000;
    // Populate a test queue with uniquely-identifiable messages.
    Connection conn = createConnection();
    try {
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < QUEUE_SIZE; i++) {
            Message message = session.createMessage();
            message.setIntProperty("id", i);
            producer.send(message);
        }
        session.commit();
    } finally {
        conn.close();
    }
    // Access the implementation of the test queue and move the last message
    // to another queue. Verify that the move occurred within the limits of
    // the test.
    Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
    ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
    context.setBroker(broker.getBroker());
    context.getMessageEvaluationContext().setDestination(destination);
    long startTimeMillis = System.currentTimeMillis();
    Assert.assertEquals(1, queue.moveMatchingMessagesTo(context, "id=" + (QUEUE_SIZE - 1), createDestination(MOVE_TO_DESTINATION_NAME)));
    long durationMillis = System.currentTimeMillis() - startTimeMillis;
    LOG.info("It took " + durationMillis + "ms to move the last message from a queue a " + QUEUE_SIZE + " messages.");
    Assert.assertTrue("Moving the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
Also used : Message(javax.jms.Message) NonCachedMessageEvaluationContext(org.apache.activemq.filter.NonCachedMessageEvaluationContext) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Queue(org.apache.activemq.broker.region.Queue) Session(javax.jms.Session)

Example 7 with ConnectionContext

use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.

the class LargeQueueSparseDeleteTest method testRemoveMessages.

public void testRemoveMessages() throws Exception {
    final int QUEUE_SIZE = 30000;
    final long TEST_TIMEOUT = 20000;
    // Populate a test queue with uniquely-identifiable messages.
    Connection conn = createConnection();
    try {
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < QUEUE_SIZE; i++) {
            Message message = session.createMessage();
            message.setIntProperty("id", i);
            producer.send(message);
        }
        session.commit();
    } finally {
        conn.close();
    }
    // Access the implementation of the test queue and move the last message
    // to another queue. Verify that the move occurred within the limits of
    // the test.
    Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
    ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
    context.setBroker(broker.getBroker());
    context.getMessageEvaluationContext().setDestination(destination);
    long startTimeMillis = System.currentTimeMillis();
    Assert.assertEquals(1, queue.removeMatchingMessages("id=" + (QUEUE_SIZE - 1)));
    long durationMillis = System.currentTimeMillis() - startTimeMillis;
    LOG.info("It took " + durationMillis + "ms to remove the last message from a queue a " + QUEUE_SIZE + " messages.");
    Assert.assertTrue("Removing the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
Also used : Message(javax.jms.Message) NonCachedMessageEvaluationContext(org.apache.activemq.filter.NonCachedMessageEvaluationContext) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Queue(org.apache.activemq.broker.region.Queue) Session(javax.jms.Session)

Example 8 with ConnectionContext

use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.

the class LargeQueueSparseDeleteTest method testCopyMessages.

public void testCopyMessages() throws Exception {
    final int QUEUE_SIZE = 30000;
    final String MOVE_TO_DESTINATION_NAME = getDestinationString() + ".dest";
    final long TEST_TIMEOUT = 10000;
    // Populate a test queue with uniquely-identifiable messages.
    Connection conn = createConnection();
    try {
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < QUEUE_SIZE; i++) {
            Message message = session.createMessage();
            message.setIntProperty("id", i);
            producer.send(message);
        }
        session.commit();
    } finally {
        conn.close();
    }
    // Access the implementation of the test queue and move the last message
    // to another queue. Verify that the move occurred within the limits of
    // the test.
    Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
    ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
    context.setBroker(broker.getBroker());
    context.getMessageEvaluationContext().setDestination(destination);
    long startTimeMillis = System.currentTimeMillis();
    Assert.assertEquals(1, queue.copyMatchingMessagesTo(context, "id=" + (QUEUE_SIZE - 1), createDestination(MOVE_TO_DESTINATION_NAME)));
    long durationMillis = System.currentTimeMillis() - startTimeMillis;
    LOG.info("It took " + durationMillis + "ms to copy the last message from a queue a " + QUEUE_SIZE + " messages.");
    Assert.assertTrue("Copying the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
Also used : Message(javax.jms.Message) NonCachedMessageEvaluationContext(org.apache.activemq.filter.NonCachedMessageEvaluationContext) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Queue(org.apache.activemq.broker.region.Queue) Session(javax.jms.Session)

Example 9 with ConnectionContext

use of org.apache.activemq.broker.ConnectionContext in project activemq-artemis by apache.

the class BrokerQueueNetworkWithDisconnectTest method testNoStuckConnectionsWithTransportDisconnect.

public void testNoStuckConnectionsWithTransportDisconnect() throws Exception {
    inactiveDuration = 60000L;
    useDuplexNetworkBridge = true;
    bridgeBrokers(SPOKE, HUB);
    final BrokerItem hub = brokers.get(HUB);
    hub.broker.setPlugins(new BrokerPlugin[] { new BrokerPluginSupport() {

        int sleepCount = 2;

        @Override
        public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
            try {
                while (--sleepCount >= 0) {
                    LOG.info("sleeping for a bit in close impl to simulate load where reconnect fails due to a pending close");
                    TimeUnit.SECONDS.sleep(2);
                }
            } catch (Exception ignored) {
            }
            super.removeConnection(context, info, error);
        }
    } });
    startAllBrokers();
    waitForBridgeFormation();
    // remote side will need to spot duplicate network and stop/kill the original
    for (int i = 0; i < 3; i++) {
        socketProxy.halfClose();
        sleep(10000);
    }
    // wait for full reformation of bridge
    // verify no extra connections
    boolean allGood = Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            long numConnections = hub.broker.getTransportConnectors().get(0).getConnections().size();
            LOG.info("Num connetions:" + numConnections);
            return numConnections == 1;
        }
    });
    if (!allGood) {
        dumpAllThreads("ExtraHubConnection");
    }
    assertTrue("should be only one transport connection for the single duplex network connector", allGood);
    allGood = Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            long numVmConnections = VMTransportFactory.SERVERS.get(HUB).getConnectionCount();
            LOG.info("Num VM connetions:" + numVmConnections);
            return numVmConnections == 2;
        }
    });
    if (!allGood) {
        dumpAllThreads("ExtraHubVMConnection");
    }
    assertTrue("should be only 2 vm connections for the single network duplex network connector", allGood);
}
Also used : BrokerPluginSupport(org.apache.activemq.broker.BrokerPluginSupport) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) Wait(org.apache.activemq.util.Wait)

Example 10 with ConnectionContext

use of org.apache.activemq.broker.ConnectionContext in project gocd by gocd.

the class ActiveMqMessagingService method removeQueue.

@Override
public void removeQueue(String queueName) {
    try {
        ActiveMQQueue destination = new ActiveMQQueue(queueName);
        ConnectionContext connectionContext = BrokerSupport.getConnectionContext(broker.getBroker());
        Destination brokerDestination = broker.getDestination(destination);
        List<Subscription> consumers = brokerDestination.getConsumers();
        for (Subscription consumer : consumers) {
            consumer.remove(connectionContext, brokerDestination);
            brokerDestination.removeSubscription(connectionContext, consumer, 0);
        }
        broker.getBroker().removeDestination(connectionContext, destination, 1000);
        broker.removeDestination(destination);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : Destination(org.apache.activemq.broker.region.Destination) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Subscription(org.apache.activemq.broker.region.Subscription)

Aggregations

ConnectionContext (org.apache.activemq.broker.ConnectionContext)16 Queue (org.apache.activemq.broker.region.Queue)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)4 Principal (java.security.Principal)3 Connection (javax.jms.Connection)3 Message (javax.jms.Message)3 MessageProducer (javax.jms.MessageProducer)3 Session (javax.jms.Session)3 Connector (org.apache.activemq.broker.Connector)3 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)3 Message (org.apache.activemq.command.Message)3 NonCachedMessageEvaluationContext (org.apache.activemq.filter.NonCachedMessageEvaluationContext)3 GroupPrincipal (org.apache.activemq.jaas.GroupPrincipal)3 UserPrincipal (org.apache.activemq.jaas.UserPrincipal)3 MessageStore (org.apache.activemq.store.MessageStore)3 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)3 IOException (java.io.IOException)2 ProducerBrokerExchange (org.apache.activemq.broker.ProducerBrokerExchange)2 StubBroker (org.apache.activemq.broker.StubBroker)2