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