private static void artificialDelayOf(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { LOGGER.error("sleep interrupted", e); } }
private static long ap(long i) { try { Thread.sleep(i); } catch (InterruptedException e) { LOGGER.error("Exception caught.", e); } return i * (i + 1) / 2; } }
/** * Simulate the write operation */ public void write() throws InterruptedException { LOGGER.info("{} begin", name); Thread.sleep(writingTime); LOGGER.info("{} finished after writing {}ms", name, writingTime); } }
/** * Simulate the read operation * */ public void read() throws InterruptedException { LOGGER.info("{} begin", name); Thread.sleep(readingTime); LOGGER.info("{} finish after reading {}ms", name, readingTime); } }
/** * Constructor */ public Oliphaunt() { id = counter.incrementAndGet(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } }
@Override public Integer apply(Integer t) { if (c++ <= 0) { try { Thread.sleep(500); } catch (InterruptedException e) { } } return t; }
@Override public void accept(Integer v) throws Exception { if (v == 1) { Thread.sleep(100); } } })
@Override public Object call() throws Exception { Thread.sleep(50); return null; } }).timeout(100, TimeUnit.MILLISECONDS, normal.completable);
@Override public Integer apply(Integer t) { if (c++ <= 0) { try { Thread.sleep(500); } catch (InterruptedException e) { } } return t; }
@Override public void run() { LOGGER.info("{} processing {}", Thread.currentThread().getName(), task.toString()); try { Thread.sleep(task.getTimeMs()); } catch (InterruptedException e) { e.printStackTrace(); } } }
@Override public Object get() throws InterruptedException, ExecutionException { Thread.sleep(500); isDone.compareAndSet(false, true); return "foo"; }
@Override public void run() throws Exception { try { Thread.sleep(3000); } catch (InterruptedException ex) { interrupted.set(true); } } })
@Override public Integer apply(Integer t1) { if (c++ <= 1) { // slow try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } return t1; }
@Override public String apply(Long t1) { System.out.println(t1); try { Thread.sleep(100); } catch (InterruptedException e) { } return t1 + " slow value"; }
@Override public void accept(Integer t1) { if (count.incrementAndGet() == 500000) { // give it a small break halfway through try { Thread.sleep(50); } catch (InterruptedException ex) { // ignored } } }
@Override public void accept(String t1) { try { // simulate a slow observer Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } value1.set(t1); }
@Override public void onNext(Integer t) { // Consume after sleep for 1 ms try { Thread.sleep(1); } catch (InterruptedException e) { // ignored } if (counter.getAndIncrement() % 100 == 0) { System.out.println("testIssue2890NoStackoverflow -> " + counter.get()); }; }
void beforeCancelSleep(BaseTestConsumer<?, ?> ts) throws Exception { long before = System.currentTimeMillis(); Thread.sleep(50); if (System.currentTimeMillis() - before > 100) { ts.dispose(); throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before)); } }
@Override public void run() { try { Thread.sleep(500); } catch (InterruptedException e) { // ignore } o.onNext(value); } }.start();
@Test public void testUnsubscribeOnNestedTakeAndSyncInfiniteStream() throws InterruptedException { final AtomicInteger subscribeCounter = new AtomicInteger(); final AtomicInteger sentEventCounter = new AtomicInteger(); doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(SYNC_INFINITE_OBSERVABLE_OF_EVENT(2, subscribeCounter, sentEventCounter), subscribeCounter); Thread.sleep(500); assertEquals(39, sentEventCounter.get()); }