Search in sources :

Example 1 with LocalTxQueueTransactionJournal

use of org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal in project mule by mulesoft.

the class LocalTxQueueTransactionRecovererTestCase method pollAndFailThenRecover.

@Test
public void pollAndFailThenRecover() throws Exception {
    inQueue.offer(testEvent(), 0, TIMEOUT);
    Serializable value = persistentTransactionContext.poll(inQueue, 100000);
    assertThat(inQueue.poll(TIMEOUT), nullValue());
    assertThat(value, notNullValue());
    txLog.close();
    txLog = new LocalTxQueueTransactionJournal(temporaryFolder.getRoot().getAbsolutePath(), muleContext);
    queueTransactionRecoverer.recover();
    CoreEvent muleEvent = (CoreEvent) inQueue.poll(TIMEOUT);
    assertThat(muleEvent, notNullValue());
    assertThat(testEvent().getContext().getId(), equalTo(muleEvent.getContext().getId()));
}
Also used : Serializable(java.io.Serializable) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) LocalTxQueueTransactionJournal(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal) Test(org.junit.Test)

Example 2 with LocalTxQueueTransactionJournal

use of org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal in project mule by mulesoft.

the class LocalTxQueueTransactionRecovererTestCase method failBetweenLogEntryWriteAndRealPoolThenRecover.

@Test
public void failBetweenLogEntryWriteAndRealPoolThenRecover() throws Exception {
    inQueue.offer(testEvent(), 0, TIMEOUT);
    persistentTransactionContext.poll(inQueue, TIMEOUT);
    txLog.close();
    txLog = new LocalTxQueueTransactionJournal(temporaryFolder.getRoot().getAbsolutePath(), muleContext);
    queueTransactionRecoverer.recover();
    CoreEvent muleEvent = (CoreEvent) inQueue.poll(TIMEOUT);
    assertThat(muleEvent, notNullValue());
    assertThat(testEvent().getContext().getId(), equalTo(muleEvent.getContext().getId()));
    muleEvent = (CoreEvent) inQueue.poll(TIMEOUT);
    assertThat(muleEvent, nullValue());
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) LocalTxQueueTransactionJournal(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal) Test(org.junit.Test)

Example 3 with LocalTxQueueTransactionJournal

use of org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal in project mule by mulesoft.

the class LocalTxQueueTransactionRecovererTestCase method pollAndFailThenRecoverWithTwoElements.

@Test
public void pollAndFailThenRecoverWithTwoElements() throws Exception {
    final String MESSAGE_CONTENT_2 = TEST_PAYLOAD + "2";
    CoreEvent testEvent2 = eventBuilder(muleContext).message(of(MESSAGE_CONTENT_2)).build();
    inQueue.offer(testEvent(), 0, TIMEOUT);
    inQueue.offer(testEvent2, 0, TIMEOUT);
    Serializable value = persistentTransactionContext.poll(inQueue, 100000);
    assertThat(inQueue.getSize(), is(1));
    assertThat(value, notNullValue());
    txLog.close();
    txLog = new LocalTxQueueTransactionJournal(temporaryFolder.getRoot().getAbsolutePath(), muleContext);
    queueTransactionRecoverer.recover();
    CoreEvent muleEvent = (CoreEvent) inQueue.poll(TIMEOUT);
    assertThat(muleEvent, notNullValue());
    // recovered element should be
    assertThat(muleEvent.getMessage().getPayload().getValue().toString(), is(MESSAGE_CONTENT_2));
    // last
    muleEvent = (CoreEvent) inQueue.poll(TIMEOUT);
    assertThat(muleEvent, notNullValue());
    // recovered element
    assertThat(muleEvent.getMessage().getPayload().getValue().toString(), is(TEST_PAYLOAD));
}
Also used : Serializable(java.io.Serializable) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) LocalTxQueueTransactionJournal(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal) Test(org.junit.Test)

Example 4 with LocalTxQueueTransactionJournal

use of org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal 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)

Example 5 with LocalTxQueueTransactionJournal

use of org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal in project mule by mulesoft.

the class LocalTxQueueTransactionRecovererTestCase method offerAndFailThenRecover.

@Test
public void offerAndFailThenRecover() throws Exception {
    final DefaultQueueStore outQueue = new DefaultQueueStore(QUEUE_NAME, muleContext, new DefaultQueueConfiguration(0, true));
    persistentTransactionContext = new PersistentQueueTransactionContext(txLog, createQueueProvider(outQueue));
    persistentTransactionContext.offer(outQueue, testEvent(), TIMEOUT);
    assertThat(outQueue.poll(TIMEOUT), nullValue());
    txLog.close();
    txLog = new LocalTxQueueTransactionJournal(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) LocalTxQueueTransactionJournal(org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal) Test(org.junit.Test)

Aggregations

LocalTxQueueTransactionJournal (org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionJournal)6 Test (org.junit.Test)4 Serializable (java.io.Serializable)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 LocalTxQueueTransactionRecoverer (org.mule.runtime.core.internal.util.journal.queue.LocalTxQueueTransactionRecoverer)3 DefaultQueueConfiguration (org.mule.runtime.core.api.util.queue.DefaultQueueConfiguration)2 DefaultMuleConfiguration (org.mule.runtime.core.api.config.DefaultMuleConfiguration)1 XaTxQueueTransactionJournal (org.mule.runtime.core.internal.util.journal.queue.XaTxQueueTransactionJournal)1 XaTransactionRecoverer (org.mule.runtime.core.internal.util.xa.XaTransactionRecoverer)1