hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1359214 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src: main/java/org/apache/http/impl/nio/conn/AsyncSchemeRegistryFactory.java test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
Date Mon, 09 Jul 2012 15:17:50 GMT
Author: olegk
Date: Mon Jul  9 15:17:50 2012
New Revision: 1359214

URL: http://svn.apache.org/viewvc?rev=1359214&view=rev
Log:
HTTPASYNC-21: test cases for premature connection termination

Added:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
  (with props)
Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/AsyncSchemeRegistryFactory.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/AsyncSchemeRegistryFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/AsyncSchemeRegistryFactory.java?rev=1359214&r1=1359213&r2=1359214&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/AsyncSchemeRegistryFactory.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/AsyncSchemeRegistryFactory.java
Mon Jul  9 15:17:50 2012
@@ -31,9 +31,6 @@ import org.apache.http.nio.conn.scheme.A
 import org.apache.http.nio.conn.scheme.AsyncSchemeRegistry;
 import org.apache.http.nio.conn.ssl.SSLLayeringStrategy;
 
-/**
- * @since 4.1
- */
 @ThreadSafe
 public final class AsyncSchemeRegistryFactory {
 

Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java?rev=1359214&view=auto
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
(added)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
Mon Jul  9 15:17:50 2012
@@ -0,0 +1,273 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.impl.nio.client;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.HttpAsyncTestBase;
+import org.apache.http.HttpConnection;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.concurrent.FutureCallback;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
+import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
+import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
+import org.apache.http.nio.protocol.HttpAsyncExchange;
+import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
+import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
+import org.apache.http.nio.protocol.HttpAsyncService;
+import org.apache.http.nio.reactor.IOReactorStatus;
+import org.apache.http.nio.reactor.ListenerEndpoint;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class TestHttpAsyncPrematureTermination extends HttpAsyncTestBase {
+
+    @Before
+    public void setUp() throws Exception {
+        initServer();
+        initClient();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
+    }
+
+    @Override
+    protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
+            final HttpParams params) throws Exception {
+        return new DefaultNHttpServerConnectionFactory(params);
+    }
+
+    @Override
+    protected String getSchemeName() {
+        return "http";
+    }
+
+    private HttpHost start(
+            final HttpAsyncRequestHandlerResolver requestHandlerResolver,
+            final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
+        HttpAsyncService serviceHandler = new HttpAsyncService(
+                this.serverHttpProc,
+                new DefaultConnectionReuseStrategy(),
+                new DefaultHttpResponseFactory(),
+                requestHandlerResolver,
+                expectationVerifier,
+                this.serverParams);
+        this.server.start(serviceHandler);
+        this.httpclient.start();
+
+        ListenerEndpoint endpoint = this.server.getListenerEndpoint();
+        endpoint.waitFor();
+
+        Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
+        HttpHost target = new HttpHost("localhost", address.getPort(), getSchemeName());
+        return target;
+    }
+
+    @Test @Ignore
+    public void testConnectionTerminatedProcessingRequest() throws Exception {
+        HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+        registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+
+            public HttpAsyncRequestConsumer<HttpRequest> processRequest(
+                    final HttpRequest request,
+                    final HttpContext context) throws HttpException, IOException {
+                HttpConnection conn = (HttpConnection) context.getAttribute(
+                        ExecutionContext.HTTP_CONNECTION);
+                System.out.println("Boom!!!!");
+                conn.shutdown();
+                return new BasicAsyncRequestConsumer();
+            }
+
+            public void handle(
+                    final HttpRequest request,
+                    final HttpAsyncExchange httpExchange,
+                    final HttpContext context) throws HttpException, IOException {
+                HttpResponse response = httpExchange.getResponse();
+                response.setEntity(new NStringEntity("all is well", ContentType.TEXT_PLAIN));
+                httpExchange.submitResponse();
+            }
+
+        });
+        HttpHost target = start(registry, null);
+        HttpGet httpget = new HttpGet("/");
+
+        final CountDownLatch latch = new CountDownLatch(1);
+
+        FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>()
{
+
+            public void cancelled() {
+                latch.countDown();
+            }
+
+            public void failed(final Exception ex) {
+                latch.countDown();
+            }
+
+            public void completed(final HttpResponse response) {
+                Assert.fail();
+            }
+
+        };
+
+        this.httpclient.execute(target, httpget, callback);
+        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+    }
+
+    @Test @Ignore
+    public void testConnectionTerminatedHandlingRequest() throws Exception {
+        HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+        registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+
+            public HttpAsyncRequestConsumer<HttpRequest> processRequest(
+                    final HttpRequest request,
+                    final HttpContext context) throws HttpException, IOException {
+                return new BasicAsyncRequestConsumer();
+            }
+
+            public void handle(
+                    final HttpRequest request,
+                    final HttpAsyncExchange httpExchange,
+                    final HttpContext context) throws HttpException, IOException {
+                HttpConnection conn = (HttpConnection) context.getAttribute(
+                        ExecutionContext.HTTP_CONNECTION);
+                System.out.println("Boom!!!!");
+                conn.shutdown();
+                HttpResponse response = httpExchange.getResponse();
+                response.setEntity(new NStringEntity("all is well", ContentType.TEXT_PLAIN));
+                httpExchange.submitResponse();
+            }
+
+        });
+        HttpHost target = start(registry, null);
+        HttpGet httpget = new HttpGet("/");
+
+        final CountDownLatch latch = new CountDownLatch(1);
+
+        FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>()
{
+
+            public void cancelled() {
+                latch.countDown();
+            }
+
+            public void failed(final Exception ex) {
+                latch.countDown();
+            }
+
+            public void completed(final HttpResponse response) {
+                Assert.fail();
+            }
+
+        };
+
+        this.httpclient.execute(target, httpget, callback);
+        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+    }
+
+    @Test
+    public void testConnectionTerminatedSendingResponse() throws Exception {
+        HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+        registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+
+            public HttpAsyncRequestConsumer<HttpRequest> processRequest(
+                    final HttpRequest request,
+                    final HttpContext context) throws HttpException, IOException {
+                return new BasicAsyncRequestConsumer();
+            }
+
+            public void handle(
+                    final HttpRequest request,
+                    final HttpAsyncExchange httpExchange,
+                    final HttpContext context) throws HttpException, IOException {
+                HttpResponse response = httpExchange.getResponse();
+                response.setEntity(new NStringEntity("all is well", ContentType.TEXT_PLAIN));
+                httpExchange.submitResponse(new BasicAsyncResponseProducer(response) {
+
+                    @Override
+                    public synchronized void produceContent(
+                            final ContentEncoder encoder,
+                            final IOControl ioctrl) throws IOException {
+                        ioctrl.shutdown();
+                    }
+
+                });
+            }
+
+        });
+        HttpHost target = start(registry, null);
+        HttpGet httpget = new HttpGet("/");
+
+        final CountDownLatch latch = new CountDownLatch(1);
+
+        FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>()
{
+
+            public void cancelled() {
+                latch.countDown();
+            }
+
+            public void failed(final Exception ex) {
+                latch.countDown();
+            }
+
+            public void completed(final HttpResponse response) {
+                Assert.fail();
+            }
+
+        };
+
+        this.httpclient.execute(target, httpget, callback);
+        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+    }
+
+}

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsyncPrematureTermination.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message