var t = new Timeout(function () { alert('this is a test'); }, 5000); console.log(t.cleared); // false t.clear(); console.log(t.cleared); // true
@Override public Timeout timeout() { return new Timeout().timeout(executeTimeoutMillis, TimeUnit.MILLISECONDS); }
@Test public synchronized void threadInterruptedOnThrowIfReached() throws Exception { Timeout timeout = new Timeout(); Thread.currentThread().interrupt(); try { timeout.throwIfReached(); fail(); } catch (InterruptedIOException expected) { assertEquals("interrupted", expected.getMessage()); assertTrue(Thread.interrupted()); } }
@Test public void getAndSetDelegate() { Timeout timeout1 = new Timeout(); Timeout timeout2 = new Timeout(); ForwardingTimeout forwardingTimeout = new ForwardingTimeout(timeout1); forwardingTimeout.timeout(5, TimeUnit.SECONDS); assertThat(timeout1.timeoutNanos()).isNotEqualTo(0L); assertThat(timeout2.timeoutNanos()).isEqualTo(0L); forwardingTimeout.clearTimeout(); assertThat(timeout1.timeoutNanos()).isEqualTo(0L); assertThat(timeout2.timeoutNanos()).isEqualTo(0L); assertThat(forwardingTimeout.delegate()).isEqualTo(timeout1); assertThat(forwardingTimeout.setDelegate(timeout2)).isEqualTo(forwardingTimeout); forwardingTimeout.timeout(5, TimeUnit.SECONDS); assertThat(timeout1.timeoutNanos()).isEqualTo(0L); assertThat(timeout2.timeoutNanos()).isNotEqualTo(0L); forwardingTimeout.clearTimeout(); assertThat(timeout1.timeoutNanos()).isEqualTo(0L); assertThat(timeout2.timeoutNanos()).isEqualTo(0L); assertThat(forwardingTimeout.delegate()).isEqualTo(timeout2); } }
@Test public synchronized void notified() throws InterruptedIOException { Timeout timeout = new Timeout(); timeout.timeout(5000, TimeUnit.MILLISECONDS); double start = now(); executorService.schedule(new Runnable() { @Override public void run() { synchronized (WaitUntilNotifiedTest.this) { WaitUntilNotifiedTest.this.notify(); } } }, 1000, TimeUnit.MILLISECONDS); timeout.waitUntilNotified(this); assertElapsed(1000.0, start); }
@Test public synchronized void threadInterrupted() { Timeout timeout = new Timeout(); double start = now(); Thread.currentThread().interrupt(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("interrupted", expected.getMessage()); assertTrue(Thread.interrupted()); } assertElapsed(0.0, start); }
@Test public synchronized void deadlineAlreadyReached() { Timeout timeout = new Timeout(); timeout.deadlineNanoTime(System.nanoTime()); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(0.0, start); }
public class TestBase { @Rule public Timeout globalTimeout = new Timeout(10000); }
@Test public synchronized void timeout() { Timeout timeout = new Timeout(); timeout.timeout(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void deadline() { Timeout timeout = new Timeout(); timeout.deadline(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void deadlineBeforeTimeout() { Timeout timeout = new Timeout(); timeout.timeout(5000, TimeUnit.MILLISECONDS); timeout.deadline(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void timeoutBeforeDeadline() { Timeout timeout = new Timeout(); timeout.timeout(1000, TimeUnit.MILLISECONDS); timeout.deadline(5000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
Timeout t = new Timeout(5, TimeUnit.SECONDS); AskableActorSelection asker = new AskableActorSelection(sel); Future<Object> fut = asker.ask(new Identify(1), t);
@RunWith(Suite.class) @SuiteClasses({ Test1.class, Test2.class}) public class SuiteWithTimeout { @ClassRule public static Timeout timeout = new Timeout(1000); }
public class ParameterWithTimeoutTest { @ClassRule public static final TestRule globalTimeout = new Timeout(5000); @Parameters public static Iterable<Object[]> data() { return Arrays.asList(new Object[][] {{ 5 }, { 2 }, { 1 }}); } // ...
@Rule public Timeout timeout = new Timeout(100); @Test // Exception: test timed out after 100 milliseconds public void methodTimeout() throws Exception { Thread.sleep(200); } @Test public void methodInTime() throws Exception { Thread.sleep(50); }
@ClassRule public static Timeout classTimeout = new Timeout(200); @Test public void test1() throws Exception { Thread.sleep(150); } @Test // InterruptedException: sleep interrupted public void test2() throws Exception { Thread.sleep(100); }
public ActorRef getActor(Class<? extends UntypedActor> clsActor, int id) { String sName = clsActor.getName() + "-" + id; ActorSelection sel = m_actorSystem.actorSelection("user/" + sName); Timeout timeout = new Timeout(100, TimeUnit.MILLISECONDS); Future<ActorRef> fut = sel.resolveOne(timeout); ActorRef actor= Await.result(fut, timeout.duration()); return actor; }
ActorSystem system = ActorSystem.create("system"); ActorRef actor = system.actorOf(Props.create(SomeActor.class), "someActor"); Timeout t = new Timeout(5, TimeUnit.SECONDS); Future<Object> future = Patterns.ask(actor, "some message", 1000); try {String response = (String) Await.result(future, t.duration());} catch(Exception e){}