use of org.mule.runtime.core.api.util.queue.QueueManager in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testOffer.
@Test
public void testOffer() throws Exception {
final QueueManager mgr = createQueueManager();
mgr.setDefaultQueueConfiguration(new DefaultQueueConfiguration(1, false));
try {
mgr.start();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertThat("Queue size", q.size(), is(0));
assertThat(q.offer("String1", 0L), is(true));
assertThat("Queue size", q.size(), is(1));
assertThat(q.offer("String2", 1000), is(false));
assertThat("Queue size", q.size(), is(1));
final Latch takeExecutionLatch = new Latch();
final Thread takeExecutionThread = new Thread(() -> {
try {
takeExecutionLatch.release();
QueueSession s1 = mgr.getQueueSession();
Queue q1 = s1.getQueue("queue1");
assertThat("Queue content", q1.take(), is("String1"));
} catch (Exception e) {
// unlikely to happen. But if it does lets show it in the test logs.
logger.warn("Error using queue session", e);
}
});
takeExecutionThread.start();
if (!takeExecutionLatch.await(THREAD_EXECUTION_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Thread executing put over queue was not executed");
}
assertThat(q.offer("String2", 1000), is(true));
takeExecutionThread.join(THREAD_EXECUTION_TIMEOUT);
assertThat("Queue size", q.size(), is(1));
} finally {
mgr.stop();
}
}
use of org.mule.runtime.core.api.util.queue.QueueManager in project mule by mulesoft.
the class AbstractTransactionQueueManagerTestCase method testClearWithoutTransaction.
@Test
public void testClearWithoutTransaction() throws Exception {
final 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());
q.clear();
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 testPoll.
@Test
public void testPoll() throws Exception {
final QueueManager mgr = createQueueManager();
try {
mgr.start();
QueueSession s = mgr.getQueueSession();
Queue q = s.getQueue("queue1");
assertEquals("Queue size", 0, q.size());
Object o = q.poll(0);
assertEquals("Queue size", 0, q.size());
assertNull(o);
o = q.poll(1000);
assertEquals("Queue size", 0, q.size());
assertNull(o);
q.put("String1");
assertEquals("Queue size", 1, q.size());
o = q.poll(0);
assertEquals("Queue size", 0, q.size());
assertEquals("Queue content", "String1", o);
final Latch putExecutionLatch = new Latch();
Thread putExecutionThread = new Thread(() -> {
try {
QueueSession s1 = mgr.getQueueSession();
Queue q1 = s1.getQueue("queue1");
putExecutionLatch.release();
q1.put("String1");
} catch (Exception e) {
// unlikely to happen. But if it does lets show it in the test logs.
logger.warn("Error using queue session", e);
}
});
putExecutionThread.start();
if (!putExecutionLatch.await(THREAD_EXECUTION_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Thread executing put over queue was not executed");
}
o = q.poll(RECEIVE_TIMEOUT);
putExecutionThread.join(THREAD_EXECUTION_TIMEOUT);
assertEquals("Queue size", q.size(), 0);
assertEquals("Queue content", "String1", o);
} finally {
mgr.stop();
}
}
use of org.mule.runtime.core.api.util.queue.QueueManager in project mule by mulesoft.
the class TransactionalQueueManagerTestCase method allowChangingConfigurationOnDisposedQueue.
@Test
public void allowChangingConfigurationOnDisposedQueue() throws Exception {
QueueManager queueManager = muleContext.getQueueManager();
queueManager.setQueueConfiguration(TEST_QUEUE_NAME, new DefaultQueueConfiguration(0, true));
QueueSession queueSession = queueManager.getQueueSession();
Queue queue = queueSession.getQueue(TEST_QUEUE_NAME);
queue.dispose();
queueManager.setQueueConfiguration(TEST_QUEUE_NAME, new DefaultQueueConfiguration(0, false));
}
use of org.mule.runtime.core.api.util.queue.QueueManager in project mule by mulesoft.
the class TransactionalQueueManagerTestCase method createDanglingTx.
private void createDanglingTx() throws InterruptedException, MuleException {
QueueManager queueManager = muleContext.getQueueManager();
queueManager.setDefaultQueueConfiguration(new DefaultQueueConfiguration(0, true));
QueueSession queueSession = queueManager.getQueueSession();
queueSession.getQueue(TEST_QUEUE_NAME).put("value");
queueSession.begin();
queueSession.getQueue(TEST_QUEUE_NAME).poll(10);
queueManager.stop();
}
Aggregations