Skip to content

Commit

Permalink
Remove all *NastyClose tests because (a) the tests are not useful and…
Browse files Browse the repository at this point in the history
… (b) the behavior is completely variable by platform anyway
  • Loading branch information
dmlloyd committed Sep 19, 2014
1 parent 9bf2cb0 commit 0811fe2
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 803 deletions.
Expand Up @@ -319,130 +319,6 @@ public void handleEvent(final StreamSinkChannel channel) {
rightChannelOK.set(true);
}

@Test
public void leftSourceChannelNastyClose() throws Exception {
log.info("Test: leftSourceChannelNastyClose");
final CountDownLatch latch = new CountDownLatch(2);
doConnectionTest(new LatchAwaiter(latch), new ChannelListener<S>() {
public void handleEvent(final S channel) {
try {
channel.getCloseSetter().set(new ChannelListener<StreamSourceChannel>() {
public void handleEvent(final StreamSourceChannel channel) {
latch.countDown();
}
});
channel.setOption(Options.CLOSE_ABORT, Boolean.TRUE);
channel.close();
leftChannelOK.set(true);
} catch (Throwable t) {
log.errorf(t, "Failed to close channel (propagating as RT exception)");
latch.countDown();
throw new RuntimeException(t);
}
}
}, new ChannelListener<T>() {
public void handleEvent(final T channel) {
try {
channel.getCloseSetter().set(new ChannelListener<StreamSinkChannel>() {
public void handleEvent(final StreamSinkChannel channel) {
latch.countDown();
}
});
channel.getWriteSetter().set(new ChannelListener<StreamSinkChannel>() {
public void handleEvent(final StreamSinkChannel channel) {
try {
channel.write(ByteBuffer.allocate(100));
} catch (IOException e) { // broken pipe
IoUtils.safeClose(channel);
rightChannelOK.set(true);
return;
}
}
});
channel.resumeWrites();
} catch (Throwable t) {
log.errorf(t, "Failed to close channel (propagating as RT exception)");
latch.countDown();
throw new RuntimeException(t);
}
}
});
}

@Test
public void rightSinkChannelNastyClose() throws Exception {
log.info("Test: rightSinkChannelNastyClose");
final CountDownLatch latch = new CountDownLatch(2);
final CountDownLatch rightChannelLatch = new CountDownLatch(1);
doConnectionTest(new LatchAwaiter(latch), new ChannelListener<S>() {
public void handleEvent(final S channel) {
try {
log.info("Left channel opened");
channel.getCloseSetter().set(new ChannelListener<StreamSourceChannel>() {
public void handleEvent(final StreamSourceChannel channel) {
latch.countDown();
}
});
channel.getReadSetter().set(new ChannelListener<StreamSourceChannel>() {
public void handleEvent(final StreamSourceChannel channel) {
int res;
try {
res = channel.read(ByteBuffer.allocate(100));
} catch (IOException e) {
IoUtils.safeClose(channel);
return;
}
if (res == -1) {
leftChannelOK.set(true);
IoUtils.safeClose(channel);
}
}
});
channel.resumeReads();
rightChannelLatch.countDown();
} catch (Throwable t) {
log.error("Error occurred on client", t);
try {
channel.close();
} catch (Throwable t2) {
log.error("Error occurred on client (close)", t2);
latch.countDown();
throw new RuntimeException(t);
}
throw new RuntimeException(t);
}
}
}, new ChannelListener<T>() {
public void handleEvent(final T channel) {
try {
log.info("Right channel opened");
channel.getCloseSetter().set(new ChannelListener<StreamSinkChannel>() {
public void handleEvent(final StreamSinkChannel channel) {
latch.countDown();
}
});
channel.getWriteSetter().set(new ChannelListener<StreamSinkChannel>() {
public void handleEvent(final StreamSinkChannel channel) {
try {
if (channel.write(ByteBuffer.allocate(1)) > 0) {
IoUtils.safeClose(channel);
rightChannelOK.set(true);
}
} catch (IOException e) {
IoUtils.safeClose(channel);
}
}
});
channel.resumeWrites();
} catch (Throwable t) {
log.error("Error occurred on server", t);
latch.countDown();
throw new RuntimeException(t);
}
}
});
}

private static class ChannelListenerInvoker<T extends Channel> implements Runnable {
private final ChannelListener<T> channelListener;
private final T channel;
Expand Down
174 changes: 0 additions & 174 deletions nio-impl/src/test/java/org/xnio/nio/test/AbstractNioTcpTest.java
Expand Up @@ -620,178 +620,4 @@ public void handleEvent(final StreamSinkChannel channel) {
assertEquals(serverSent.get(), clientReceived.get());
assertEquals(clientSent.get(), serverReceived.get());
}

@Test
public void clientNastyClose() throws Exception {
log.info("Test: clientNastyClose");
final CountDownLatch latch = new CountDownLatch(2);
final AtomicBoolean clientOK = new AtomicBoolean(false);
final AtomicBoolean serverOK = new AtomicBoolean(false);
doConnectionTest(new Runnable() {
public void run() {
try {
assertTrue(latch.await(500L, TimeUnit.MILLISECONDS));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}, new ChannelListener<T>() {
public void handleEvent(final T channel) {
try {
channel.getCloseSetter().set(new ChannelListener<ConnectedChannel>() {
public void handleEvent(final ConnectedChannel channel) {
log.info("at client close listener");
latch.countDown();
}
});
channel.setOption(Options.CLOSE_ABORT, Boolean.TRUE);
log.info("client closing channel");
channel.close();
clientOK.set(true);
} catch (EOFException e) {
// eof exception is fine
clientOK.set(true);
latch.countDown();
} catch (Throwable t) {
log.errorf(t, "Failed to close channel (propagating as RT exception)");
latch.countDown();
throw new RuntimeException(t);
}
}
}, new ChannelListener<T>() {
public void handleEvent(final T channel) {
try {
channel.getCloseSetter().set(new ChannelListener<ConnectedChannel>() {
public void handleEvent(final ConnectedChannel channel) {
log.info("at server close listener");
latch.countDown();
}
});
setReadListener(channel, new ChannelListener<R>() {
public void handleEvent(final R sourceChannel) {
int res;
try {
res = sourceChannel.read(ByteBuffer.allocate(100));
log.info("server read " + res);
} catch (IOException e) {
serverOK.set(true);
IoUtils.safeClose(channel);
return;
}
if (res > 0) IoUtils.safeClose(channel);
}
});
log.info("resuming reads for server");
resumeReads(channel);
} catch (Throwable t) {
log.errorf(t, "Failed to close channel (propagating as RT exception)");
latch.countDown();
throw new RuntimeException(t);
}
}
});
assertTrue(serverOK.get());
assertTrue(clientOK.get());
}

@Test
public void serverNastyClose() throws Exception {
log.info("Test: serverNastyClose");
final CountDownLatch latch = new CountDownLatch(2);
final AtomicBoolean clientOK = new AtomicBoolean(false);
final AtomicBoolean serverOK = new AtomicBoolean(false);
final CountDownLatch serverLatch = new CountDownLatch(1);
doConnectionTest(new Runnable() {
public void run() {
try {
assertTrue(latch.await(500L, TimeUnit.MILLISECONDS));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}, new ChannelListener<T>() {
public void handleEvent(final T channel) {
try {
log.info("Client opened");
channel.getCloseSetter().set(new ChannelListener<ConnectedChannel>() {
public void handleEvent(final ConnectedChannel channel) {
latch.countDown();
}
});
setReadListener(channel, new ChannelListener<R>() {
public void handleEvent(final R sourceChannel) {
int res;
try {
res = sourceChannel.read(ByteBuffer.allocate(100));
} catch (IOException e) {
clientOK.set(true);
IoUtils.safeClose(channel);
return;
}
if (res == -1) {
clientOK.set(true);
IoUtils.safeClose(channel);
}
}
});
setWriteListener(channel, new ChannelListener<W>() {
public void handleEvent(final W sinkChannel) {
try {
if (sinkChannel.write(ByteBuffer.wrap(new byte[] { 1 })) > 0) {
sinkChannel.suspendWrites();
}
} catch (IOException e) {
IoUtils.safeClose(channel);
}
}
});
resumeReads(channel);
resumeWrites(channel);
serverLatch.countDown();
} catch (Throwable t) {
log.error("Error occurred on client", t);
try {
channel.close();
} catch (Throwable t2) {
log.error("Error occurred on client (close)", t2);
latch.countDown();
throw new RuntimeException(t);
}
throw new RuntimeException(t);
}
}
}, new ChannelListener<T>() {
public void handleEvent(final T channel) {
try {
log.info("Server opened");
channel.getCloseSetter().set(new ChannelListener<ConnectedChannel>() {
public void handleEvent(final ConnectedChannel channel) {
latch.countDown();
}
});
setReadListener(channel, new ChannelListener<R>() {
public void handleEvent(final R sourceChannel) {
try {
if (sourceChannel.read(ByteBuffer.allocate(1)) > 0) {
log.info("Closing connection...");
channel.setOption(Options.CLOSE_ABORT, Boolean.TRUE);
channel.close();
serverOK.set(true);
}
} catch (IOException e) {
IoUtils.safeClose(channel);
}
}
});
resumeReads(channel);
} catch (Throwable t) {
log.error("Error occurred on server", t);
latch.countDown();
throw new RuntimeException(t);
}
}
});
assertTrue(serverOK.get());
assertTrue(clientOK.get());
}
}
Expand Up @@ -18,7 +18,6 @@
package org.xnio.nio.test;

import org.junit.Before;
import org.junit.Ignore;

/**
* Runs NioSslTcpChannelTestCase with 5 I/O threads.
Expand All @@ -32,7 +31,4 @@ public class MultiThreadedNioSslTcpChannelTestCase extends NioSslTcpChannelTestC
public void setThreads() {
super.setNumberOfThreads(5);
}

@Override @Ignore
public void clientNastyClose() {}
}
Expand Up @@ -18,7 +18,6 @@
package org.xnio.nio.test;

import org.junit.Before;
import org.junit.Ignore;

/**
* Runs NioSslTcpConnectionTestCase with 3 I/O threads.
Expand All @@ -32,7 +31,4 @@ public class MultiThreadedNioSslTcpConnectionTestCase extends NioSslTcpConnectio
public void setThreads() {
super.setNumberOfThreads(3);
}

@Override @Ignore
public void clientNastyClose() {}
}

0 comments on commit 0811fe2

Please sign in to comment.