Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java')
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java76
1 files changed, 31 insertions, 45 deletions
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java
index bd02b034d8..0b02ee1b8a 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ShutdownMonitorTest.java
@@ -26,43 +26,36 @@ import java.io.LineNumberReader;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
/**
* ShutdownMonitorTest
- *
- *
- *
*/
public class ShutdownMonitorTest
{
-
-
@Test
- public void testShutdown ()
- throws Exception
+ public void testShutdown() throws Exception
{
-
- //test port and key assignment
+ // test port and key assignment
ShutdownMonitor.getInstance().setPort(0);
ShutdownMonitor.getInstance().setExitVm(false);
ShutdownMonitor.getInstance().start();
String key = ShutdownMonitor.getInstance().getKey();
int port = ShutdownMonitor.getInstance().getPort();
-
- //try starting a 2nd time (should be ignored)
- ShutdownMonitor.getInstance().start();
-
-
+
+ // try starting a 2nd time (should be ignored)
+ ShutdownMonitor.getInstance().start();
+
stop(port,key,true);
assertTrue(!ShutdownMonitor.getInstance().isAlive());
-
- //should be able to change port and key because it is stopped
+
+ // should be able to change port and key because it is stopped
ShutdownMonitor.getInstance().setPort(0);
- ShutdownMonitor.getInstance().setKey("foo");
+ ShutdownMonitor.getInstance().setKey("foo");
ShutdownMonitor.getInstance().start();
-
+
key = ShutdownMonitor.getInstance().getKey();
port = ShutdownMonitor.getInstance().getPort();
assertTrue(ShutdownMonitor.getInstance().isAlive());
@@ -71,41 +64,34 @@ public class ShutdownMonitorTest
assertTrue(!ShutdownMonitor.getInstance().isAlive());
}
-
- public void stop (int port, String key, boolean check)
- throws Exception
+ public void stop(int port, String key, boolean check) throws Exception
{
- Socket s = null;
-
- try
+ System.out.printf("Attempting stop to localhost:%d (%b)%n",port,check);
+ try (Socket s = new Socket(InetAddress.getByName("127.0.0.1"),port))
{
- //send stop command
- s = new Socket(InetAddress.getByName("127.0.0.1"),port);
-
- OutputStream out = s.getOutputStream();
- out.write((key + "\r\nstop\r\n").getBytes());
- out.flush();
-
- if (check)
+ // send stop command
+ try (OutputStream out = s.getOutputStream())
{
- //wait a little
- Thread.currentThread().sleep(600);
+ out.write((key + "\r\nstop\r\n").getBytes());
+ out.flush();
- //check for stop confirmation
- LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
- String response;
- if ((response = lin.readLine()) != null)
+ if (check)
{
- assertEquals("Stopped", response);
+ // wait a little
+ TimeUnit.MILLISECONDS.sleep(600);
+
+ // check for stop confirmation
+ LineNumberReader lin = new LineNumberReader(new InputStreamReader(s.getInputStream()));
+ String response;
+ if ((response = lin.readLine()) != null)
+ {
+ assertEquals("Stopped",response);
+ }
+ else
+ throw new IllegalStateException("No stop confirmation");
}
- else
- throw new IllegalStateException("No stop confirmation");
}
}
- finally
- {
- if (s != null) s.close();
- }
}
}

Back to the top