@Override public void tearDown() { Thread.interrupted(); } });
@Override public void tearDown() { Thread.interrupted(); } });
@Override public void tearDown() throws Exception { super.tearDown(); // TODO(cpovirk): run tests in other thread instead of messing with main thread interrupt status currentThread().interrupted(); LocalCache.logger.removeHandler(logHandler); }
@Override public Boolean call() throws Exception { Object actual; if (allowInterruption) { actual = future.get(); } else { actual = getUninterruptibly(future); } assertEquals(RESULT, actual); return Thread.interrupted(); } });
@Test public void interrupted() { Iterator<Object> it = Observable.never().blockingLatest().iterator(); Thread.currentThread().interrupt(); try { it.hasNext(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } Thread.interrupted(); }
@Test public void interrupted() { Iterator<Object> it = Flowable.never().blockingLatest().iterator(); Thread.currentThread().interrupt(); try { it.hasNext(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } Thread.interrupted(); }
@Override public void subscribe(ObservableEmitter<Boolean> emitter) throws Exception { emitter.onNext(Thread.interrupted()); emitter.onComplete(); } })
@GwtIncompatible // Thread.interrupt public void testGetUnchecked_interrupted() { Thread.currentThread().interrupt(); try { assertEquals("foo", getUnchecked(immediateFuture("foo"))); assertTrue(Thread.currentThread().isInterrupted()); } finally { Thread.interrupted(); } }
@Override public void subscribe(FlowableEmitter<Boolean> emitter) throws Exception { emitter.onNext(Thread.interrupted()); emitter.onComplete(); } }, BackpressureStrategy.MISSING)
@GwtIncompatible // threads public void testSubmitAsync_asyncCallable_returnsInterruptedFuture() throws InterruptedException { assertThat(Thread.interrupted()).isFalse(); SettableFuture<Integer> cancelledFuture = SettableFuture.create(); cancelledFuture.cancel(true); assertThat(Thread.interrupted()).isFalse(); ListenableFuture<Integer> future = submitAsync(constantAsyncCallable(cancelledFuture), directExecutor()); assertThat(future.isDone()).isTrue(); assertThat(Thread.interrupted()).isFalse(); }
@Test public void blockingGetErrorInterrupt() { final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>(); Thread.currentThread().interrupt(); try { assertTrue(bmo.blockingGetError() instanceof InterruptedException); } finally { Thread.interrupted(); } }
@Test public void awaitTerminalEventInterrupt() { final TestSubscriber<Integer> ts = TestSubscriber.create(); ts.onSubscribe(new BooleanSubscription()); Thread.currentThread().interrupt(); ts.awaitTerminalEvent(); assertTrue(Thread.interrupted()); Thread.currentThread().interrupt(); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); assertTrue(Thread.interrupted()); }
@Test public void awaitTerminalEventInterrupt() { final TestObserver<Integer> to = TestObserver.create(); to.onSubscribe(Disposables.empty()); Thread.currentThread().interrupt(); to.awaitTerminalEvent(); assertTrue(Thread.interrupted()); Thread.currentThread().interrupt(); to.awaitTerminalEvent(5, TimeUnit.SECONDS); assertTrue(Thread.interrupted()); }
@Test public void blockingGetErrorTimeoutInterrupt() { final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>(); Thread.currentThread().interrupt(); try { bmo.blockingGetError(1, TimeUnit.MINUTES); fail("Should have thrown"); } catch (RuntimeException ex) { assertTrue(ex.getCause() instanceof InterruptedException); } finally { Thread.interrupted(); } }
@Test public void blockingGetDefaultInterrupt() { final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>(); Thread.currentThread().interrupt(); try { bmo.blockingGet(0); fail("Should have thrown"); } catch (RuntimeException ex) { assertTrue(ex.getCause() instanceof InterruptedException); } finally { Thread.interrupted(); } }
@Test public void interrupt() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L); Thread.currentThread().interrupt(); try { Flowable.just(1) .blockingSubscribe(ts); ts.assertFailure(InterruptedException.class); } finally { Thread.interrupted(); // clear interrupted status just in case } }
@Test public void interrupted() { CountDownLatch cdl = new CountDownLatch(1); Disposable d = Disposables.empty(); Thread.currentThread().interrupt(); try { BlockingHelper.awaitForComplete(cdl, d); } catch (IllegalStateException ex) { // expected } assertTrue(d.isDisposed()); assertTrue(Thread.interrupted()); }
@Test public void scheduleDirectInterrupt() { Thread.currentThread().interrupt(); final int[] calls = { 0 }; assertSame(EmptyDisposable.INSTANCE, Schedulers.trampoline().scheduleDirect(new Runnable() { @Override public void run() { calls[0]++; } }, 1, TimeUnit.SECONDS)); assertTrue(Thread.interrupted()); assertEquals(0, calls[0]); }
public final void run() { try { realRun(); threadShouldThrow("InterruptedException"); } catch (InterruptedException success) { threadAssertFalse(Thread.interrupted()); } catch (Throwable t) { threadUnexpectedException(t); } } }
@Test public void timeoutIndicated() throws InterruptedException { Thread.interrupted(); // clear flag TestSubscriber<Object> ts = Flowable.never() .test(); assertFalse(ts.await(1, TimeUnit.MILLISECONDS)); try { ts.assertResult(1); throw new RuntimeException("Should have thrown!"); } catch (AssertionError ex) { assertTrue(ex.toString(), ex.toString().contains("timeout!")); } }