提交 ed90dd3a 编写于 作者: M mchung

Merge

......@@ -752,18 +752,9 @@ com/sun/nio/sctp/SctpChannel/Shutdown.java generic-all
# at SetLastModified.main(SetLastModified.java:107)
java/io/File/SetLastModified.java generic-all
# Fails on Solaris 10 x64, address already in use
java/nio/channels/DatagramChannel/SRTest.java generic-all
# Fails on Solaris 10 x86, times out
java/nio/channels/DatagramChannel/Sender.java generic-all
# Fails on Fedora 9 x86, address in use
java/nio/channels/Selector/SelectWrite.java generic-all
# Fails on Fedora 9 32bit times out
java/nio/channels/DatagramChannel/EmptyBuffer.java generic-all
# Fails on Windows 2000, times out
java/nio/channels/FileChannel/Transfer.java generic-all
......@@ -821,12 +812,6 @@ java/nio/channels/AsynchronousSocketChannel/Leaky.java windows-5.0
java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0
java/nio/channels/Channels/Basic2.java windows-5.0
# Solaris sparc timeout
java/nio/channels/DatagramChannel/Connect.java generic-all
# Solaris i586 timeouts
java/nio/channels/DatagramChannel/EmptyBuffer.java solaris-all
# Failed loopback connection? On windows 32bit?
# Considered a stress test, can consume all resources.
java/nio/channels/Selector/LotsOfChannels.java generic-all
......
......@@ -42,15 +42,15 @@ public class Connect {
}
static void test() throws Exception {
invoke(new Actor(), new Reactor());
Reactor r = new Reactor();
Actor a = new Actor(r.port());
invoke(a, r);
}
static void invoke(Sprintable reader, Sprintable writer) throws Exception {
Thread writerThread = new Thread(writer);
writerThread.start();
while (!writer.ready())
Thread.sleep(50);
Thread readerThread = new Thread(reader);
readerThread.start();
......@@ -64,34 +64,31 @@ public class Connect {
public interface Sprintable extends Runnable {
public void throwException() throws Exception;
public boolean ready();
}
public static class Actor implements Sprintable {
final int port;
Exception e = null;
Actor(int port) {
this.port = port;
}
public void throwException() throws Exception {
if (e != null)
throw e;
}
private volatile boolean ready = false;
public boolean ready() {
return ready;
}
public void run() {
try {
DatagramChannel dc = DatagramChannel.open();
ready = true;
// Send a message
ByteBuffer bb = ByteBuffer.allocateDirect(256);
bb.put("hello".getBytes());
bb.flip();
InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888);
InetSocketAddress isa = new InetSocketAddress(address, port);
dc.connect(isa);
dc.write(bb);
......@@ -123,26 +120,26 @@ public class Connect {
}
public static class Reactor implements Sprintable {
final DatagramChannel dc;
Exception e = null;
public void throwException() throws Exception {
if (e != null)
throw e;
Reactor() throws IOException {
dc = DatagramChannel.open().bind(new InetSocketAddress(0));
}
private volatile boolean ready = false;
int port() {
return dc.socket().getLocalPort();
}
public boolean ready() {
return ready;
public void throwException() throws Exception {
if (e != null)
throw e;
}
public void run() {
try {
// Listen for a message
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
ByteBuffer bb = ByteBuffer.allocateDirect(100);
ready = true;
SocketAddress sa = dc.receive(bb);
bb.flip();
CharBuffer cb = Charset.forName("US-ASCII").
......
......@@ -42,18 +42,16 @@ public class EmptyBuffer {
}
static void test() throws Exception {
Sprintable server = new Server();
Server server = new Server();
Thread serverThread = new Thread(server);
serverThread.start();
while (!server.ready())
Thread.sleep(50);
DatagramChannel dc = DatagramChannel.open();
ByteBuffer bb = ByteBuffer.allocateDirect(12);
bb.order(ByteOrder.BIG_ENDIAN);
bb.putInt(1).putLong(1);
bb.flip();
InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888);
InetSocketAddress isa = new InetSocketAddress(address, server.port());
dc.connect(isa);
dc.write(bb);
bb.rewind();
......@@ -65,22 +63,21 @@ public class EmptyBuffer {
server.throwException();
}
public interface Sprintable extends Runnable {
public void throwException() throws Exception;
public boolean ready();
}
public static class Server implements Sprintable {
public static class Server implements Runnable {
final DatagramChannel dc;
Exception e = null;
private volatile boolean ready = false;
public void throwException() throws Exception {
if (e != null)
throw e;
Server() throws IOException {
this.dc = DatagramChannel.open().bind(new InetSocketAddress(0));
}
public boolean ready() {
return ready;
int port() {
return dc.socket().getLocalPort();
}
void throwException() throws Exception {
if (e != null)
throw e;
}
void showBuffer(String s, ByteBuffer bb) {
......@@ -97,9 +94,6 @@ public class EmptyBuffer {
SocketAddress sa = null;
int numberReceived = 0;
try {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
ready = true;
ByteBuffer bb = ByteBuffer.allocateDirect(12);
bb.clear();
// Only one clear. The buffer will be full after
......
......@@ -33,7 +33,7 @@ import java.nio.channels.*;
public class NoSender {
public static void main(String argv[]) throws Exception {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(5441));
dc.socket().bind(new InetSocketAddress(0));
dc.configureBlocking(false);
ByteBuffer buf1 = ByteBuffer.allocateDirect(256);
SocketAddress sa1 = dc.receive(buf1);
......
......@@ -42,16 +42,23 @@ public class SRTest {
}
static void test() throws Exception {
invoke(new ClassicReader(), new ClassicWriter());
ClassicReader classicReader;
NioReader nioReader;
classicReader = new ClassicReader();
invoke(classicReader, new ClassicWriter(classicReader.port()));
log.println("Classic RW: OK");
invoke(new ClassicReader(), new NioWriter());
classicReader = new ClassicReader();
invoke(classicReader, new NioWriter(classicReader.port()));
log.println("Classic R, Nio W: OK");
invoke(new NioReader(), new ClassicWriter());
nioReader = new NioReader();
invoke(nioReader, new ClassicWriter(nioReader.port()));
log.println("Classic W, Nio R: OK");
invoke(new NioReader(), new NioWriter());
nioReader = new NioReader();
invoke(nioReader, new NioWriter(nioReader.port()));
log.println("Nio RW: OK");
}
......@@ -75,8 +82,13 @@ public class SRTest {
}
public static class ClassicWriter implements Sprintable {
final int port;
Exception e = null;
ClassicWriter(int port) {
this.port = port;
}
public void throwException() throws Exception {
if (e != null)
throw e;
......@@ -89,7 +101,7 @@ public class SRTest {
byte[] data = dataString.getBytes();
InetAddress address = InetAddress.getLocalHost();
DatagramPacket dp = new DatagramPacket(data, data.length,
address, 8888);
address, port);
ds.send(dp);
Thread.sleep(50);
ds.send(dp);
......@@ -100,8 +112,13 @@ public class SRTest {
}
public static class NioWriter implements Sprintable {
final int port;
Exception e = null;
NioWriter(int port) {
this.port = port;
}
public void throwException() throws Exception {
if (e != null)
throw e;
......@@ -114,7 +131,7 @@ public class SRTest {
bb.put("hello".getBytes());
bb.flip();
InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888);
InetSocketAddress isa = new InetSocketAddress(address, port);
dc.send(bb, isa);
Thread.sleep(50);
dc.send(bb, isa);
......@@ -125,8 +142,17 @@ public class SRTest {
}
public static class ClassicReader implements Sprintable {
final DatagramSocket ds;
Exception e = null;
ClassicReader() throws IOException {
this.ds = new DatagramSocket();
}
int port() {
return ds.getLocalPort();
}
public void throwException() throws Exception {
if (e != null)
throw e;
......@@ -136,7 +162,6 @@ public class SRTest {
try {
byte[] buf = new byte[256];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
DatagramSocket ds = new DatagramSocket(8888);
ds.receive(dp);
String received = new String(dp.getData());
log.println(received);
......@@ -148,8 +173,17 @@ public class SRTest {
}
public static class NioReader implements Sprintable {
final DatagramChannel dc;
Exception e = null;
NioReader() throws IOException {
this.dc = DatagramChannel.open().bind(new InetSocketAddress(0));
}
int port() {
return dc.socket().getLocalPort();
}
public void throwException() throws Exception {
if (e != null)
throw e;
......@@ -157,8 +191,6 @@ public class SRTest {
public void run() {
try {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
ByteBuffer bb = ByteBuffer.allocateDirect(100);
SocketAddress sa = dc.receive(bb);
bb.flip();
......
......@@ -42,13 +42,11 @@ public class Sender {
}
static void test() throws Exception {
Sprintable server = new Server();
Sprintable client = new Client();
Server server = new Server();
Client client = new Client(server.port());
Thread serverThread = new Thread(server);
serverThread.start();
while (!server.ready())
Thread.sleep(50);
Thread clientThread = new Thread(client);
clientThread.start();
......@@ -60,23 +58,17 @@ public class Sender {
client.throwException();
}
public interface Sprintable extends Runnable {
public void throwException() throws Exception;
public boolean ready();
}
public static class Client implements Sprintable {
public static class Client implements Runnable {
final int port;
Exception e = null;
public void throwException() throws Exception {
if (e != null)
throw e;
Client(int port) {
this.port = port;
}
private volatile boolean ready = false;
public boolean ready() {
return ready;
void throwException() throws Exception {
if (e != null)
throw e;
}
public void run() {
......@@ -87,7 +79,7 @@ public class Sender {
bb.putInt(1).putLong(1);
bb.flip();
InetAddress address = InetAddress.getLocalHost();
InetSocketAddress isa = new InetSocketAddress(address, 8888);
InetSocketAddress isa = new InetSocketAddress(address, port);
dc.connect(isa);
dc.write(bb);
} catch (Exception ex) {
......@@ -96,17 +88,21 @@ public class Sender {
}
}
public static class Server implements Sprintable {
public static class Server implements Runnable {
final DatagramChannel dc;
Exception e = null;
private volatile boolean ready = false;
public void throwException() throws Exception {
if (e != null)
throw e;
Server() throws IOException {
dc = DatagramChannel.open().bind(new InetSocketAddress(0));
}
int port() {
return dc.socket().getLocalPort();
}
public boolean ready() {
return ready;
void throwException() throws Exception {
if (e != null)
throw e;
}
void showBuffer(String s, ByteBuffer bb) {
......@@ -123,13 +119,10 @@ public class Sender {
SocketAddress sa = null;
try {
DatagramChannel dc = DatagramChannel.open();
dc.socket().bind(new InetSocketAddress(8888));
dc.configureBlocking(false);
ready = true;
ByteBuffer bb = ByteBuffer.allocateDirect(12);
bb.clear();
// Get the one valid datagram
dc.configureBlocking(false);
while (sa == null)
sa = dc.receive(bb);
sa = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册