Search in sources :

Example 1 with DefaultQueueConfiguration

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());
}
Also used : Serializable(java.io.Serializable) DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) LocalTxQueueTransactionRecoverer(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionRecoverer) ResourceManagerException(org.mule.runtime.core.api.transaction.xa.ResourceManagerException) Test(org.junit.Test)

Example 2 with DefaultQueueConfiguration

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;
}
Also used : MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) DefaultMuleContext(org.mule.runtime.core.internal.context.DefaultMuleContext)

Example 3 with DefaultQueueConfiguration

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();
}
Also used : DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) Latch(org.mule.runtime.api.util.concurrent.Latch) Queue(org.mule.runtime.core.api.util.queue.Queue) QueueSession(org.mule.runtime.core.api.util.queue.QueueSession) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager) AbstractQueueManager(org.mule.runtime.core.internal.util.queue.AbstractQueueManager) Test(org.junit.Test)

Example 4 with DefaultQueueConfiguration

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();
    }
}
Also used : DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) Latch(org.mule.runtime.api.util.concurrent.Latch) Queue(org.mule.runtime.core.api.util.queue.Queue) QueueSession(org.mule.runtime.core.api.util.queue.QueueSession) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager) AbstractQueueManager(org.mule.runtime.core.internal.util.queue.AbstractQueueManager) Test(org.junit.Test)

Example 5 with DefaultQueueConfiguration

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));
}
Also used : DefaultQueueConfiguration(org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration) DefaultMuleConfiguration(org.mule.runtime.core.api.config.DefaultMuleConfiguration) LocalTxQueueTransactionRecoverer(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionRecoverer) LocalTxQueueTransactionJournal(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal)

Aggregations

DefaultQueueConfiguration (org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration)12 Test (org.junit.Test)6 QueueManager (org.mule.runtime.core.api.util.queue.QueueManager)5 QueueSession (org.mule.runtime.core.api.util.queue.QueueSession)5 Queue (org.mule.runtime.core.api.util.queue.Queue)3 LocalTxQueueTransactionRecoverer (org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionRecoverer)3 Serializable (java.io.Serializable)2 Latch (org.mule.runtime.api.util.concurrent.Latch)2 LocalTxQueueTransactionJournal (org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal)2 AbstractQueueManager (org.mule.runtime.core.internal.util.queue.AbstractQueueManager)2 DefaultMuleConfiguration (org.mule.runtime.core.api.config.DefaultMuleConfiguration)1 MuleConfiguration (org.mule.runtime.core.api.config.MuleConfiguration)1 ResourceManagerException (org.mule.runtime.core.api.transaction.xa.ResourceManagerException)1 QueueConfiguration (org.mule.runtime.core.api.util.queue.QueueConfiguration)1 DefaultMuleContext (org.mule.runtime.core.internal.context.DefaultMuleContext)1