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();
}
}
}
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;
}));
}
}
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);
}
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);
}
}
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);
}
}
Aggregations