Examples of HttpExchange


Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());
    }

    @Test
    public void testResponseContentOutputCompleted() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("GET", "/");
        httpExchange.setRequest(request);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        httpExchange.setResponse(response);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
        Mockito.when(this.exchangeHandler.getConnectionReuseStrategy()).thenReturn(this.reuseStrategy);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);

        this.protocolHandler.inputReady(this.conn, this.decoder);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.exchangeHandler).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.exchangeHandler).responseCompleted(this.exchangeContext);
        Mockito.verify(this.conn, Mockito.never()).close();
    }
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.conn, Mockito.never()).close();
    }

    @Test
    public void testResponseInvalidState() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("GET", "/");
        httpExchange.setRequest(request);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        httpExchange.setResponse(response);
        httpExchange.invalidate();
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);

        this.protocolHandler.inputReady(this.conn, this.decoder);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.exchangeHandler).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.conn).close();
        Mockito.verify(this.exchangeHandler, Mockito.never()).getConnectionReuseStrategy();
    }
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.exchangeHandler, Mockito.never()).getConnectionReuseStrategy();
    }

    @Test
    public void testResponseNoKeepAlive() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpRequest request = new BasicHttpRequest("GET", "/");
        httpExchange.setRequest(request);
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        httpExchange.setResponse(response);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(false);
        Mockito.when(this.exchangeHandler.getConnectionReuseStrategy()).thenReturn(this.reuseStrategy);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);

        this.protocolHandler.inputReady(this.conn, this.decoder);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.exchangeHandler).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.exchangeHandler).responseCompleted(this.exchangeContext);
        Mockito.verify(this.conn).close();
    }
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

    }

    @Test
    public void testResponseContentRuntimeException() throws Exception {
        RuntimeException runtimeEx = new RuntimeException();
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.doThrow(runtimeEx).when(this.exchangeHandler).consumeContent(this.decoder, this.conn);

        try {
            this.protocolHandler.inputReady(this.conn, this.decoder);
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

    }

    @Test
    public void testResponseContentIOException() throws Exception {
        IOException ioex = new IOException();
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.doThrow(ioex).when(this.exchangeHandler).consumeContent(this.decoder, this.conn);

        this.protocolHandler.inputReady(this.conn, this.decoder);
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.exchangeHandler).failed(ioex);
    }

    @Test
    public void testTimeoutNoHandler() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);

        this.protocolHandler.timeout(this.conn);

        Mockito.verify(this.conn).shutdown();
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.conn).shutdown();
    }

    @Test
    public void testExpectContinueTimeout() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        httpExchange.setTimeout(1000);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);

        this.protocolHandler.timeout(this.conn);

        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getRequestState());
        Mockito.verify(this.conn).setSocketTimeout(1000);
        Mockito.verify(this.conn).requestOutput();
    }
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.conn).requestOutput();
    }

    @Test
    public void testTimeoutActiveConnection() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.getStatus()).thenReturn(NHttpConnection.ACTIVE, NHttpConnection.CLOSED);

        this.protocolHandler.timeout(this.conn);

        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getRequestState());
        Mockito.verify(this.exchangeHandler).failed(Mockito.any(SocketTimeoutException.class));
        Mockito.verify(this.conn).close();
        Mockito.verify(this.conn, Mockito.never()).setSocketTimeout(Mockito.anyInt());
    }
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.conn, Mockito.never()).setSocketTimeout(Mockito.anyInt());
    }

    @Test
    public void testTimeoutActiveConnectionBufferedData() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.getStatus()).thenReturn(NHttpConnection.ACTIVE, NHttpConnection.CLOSING);

        this.protocolHandler.timeout(this.conn);

        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getRequestState());
        Mockito.verify(this.exchangeHandler).failed(Mockito.any(SocketTimeoutException.class));
        Mockito.verify(this.conn).close();
        Mockito.verify(this.conn).setSocketTimeout(250);
    }
View Full Code Here

Examples of org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler.HttpExchange

        Mockito.verify(this.conn).setSocketTimeout(250);
    }

    @Test
    public void testTimeoutClosingConnection() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setHandler(this.exchangeHandler);
        this.connContext.setAttribute(HttpAsyncClientProtocolHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.getStatus()).thenReturn(NHttpConnection.CLOSING, NHttpConnection.CLOSED);

        this.protocolHandler.timeout(this.conn);

        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getRequestState());
        Mockito.verify(this.exchangeHandler).failed(Mockito.any(SocketTimeoutException.class));
        Mockito.verify(this.conn).shutdown();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.