Search in sources :

Example 1 with Expirable

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));
}
Also used : Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) System.currentTimeMillis(java.lang.System.currentTimeMillis) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) After(org.junit.After) Matchers.is(org.hamcrest.Matchers.is) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) Before(org.junit.Before) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Test(org.junit.Test)

Example 2 with Expirable

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));
}
Also used : Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) System.currentTimeMillis(java.lang.System.currentTimeMillis) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) After(org.junit.After) Matchers.is(org.hamcrest.Matchers.is) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) Before(org.junit.Before) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Test(org.junit.Test)

Example 3 with Expirable

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();
    }));
}
Also used : Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) System.currentTimeMillis(java.lang.System.currentTimeMillis) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) After(org.junit.After) Matchers.is(org.hamcrest.Matchers.is) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) Before(org.junit.Before) JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Test(org.junit.Test)

Example 4 with Expirable

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));
}
Also used : Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 Expirable (org.mule.runtime.core.privileged.util.monitor.Expirable)4 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)3 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)3 Matchers.is (org.hamcrest.Matchers.is)3 After (org.junit.After)3 Assert.assertThat (org.junit.Assert.assertThat)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Before (org.junit.Before)3 ExpiryMonitor (org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor)3 AbstractMuleContextTestCase (org.mule.tck.junit4.AbstractMuleContextTestCase)3 JUnitLambdaProbe (org.mule.tck.probe.JUnitLambdaProbe)3 PollingProber (org.mule.tck.probe.PollingProber)3