< prev index next >
test/java/nio/channels/SocketChannel/AdaptSocket.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2001, 2012, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 20,36 ****
--- 20,38 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
+ * @bug 8156002
* @summary Unit test for socket-channel adaptors
* @library ..
*/
import java.io.*;
import java.net.*;
import java.nio.channels.*;
+ import java.util.Arrays;
public class AdaptSocket {
static java.io.PrintStream out = System.out;
*** 98,111 ****
so.getOutputStream().write(dataString.getBytes("US-ASCII"));
InputStream is = so.getInputStream();
try {
byte[] b = new byte[100];
int n = is.read(b);
! if (n != 5)
throw new Exception("Incorrect number of bytes read: " + n);
! 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");
return;
}
--- 100,118 ----
so.getOutputStream().write(dataString.getBytes("US-ASCII"));
InputStream is = so.getInputStream();
try {
byte[] b = new byte[100];
int n = is.read(b);
! 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"))) {
throw new Exception("Incorrect data read: " + n);
+ }
} catch (SocketTimeoutException x) {
if (shouldTimeout) {
out.println("Read timed out, as expected");
return;
}
*** 133,142 ****
--- 140,150 ----
so.setSoTimeout(timeout);
out.println("timeout: " + so.getSoTimeout());
testRead(so, shouldTimeout);
for (int i = 0; i < 4; i++) {
+ out.println("loop: " + i);
testRead(so, shouldTimeout);
}
sc.close();
}
*** 161,171 ****
= TestServers.EchoServer.startNewServer()) {
testRead(echoServer, 0, false);
testRead(echoServer, 8000, false);
}
! try (TestServers.EchoServer lingerEchoServer
! = TestServers.EchoServer.startNewServer(100)) {
! testRead(lingerEchoServer, 10, true);
}
}
}
--- 169,179 ----
= TestServers.EchoServer.startNewServer()) {
testRead(echoServer, 0, false);
testRead(echoServer, 8000, false);
}
! try (TestServers.NoResponseServer noResponseServer
! = TestServers.NoResponseServer.startNewServer()) {
! testRead(noResponseServer, 10, true);
}
}
}
< prev index next >