use of org.apache.activemq.util.ProducerThread 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.ProducerThread 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.ProducerThread in project activemq-artemis by apache.
the class MemoryLimitTest method testCursorBatch.
@Test(timeout = 120000)
public void testCursorBatch() 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.CLIENT_ACKNOWLEDGE);
Queue queue = sess.createQueue("STORE");
final ProducerThread producer = new ProducerThread(sess, queue) {
@Override
protected Message createMessage(int i) throws Exception {
BytesMessage bytesMessage = sess.createBytesMessage();
bytesMessage.writeBytes(payload);
return bytesMessage;
}
};
producer.setMessageCount(2000);
producer.start();
producer.join();
Thread.sleep(1000);
// assert we didn't break high watermark (70%) usage
final Destination dest = broker.getDestination((ActiveMQQueue) queue);
LOG.info("Destination usage: " + dest.getMemoryUsage());
int percentUsage = dest.getMemoryUsage().getPercentUsage();
assertTrue("Should be less than 70% of limit but was: " + percentUsage, percentUsage <= 71);
LOG.info("Broker usage: " + broker.getSystemUsage().getMemoryUsage());
assertTrue(broker.getSystemUsage().getMemoryUsage().getPercentUsage() <= 71);
// consume one message
MessageConsumer consumer = sess.createConsumer(queue);
Message msg = consumer.receive(5000);
msg.acknowledge();
// this should free some space and allow us to get new batch of messages in the memory
// exceeding the limit
assertTrue("Limit is exceeded", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("Destination usage: " + dest.getMemoryUsage());
return dest.getMemoryUsage().getPercentUsage() >= 200;
}
}));
LOG.info("Broker usage: " + broker.getSystemUsage().getMemoryUsage());
assertTrue(broker.getSystemUsage().getMemoryUsage().getPercentUsage() >= 200);
// let's make sure we can consume all messages
for (int i = 1; i < 2000; i++) {
msg = consumer.receive(5000);
if (msg == null) {
dumpAllThreads("NoMessage");
}
assertNotNull("Didn't receive message " + i, msg);
msg.acknowledge();
}
}
use of org.apache.activemq.util.ProducerThread 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.ProducerThread in project activemq-artemis by apache.
the class JmsSchedulerTest method testJobSchedulerStoreUsage.
@Test
public void testJobSchedulerStoreUsage() throws Exception {
// Shrink the store limit down so we get the producer to block
broker.getSystemUsage().getJobSchedulerUsage().setLimit(10 * 1024);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
Connection conn = factory.createConnection();
conn.start();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final long time = 5000;
final ProducerThread producer = new ProducerThread(sess, destination) {
@Override
protected Message createMessage(int i) throws Exception {
Message message = super.createMessage(i);
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time);
return message;
}
};
producer.setMessageCount(100);
producer.start();
MessageConsumer consumer = sess.createConsumer(destination);
final CountDownLatch latch = new CountDownLatch(100);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
latch.countDown();
}
});
// wait for the producer to block, which should happen immediately, and also wait long
// enough for the delay to elapse. We should see no deliveries as the send should block
// on the first message.
Thread.sleep(10000L);
assertEquals(100, latch.getCount());
// Increase the store limit so the producer unblocks. Everything should enqueue at this point.
broker.getSystemUsage().getJobSchedulerUsage().setLimit(1024 * 1024 * 33);
// Wait long enough that the messages are enqueued and the delivery delay has elapsed.
Thread.sleep(10000L);
// Make sure we sent all the messages we expected to send
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return producer.getSentCount() == producer.getMessageCount();
}
}, 20000L);
assertEquals("Producer didn't send all messages", producer.getMessageCount(), producer.getSentCount());
// Make sure we got all the messages we expected to get
latch.await(20000L, TimeUnit.MILLISECONDS);
assertEquals("Consumer did not receive all messages.", 0, latch.getCount());
}
Aggregations