@Override public void run() { readLock.lock(); try { read(); } catch (InterruptedException e) { LOGGER.info("InterruptedException when reading", e); Thread.currentThread().interrupt(); } finally { readLock.unlock(); } }
@Override public void run() { writeLock.lock(); try { write(); } catch (InterruptedException e) { LOGGER.info("InterruptedException when writing", e); Thread.currentThread().interrupt(); } finally { writeLock.unlock(); } }
@Override public void run() { LOGGER.info("{} processing {}", Thread.currentThread().getName(), task.toString()); try { Thread.sleep(task.getTimeMs()); } catch (InterruptedException e) { e.printStackTrace(); } } }
static void uncaught(@NonNull Throwable error) { Thread currentThread = Thread.currentThread(); UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler(); handler.uncaughtException(currentThread, error); }
@Override public String apply(String v) { System.out.println("ObserveOn Thread: " + Thread.currentThread()); return v; } })
@Override public void run() { t = Thread.currentThread(); latch.countDown(); }
@Override public void accept(Throwable throwable) throws Exception { thread.set(Thread.currentThread()); latch.countDown(); } })
@Override public void run() throws Exception { name[0] = Thread.currentThread().getName(); cdl.countDown(); } })
@Override public void accept(Throwable throwable) throws Exception { thread.set(Thread.currentThread()); latch.countDown(); } })
@Override public Object apply(Integer v) throws Exception { return Thread.currentThread().getName().substring(0, 4); } }),
@Override public void accept(Object v) throws Exception { interrupted.set(Thread.currentThread().isInterrupted()); cdl.countDown(); } });
@Override public void run() throws Exception { interrupted.set(Thread.currentThread().isInterrupted()); cdl.countDown(); } });
@Override public void onNext(Integer t) { System.err.println("testSubscriber received => " + t + " on thread " + Thread.currentThread()); super.onNext(t); } };
@Override public void subscribe(Subscriber<? super Integer> t1) { subscribeThread.set(Thread.currentThread()); t1.onSubscribe(subscription); t1.onNext(1); t1.onNext(2); // observeOn will prevent canceling the upstream upon its termination now // this call is racing for that state in this test // not doing it will make sure the unsubscribeOn always gets through // t1.onComplete(); } });
@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 interruptTestWaitStrategy() { try { Thread.currentThread().interrupt(); TestWaitStrategy.SLEEP_1000MS.run(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } }
@Test public void interrupt() { Iterator<Object> it = Observable.never().blockingNext().iterator(); try { Thread.currentThread().interrupt(); it.next(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } }
@Override public void subscribe(Observer<? super Integer> t1) { subscribeThread.set(Thread.currentThread()); t1.onSubscribe(subscription); t1.onNext(1); t1.onNext(2); // observeOn will prevent canceling the upstream upon its termination now // this call is racing for that state in this test // not doing it will make sure the unsubscribeOn always gets through // t1.onComplete(); } });
@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(timeout = 5000) public void blockingFirstTimeout2() { BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>(); bf.onSubscribe(new BooleanSubscription()); Thread.currentThread().interrupt(); try { bf.blockingGet(); fail("Should have thrown!"); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } }