Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7F94CCCC6 for ; Thu, 4 Jul 2013 09:18:47 +0000 (UTC) Received: (qmail 7074 invoked by uid 500); 4 Jul 2013 09:18:47 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 7028 invoked by uid 500); 4 Jul 2013 09:18:47 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 7011 invoked by uid 99); 4 Jul 2013 09:18:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jul 2013 09:18:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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, 04 Jul 2013 09:18:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2F4D923888D7; Thu, 4 Jul 2013 09:18:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1499703 - /cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java Date: Thu, 04 Jul 2013 09:18:23 -0000 To: commits@cxf.apache.org From: amichai@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130704091823.2F4D923888D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: amichai Date: Thu Jul 4 09:18:22 2013 New Revision: 1499703 URL: http://svn.apache.org/r1499703 Log: Close sockets in AbstractDosgiTest.waitWebPage() and getFreePort() Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java?rev=1499703&r1=1499702&r2=1499703&view=diff ============================================================================== --- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java (original) +++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java Thu Jul 4 09:18:22 2013 @@ -21,6 +21,7 @@ package org.apache.cxf.dosgi.systests2.m import java.io.IOException; import java.net.ConnectException; import java.net.HttpURLConnection; +import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.ServerSocket; import java.net.Socket; @@ -103,9 +104,9 @@ public class AbstractDosgiTest { return (GreeterService)factory.create(); } - protected Bundle getBundleByName(BundleContext bc, String sn) { + protected Bundle getBundleByName(BundleContext bc, String name) { for (Bundle bundle : bc.getBundles()) { - if (bundle.getSymbolicName().equals(sn)) { + if (bundle.getSymbolicName().equals(name)) { return bundle; } } @@ -113,8 +114,10 @@ public class AbstractDosgiTest { } protected int getFreePort() throws IOException { - ServerSocket socket = new ServerSocket(0); + ServerSocket socket = new ServerSocket(); try { + socket.setReuseAddress(true); // enables quickly reopening socket on same port + socket.bind(new InetSocketAddress(0)); // zero finds a free port return socket.getLocalPort(); } finally { socket.close(); @@ -123,11 +126,12 @@ public class AbstractDosgiTest { protected void waitWebPage(String urlSt) throws InterruptedException, TimeoutException { System.out.println("Waiting for url " + urlSt); + HttpURLConnection con = null; long startTime = System.currentTimeMillis(); while (true) { try { URL url = new URL(urlSt); - HttpURLConnection con = (HttpURLConnection)url.openConnection(); + con = (HttpURLConnection)url.openConnection(); int status = con.getResponseCode(); if (status == 200) { return; @@ -138,6 +142,10 @@ public class AbstractDosgiTest { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); + } finally { + if (con != null) { + con.disconnect(); + } } sleepOrTimeout(startTime, TIMEOUT, "Timeout waiting for web page " + urlSt); }