Search in sources :

Example 11 with PollingProber

use of org.mule.tck.probe.PollingProber 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 12 with PollingProber

use of org.mule.tck.probe.PollingProber 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)

Example 13 with PollingProber

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

the class DataTypeBuilderTestCase method cacheClean.

@Test
public void cacheClean() throws InterruptedException, ClassNotFoundException {
    ClassLoader custom = new ClassLoader(this.getClass().getClassLoader()) {

        @Override
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            if (Message.class.getName().equals(name)) {
                byte[] classBytes;
                try {
                    classBytes = toByteArray(this.getClass().getResourceAsStream("/org/mule/runtime/api/message/Message.class"));
                    return this.defineClass(null, classBytes, 0, classBytes.length);
                } catch (Exception e) {
                    return super.loadClass(name);
                }
            } else {
                return super.loadClass(name);
            }
        }
    };
    PhantomReference<ClassLoader> clRef = new PhantomReference<>(custom, new ReferenceQueue<>());
    DataType.builder().type(custom.loadClass(Message.class.getName())).build();
    custom = null;
    new PollingProber(GC_POLLING_TIMEOUT, DEFAULT_POLLING_INTERVAL).check(new JUnitLambdaProbe(() -> {
        System.gc();
        assertThat(clRef.isEnqueued(), is(true));
        return true;
    }, "A hard reference is being mantained to the type of the DataType."));
}
Also used : Message(org.mule.runtime.api.message.Message) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PhantomReference(java.lang.ref.PhantomReference) PollingProber(org.mule.tck.probe.PollingProber) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 14 with PollingProber

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

the class AbstractStreamingExtensionTestCase method assertAllStreamingResourcesClosed.

private void assertAllStreamingResourcesClosed() {
    StreamingStatistics stats = streamingManager.getStreamingStatistics();
    new PollingProber(10000, 100).check(new JUnitLambdaProbe(() -> {
        assertThat("There're still open cursor providers", stats.getOpenCursorProvidersCount(), is(0));
        assertThat("There're still open cursors", stats.getOpenCursorsCount(), is(0));
        return true;
    }));
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) StreamingStatistics(org.mule.runtime.core.api.streaming.StreamingStatistics) PollingProber(org.mule.tck.probe.PollingProber)

Example 15 with PollingProber

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

the class BytesStreamingExtensionTestCase method nonRepeatableStreamIsAutomaticallyClosed.

@Test
@Description("A non repeatable stream is closed automatically when flow completes")
public void nonRepeatableStreamIsAutomaticallyClosed() throws Exception {
    InputStream stream = (InputStream) flowRunner("toNonRepeatableStream").withPayload(data).run().getMessage().getPayload().getValue();
    // Stream will close on terminate but flowRunner will be done on response
    new PollingProber(TIMEOUT, DELAY).check(new JUnitProbe() {

        @Override
        protected boolean test() throws Exception {
            assertThat(stream.read(), is(-1));
            return true;
        }

        @Override
        public String describeFailure() {
            return "Stream was not automatically closed.";
        }
    });
}
Also used : JUnitProbe(org.mule.tck.probe.JUnitProbe) InputStream(java.io.InputStream) PollingProber(org.mule.tck.probe.PollingProber) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

PollingProber (org.mule.tck.probe.PollingProber)55 Test (org.junit.Test)24 JUnitProbe (org.mule.tck.probe.JUnitProbe)22 JUnitLambdaProbe (org.mule.tck.probe.JUnitLambdaProbe)21 Prober (org.mule.tck.probe.Prober)19 Probe (org.mule.tck.probe.Probe)8 MuleException (org.mule.runtime.api.exception.MuleException)7 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)6 URISyntaxException (java.net.URISyntaxException)5 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)5 File (java.io.File)4 IOException (java.io.IOException)4 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 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 ArrayList (java.util.ArrayList)3 Matchers.is (org.hamcrest.Matchers.is)3