use of org.apache.activemq.util.ConsumerThread in project activemq-artemis by apache.
the class ProxyFailoverTest method testFailover.
public void testFailover() throws Exception {
ActiveMQConnectionFactory producerFactory = new ActiveMQConnectionFactory("failover:(tcp://localhost:61616,tcp://localhost:61626)?randomize=false");
Connection producerConnection = producerFactory.createConnection();
producerConnection.start();
Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ProducerThread producer = new ProducerThread(producerSession, producerSession.createQueue("ProxyTest"));
producer.setSleep(10);
producer.start();
ActiveMQConnectionFactory consumerFactory = new ActiveMQConnectionFactory("tcp://localhost:51618");
Connection consumerConnection = consumerFactory.createConnection();
consumerConnection.start();
Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ConsumerThread consumer = new ConsumerThread(consumerSession, consumerSession.createQueue("ProxyTest"));
consumer.start();
TimeUnit.SECONDS.sleep(15);
remoteBroker.stop();
remoteBroker.waitUntilStopped();
startRemoteBroker(false);
producer.join();
consumer.join();
assertEquals(1000, consumer.getReceived());
}
use of org.apache.activemq.util.ConsumerThread in project activemq-artemis by apache.
the class NIOSSLLoadTest method testLoad.
public void testLoad() throws Exception {
Queue dest = session.createQueue("TEST");
for (int i = 0; i < PRODUCER_COUNT; i++) {
ProducerThread producer = new ProducerThread(session, dest);
producer.setMessageCount(MESSAGE_COUNT);
producer.start();
}
for (int i = 0; i < CONSUMER_COUNT; i++) {
ConsumerThread consumer = new ConsumerThread(session, dest);
consumer.setMessageCount(MESSAGE_COUNT);
consumer.start();
consumers[i] = consumer;
}
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return getReceived() == PRODUCER_COUNT * MESSAGE_COUNT;
}
}, 60000);
assertEquals(PRODUCER_COUNT * MESSAGE_COUNT, getReceived());
}
use of org.apache.activemq.util.ConsumerThread in project activemq-artemis by apache.
the class MemoryLimitTest method testLimit.
/**
* Handy test for manually checking what's going on
*/
@Ignore
@Test(timeout = 120000)
public void testLimit() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=10");
factory.setOptimizeAcknowledge(true);
Connection conn = factory.createConnection();
conn.start();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final ProducerThread producer = new ProducerThread(sess, sess.createQueue("STORE.1")) {
@Override
protected Message createMessage(int i) throws Exception {
return sess.createTextMessage(Arrays.toString(payload) + "::" + i);
}
};
producer.setMessageCount(1000);
final ProducerThread producer2 = new ProducerThread(sess, sess.createQueue("STORE.2")) {
@Override
protected Message createMessage(int i) throws Exception {
return sess.createTextMessage(Arrays.toString(payload) + "::" + i);
}
};
producer2.setMessageCount(1000);
ConsumerThread consumer = new ConsumerThread(sess, sess.createQueue("STORE.1"));
consumer.setBreakOnNull(false);
consumer.setMessageCount(1000);
producer.start();
producer.join();
producer2.start();
Thread.sleep(300);
consumer.start();
consumer.join();
producer2.join();
assertEquals("consumer got all produced messages", producer.getMessageCount(), consumer.getReceived());
}
use of org.apache.activemq.util.ConsumerThread in project activemq-artemis by apache.
the class MessageRedistributionTest method closeConsumerAndConnectionConcurrently.
private void closeConsumerAndConnectionConcurrently(int targetNode, int remoteNode) throws Exception {
String targetUri = getServerUri(targetNode);
System.out.println("uri is " + targetUri);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(targetUri);
Connection conn = null;
CountDownLatch active = new CountDownLatch(1);
try {
conn = factory.createConnection();
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = ActiveMQDestination.createDestination("queue0", ActiveMQDestination.QUEUE_TYPE);
ConsumerThread consumer = new ConsumerThread(session, dest);
consumer.setMessageCount(0);
consumer.setFinished(active);
consumer.start();
assertTrue("consumer takes too long to finish!", active.await(5, TimeUnit.SECONDS));
} finally {
conn.close();
}
Wait.waitFor(() -> getRemoteQueueBinding(servers[remoteNode]) != null);
// check remote server's consumer count
RemoteQueueBinding remoteBinding = getRemoteQueueBinding(servers[remoteNode]);
assertNotNull(remoteBinding);
Wait.waitFor(() -> remoteBinding.consumerCount() >= 0);
int count = remoteBinding.consumerCount();
assertTrue("consumer count should never be negative " + count, count >= 0);
}
Aggregations