use of java.nio.channels.ClosedChannelException in project hadoop by apache.
the class TestClose method testWriteAfterClose.
@Test
public void testWriteAfterClose() throws IOException {
Configuration conf = new Configuration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
try {
final byte[] data = "foo".getBytes();
FileSystem fs = FileSystem.get(conf);
OutputStream out = fs.create(new Path("/test"));
out.write(data);
out.close();
try {
// Should fail.
out.write(data);
fail("Should not have been able to write more data after file is closed.");
} catch (ClosedChannelException cce) {
// We got the correct exception. Ignoring.
}
// Should succeed. Double closes are OK.
out.close();
} finally {
if (cluster != null) {
cluster.shutdown();
}
}
}
use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class SocketChannelTest method testWriteByteBuffer.
public void testWriteByteBuffer() throws IOException {
assertTrue(this.server1.isBound());
java.nio.ByteBuffer writeBuf = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
assertFalse(this.channel1.isRegistered());
assertTrue(this.channel1.isBlocking());
assertFalse(this.channel1.isConnected());
assertFalse(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
try {
channel1.write(writeBuf);
fail("Should throw NotYetConnectedException");
} catch (NotYetConnectedException e) {
// correct
}
this.channel1.connect(localAddr1);
assertTrue(this.channel1.isBlocking());
assertTrue(this.channel1.isConnected());
assertFalse(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
assertEquals(CAPACITY_NORMAL, this.channel1.write(writeBuf));
this.channel1.close();
try {
channel1.write(writeBuf);
fail("Should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// correct
}
}
use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class SocketChannelTest method testReadByteBuffer.
// -------------------------------------------------
// Test for read/write but no real data expressed
// -------------------------------------------------
public void testReadByteBuffer() throws Exception {
assertTrue(this.server1.isBound());
java.nio.ByteBuffer readBuf = java.nio.ByteBuffer.allocate(CAPACITY_NORMAL);
assertFalse(this.channel1.isRegistered());
assertTrue(this.channel1.isBlocking());
assertFalse(this.channel1.isConnected());
assertFalse(this.channel1.isConnectionPending());
assertTrue(this.channel1.isOpen());
// note: blocking-mode will make the read process endless!
this.channel1.configureBlocking(false);
try {
channel1.read(readBuf);
fail("Should throw NotYetConnectedException");
} catch (NotYetConnectedException e) {
// correct
}
boolean connected = this.channel1.connect(localAddr1);
if (!connected) {
assertFalse(this.channel1.isBlocking());
assertTrue(this.channel1.isConnectionPending());
assertFalse(this.channel1.isConnected());
}
if (tryFinish()) {
assertEquals(0, this.channel1.read(readBuf));
}
this.channel1.close();
try {
channel1.read(readBuf);
fail("Should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// correct
}
}
use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class ServerSocketChannelTest method test_socket_accept_Blocking_Bound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Blocking_Bound() throws IOException {
// regression test for Harmony-748
serverChannel.configureBlocking(true);
ServerSocket gotSocket = serverChannel.socket();
gotSocket.bind(localAddr1);
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw a ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
}
use of java.nio.channels.ClosedChannelException in project robovm by robovm.
the class ServerSocketChannelTest method test_socket_accept_Nonblocking_Bound.
/**
* @tests ServerSocket#socket().accept()
*/
public void test_socket_accept_Nonblocking_Bound() throws IOException {
// regression test for Harmony-748
serverChannel.configureBlocking(false);
ServerSocket gotSocket = serverChannel.socket();
gotSocket.bind(localAddr1);
try {
gotSocket.accept();
fail("Should throw an IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
serverChannel.close();
try {
gotSocket.accept();
fail("Should throw a ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
}
Aggregations