use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testRecoverColdRestart.
@Test
public void testRecoverColdRestart() throws Exception {
QueueManager mgr = createQueueManager();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("warmRecoverQueue");
mgr.start();
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(toPopulate, q.size());
// Stop and recreate TransactionalQueueManager simulating a cold restart
mgr.stop();
mgr = createQueueManager();
s = mgr.getQueueSession();
q = s.getQueue("warmRecoverQueue");
mgr.start();
if (isPersistent()) {
assertEquals(toPopulate, q.size());
} else {
assertEquals(0, q.size());
}
}
use of org.mule.runtime.core.api.util.queue.QueueSession in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testTakePut.
@Test
public void testTakePut() 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");
} 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", "String1", 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 testPutTake.
@Test
public void testPutTake() throws Exception {
QueueManager mgr = createQueueManager();
mgr.start();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
q.put("String1");
assertEquals("Queue size", 1, q.size());
Object o = q.take();
assertNotNull(o);
assertEquals("Queue content", "String1", o);
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 testTakePutOverCapacity.
@Test
public void testTakePutOverCapacity() throws Exception {
final QueueManager mgr = createQueueManager();
mgr.start();
mgr.setDefaultQueueConfiguration(new DefaultQueueConfiguration(2, false));
final Latch latch = new Latch();
Thread t = new Thread() {
@Override
public void run() {
try {
latch.await();
Thread.sleep(200);
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
Object o = q.take();
assertEquals("Queue content", "String1", o);
} catch (Exception e) {
// ignore, let test fail
}
}
};
t.start();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
q.put("String1");
q.put("String2");
latch.countDown();
long t0 = System.currentTimeMillis();
q.put("String3");
long t1 = System.currentTimeMillis();
t.join();
assertEquals("Queue size", 2, 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 testPeek.
@Test
public void testPeek() throws Exception {
QueueManager mgr = createQueueManager();
try {
mgr.start();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
Object o = q.peek();
assertEquals("Queue size", 0, q.size());
assertNull(o);
q.put("String1");
assertEquals("Queue size", 1, q.size());
o = q.peek();
assertEquals("Queue size", 1, q.size());
assertEquals("Queue content", "String1", o);
o = q.poll(1000);
assertEquals("Queue size", 0, q.size());
assertEquals("Queue content", "String1", o);
} finally {
mgr.stop();
}
}
Aggregations