use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testPutTakeUntakeRollbackUntake.
@Test
public void testPutTakeUntakeRollbackUntake() throws Exception {
final QueueManager mgr = createQueueManager();
mgr.start();
final Latch latch = new Latch();
final Serializable object1 = "string1";
final Serializable object2 = "string2";
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());
s.begin();
q.untake(object1);
s.commit();
s.begin();
q.untake(object2);
s.rollback();
} 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());
Object o = q.take();
long t1 = System.currentTimeMillis();
t.join();
assertNotNull(o);
assertEquals("Queue content", object1, o);
assertEquals("Queue size", 0, q.size());
assertTrue(t1 - t0 > 100);
mgr.stop();
}
use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testRecoverWarmRestart.
@Test
public void testRecoverWarmRestart() throws Exception {
QueueManager mgr = createQueueManager();
mgr.start();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("warmRecoverQueue");
int toPopulate = 50;
// Populate queue
Random rnd = new Random();
for (int j = 0; j < toPopulate; j++) {
byte[] o = new byte[2048];
rnd.nextBytes(o);
q.put(o);
}
assertEquals(q.size(), toPopulate);
// Stop and start TransactionalQueueManager
mgr.stop();
mgr.start();
assertEquals(toPopulate, q.size());
}
use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testTransactedPutCommitWithPersistence.
@Test
public void testTransactedPutCommitWithPersistence() throws Exception {
if (isPersistent()) {
AbstractQueueManager mgr = createQueueManager();
try {
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
mgr.start();
s.begin();
q.put("String1");
assertEquals("Queue size", 1, q.size());
s.commit();
assertEquals("Queue size", 1, q.size());
s = mgr.getQueueSession();
q = s.getQueue("queue1");
assertEquals("Queue size", 1, q.size());
mgr.stop();
mgr = createQueueManager();
s = mgr.getQueueSession();
q = s.getQueue("queue1");
mgr.start();
assertEquals("Queue size", 1, q.size());
} finally {
mgr.stop();
mgr.dispose();
}
} else {
logger.info("Ignoring test because queue manager is not persistent");
}
}
use of org.mule.runtime.core.api.util.queue.QueueSession 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.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testPutTake_RespectsOrderOnPersistence.
@Test
public void testPutTake_RespectsOrderOnPersistence() throws Exception {
if (isPersistent()) {
AbstractQueueManager mgr1 = createQueueManager();
QueueSession s1 = mgr1.getQueueSession();
Queue q1 = s1.getQueue("queue1");
mgr1.start();
assertEquals("Queue size", 0, q1.size());
final int numberOfElements = 10;
for (int i = 1; i <= numberOfElements; i++) {
q1.put("String" + i);
assertEquals("Queue size", i, q1.size());
}
mgr1.stop();
AbstractQueueManager mgr2 = createQueueManager();
QueueSession s2 = mgr2.getQueueSession();
Queue q2 = s2.getQueue("queue1");
mgr2.start();
for (int i = 1; i <= numberOfElements; i++) {
Object o = q2.take();
assertNotNull(o);
assertEquals("Queue content", "String" + i, o);
}
assertEquals("Queue size", 0, q2.size());
mgr2.stop();
mgr2.dispose();
}
}
Aggregations