Search in sources :

Example 16 with PollingProber

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

the class BytesStreamingExtensionTestCase method startSourceAndListenSpell.

private void startSourceAndListenSpell(Flow flow, Predicate<String> predicate) throws Exception {
    flow.start();
    new PollingProber(4000, 100).check(new JUnitLambdaProbe(() -> {
        synchronized (CASTED_SPELLS) {
            return CASTED_SPELLS.stream().anyMatch(predicate);
        }
    }));
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber)

Example 17 with PollingProber

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

the class PetStoreSourceRetryPolicyProviderTestCase method retryPolicySourceFailWithConnectionException.

@Test
public void retryPolicySourceFailWithConnectionException() throws Exception {
    startFlow("source-fail-with-connection-exception");
    new PollingProber(TIMEOUT_MILLIS, POLL_DELAY_MILLIS).check(new JUnitLambdaProbe(() -> {
        assertThat(PetStoreConnector.timesStarted, is(3));
        return true;
    }));
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Test(org.junit.Test)

Example 18 with PollingProber

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

the class LifecycleAwareConfigurationInstanceAsyncRetryTestCase method testConnectivityUponStart.

@Override
@Test
public void testConnectivityUponStart() throws Exception {
    if (connectionProvider.isPresent()) {
        valueStarted();
        new PollingProber().check(new JUnitLambdaProbe(() -> {
            verify(connectionManager).testConnectivity(interceptable);
            return true;
        }));
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Test(org.junit.Test)

Example 19 with PollingProber

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

the class LifecycleAwareConfigurationInstanceAsyncRetryTestCase method stopWhileConnectivityTestingExecuting.

@Test
public void stopWhileConnectivityTestingExecuting() throws Throwable {
    if (connectionProvider.isPresent()) {
        final Latch testConnectivityInvokedLatch = new Latch();
        final Latch interceptableShutdownLatch = new Latch();
        reset(connectionManager);
        AtomicBoolean stopped = new AtomicBoolean();
        AtomicReference<Throwable> thrownByTestConnectivity = new AtomicReference<>();
        AtomicBoolean testConnectivityFinished = new AtomicBoolean();
        when(connectionManager.getRetryTemplateFor(connectionProvider.get())).thenReturn(retryPolicyTemplate);
        when(connectionManager.testConnectivity(Mockito.any(ConfigurationInstance.class))).then(inv -> {
            testConnectivityInvokedLatch.countDown();
            try {
                interceptableShutdownLatch.await(10, SECONDS);
                assertThat(stopped.get(), is(false));
            } catch (Throwable t) {
                thrownByTestConnectivity.set(t);
            }
            testConnectivityFinished.set(true);
            return success();
        });
        interceptable.initialise();
        interceptable.start();
        assertThat(testConnectivityInvokedLatch.await(10, SECONDS), is(true));
        interceptable.stop();
        stopped.set(true);
        interceptableShutdownLatch.countDown();
        new PollingProber(15000, 1000).check(new JUnitLambdaProbe(() -> {
            return testConnectivityFinished.get();
        }));
        if (thrownByTestConnectivity.get() != null) {
            throw thrownByTestConnectivity.get();
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Latch(org.mule.runtime.api.util.concurrent.Latch) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Example 20 with PollingProber

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

the class LifecycleAwareConfigurationInstanceAsyncRetryTestCase method testConnectivityFailsUponStart.

@Override
@Test
public void testConnectivityFailsUponStart() throws Exception {
    if (connectionProvider.isPresent()) {
        Exception connectionException = new ConnectionException("Oops!");
        when(connectionManager.testConnectivity(interceptable)).thenReturn(failure(connectionException.getMessage(), connectionException));
        interceptable.initialise();
        interceptable.start();
        new PollingProber().check(new JUnitLambdaProbe(() -> {
            verify(connectionManager, times(RECONNECTION_MAX_ATTEMPTS + 1)).testConnectivity(interceptable);
            return true;
        }));
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) 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