Search in sources :

Example 26 with PollingProber

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

the class DefaultSchedulerMessageSourceTestCase method simplePoll.

@Test
public void simplePoll() throws Exception {
    DefaultSchedulerMessageSource schedulerMessageSource = createMessageSource();
    SensingNullMessageProcessor flow = getSensingNullMessageProcessor();
    schedulerMessageSource.setListener(flow);
    schedulerMessageSource.setAnnotations(singletonMap(LOCATION_KEY, TEST_CONNECTOR_LOCATION));
    schedulerMessageSource.trigger();
    new PollingProber(RECEIVE_TIMEOUT, 100).check(new Probe() {

        @Override
        public boolean isSatisfied() {
            return flow.event != null;
        }

        @Override
        public String describeFailure() {
            return "flow event never set by the source flow";
        }
    });
}
Also used : DefaultSchedulerMessageSource(org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource) PollingProber(org.mule.tck.probe.PollingProber) Probe(org.mule.tck.probe.Probe) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 27 with PollingProber

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

the class ManagedStoresTestCase method testObjectStoreExpiry.

private void testObjectStoreExpiry(ObjectStoreManager manager, String storeName, ObjectStoreSettings settings) throws ObjectStoreException, InterruptedException {
    ObjectStore<String> objectStore = manager.createObjectStore(storeName, settings);
    try {
        objectStore.store("key1", "value1");
        assertEquals("value1", objectStore.retrieve("key1"));
        new PollingProber(2000, 50).check(new JUnitLambdaProbe(() -> {
            try {
                assertFalse("Object with key1 still exists.", objectStore.contains("key1"));
            } catch (Exception e) {
                fail(e.getMessage());
            }
            return true;
        }));
    } finally {
        manager.disposeStore(storeName);
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 28 with PollingProber

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

the class ManagedStoresTestCase method testObjectStoreMaxEntries.

private void testObjectStoreMaxEntries(ObjectStoreManager manager, String storeName, ObjectStoreSettings settings) throws ObjectStoreException, InterruptedException {
    ObjectStore<String> objectStore = manager.createObjectStore(storeName, settings);
    try {
        storeObjects(objectStore, 0, 90);
        ensureMillisecondChanged();
        storeObjects(objectStore, 90, 100);
        new PollingProber(2000, 50).check(new JUnitLambdaProbe(() -> {
            try {
                assertEquals(10, objectStore.allKeys().size());
                for (int i = 90; i < 100; i++) {
                    assertTrue("Checking that key" + i + " exists", objectStore.contains("key" + i));
                }
            } catch (Exception e) {
                fail(e.getMessage());
            }
            return true;
        }));
    } finally {
        manager.disposeStore(storeName);
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 29 with PollingProber

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

the class MuleObjectStoreManagerIntegrationTestCase method onlySizeBoundedObjectStore.

@Test
public void onlySizeBoundedObjectStore() throws Exception {
    final int maxEntries = 5;
    final int entryTTL = UNBOUNDED;
    final ObjectStore os = objectStoreFactory.createObjectStore("myOs", maxEntries, entryTTL, 1000);
    os.store("0", 0);
    ensureMilisecondChanged();
    for (int i = 1; i < maxEntries + 1; i++) {
        os.store(valueOf(i), i);
    }
    PollingProber prober = new PollingProber(5000, 1000);
    prober.check(new JUnitProbe() {

        @Override
        public boolean test() throws Exception {
            assertThat(os.allKeys().size(), is(maxEntries));
            for (int i = 1; i < maxEntries + 1; i++) {
                assertThat(os.contains(valueOf(i)), is(true));
            }
            return true;
        }

        @Override
        public String describeFailure() {
            return "objectStore was not trimmed";
        }
    });
}
Also used : JUnitProbe(org.mule.tck.probe.JUnitProbe) ObjectStore(org.mule.runtime.api.store.ObjectStore) PollingProber(org.mule.tck.probe.PollingProber) ObjectStoreNotAvailableException(org.mule.runtime.api.store.ObjectStoreNotAvailableException) Test(org.junit.Test)

Example 30 with PollingProber

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

the class ExpiryMonitorTestCase method testNotExpiry.

@Test
public void testNotExpiry() throws InterruptedException {
    Expirable e = () -> expire();
    long startTime = currentTimeMillis();
    monitor.addExpirable(EXPIRE_TIME, MILLISECONDS, e);
    monitor.run();
    assertThat(expired, is(false));
    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

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