use of org.mule.runtime.core.privileged.util.monitor.Expirable 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.runtime.core.privileged.util.monitor.Expirable 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));
}
use of org.mule.runtime.core.privileged.util.monitor.Expirable in project mule by mulesoft.
the class ExpiryMonitorTestCase method testExpiry.
@Test
public void testExpiry() throws InterruptedException {
Expirable e = () -> expire();
monitor.addExpirable(EXPIRE_TIME, MILLISECONDS, e);
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();
}));
}
use of org.mule.runtime.core.privileged.util.monitor.Expirable in project mule by mulesoft.
the class ExpiryMonitorTestCase method testNotExpiryWithRemove.
@Test
public void testNotExpiryWithRemove() throws InterruptedException {
Expirable e = () -> expire();
monitor.addExpirable(EXPIRE_TIME, MILLISECONDS, e);
monitor.run();
assertThat(expired, is(false));
monitor.removeExpirable(e);
Thread.sleep(EXPIRE_TIMEOUT);
assertThat(monitor.isRegistered(e), is(false));
assertThat(expired, is(false));
}
Aggregations