8156002: java/nio/channels/SocketChannel/AdaptSocket.java Fails in Mesos on OSX
Reviewed-by: dfuchs
--- a/jdk/test/java/nio/channels/SocketChannel/AdaptSocket.java Tue May 10 00:44:28 2016 +0000
+++ b/jdk/test/java/nio/channels/SocketChannel/AdaptSocket.java Tue May 10 15:12:04 2016 +0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, 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
@@ -22,6 +22,7 @@
*/
/* @test
+ * @bug 8156002
* @summary Unit test for socket-channel adaptors
* @library ..
*/
@@ -29,6 +30,7 @@
import java.io.*;
import java.net.*;
import java.nio.channels.*;
+import java.util.Arrays;
public class AdaptSocket {
@@ -100,10 +102,15 @@
try {
byte[] b = new byte[100];
int n = is.read(b);
- if (n != 5)
+ if (shouldTimeout) {
+ throw new Exception("Should time out, but not, data: " + Arrays.toString(b));
+ }
+ if (n != 5) {
throw new Exception("Incorrect number of bytes read: " + n);
- if (!dataString.equals(new String(b, 0, n, "US-ASCII")))
+ }
+ if (!dataString.equals(new String(b, 0, n, "US-ASCII"))) {
throw new Exception("Incorrect data read: " + n);
+ }
} catch (SocketTimeoutException x) {
if (shouldTimeout) {
out.println("Read timed out, as expected");
@@ -135,6 +142,7 @@
testRead(so, shouldTimeout);
for (int i = 0; i < 4; i++) {
+ out.println("loop: " + i);
testRead(so, shouldTimeout);
}
@@ -163,9 +171,9 @@
testRead(echoServer, 8000, false);
}
- try (TestServers.EchoServer lingerEchoServer
- = TestServers.EchoServer.startNewServer(100)) {
- testRead(lingerEchoServer, 10, true);
+ try (TestServers.NoResponseServer noResponseServer
+ = TestServers.NoResponseServer.startNewServer()) {
+ testRead(noResponseServer, 10, true);
}
}
}
--- a/jdk/test/java/nio/channels/TestServers.java Tue May 10 00:44:28 2016 +0000
+++ b/jdk/test/java/nio/channels/TestServers.java Tue May 10 15:12:04 2016 +0800
@@ -340,7 +340,7 @@
* exactly matches the RFC - the only purpose of this server is to have
* something that responds to nio tests...
*/
- static final class EchoServer extends AbstractTcpServer {
+ static class EchoServer extends AbstractTcpServer {
public EchoServer() {
this(0L);
@@ -400,6 +400,21 @@
}
/**
+ * A small TCP Server that accept connections but does not response to any input.
+ */
+ static final class NoResponseServer extends EchoServer {
+ public NoResponseServer() {
+ super(Long.MAX_VALUE);
+ }
+
+ public static NoResponseServer startNewServer() throws IOException {
+ final NoResponseServer noResponseServer = new NoResponseServer();
+ noResponseServer.start();
+ return noResponseServer;
+ }
+ }
+
+ /**
* A small TCP server that emulates the Day & Time service for tests
* purposes. See http://en.wikipedia.org/wiki/Daytime_Protocol This server
* uses an anonymous port - NOT the standard port 13. We don't guarantee