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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations