use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testPutTakeUntake.
@Test
public void testPutTakeUntake() throws Exception {
final QueueManager mgr = createQueueManager();
mgr.start();
final Latch latch = new Latch();
Thread t = new Thread() {
@Override
public void run() {
try {
latch.countDown();
Thread.sleep(200);
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
q.put("String1");
q.put("String2");
} catch (Exception e) {
// ignore, let test fail
}
}
};
t.start();
latch.await();
long t0 = System.currentTimeMillis();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
Serializable o = q.take();
long t1 = System.currentTimeMillis();
t.join();
assertNotNull(o);
assertEquals("Queue content", "String1", o);
assertEquals("Queue size", 1, q.size());
assertTrue(t1 - t0 > 100);
// Same as put/take until now, but now we do an untake
q.untake(o);
// Ensure queue size is now 2
assertEquals("Queue size", 2, q.size());
// Take to ensure order is correct
Object o2 = q.take();
assertEquals("Queue content", "String1", o2);
assertEquals("Queue size", 1, q.size());
mgr.stop();
}
use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class QueueTestComponent method testDisposal.
public void testDisposal(QueueManager mgr, boolean transactional) throws Exception {
final String queueName = "myQueue";
mgr.start();
QueueSession session = mgr.getQueueSession();
if (transactional) {
session.begin();
}
Queue queue = mgr.getQueueSession().getQueue(queueName);
this.assertQueueDisposal(mgr, queue, transactional ? session : null, queueName);
}
Aggregations