Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 27555 invoked from network); 21 Aug 2008 13:19:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Aug 2008 13:19:46 -0000 Received: (qmail 7110 invoked by uid 500); 21 Aug 2008 13:19:38 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 6603 invoked by uid 500); 21 Aug 2008 13:19:37 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 6592 invoked by uid 99); 21 Aug 2008 13:19:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Aug 2008 06:19:37 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Aug 2008 13:18:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 59EA523889C2; Thu, 21 Aug 2008 06:19:18 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r687745 - in /tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni: SocketServerTestBind.java SocketServerTestSuite.java Date: Thu, 21 Aug 2008 13:19:17 -0000 To: dev@tomcat.apache.org From: jfclere@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080821131918.59EA523889C2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jfclere Date: Thu Aug 21 06:19:15 2008 New Revision: 687745 URL: http://svn.apache.org/viewvc?rev=687745&view=rev Log: Add a test related to PR#43327. Added: tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java Modified: tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java Added: tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java?rev=687745&view=auto ============================================================================== --- tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java (added) +++ tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java Thu Aug 21 06:19:15 2008 @@ -0,0 +1,133 @@ +/* + * 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. + */ + +package org.apache.tomcat.jni; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import junit.framework.TestCase; + +import java.io.OutputStream; +import java.net.NetworkInterface; +import java.net.InetAddress; +import java.util.*; + +/** + * A basic test suite that tests Socket Server feature. + * + * @author Jean-Frederic Clere + * @version $Revision: 466585 $, $Date: 2006-10-22 00:16:34 +0200 (Sun, 22 Oct 2006) $ + * @see org.apache.tomcat.jni + */ +public class SocketServerTestBind extends TestCase { + + private long serverSock = 0; + private int port=6666; + private String host=null; + + public static long serverPool = 0; + + public void testSocketServerTestBind() throws Exception { + + System.out.println("Starting: testSocketServerTestBind"); + /* Load APR library */ + Library.initialize(null); + + /* Create the server socket and listen on it */ + serverPool = Pool.create(0); + long inetAddress = Address.info(host, Socket.APR_UNSPEC, + port, 0, serverPool); + serverSock = Socket.create(Address.getInfo(inetAddress).family, + Socket.SOCK_STREAM, + Socket.APR_PROTO_TCP, serverPool); + int rc = Socket.bind(serverSock, inetAddress); + if (rc != 0) { + throw(new Exception("Can't bind: " + Error.strerror(rc))); + } + Socket.listen(serverSock, 5); + + /* Start the client that connects to the server */ + Client client = new Client(); + client.start(); + java.lang.Thread.sleep(100); + + boolean running = true; + while (running) { + /* Accept it */ + long clientSock = Socket.accept(serverSock); + byte [] buf = new byte[1]; + while (Socket.recv(clientSock, buf, 0, 1) == 1) { + } + if (buf[0] != 'A') + break; + } + client.join(); + Library.terminate(); + System.out.println("Done: testSocketServerTestBind"); + } + + /* small client that connects and sends one byte */ + private class Client extends java.lang.Thread { + public void run() { + try { + Enumeration nets = NetworkInterface.getNetworkInterfaces(); + while (nets.hasMoreElements()) { + NetworkInterface net = (NetworkInterface) nets.nextElement(); + + Enumeration addrs = net.getInetAddresses(); + + while (addrs.hasMoreElements()) { + InetAddress ia = (InetAddress)addrs.nextElement(); + System.out.println("Trying: " + ia.getHostAddress()); + java.net.Socket sock = new java.net.Socket(ia, port); + OutputStream ou = sock.getOutputStream(); + ou.write('A'); + ou.flush(); + java.lang.Thread.sleep(10000); + ou.close(); + } + } + } catch(Exception ex ) { + ex.printStackTrace(); + } + + /* Now use localhost to write 'E' */ + try { + java.net.Socket sock = new java.net.Socket("localhost", port); + OutputStream ou = sock.getOutputStream(); + ou.write('E'); + ou.flush(); + java.lang.Thread.sleep(10000); + ou.close(); + } catch(Exception ex ) { + ex.printStackTrace(); + } + } + } + + public static void main(String[] args) { + TestRunner.run(suite()); + } + + public static Test suite() + { + TestSuite suite = new TestSuite( "Tomcat Native Server Socket" ); + suite.addTest(new TestSuite(SocketServerTestSuite.class)); + return suite; + } +} Modified: tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java?rev=687745&r1=687744&r2=687745&view=diff ============================================================================== --- tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java (original) +++ tomcat/connectors/trunk/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java Thu Aug 21 06:19:15 2008 @@ -111,6 +111,7 @@ wait = System.currentTimeMillis() - start; if (wait > 1 && ! ok) throw new Exception("non_blocking accept Socket.APR_SO_NONBLOCK failed"); + client.join(); /* Try the same on client socket */ client = new Client(); @@ -136,6 +137,9 @@ wait = System.currentTimeMillis() - start; if (wait < 1) throw new Exception("non_blocking client Socket.APR_SO_NONBLOCK false failed"); + + client.join(); + Library.terminate(); } /* small client that connects and sends one byte */ @@ -165,6 +169,7 @@ { TestSuite suite = new TestSuite( "Tomcat Native Server Socket" ); suite.addTest(new TestSuite(SocketServerTestSuite.class)); + suite.addTest(new TestSuite(SocketServerTestBind.class)); return suite; } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org