Search in sources :

Example 1 with JUnitLambdaProbe

use of org.mule.tck.probe.JUnitLambdaProbe in project mule by mulesoft.

the class AsyncRequestReplyRequesterTestCase method testMultiple.

@Test
@Ignore("See MULE-8830")
public void testMultiple() throws Exception {
    asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
    SensingNullMessageProcessor target = getSensingNullMessageProcessor();
    target.setWaitTime(50);
    AsyncDelegateMessageProcessor asyncMP = createAsyncMessageProcessor(target);
    asyncMP.initialise();
    asyncReplyMP.setListener(asyncMP);
    asyncReplyMP.setReplySource(target.getMessageSource());
    final AtomicInteger count = new AtomicInteger();
    for (int i = 0; i < 500; i++) {
        scheduler.execute(() -> {
            try {
                CoreEvent resultEvent = asyncReplyMP.process(testEvent());
                // Can't assert same because we copy event for async currently
                assertEquals(((PrivilegedEvent) testEvent()).getMessageAsString(muleContext), ((PrivilegedEvent) resultEvent).getMessageAsString(muleContext));
                count.incrementAndGet();
                LOGGER.debug("Finished " + count.get());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }
    new PollingProber().check(new JUnitLambdaProbe(() -> {
        assertThat(count.get(), greaterThanOrEqualTo(500));
        return true;
    }));
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) PollingProber(org.mule.tck.probe.PollingProber) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ResponseTimeoutException(org.mule.runtime.core.privileged.routing.ResponseTimeoutException) MuleException(org.mule.runtime.api.exception.MuleException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with JUnitLambdaProbe

use of org.mule.tck.probe.JUnitLambdaProbe in project mule by mulesoft.

the class DynamicConfigExpirationTestCase method assertExpired.

private void assertExpired(HeisenbergExtension config, long timeoutMilis, long pollDelayMillis) {
    PollingProber prober = new PollingProber(timeoutMilis, pollDelayMillis);
    prober.check(new JUnitLambdaProbe(() -> {
        assertThat(config.getStop(), is(1));
        assertThat(config.getDispose(), is(1));
        return true;
    }, "config was not stopped or disposed"));
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber)

Example 3 with JUnitLambdaProbe

use of org.mule.tck.probe.JUnitLambdaProbe in project mule by mulesoft.

the class DefaultEventContextTestCase method childSuccessWithResultForPublisherFreesChild.

@Test
@Description("Once a child context is completed, its event is not kept in memory after the response publisher is consumed.")
public void childSuccessWithResultForPublisherFreesChild() throws Exception {
    child = addChild(parent);
    CoreEvent eventChild = getEventBuilder().message(Message.of(TEST_PAYLOAD)).build();
    CoreEvent eventParent = getEventBuilder().message(Message.of(TEST_PAYLOAD)).build();
    PhantomReference<CoreEvent> childRef = new PhantomReference<>(eventChild, new ReferenceQueue<>());
    Publisher<CoreEvent> responsePublisher = child.getResponsePublisher();
    child.success(eventChild);
    eventChild = null;
    childResultValue.set(null);
    // Force finalization of the response publisher
    from(responsePublisher).block();
    responsePublisher = null;
    new PollingProber(GC_POLLING_TIMEOUT, DEFAULT_POLLING_INTERVAL).check(new JUnitLambdaProbe(() -> {
        System.gc();
        assertThat(childRef.isEnqueued(), is(true));
        return true;
    }, "A hard reference is being mantained to the child event."));
    parent.success(eventParent);
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) PhantomReference(java.lang.ref.PhantomReference) PollingProber(org.mule.tck.probe.PollingProber) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 4 with JUnitLambdaProbe

use of org.mule.tck.probe.JUnitLambdaProbe in project mule by mulesoft.

the class MuleObjectStoreManagerTestCase method expireTwoStoresInParallel.

@Test
public void expireTwoStoresInParallel() throws ObjectStoreException, InitialisationException, InterruptedException {
    when(muleContext.isPrimaryPollingInstance()).thenReturn(true);
    expireDelayLatch = new CountDownLatch(1);
    addJavaSerializerToMockMuleContext(muleContext);
    storeManager.initialise();
    storeManager.createObjectStore(TEST_PARTITION_NAME + "_1", ObjectStoreSettings.builder().persistent(false).entryTtl(10L).expirationInterval(10L).build());
    storeManager.createObjectStore(TEST_PARTITION_NAME + "_2", ObjectStoreSettings.builder().persistent(false).entryTtl(10L).expirationInterval(10L).build());
    new PollingProber(POLLING_TIMEOUT, POLLING_DELAY).check(new JUnitLambdaProbe(() -> {
        assertThat(expires.get(), is(2));
        return true;
    }));
    expireDelayLatch.countDown();
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) CountDownLatch(java.util.concurrent.CountDownLatch) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with JUnitLambdaProbe

use of org.mule.tck.probe.JUnitLambdaProbe in project mule by mulesoft.

the class ExpiryMonitorTestCase method testExpiryWithReset.

@Test
public void testExpiryWithReset() throws InterruptedException {
    Expirable e = () -> expire();
    monitor.addExpirable(EXPIRE_TIME, MILLISECONDS, e);
    monitor.run();
    assertThat(expired, is(false));
    long startTime = currentTimeMillis();
    monitor.resetExpirable(e);
    monitor.run();
    assertTrue(!expired);
    new PollingProber(EXPIRE_TIMEOUT, 50).check(new JUnitLambdaProbe(() -> {
        assertThat(monitor.isRegistered(e), is(false));
        assertThat(expired, is(true));
        return true;
    }, ae -> {
        ae.printStackTrace();
        return "" + currentTimeMillis() + " - " + monitor.toString();
    }));
    assertThat(expiredTime - startTime, greaterThanOrEqualTo(EXPIRE_TIME - DELTA_TIME));
}
Also used : Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) System.currentTimeMillis(java.lang.System.currentTimeMillis) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) After(org.junit.After) Matchers.is(org.hamcrest.Matchers.is) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) Before(org.junit.Before) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Test(org.junit.Test)

Aggregations

JUnitLambdaProbe (org.mule.tck.probe.JUnitLambdaProbe)21 PollingProber (org.mule.tck.probe.PollingProber)21 Test (org.junit.Test)15 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)4 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)4 After (org.junit.After)4 Assert.assertThat (org.junit.Assert.assertThat)4 Before (org.junit.Before)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)4 AbstractMuleContextTestCase (org.mule.tck.junit4.AbstractMuleContextTestCase)4 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 PhantomReference (java.lang.ref.PhantomReference)3 Matchers.is (org.hamcrest.Matchers.is)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)3 Expirable (org.mule.runtime.core.privileged.util.monitor.Expirable)3 ExpiryMonitor (org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor)3 Description (io.qameta.allure.Description)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ObjectAlreadyExistsException (org.mule.runtime.api.store.ObjectAlreadyExistsException)2