From 0d630fbe44c8064befdd6948b94923607e2770af Mon Sep 17 00:00:00 2001 From: Mikko Karjalainen Date: Mon, 8 Oct 2018 16:40:00 +0100 Subject: [PATCH] Remove unused cancel() method from HttpTransaction and Transport classes. --- .../hotels/styx/client/HttpTransaction.java | 7 ----- .../com/hotels/styx/client/Transport.java | 9 +----- .../com/hotels/styx/client/TransportTest.java | 31 ++++--------------- 3 files changed, 7 insertions(+), 40 deletions(-) diff --git a/components/client/src/main/java/com/hotels/styx/client/HttpTransaction.java b/components/client/src/main/java/com/hotels/styx/client/HttpTransaction.java index 349352604c..4cf7efcfc7 100644 --- a/components/client/src/main/java/com/hotels/styx/client/HttpTransaction.java +++ b/components/client/src/main/java/com/hotels/styx/client/HttpTransaction.java @@ -30,13 +30,6 @@ interface HttpTransaction { */ Observable response(); - /** - * Cancels the ongoing transaction. Default implementation does nothing. - */ - default void cancel() { - // do nothing - } - /** * Checks whether the current transaction is cancelled (non-consumable). Default implementation always returns false. * diff --git a/components/client/src/main/java/com/hotels/styx/client/Transport.java b/components/client/src/main/java/com/hotels/styx/client/Transport.java index 4a3d09d459..97c12c34b7 100644 --- a/components/client/src/main/java/com/hotels/styx/client/Transport.java +++ b/components/client/src/main/java/com/hotels/styx/client/Transport.java @@ -18,8 +18,8 @@ import com.hotels.styx.api.HttpRequest; import com.hotels.styx.api.HttpResponse; import com.hotels.styx.api.Id; -import com.hotels.styx.client.connectionpool.ConnectionPool; import com.hotels.styx.api.exceptions.NoAvailableHostsException; +import com.hotels.styx.client.connectionpool.ConnectionPool; import rx.Observable; import java.util.Optional; @@ -53,13 +53,6 @@ public HttpTransaction send(HttpRequest request, Optional origin return new HttpTransaction() { private final AtomicBoolean cancelled = new AtomicBoolean(false); - @Override - public void cancel() { - if (!cancelled.getAndSet(true)) { - closeIfConnected(origin, connectionRef); - } - } - @Override public Observable response() { return observableResponse diff --git a/components/client/src/test/unit/java/com/hotels/styx/client/TransportTest.java b/components/client/src/test/unit/java/com/hotels/styx/client/TransportTest.java index a5c62769b9..218af9ebc9 100644 --- a/components/client/src/test/unit/java/com/hotels/styx/client/TransportTest.java +++ b/components/client/src/test/unit/java/com/hotels/styx/client/TransportTest.java @@ -20,8 +20,8 @@ import com.hotels.styx.api.HttpResponse; import com.hotels.styx.api.Id; import com.hotels.styx.api.StyxObservable; -import com.hotels.styx.client.connectionpool.ConnectionPool; import com.hotels.styx.api.exceptions.NoAvailableHostsException; +import com.hotels.styx.client.connectionpool.ConnectionPool; import io.netty.buffer.ByteBuf; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -33,8 +33,8 @@ import java.util.Optional; import static com.hotels.styx.api.HttpRequest.get; -import static com.hotels.styx.api.Id.id; import static com.hotels.styx.api.HttpResponseStatus.OK; +import static com.hotels.styx.api.Id.id; import static io.netty.buffer.Unpooled.copiedBuffer; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; @@ -115,7 +115,7 @@ public void releasesConnectionWhenRequestFailsAfterHeaders() { } @Test - public void releasesIfRequestIsCancelledBeforeHeaders() { + public void releasesIfRequestIsUnsubscribedBeforeHeaders() { Connection connection = mockConnection(responseProvider); ConnectionPool pool = mockPool(connection); @@ -123,12 +123,12 @@ public void releasesIfRequestIsCancelledBeforeHeaders() { transaction.response().subscribe(subscriber); - transaction.cancel(); + subscriber.unsubscribe(); verify(pool).closeConnection(any(Connection.class)); } @Test - public void releasesIfRequestIsCancelledAfterHeaders() { + public void releasesIfRequestIsUnsubscribedAfterHeaders() { Connection connection = mockConnection(responseProvider); ConnectionPool pool = mockPool(connection); @@ -138,26 +138,7 @@ public void releasesIfRequestIsCancelledAfterHeaders() { responseProvider.onNext(response); - transaction.cancel(); - verify(pool).closeConnection(any(Connection.class)); - } - - @Test - public void closesConnectionOnlyOnce() { - ConnectionPool pool = mockPool(mockConnection(responseProvider)); - - HttpTransaction transaction = transport.send(request, Optional.of(pool), APP_ID); - - transaction.response().subscribe(new TestSubscriber<>()); - - responseProvider.onNext(response); - - verify(pool, never()).closeConnection(any(Connection.class)); - - transaction.cancel(); - transaction.cancel(); - transaction.cancel(); - + subscriber.unsubscribe(); verify(pool).closeConnection(any(Connection.class)); }