@Test public void testCancel() { AsyncHandler<?> asyncHandler = mock(AsyncHandler.class); NettyResponseFuture<?> nettyResponseFuture = new NettyResponseFuture<>(null, asyncHandler, null, 3, null, null, null); boolean result = nettyResponseFuture.cancel(false); verify(asyncHandler).onThrowable(anyObject()); assertTrue(result, "Cancel should return true if the Future was cancelled successfully"); assertTrue(nettyResponseFuture.isCancelled(), "isCancelled should return true for a cancelled Future"); }
@Override public boolean cancel(boolean force) { releasePartitionKeyLock(); cancelTimeouts(); if (IS_CANCELLED_FIELD.getAndSet(this, 1) != 0) return false; if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } future.cancel(false); return true; }
NettyResponseFuture implements ListenableFuture<V> { @Override public boolean cancel(boolean force) { releasePartitionKeyLock(); cancelTimeouts(); if (IS_CANCELLED_FIELD.getAndSet(this, 1) != 0) return false; if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } future.cancel(false); return true; } }
NettyResponseFuture implements ListenableFuture<V> { @Override public boolean cancel(boolean force) { releasePartitionKeyLock(); cancelTimeouts(); if (IS_CANCELLED_FIELD.getAndSet(this, 1) != 0) return false; if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } future.cancel(false); return true; } NettyResponseFuture(Request originalRequest,
                             AsyncHandler<V> asyncHandler,
                             NettyRequest nettyRequest,
                             int maxRetry,
                             ChannelPoolPartitioning connectionPoolPartitioning,
                             ConnectionSemaphore connectionSemaphore,
                             ProxyServer proxyServer); }
NettyResponseFuture implements ListenableFuture<V> { @Override public boolean cancel(boolean force) { releasePartitionKeyLock(); cancelTimeouts(); if (IS_CANCELLED_FIELD.getAndSet(this, 1) != 0) return false; if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } future.cancel(false); return true; } NettyResponseFuture(Request originalRequest,
                             AsyncHandler<V> asyncHandler,
                             NettyRequest nettyRequest,
                             int maxRetry,
                             ChannelPoolPartitioning connectionPoolPartitioning,
                             ConnectionSemaphore connectionSemaphore,
                             ProxyServer proxyServer); Object takePartitionKeyLock(); @Override boolean isDone(); @Override boolean isCancelled(); @Override boolean cancel(boolean force); @Override V get(); @Override V get(long l, TimeUnit tu); final void done(); final void abort(final Throwable t); @Override void touch(); @Override ListenableFuture<V> addListener(Runnable listener, Executor exec); @Override CompletableFuture<V> toCompletableFuture(); Uri getUri(); ProxyServer getProxyServer(); void cancelTimeouts(); final Request getTargetRequest(); void setTargetRequest(Request targetRequest); final Request getCurrentRequest(); void setCurrentRequest(Request currentRequest); final NettyRequest getNettyRequest(); final void setNettyRequest(NettyRequest nettyRequest); final AsyncHandler<V> getAsyncHandler(); void setAsyncHandler(AsyncHandler<V> asyncHandler); final boolean isKeepAlive(); final void setKeepAlive(final boolean keepAlive); int incrementAndGetCurrentRedirectCount(); TimeoutsHolder getTimeoutsHolder(); void setTimeoutsHolder(TimeoutsHolder timeoutsHolder); boolean isInAuth(); void setInAuth(boolean inAuth); boolean isAndSetInAuth(boolean set); boolean isInProxyAuth(); void setInProxyAuth(boolean inProxyAuth); boolean isAndSetInProxyAuth(boolean inProxyAuth); ChannelState getChannelState(); void setChannelState(ChannelState channelState); boolean isStreamConsumed(); void setStreamConsumed(boolean streamConsumed); long getLastTouch(); boolean isHeadersAlreadyWrittenOnContinue(); void setHeadersAlreadyWrittenOnContinue(boolean headersAlreadyWrittenOnContinue); boolean isDontWriteBodyBecauseExpectContinue(); void setDontWriteBodyBecauseExpectContinue(boolean dontWriteBodyBecauseExpectContinue); boolean isConnectAllowed(); void setConnectAllowed(boolean allowConnect); void attachChannel(Channel channel, boolean reuseChannel); Channel channel(); boolean isReuseChannel(); void setReuseChannel(boolean reuseChannel); boolean incrementRetryAndCheck(); boolean isReplayPossible(); long getStart(); Object getPartitionKey(); void acquirePartitionLockLazily(); Realm getRealm(); void setRealm(Realm realm); Realm getProxyRealm(); void setProxyRealm(Realm proxyRealm); @Override String toString(); }
NettyResponseFuture implements ListenableFuture<V> { @Override public boolean cancel(boolean force) { releasePartitionKeyLock(); cancelTimeouts(); if (IS_CANCELLED_FIELD.getAndSet(this, 1) != 0) return false; if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } future.cancel(false); return true; } NettyResponseFuture(Request originalRequest,
                             AsyncHandler<V> asyncHandler,
                             NettyRequest nettyRequest,
                             int maxRetry,
                             ChannelPoolPartitioning connectionPoolPartitioning,
                             ConnectionSemaphore connectionSemaphore,
                             ProxyServer proxyServer); Object takePartitionKeyLock(); @Override boolean isDone(); @Override boolean isCancelled(); @Override boolean cancel(boolean force); @Override V get(); @Override V get(long l, TimeUnit tu); final void done(); final void abort(final Throwable t); @Override void touch(); @Override ListenableFuture<V> addListener(Runnable listener, Executor exec); @Override CompletableFuture<V> toCompletableFuture(); Uri getUri(); ProxyServer getProxyServer(); void cancelTimeouts(); final Request getTargetRequest(); void setTargetRequest(Request targetRequest); final Request getCurrentRequest(); void setCurrentRequest(Request currentRequest); final NettyRequest getNettyRequest(); final void setNettyRequest(NettyRequest nettyRequest); final AsyncHandler<V> getAsyncHandler(); void setAsyncHandler(AsyncHandler<V> asyncHandler); final boolean isKeepAlive(); final void setKeepAlive(final boolean keepAlive); int incrementAndGetCurrentRedirectCount(); TimeoutsHolder getTimeoutsHolder(); void setTimeoutsHolder(TimeoutsHolder timeoutsHolder); boolean isInAuth(); void setInAuth(boolean inAuth); boolean isAndSetInAuth(boolean set); boolean isInProxyAuth(); void setInProxyAuth(boolean inProxyAuth); boolean isAndSetInProxyAuth(boolean inProxyAuth); ChannelState getChannelState(); void setChannelState(ChannelState channelState); boolean isStreamConsumed(); void setStreamConsumed(boolean streamConsumed); long getLastTouch(); boolean isHeadersAlreadyWrittenOnContinue(); void setHeadersAlreadyWrittenOnContinue(boolean headersAlreadyWrittenOnContinue); boolean isDontWriteBodyBecauseExpectContinue(); void setDontWriteBodyBecauseExpectContinue(boolean dontWriteBodyBecauseExpectContinue); boolean isConnectAllowed(); void setConnectAllowed(boolean allowConnect); void attachChannel(Channel channel, boolean reuseChannel); Channel channel(); boolean isReuseChannel(); void setReuseChannel(boolean reuseChannel); boolean incrementRetryAndCheck(); boolean isReplayPossible(); long getStart(); Object getPartitionKey(); void acquirePartitionLockLazily(); Realm getRealm(); void setRealm(Realm realm); Realm getProxyRealm(); void setProxyRealm(Realm proxyRealm); @Override String toString(); public Throwable pendingException; }