You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/04/01 17:11:23 UTC
svn commit: r1789822 [2/2] - in /httpcomponents/httpcore/trunk:
httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/
httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/
httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/ h...
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java Sat Apr 1 17:11:22 2017
@@ -46,6 +46,7 @@ import java.util.concurrent.atomic.Atomi
import java.util.concurrent.atomic.AtomicReference;
import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.util.Args;
/**
@@ -443,7 +444,7 @@ public abstract class AbstractMultiworke
}
}
- void forceShutdown() {
+ private void forceShutdown() {
this.status.set(IOReactorStatus.SHUT_DOWN);
this.selector.wakeup();
for (int i = 0; i < this.dispatchers.length; i++) {
@@ -459,22 +460,24 @@ public abstract class AbstractMultiworke
}
@Override
- public void shutdown(final long graceTime, final TimeUnit timeUnit) {
- Args.notNull(timeUnit, "Time unit");
+ public void shutdown(final ShutdownType shutdownType) {
if (this.status.get() == IOReactorStatus.INACTIVE) {
return;
}
initiateShutdown();
try {
- awaitShutdown(graceTime, timeUnit);
+ if (shutdownType == ShutdownType.GRACEFUL) {
+ awaitShutdown(2, TimeUnit.SECONDS);
+ }
forceShutdown();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
- public void shutdown() {
- shutdown(2, TimeUnit.SECONDS);
+ @Override
+ public void close() {
+ shutdown(ShutdownType.GRACEFUL);
}
static void closeChannel(final Channel channel) {
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactor.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactor.java Sat Apr 1 17:11:22 2017
@@ -30,6 +30,8 @@ package org.apache.hc.core5.reactor;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
+import org.apache.hc.core5.io.GracefullyCloseable;
+
/**
* HttpCore NIO is based on the Reactor pattern as described by Doug Lea.
* The purpose of I/O reactors is to react to I/O events and to dispatch event
@@ -47,7 +49,7 @@ import java.util.concurrent.TimeUnit;
*
* @since 4.0
*/
-public interface IOReactor {
+public interface IOReactor extends GracefullyCloseable {
/**
* Returns the current status of the reactor.
@@ -65,19 +67,6 @@ public interface IOReactor {
void execute() throws IOException;
/**
- * Initiates shutdown of the reactor and blocks approximately for the given
- * period of time in milliseconds waiting for the reactor to terminate all
- * active connections, to shut down itself and to release system resources
- * it currently holds.
- *
- * @param graceTime grace time in units.
- * @param timeUnit time unit
- *
- * @since 5.0
- */
- void shutdown(long graceTime, TimeUnit timeUnit);
-
- /**
* Initiates shutdown of the reactor without blocking. The reactor is expected
* to terminate all active connections, to shut down itself and to release
* system resources it currently holds
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java Sat Apr 1 17:11:22 2017
@@ -45,6 +45,7 @@ import java.util.concurrent.atomic.Atomi
import org.apache.hc.core5.concurrent.Cancellable;
import org.apache.hc.core5.function.Callback;
+import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.util.Args;
/**
@@ -249,9 +250,9 @@ class IOReactorImpl implements IOReactor
session.onOutputReady();
}
} catch (final CancelledKeyException ex) {
- session.shutdown();
+ session.shutdown(ShutdownType.GRACEFUL);
} catch (final RuntimeException ex) {
- session.shutdown();
+ session.shutdown(ShutdownType.IMMEDIATE);
handleRuntimeException(ex);
}
}
@@ -293,7 +294,7 @@ class IOReactorImpl implements IOReactor
handleRuntimeException(ex);
}
} catch (final CancelledKeyException ex) {
- session.shutdown();
+ session.shutdown(ShutdownType.GRACEFUL);
}
}
}
@@ -325,9 +326,9 @@ class IOReactorImpl implements IOReactor
}
}
} catch (final CancelledKeyException ex) {
- session.shutdown();
+ session.shutdown(ShutdownType.GRACEFUL);
} catch (final RuntimeException ex) {
- session.shutdown();
+ session.shutdown(ShutdownType.IMMEDIATE);
handleRuntimeException(ex);
}
}
@@ -384,16 +385,23 @@ class IOReactorImpl implements IOReactor
}
@Override
- public void shutdown(final long graceTime, final TimeUnit timeUnit) {
+ public void shutdown(final ShutdownType shutdownType) {
initiateShutdown();
try {
- awaitShutdown(graceTime, timeUnit);
+ if (shutdownType == ShutdownType.GRACEFUL) {
+ awaitShutdown(2, TimeUnit.SECONDS);
+ }
forceShutdown();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
+ @Override
+ public void close() {
+ shutdown(ShutdownType.GRACEFUL);
+ }
+
private static class PendingSession {
final SocketChannel socketChannel;
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java Sat Apr 1 17:11:22 2017
@@ -27,10 +27,10 @@
package org.apache.hc.core5.reactor;
-import java.io.Closeable;
import java.net.SocketAddress;
import java.nio.channels.ByteChannel;
+import org.apache.hc.core5.io.GracefullyCloseable;
import org.apache.hc.core5.util.Identifiable;
/**
@@ -49,7 +49,7 @@ import org.apache.hc.core5.util.Identifi
*
* @since 4.0
*/
-public interface IOSession extends Closeable, Identifiable {
+public interface IOSession extends GracefullyCloseable, Identifiable {
int ACTIVE = 0;
int CLOSING = 1;
@@ -151,11 +151,6 @@ public interface IOSession extends Close
void close();
/**
- * Terminates the session by shutting down the underlying I/O channel.
- */
- void shutdown();
-
- /**
* Returns status of the session:
* <p>
* {@link #ACTIVE}: session is active.
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java Sat Apr 1 17:11:22 2017
@@ -39,6 +39,7 @@ import java.util.concurrent.atomic.Atomi
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.util.Args;
/**
@@ -215,7 +216,7 @@ class IOSessionImpl implements IOSession
}
@Override
- public void shutdown() {
+ public void shutdown(final ShutdownType shutdownType) {
// For this type of session, a close() does exactly
// what we need and nothing more.
close();
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java Sat Apr 1 17:11:22 2017
@@ -39,6 +39,7 @@ import javax.net.ssl.SSLSession;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
import org.apache.hc.core5.reactor.ssl.SSLIOSession;
@@ -119,7 +120,7 @@ class ManagedIOSession implements IOSess
handler.connected(this);
}
} catch (final RuntimeException ex) {
- shutdown();
+ shutdown(ShutdownType.IMMEDIATE);
throw ex;
}
}
@@ -141,13 +142,13 @@ class ManagedIOSession implements IOSess
tlsSession.inboundTransport();
} catch (final IOException ex) {
handler.exception(tlsSession, ex);
- tlsSession.shutdown();
+ tlsSession.shutdown(ShutdownType.IMMEDIATE);
}
} else {
handler.inputReady(this);
}
} catch (final RuntimeException ex) {
- shutdown();
+ shutdown(ShutdownType.IMMEDIATE);
throw ex;
}
}
@@ -167,13 +168,13 @@ class ManagedIOSession implements IOSess
tlsSession.outboundTransport();
} catch (final IOException ex) {
handler.exception(tlsSession, ex);
- tlsSession.shutdown();
+ tlsSession.shutdown(ShutdownType.IMMEDIATE);
}
} else {
handler.outputReady(this);
}
} catch (final RuntimeException ex) {
- shutdown();
+ shutdown(ShutdownType.IMMEDIATE);
throw ex;
}
}
@@ -186,11 +187,11 @@ class ManagedIOSession implements IOSess
if (tlsSession != null) {
if (tlsSession.isOutboundDone() && !tlsSession.isInboundDone()) {
// The session failed to terminate cleanly
- tlsSession.shutdown();
+ tlsSession.shutdown(ShutdownType.IMMEDIATE);
}
}
} catch (final RuntimeException ex) {
- shutdown();
+ shutdown(ShutdownType.IMMEDIATE);
throw ex;
}
}
@@ -236,10 +237,10 @@ class ManagedIOSession implements IOSess
}
@Override
- public void shutdown() {
+ public void shutdown(final ShutdownType shutdownType) {
if (closed.compareAndSet(false, true)) {
try {
- getSessionImpl().shutdown();
+ getSessionImpl().shutdown(shutdownType);
} finally {
closedSessions.add(this);
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java Sat Apr 1 17:11:22 2017
@@ -45,6 +45,7 @@ import javax.net.ssl.SSLSession;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.io.ShutdownType;
import org.apache.hc.core5.net.NamedEndpoint;
import org.apache.hc.core5.reactor.Command;
import org.apache.hc.core5.reactor.EventMask;
@@ -630,12 +631,12 @@ public class SSLIOSession implements IOS
try {
updateEventMask();
} catch (final CancelledKeyException ex) {
- shutdown();
+ shutdown(ShutdownType.GRACEFUL);
}
}
@Override
- public synchronized void shutdown() {
+ public synchronized void shutdown(final ShutdownType shutdownType) {
if (this.status == CLOSED) {
return;
}
@@ -645,7 +646,7 @@ public class SSLIOSession implements IOS
this.outPlain.release();
this.status = CLOSED;
- this.session.shutdown();
+ this.session.shutdown(shutdownType);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java Sat Apr 1 17:11:22 2017
@@ -40,6 +40,7 @@ import org.apache.hc.core5.http.ContentL
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.config.H1Config;
import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.apache.hc.core5.io.ShutdownType;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -136,7 +137,7 @@ public class TestBHttpConnectionBase {
Assert.assertTrue(conn.isOpen());
- conn.shutdown();
+ conn.shutdown(ShutdownType.GRACEFUL);
Assert.assertFalse(conn.isOpen());
@@ -149,7 +150,7 @@ public class TestBHttpConnectionBase {
conn.close();
Mockito.verify(socket, Mockito.times(1)).close();
- conn.shutdown();
+ conn.shutdown(ShutdownType.GRACEFUL);
Mockito.verify(socket, Mockito.times(1)).close();
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestPoolEntry.java Sat Apr 1 17:11:22 2017
@@ -29,6 +29,7 @@ package org.apache.hc.core5.pool;
import java.util.concurrent.TimeUnit;
import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.io.ShutdownType;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -50,7 +51,7 @@ public class TestPoolEntry {
Assert.assertEquals(entry1.getValidityDeadline(), entry1.getExpiry());
Assert.assertEquals(entry1.getUpdated() + 10L, entry1.getValidityDeadline());
- entry1.discardConnection();
+ entry1.discardConnection(ShutdownType.IMMEDIATE);
Assert.assertEquals(0, entry1.getUpdated());
Assert.assertEquals(0, entry1.getExpiry());
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestRouteSpecificPool.java Sat Apr 1 17:11:22 2017
@@ -26,9 +26,10 @@
*/
package org.apache.hc.core5.pool;
-import java.net.Socket;
import java.util.concurrent.TimeUnit;
+import org.apache.hc.core5.io.GracefullyCloseable;
+import org.apache.hc.core5.io.ShutdownType;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -39,7 +40,7 @@ public class TestRouteSpecificPool {
@Test
public void testEmptyPool() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
Assert.assertEquals(ROUTE, pool.getRoute());
Assert.assertEquals(0, pool.getAllocatedCount());
Assert.assertEquals(0, pool.getAvailableCount());
@@ -50,9 +51,9 @@ public class TestRouteSpecificPool {
@Test
public void testAdd() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry.assignConnection(conn);
Assert.assertEquals(1, pool.getAllocatedCount());
Assert.assertEquals(0, pool.getAvailableCount());
@@ -63,15 +64,15 @@ public class TestRouteSpecificPool {
@Test
public void testLeaseRelease() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn1 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn1 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry1.assignConnection(conn1);
- final Socket conn2 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn2 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry2.assignConnection(conn2);
- final Socket conn3 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn3 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry3.assignConnection(conn3);
Assert.assertNotNull(entry1);
@@ -103,15 +104,15 @@ public class TestRouteSpecificPool {
@Test
public void testLeaseOrder() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn1 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn1 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry1.assignConnection(conn1);
- final Socket conn2 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn2 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry2.assignConnection(conn2);
- final Socket conn3 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn3 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry3.assignConnection(conn3);
Assert.assertNotNull(entry1);
@@ -135,15 +136,15 @@ public class TestRouteSpecificPool {
@Test
public void testLeaseReleaseStateful() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn1 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn1 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry1.assignConnection(conn1);
- final Socket conn2 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn2 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry2.assignConnection(conn2);
- final Socket conn3 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn3 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry3.assignConnection(conn3);
Assert.assertNotNull(entry1);
@@ -181,23 +182,23 @@ public class TestRouteSpecificPool {
@Test(expected=IllegalStateException.class)
public void testReleaseInvalidEntry() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry = new PoolEntry<>(ROUTE);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry = new PoolEntry<>(ROUTE);
pool.free(entry, true);
}
@Test
public void testRemove() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn1 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn1 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry1.assignConnection(conn1);
- final Socket conn2 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn2 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry2.assignConnection(conn2);
- final Socket conn3 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn3 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry3 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry3.assignConnection(conn3);
Assert.assertNotNull(entry1);
@@ -232,24 +233,24 @@ public class TestRouteSpecificPool {
@Test(expected=IllegalArgumentException.class)
public void testReleaseInvalid() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
pool.free(null, true);
}
@Test(expected=IllegalArgumentException.class)
public void testRemoveInvalid() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
pool.remove(null);
}
@Test
public void testShutdown() throws Exception {
- final RoutePool<String, Socket> pool = new RoutePool<>("whatever");
- final Socket conn1 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final RoutePool<String, GracefullyCloseable> pool = new RoutePool<>("whatever");
+ final GracefullyCloseable conn1 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry1 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry1.assignConnection(conn1);
- final Socket conn2 = Mockito.mock(Socket.class);
- final PoolEntry<String, Socket> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
+ final GracefullyCloseable conn2 = Mockito.mock(GracefullyCloseable.class);
+ final PoolEntry<String, GracefullyCloseable> entry2 = pool.createEntry(0, TimeUnit.MILLISECONDS);
entry2.assignConnection(conn2);
Assert.assertNotNull(entry1);
@@ -261,14 +262,14 @@ public class TestRouteSpecificPool {
Assert.assertEquals(1, pool.getAvailableCount());
Assert.assertEquals(1, pool.getLeasedCount());
- pool.shutdown();
+ pool.shutdown(ShutdownType.GRACEFUL);
Assert.assertEquals(0, pool.getAllocatedCount());
Assert.assertEquals(0, pool.getAvailableCount());
Assert.assertEquals(0, pool.getLeasedCount());
- Mockito.verify(conn2).close();
- Mockito.verify(conn1).close();
+ Mockito.verify(conn2).shutdown(ShutdownType.GRACEFUL);
+ Mockito.verify(conn1).shutdown(ShutdownType.GRACEFUL);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java?rev=1789822&r1=1789821&r2=1789822&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/pool/TestStrictConnPool.java Sat Apr 1 17:11:22 2017
@@ -31,6 +31,7 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.io.ShutdownType;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
@@ -92,9 +93,9 @@ public class TestStrictConnPool {
pool.release(entry1, true);
pool.release(entry2, true);
pool.release(entry3, false);
- Mockito.verify(conn1, Mockito.never()).close();
- Mockito.verify(conn2, Mockito.never()).close();
- Mockito.verify(conn3, Mockito.times(1)).close();
+ Mockito.verify(conn1, Mockito.never()).shutdown(Mockito.<ShutdownType>any());
+ Mockito.verify(conn2, Mockito.never()).shutdown(Mockito.<ShutdownType>any());
+ Mockito.verify(conn3, Mockito.times(1)).shutdown(ShutdownType.GRACEFUL);
final PoolStats totals = pool.getTotalStats();
Assert.assertEquals(2, totals.getAvailable());
@@ -345,8 +346,8 @@ public class TestStrictConnPool {
Assert.assertTrue(future5.isDone());
- Mockito.verify(conn2).close();
- Mockito.verify(conn1, Mockito.never()).close();
+ Mockito.verify(conn2).shutdown(ShutdownType.GRACEFUL);
+ Mockito.verify(conn1, Mockito.never()).shutdown(Mockito.<ShutdownType>any());
totals = pool.getTotalStats();
Assert.assertEquals(1, totals.getAvailable());
@@ -375,7 +376,7 @@ public class TestStrictConnPool {
Assert.assertTrue(future2.isDone());
- Mockito.verify(conn1).close();
+ Mockito.verify(conn1).shutdown(ShutdownType.GRACEFUL);
final PoolStats totals = pool.getTotalStats();
Assert.assertEquals(0, totals.getAvailable());
@@ -415,8 +416,8 @@ public class TestStrictConnPool {
pool.closeExpired();
- Mockito.verify(conn1).close();
- Mockito.verify(conn2, Mockito.never()).close();
+ Mockito.verify(conn1).shutdown(ShutdownType.GRACEFUL);
+ Mockito.verify(conn2, Mockito.never()).shutdown(Mockito.<ShutdownType>any());
final PoolStats totals = pool.getTotalStats();
Assert.assertEquals(1, totals.getAvailable());
@@ -457,8 +458,8 @@ public class TestStrictConnPool {
pool.closeIdle(50, TimeUnit.MILLISECONDS);
- Mockito.verify(conn1).close();
- Mockito.verify(conn2, Mockito.never()).close();
+ Mockito.verify(conn1).shutdown(ShutdownType.GRACEFUL);
+ Mockito.verify(conn2, Mockito.never()).shutdown(Mockito.<ShutdownType>any());
PoolStats totals = pool.getTotalStats();
Assert.assertEquals(1, totals.getAvailable());
@@ -471,7 +472,7 @@ public class TestStrictConnPool {
pool.closeIdle(-1, TimeUnit.MILLISECONDS);
- Mockito.verify(conn2).close();
+ Mockito.verify(conn2).shutdown(ShutdownType.GRACEFUL);
totals = pool.getTotalStats();
Assert.assertEquals(0, totals.getAvailable());
@@ -569,7 +570,7 @@ public class TestStrictConnPool {
@Test
public void testShutdown() throws Exception {
final StrictConnPool<String, HttpConnection> pool = new StrictConnPool<>(2, 2);
- pool.shutdown();
+ pool.shutdown(ShutdownType.GRACEFUL);
try {
pool.lease("somehost", null);
Assert.fail("IllegalStateException should have been thrown");