Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused cancel method from HttpTransaction interface #305

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ interface HttpTransaction {
*/
Observable<HttpResponse> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,13 +53,6 @@ public HttpTransaction send(HttpRequest request, Optional<ConnectionPool> 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<HttpResponse> response() {
return observableResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -115,20 +115,20 @@ public void releasesConnectionWhenRequestFailsAfterHeaders() {
}

@Test
public void releasesIfRequestIsCancelledBeforeHeaders() {
public void releasesIfRequestIsUnsubscribedBeforeHeaders() {
Connection connection = mockConnection(responseProvider);
ConnectionPool pool = mockPool(connection);

HttpTransaction transaction = transport.send(request, Optional.of(pool), APP_ID);

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);

Expand All @@ -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));
}

Expand Down