hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r575707 - in /jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http: impl/nio/reactor/TestAll.java impl/nio/reactor/TestDefaultIOReactors.java mockup/TestHttpSSLClient.java mockup/TestHttpSSLServer.java
Date Fri, 14 Sep 2007 14:46:32 GMT
Author: olegk
Date: Fri Sep 14 07:46:31 2007
New Revision: 575707

URL: http://svn.apache.org/viewvc?rev=575707&view=rev
Log:
HTTPCORE-109: Ported I/O reactor shutdown test from NIO to NIOSSL module

Added:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
  (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java?rev=575707&r1=575706&r2=575707&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java
Fri Sep 14 07:46:31 2007
@@ -42,6 +42,7 @@
         TestSuite suite = new TestSuite();
         suite.addTest(TestNIOSSLHttp.suite());
         suite.addTest(TestBaseIOReactorSSL.suite());
+        suite.addTest(TestDefaultIOReactors.suite());
         return suite;
     }
 

Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java?rev=575707&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
Fri Sep 14 07:46:31 2007
@@ -0,0 +1,188 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.reactor;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.http.HttpCoreNIOSSLTestBase;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.mockup.RequestCount;
+import org.apache.http.mockup.SimpleEventListener;
+import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpConnection;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.protocol.EventListener;
+import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestHandler;
+
+/**
+ * Basic functionality tests for SSL I/O reactors.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public class TestDefaultIOReactors extends HttpCoreNIOSSLTestBase {
+
+    // ------------------------------------------------------------ Constructor
+    public TestDefaultIOReactors(String testName) {
+        super(testName);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestDefaultIOReactors.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        return new TestSuite(TestDefaultIOReactors.class);
+    }
+
+    public void testRestartListeningIOReactor() throws Exception {
+        HttpParams params = new BasicHttpParams();
+        
+        DefaultListeningIOReactor ioReactor = new DefaultListeningIOReactor(1, params);
+        ioReactor.listen(new InetSocketAddress(9999));
+        ioReactor.shutdown();
+        
+        ioReactor = new DefaultListeningIOReactor(1, params);
+        ioReactor.listen(new InetSocketAddress(9999));
+        ioReactor.shutdown();         
+    }
+    
+    public void testGracefulShutdown() throws Exception {
+
+        // Open some connection and make sure 
+        // they get cleanly closed upon shutdown
+        
+        final int connNo = 10;
+        final RequestCount requestConns = new RequestCount(connNo); 
+        final RequestCount closedServerConns = new RequestCount(connNo); 
+        final RequestCount closedClientConns = new RequestCount(connNo); 
+        
+        HttpRequestHandler requestHandler = new HttpRequestHandler() {
+
+            public void handle(
+                    final HttpRequest request, 
+                    final HttpResponse response, 
+                    final HttpContext context) throws HttpException, IOException {
+            }
+            
+        };
+        
+        HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
+
+            public void initalizeContext(final HttpContext context, final Object attachment)
{
+            }
+
+            public void finalizeContext(final HttpContext context) {
+            }
+
+            public HttpRequest submitRequest(final HttpContext context) {
+                Boolean b = ((Boolean) context.getAttribute("done"));
+                if (b == null) {
+                    BasicHttpRequest get = new BasicHttpRequest("GET", "/");
+                    context.setAttribute("done", Boolean.TRUE);
+                    return get;
+                } else {
+                    return null;
+                }
+            }
+            
+            public void handleResponse(final HttpResponse response, final HttpContext context)
{
+                requestConns.decrement();                    
+            }
+            
+        };
+     
+        EventListener serverEventListener = new SimpleEventListener() {
+
+            public void connectionClosed(NHttpConnection conn) {
+                closedServerConns.decrement();
+                super.connectionClosed(conn);
+            }
+            
+        };
+        
+        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
+                requestHandler, 
+                null,
+                serverEventListener);
+        
+        EventListener clientEventListener = new SimpleEventListener() {
+
+            public void connectionClosed(NHttpConnection conn) {
+                closedClientConns.decrement();
+                super.connectionClosed(conn);
+            }
+            
+        };
+        
+        NHttpClientHandler clientHandler = createHttpClientHandler(
+                requestExecutionHandler,
+                clientEventListener);
+
+        this.server.start(serviceHandler);
+        this.client.start(clientHandler);
+        
+        InetSocketAddress serverAddress = (InetSocketAddress) this.server.getSocketAddress();
+        
+        for (int i = 0; i < connNo; i++) {
+            this.client.openConnection(
+                    new InetSocketAddress("localhost", serverAddress.getPort()), 
+                    null);
+        }
+     
+        requestConns.await(10000);
+        assertEquals(0, requestConns.getValue());
+     
+        this.client.shutdown();
+        this.server.shutdown();
+        
+        closedClientConns.await(10000);
+        assertEquals(0, closedClientConns.getValue());
+     
+        closedServerConns.await(10000);
+        assertEquals(0, closedServerConns.getValue());
+    }
+    
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java?rev=575707&r1=575706&r2=575707&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
Fri Sep 14 07:46:31 2007
@@ -1,7 +1,7 @@
 /*
- * $HeadURL$
- * $Revision$
- * $Date$
+ * $HeadURL:https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLClient.java
$
+ * $Revision:575703 $
+ * $Date:2007-09-14 16:40:15 +0200 (Fri, 14 Sep 2007) $
  *
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -98,7 +98,9 @@
     public void shutdown() throws IOException {
         this.ioReactor.shutdown();
         try {
-            this.thread.join(500);
+            if (this.thread != null) {
+                this.thread.join(500);
+            }
         } catch (InterruptedException ignore) {
         }
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java?rev=575707&r1=575706&r2=575707&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
Fri Sep 14 07:46:31 2007
@@ -1,7 +1,7 @@
 /*
- * $HeadURL$
- * $Revision$
- * $Date$
+ * $HeadURL:https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/mockup/TestHttpSSLServer.java
$
+ * $Revision:575703 $
+ * $Date:2007-09-14 16:40:15 +0200 (Fri, 14 Sep 2007) $
  *
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -116,7 +116,9 @@
     public void shutdown() throws IOException {
         this.ioReactor.shutdown();
         try {
-            this.thread.join(500);
+            if (this.thread != null) {
+                this.thread.join(500);
+            }
         } catch (InterruptedException ignore) {
         }
     }



Mime
View raw message