use of org.mule.runtime.core.api.util.queue.QueueManager in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testClearInTransaction.
@Test
public void testClearInTransaction() throws Exception {
final QueueManager mgr = createQueueManager();
mgr.start();
QueueSession s = mgr.getQueueSession();
// insert item in transaction
s.begin();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
q.put("String1");
s.commit();
assertEquals("Queue size", 1, q.size());
// clear queue but rollback
s.begin();
assertEquals("Queue size", 1, q.size());
q.clear();
s.rollback();
assertEquals("Queue size", 1, q.size());
// do clear in transaction
s.begin();
assertEquals("Queue size", 1, q.size());
q.clear();
s.commit();
assertEquals("Queue size", 0, q.size());
mgr.stop();
}
use of org.mule.runtime.core.api.util.queue.QueueManager 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.QueueManager in project mule by mulesoft.
the class MuleContextLifecycleTestCase method buildStartedMuleContext.
private MuleContext buildStartedMuleContext() throws Exception {
ctx.initialise();
// DefaultMuleContext refuses to start without these objects in place
SecurityManager securityManager = mock(SecurityManager.class);
((MuleContextWithRegistries) ctx).getRegistry().registerObject(UUID.getUUID(), securityManager);
QueueManager queueManager = mock(QueueManager.class);
((MuleContextWithRegistries) ctx).getRegistry().registerObject(UUID.getUUID(), queueManager);
ctx.start();
return ctx;
}
Aggregations