From fbdbc9ed641bb1280469874acf01883177211d05 Mon Sep 17 00:00:00 2001 From: allwin Date: Fri, 11 Oct 2013 14:23:23 +0200 Subject: [PATCH] 8004183: test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java doesn't clean-up Reviewed-by: sjiang, dfuchs, dholmes, olagneau, dholmes, jbachorik --- .../LocalRMIServerSocketFactoryTest.java | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java b/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java index 620b828ca..777fde340 100644 --- a/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java +++ b/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,7 @@ public class LocalRMIServerSocketFactoryTest { private static final SynchronousQueue queue = new SynchronousQueue(); + private static volatile boolean isRunning = true; static final class Result extends Exception { @@ -91,19 +92,23 @@ public class LocalRMIServerSocketFactoryTest { Thread t = new Thread() { public void run() { - while (true) { + while (isRunning) { Exception error = Result.SUCCESS; try { System.err.println("Accepting: "); final Socket ss = s.accept(); System.err.println(ss.getInetAddress() + " accepted"); } catch (Exception x) { - x.printStackTrace(); + if (isRunning) { + x.printStackTrace(); + } error = x; } finally { try { - // wait for the client to get the exception. - queue.put(error); + if (isRunning) { + // wait for the client to get the exception. + queue.put(error); + } } catch (Exception x) { // too bad! System.err.println("Could't send result to client!"); @@ -114,32 +119,38 @@ public class LocalRMIServerSocketFactoryTest { } } }; - t.setDaemon(true); - t.start(); - - System.err.println("new Socket((String)null, port)"); - final Socket s1 = new Socket((String) null, port); - checkError("new Socket((String)null, port)"); - s1.close(); - System.err.println("new Socket((String)null, port): PASSED"); - - System.err.println("new Socket(InetAddress.getByName(null), port)"); - final Socket s2 = new Socket(InetAddress.getByName(null), port); - checkError("new Socket(InetAddress.getByName(null), port)"); - s2.close(); - System.err.println("new Socket(InetAddress.getByName(null), port): PASSED"); - - System.err.println("new Socket(localhost, port)"); - final Socket s3 = new Socket("localhost", port); - checkError("new Socket(localhost, port)"); - s3.close(); - System.err.println("new Socket(localhost, port): PASSED"); - - System.err.println("new Socket(127.0.0.1, port)"); - final Socket s4 = new Socket("127.0.0.1", port); - checkError("new Socket(127.0.0.1, port)"); - s4.close(); - System.err.println("new Socket(127.0.0.1, port): PASSED"); + try { + t.start(); + + System.err.println("new Socket((String)null, port)"); + final Socket s1 = new Socket((String) null, port); + checkError("new Socket((String)null, port)"); + s1.close(); + System.err.println("new Socket((String)null, port): PASSED"); + + System.err.println("new Socket(InetAddress.getByName(null), port)"); + final Socket s2 = new Socket(InetAddress.getByName(null), port); + checkError("new Socket(InetAddress.getByName(null), port)"); + s2.close(); + System.err.println("new Socket(InetAddress.getByName(null), port): PASSED"); + + System.err.println("new Socket(localhost, port)"); + final Socket s3 = new Socket("localhost", port); + checkError("new Socket(localhost, port)"); + s3.close(); + System.err.println("new Socket(localhost, port): PASSED"); + + System.err.println("new Socket(127.0.0.1, port)"); + final Socket s4 = new Socket("127.0.0.1", port); + checkError("new Socket(127.0.0.1, port)"); + s4.close(); + System.err.println("new Socket(127.0.0.1, port): PASSED"); + } + finally { + isRunning = false; + s.close(); + t.join(); + } } } -- GitLab