use of org.mule.runtime.core.api.util.func.Once.RunOnce in project mule by mulesoft.
the class OnceTestCase method concurrentRun.
@Test
public void concurrentRun() {
Latch controlLath = new Latch();
Latch testLath = new Latch();
CountingRunnable runnable = new CountingRunnable();
RunOnce once = Once.of(runnable);
new Thread(() -> {
await(controlLath);
once.runOnce();
}).start();
new Thread(() -> {
controlLath.release();
once.runOnce();
testLath.release();
}).start();
await(testLath);
assertThat(runnable.getInvokationCount(), is(1));
}
use of org.mule.runtime.core.api.util.func.Once.RunOnce in project mule by mulesoft.
the class OnceTestCase method runUntilSuccessful.
@Test
public void runUntilSuccessful() {
CountingRunnable runnable = new CountingRunnable();
RunOnce once = Once.of(() -> {
runnable.runChecked();
int count = runnable.getInvokationCount();
if (count < 3) {
throw new RuntimeException();
}
});
for (int i = 0; i < 5; i++) {
try {
once.runOnce();
break;
} catch (Exception e) {
}
}
assertThat(runnable.getInvokationCount(), is(3));
}
use of org.mule.runtime.core.api.util.func.Once.RunOnce in project mule by mulesoft.
the class OnceTestCase method runOnlyOnce.
@Test
public void runOnlyOnce() {
CountingRunnable runnable = new CountingRunnable();
RunOnce once = Once.of(runnable);
once.runOnce();
once.runOnce();
assertThat(runnable.getInvokationCount(), is(1));
}