Search in sources :

Example 1 with MockResponseListener

use of org.webpieces.httpclient.mocks.MockResponseListener in project webpieces by deanhiller.

the class TestCancelStream method testServerCloseSocket.

@Test
public void testServerCloseSocket() throws InterruptedException, ExecutionException, TimeoutException {
    XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
    MockResponseListener mockListener = new MockResponseListener();
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/home", false);
    mockChannel.addWriteResponse(XFuture.completedFuture(null));
    httpSocket.send(req, mockListener);
    mockChannel.simulateClose();
    Assert.assertTrue(mockListener.isClosed());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) InetSocketAddress(java.net.InetSocketAddress) MockResponseListener(org.webpieces.httpclient.mocks.MockResponseListener) Test(org.junit.Test)

Example 2 with MockResponseListener

use of org.webpieces.httpclient.mocks.MockResponseListener in project webpieces by deanhiller.

the class TestCancelStream method testClientCancelNoKeepAlive.

@Test
public void testClientCancelNoKeepAlive() {
    XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
    MockResponseListener mockListener = new MockResponseListener();
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/home", false);
    mockChannel.addWriteResponse(XFuture.completedFuture(null));
    HttpStreamRef ref = httpSocket.send(req, mockListener);
    XFuture<Void> cancelDone = ref.cancel("some reason");
    Assert.assertTrue(cancelDone.isDone());
    // Assert the socket is NOT closed
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) InetSocketAddress(java.net.InetSocketAddress) HttpStreamRef(org.webpieces.httpclient11.api.HttpStreamRef) MockResponseListener(org.webpieces.httpclient.mocks.MockResponseListener) Test(org.junit.Test)

Example 3 with MockResponseListener

use of org.webpieces.httpclient.mocks.MockResponseListener in project webpieces by deanhiller.

the class TestCancelStream method testClientCancelWithKeepAlive.

// @Test
// public void testRequestResponseXFutureCancelNoKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
// 
// @Test
// public void testRequestResponseXFutureCancelWithKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
@Test
public void testClientCancelWithKeepAlive() {
    XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
    MockResponseListener mockListener = new MockResponseListener();
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/home", false);
    req.addHeader(new Header(KnownHeaderName.CONNECTION, "keep-alive"));
    mockChannel.addWriteResponse(XFuture.completedFuture(null));
    HttpStreamRef ref = httpSocket.send(req, mockListener);
    XFuture<Void> cancelDone = ref.cancel("some reason");
    Assert.assertTrue(cancelDone.isDone());
    // Assert the socket is NOT closed
    Assert.assertFalse(mockChannel.isClosed());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Header(org.webpieces.httpparser.api.common.Header) InetSocketAddress(java.net.InetSocketAddress) HttpStreamRef(org.webpieces.httpclient11.api.HttpStreamRef) MockResponseListener(org.webpieces.httpclient.mocks.MockResponseListener) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)3 Test (org.junit.Test)3 MockResponseListener (org.webpieces.httpclient.mocks.MockResponseListener)3 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)3 HttpStreamRef (org.webpieces.httpclient11.api.HttpStreamRef)2 Header (org.webpieces.httpparser.api.common.Header)1