Search in sources :

Example 11 with JUnitLambdaProbe

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

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

Example 13 with JUnitLambdaProbe

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

the class DefaultEventContextTestCase method childSuccessWithResultFreesChild.

@Test
@Description("Once a child context is completed, its event is not kept in memory.")
public void childSuccessWithResultFreesChild() 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<>());
    child.success(eventChild);
    eventChild = null;
    childResultValue.set(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 14 with JUnitLambdaProbe

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

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

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