use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueImplTest method testScheduled.
@Test
public void testScheduled() throws Exception {
QueueImpl queue = new QueueImpl(1, new SimpleString("address1"), new SimpleString("queue1"), null, null, false, true, false, scheduledExecutor, null, null, null, ArtemisExecutor.delegate(executor), null, null);
FakeConsumer consumer = null;
// Send one scheduled
long now = System.currentTimeMillis();
MessageReference ref1 = generateReference(queue, 1);
ref1.setScheduledDeliveryTime(now + 700);
queue.addTail(ref1);
// Send some non scheduled messages
MessageReference ref2 = generateReference(queue, 2);
queue.addTail(ref2);
MessageReference ref3 = generateReference(queue, 3);
queue.addTail(ref3);
MessageReference ref4 = generateReference(queue, 4);
queue.addTail(ref4);
// Now send some more scheduled messages
MessageReference ref5 = generateReference(queue, 5);
ref5.setScheduledDeliveryTime(now + 500);
queue.addTail(ref5);
MessageReference ref6 = generateReference(queue, 6);
ref6.setScheduledDeliveryTime(now + 400);
queue.addTail(ref6);
MessageReference ref7 = generateReference(queue, 7);
ref7.setScheduledDeliveryTime(now + 300);
queue.addTail(ref7);
MessageReference ref8 = generateReference(queue, 8);
ref8.setScheduledDeliveryTime(now + 600);
queue.addTail(ref8);
consumer = new FakeConsumer();
queue.addConsumer(consumer);
queue.deliverNow();
List<MessageReference> refs = new ArrayList<>();
refs.add(ref2);
refs.add(ref3);
refs.add(ref4);
assertRefListsIdenticalRefs(refs, consumer.getReferences());
refs.clear();
consumer.getReferences().clear();
MessageReference ref = consumer.waitForNextReference(QueueImplTest.TIMEOUT);
Assert.assertEquals(ref7, ref);
long now2 = System.currentTimeMillis();
Assert.assertTrue(now2 - now >= 300);
ref = consumer.waitForNextReference(QueueImplTest.TIMEOUT);
Assert.assertEquals(ref6, ref);
now2 = System.currentTimeMillis();
Assert.assertTrue(now2 - now >= 400);
ref = consumer.waitForNextReference(QueueImplTest.TIMEOUT);
Assert.assertEquals(ref5, ref);
now2 = System.currentTimeMillis();
Assert.assertTrue(now2 - now >= 500);
ref = consumer.waitForNextReference(QueueImplTest.TIMEOUT);
Assert.assertEquals(ref8, ref);
now2 = System.currentTimeMillis();
Assert.assertTrue(now2 - now >= 600);
ref = consumer.waitForNextReference(QueueImplTest.TIMEOUT);
Assert.assertEquals(ref1, ref);
now2 = System.currentTimeMillis();
Assert.assertTrue(now2 - now >= 700);
Assert.assertTrue(consumer.getReferences().isEmpty());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class QueueConcurrentTest method testConcurrentAddsDeliver.
/*
* Concurrent set consumer not busy, busy then, call deliver while messages are being added and consumed
*/
@Test
public void testConcurrentAddsDeliver() throws Exception {
QueueImpl queue = (QueueImpl) queueFactory.createQueueWith(QueueConfig.builderWith(1, new SimpleString("address1"), new SimpleString("queue1")).durable(false).temporary(false).autoCreated(false).build());
FakeConsumer consumer = new FakeConsumer();
queue.addConsumer(consumer);
final long testTime = 5000;
Sender sender = new Sender(queue, testTime);
Toggler toggler = new Toggler(queue, consumer, testTime);
sender.start();
toggler.start();
sender.join();
toggler.join();
consumer.setStatusImmediate(HandleStatus.HANDLED);
queue.deliverNow();
if (sender.getException() != null) {
throw sender.getException();
}
if (toggler.getException() != null) {
throw toggler.getException();
}
assertRefListsIdenticalRefs(sender.getReferences(), consumer.getReferences());
QueueConcurrentTest.log.info("num refs: " + sender.getReferences().size());
QueueConcurrentTest.log.info("num toggles: " + toggler.getNumToggles());
}
use of org.apache.activemq.artemis.core.server.impl.QueueImpl in project activemq-artemis by apache.
the class TopicCleanupTest method testSendTopic.
@Test
public void testSendTopic() throws Exception {
Topic topic = createTopic("topic");
Connection conn = cf.createConnection();
try {
conn.setClientID("someID");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sess.createDurableSubscriber(topic, "someSub");
conn.start();
MessageProducer prod = sess.createProducer(topic);
TextMessage msg1 = sess.createTextMessage("text");
prod.send(msg1);
assertNotNull(cons.receive(5000));
conn.close();
StorageManager storage = server.getStorageManager();
for (int i = 0; i < 100; i++) {
long txid = storage.generateID();
final Queue queue = new QueueImpl(storage.generateID(), SimpleString.toSimpleString("topic"), SimpleString.toSimpleString("topic"), FilterImpl.createFilter(Filter.GENERIC_IGNORED_FILTER), null, true, false, false, server.getScheduledPool(), server.getPostOffice(), storage, server.getAddressSettingsRepository(), server.getExecutorFactory().getExecutor(), server, null);
LocalQueueBinding binding = new LocalQueueBinding(queue.getAddress(), queue, server.getNodeID());
storage.addQueueBinding(txid, binding);
storage.commitBindings(txid);
}
jmsServer.stop();
jmsServer.start();
} finally {
try {
conn.close();
} catch (Throwable igonred) {
}
}
}
Aggregations