use of org.apache.activemq.artemis.core.server.Consumer in project activemq-artemis by apache.
the class QueueImplTest method testAddRemoveConsumer.
@Test
public void testAddRemoveConsumer() throws Exception {
Consumer cons1 = new FakeConsumer();
Consumer cons2 = new FakeConsumer();
Consumer cons3 = new FakeConsumer();
QueueImpl queue = getTemporaryQueue();
Assert.assertEquals(0, queue.getConsumerCount());
queue.addConsumer(cons1);
Assert.assertEquals(1, queue.getConsumerCount());
queue.removeConsumer(cons1);
Assert.assertEquals(0, queue.getConsumerCount());
queue.addConsumer(cons1);
queue.addConsumer(cons2);
queue.addConsumer(cons3);
Assert.assertEquals(3, queue.getConsumerCount());
queue.removeConsumer(new FakeConsumer());
Assert.assertEquals(3, queue.getConsumerCount());
queue.removeConsumer(cons1);
Assert.assertEquals(2, queue.getConsumerCount());
queue.removeConsumer(cons2);
Assert.assertEquals(1, queue.getConsumerCount());
queue.removeConsumer(cons3);
Assert.assertEquals(0, queue.getConsumerCount());
queue.removeConsumer(cons3);
}
use of org.apache.activemq.artemis.core.server.Consumer in project activemq-artemis by apache.
the class QueueImplTest method testDeliveryScheduled.
@Test
public void testDeliveryScheduled() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
Consumer consumer = new FakeConsumer() {
@Override
public synchronized HandleStatus handle(final MessageReference reference) {
countDownLatch.countDown();
return HandleStatus.HANDLED;
}
@Override
public void disconnect() {
}
};
QueueImpl queue = new QueueImpl(1, new SimpleString("address1"), QueueImplTest.queue1, null, null, false, true, false, scheduledExecutor, null, null, null, ArtemisExecutor.delegate(executor), null, null);
MessageReference messageReference = generateReference(queue, 1);
queue.addConsumer(consumer);
messageReference.setScheduledDeliveryTime(System.currentTimeMillis() + 200);
queue.addHead(messageReference, false);
boolean gotLatch = countDownLatch.await(3000, TimeUnit.MILLISECONDS);
Assert.assertTrue(gotLatch);
}
use of org.apache.activemq.artemis.core.server.Consumer in project activemq-artemis by apache.
the class QueueImpl method hasMatchingConsumer.
@Override
public boolean hasMatchingConsumer(final Message message) {
for (ConsumerHolder holder : consumerList) {
Consumer consumer = holder.consumer;
if (consumer instanceof Redistributor) {
continue;
}
Filter filter1 = consumer.getFilter();
if (filter1 == null) {
return true;
} else {
if (filter1.match(message)) {
return true;
}
}
}
return false;
}
Aggregations