@Override public void run() { long lastHeartbeat = getLastHeartbeat(); long currentTimestamp = System.currentTimeMillis(); boolean isWaitingOnSubprocess = waitingOnSubprocess.get(); LOG.debug("last heartbeat : {}, waiting subprocess now : {}, worker timeout (ms) : {}", lastHeartbeat, isWaitingOnSubprocess, workerTimeoutMills); if (isWaitingOnSubprocess && currentTimestamp - lastHeartbeat > workerTimeoutMills) { spout.die(new RuntimeException("subprocess heartbeat timeout")); } } }
@Test(timeout = 5000) public void subscribeActionNormal() { final AtomicBoolean run = new AtomicBoolean(); normal.completable.subscribe(new Action() { @Override public void run() { run.set(true); } }); Assert.assertTrue("Not completed", run.get()); }
/** * If {@code key} is not already associated with a value or if {@code key} is associated with * zero, associate it with {@code newValue}. Returns the previous value associated with {@code * key}, or zero if there was no mapping for {@code key}. */ long putIfAbsent(K key, long newValue) { AtomicBoolean noValue = new AtomicBoolean(false); Long result = map.compute( key, (k, oldValue) -> { if (oldValue == null || oldValue == 0) { noValue.set(true); return newValue; } else { return oldValue; } }); return noValue.get() ? 0L : result.longValue(); }
@Test public void doOnTerminateComplete() { final AtomicBoolean r = new AtomicBoolean(); String output = Observable.just("one").doOnTerminate(new Action() { @Override public void run() { r.set(true); } }).blockingSingle(); assertEquals("one", output); assertTrue(r.get()); }
private void waitUntilReady() throws PacemakerConnectionException, InterruptedException { // Wait for 'ready' (channel connected and maybe authentication) if (!ready.get() || channelRef.get() == null) { synchronized (this) { if (!ready.get()) { LOG.debug("Waiting for netty channel to be ready."); this.wait(1000); if (!ready.get() || channelRef.get() == null) { throw new PacemakerConnectionException("Timed out waiting for channel ready."); } } } } }
@Override public WebSocket writeError(AtmosphereResponse r, int errorCode, String message) throws IOException { super.writeError(r, errorCode, message); if (!firstWrite.get()) { logger.debug("The WebSocket handshake succeeded but the dispatched URI failed with status {} : {} " + "The WebSocket connection is still open and client can continue sending messages.", errorCode + " " + message, uuid()); } else { logger.warn("Unable to write {} {}", errorCode, message); } return this; }
public AsyncQueue<InternalHiveSplit> queueFor(OptionalInt bucketNumber) { checkArgument(bucketNumber.isPresent()); AtomicBoolean isNew = new AtomicBoolean(); AsyncQueue<InternalHiveSplit> queue = queues.computeIfAbsent(bucketNumber.getAsInt(), ignored -> { isNew.set(true); return new AsyncQueue<>(estimatedOutstandingSplitsPerBucket, executor); }); if (isNew.get() && finished.get()) { // Check `finished` and invoke `queue.finish` after the `queue` is added to the map. // Otherwise, `queue.finish` may not be invoked if `finished` is set while the lambda above is being evaluated. queue.finish(); } return queue; } },
@Test public void testDoOnCompleted() { final AtomicBoolean r = new AtomicBoolean(); String output = Observable.just("one").doOnComplete(new Action() { @Override public void run() { r.set(true); } }).blockingSingle(); assertEquals("one", output); assertTrue(r.get()); }
public void serviceTransportException(IOException e) { if (!stopping.get() && status.get() != PENDING_STOP) { transportException.set(e); if (TRANSPORTLOG.isDebugEnabled()) { TRANSPORTLOG.debug(this + " failed: " + e, e); } else if (TRANSPORTLOG.isWarnEnabled() && !suppressed(e)) { TRANSPORTLOG.warn(this + " failed: " + e); } stopAsync(e); } }
@Test void streamShouldCloseSingleOnCompleted() { // Given AtomicBoolean closed = new AtomicBoolean( false ); ResourceIterator<Integer> resourceIterator = newResourceIterator( iterator( new Integer[]{1, 2, 3} ), () -> closed.set( true ) ); ResourceIterable<Integer> iterable = () -> resourceIterator; // When List<Integer> result = iterable.stream().collect( Collectors.toList() ); // Then assertEquals( asList(1,2,3), result ); assertTrue( closed.get() ); }
@Test public void onTerminateCalledWhenOnError() { final AtomicBoolean didRunOnTerminate = new AtomicBoolean(); UnicastProcessor<Integer> us = UnicastProcessor.create(Observable.bufferSize(), new Runnable() { @Override public void run() { didRunOnTerminate.set(true); } }); assertEquals(false, didRunOnTerminate.get()); us.onError(new RuntimeException("some error")); assertEquals(true, didRunOnTerminate.get()); }