use of org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration in project mule by mulesoft.
the class LocalTxQueueTransactionRecovererTestCase method offerAndFailBetweenRealOfferAndCommitThenRecover.
@Test
public void offerAndFailBetweenRealOfferAndCommitThenRecover() throws Exception {
txLog = new TestTransactionLogger(temporaryFolder.getRoot().getAbsolutePath(), muleContext).failDuringLogCommit();
final DefaultQueueStore outQueue = new DefaultQueueStore(QUEUE_NAME, muleContext, new DefaultQueueConfiguration(0, true));
persistentTransactionContext = new PersistentQueueTransactionContext(txLog, createQueueProvider(outQueue));
persistentTransactionContext.offer(outQueue, testEvent(), TIMEOUT);
try {
persistentTransactionContext.doCommit();
fail();
} catch (ResourceManagerException e) {
// expected
}
txLog.close();
txLog = new TestTransactionLogger(temporaryFolder.getRoot().getAbsolutePath(), muleContext);
queueTransactionRecoverer = new LocalTxQueueTransactionRecoverer(txLog, createQueueProvider(outQueue));
queueTransactionRecoverer.recover();
Serializable muleEvent = outQueue.poll(TIMEOUT);
assertThat(muleEvent, nullValue());
}
use of org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration in project mule by mulesoft.
the class FilePersistenceTestCase method createQueueManager.
@Override
protected TransactionalQueueManager createQueueManager() throws Exception {
TransactionalQueueManager mgr = new TransactionalQueueManager();
MuleConfiguration mockConfiguration = mock(MuleConfiguration.class);
when(mockConfiguration.getWorkingDirectory()).thenReturn(temporaryFolder.getRoot().getAbsolutePath());
when(mockConfiguration.getMaxQueueTransactionFilesSizeInMegabytes()).thenReturn(100);
((DefaultMuleContext) muleContext).setMuleConfiguration(mockConfiguration);
mgr.setMuleContext(muleContext);
mgr.initialise();
mgr.setDefaultQueueConfiguration(new DefaultQueueConfiguration(0, true));
return mgr;
}
use of org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration 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.DefaultQueueConfiguration 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.DefaultQueueConfiguration in project mule by mulesoft.
the class LocalTxQueueTransactionRecovererTestCase method doSetUp.
@Override
protected void doSetUp() throws Exception {
((DefaultMuleConfiguration) muleContext.getConfiguration()).setWorkingDirectory(temporaryFolder.getRoot().getAbsolutePath());
txLog = new LocalTxQueueTransactionJournal(temporaryFolder.getRoot().getAbsolutePath(), muleContext);
inQueue = new DefaultQueueStore(QUEUE_NAME, muleContext, new DefaultQueueConfiguration(0, true));
persistentTransactionContext = new PersistentQueueTransactionContext(txLog, createQueueProvider(inQueue));
queueTransactionRecoverer = new LocalTxQueueTransactionRecoverer(txLog, createQueueProvider(inQueue));
}
Aggregations