use of java.nio.channels.SocketChannel in project hadoop by apache.
the class TestWebHdfsTimeouts method setUp.
@Before
public void setUp() throws Exception {
Configuration conf = WebHdfsTestUtil.createConf();
serverSocket = new ServerSocket(0, CONNECTION_BACKLOG);
nnHttpAddress = new InetSocketAddress("localhost", serverSocket.getLocalPort());
conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "localhost:" + serverSocket.getLocalPort());
if (timeoutSource == TimeoutSource.Configuration) {
String v = Integer.toString(SHORT_SOCKET_TIMEOUT) + "ms";
conf.set(HdfsClientConfigKeys.DFS_WEBHDFS_SOCKET_CONNECT_TIMEOUT_KEY, v);
conf.set(HdfsClientConfigKeys.DFS_WEBHDFS_SOCKET_READ_TIMEOUT_KEY, v);
}
fs = WebHdfsTestUtil.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME);
if (timeoutSource == TimeoutSource.ConnectionFactory) {
fs.connectionFactory = connectionFactory;
}
clients = new ArrayList<SocketChannel>();
serverThread = null;
}
use of java.nio.channels.SocketChannel in project robovm by robovm.
the class SocketChannelTest method test_socketChannel_read_ByteBufferII_remoteClosed.
/**
* @tests SocketChannel#read(ByteBuffer[], int, int) when remote server
* closed
*/
public void test_socketChannel_read_ByteBufferII_remoteClosed() throws Exception {
// regression 1 for HARMONY-549
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr2);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr2);
ssc.accept().close();
ByteBuffer[] buf = { ByteBuffer.allocate(10) };
assertEquals(-1, sc.read(buf, 0, 1));
ssc.close();
sc.close();
}
use of java.nio.channels.SocketChannel in project robovm by robovm.
the class SocketChannelTest method test_write$LByteBuffer_invalid.
/**
* @tests java.nio.channels.SocketChannel#write(ByteBuffer[])
*/
public void test_write$LByteBuffer_invalid() throws IOException {
// Set-up
ServerSocketChannel server = ServerSocketChannel.open();
server.socket().bind(null);
SocketChannel client = SocketChannel.open();
client.connect(server.socket().getLocalSocketAddress());
SocketChannel worker = server.accept();
// Do some stuff
try {
client.write((ByteBuffer[]) null);
fail("Should throw a NPE");
} catch (NullPointerException e) {
// expected
}
try {
client.write((ByteBuffer[]) null, 0, 0);
fail("Should throw a NPE");
} catch (NullPointerException e) {
// expected
}
try {
client.write((ByteBuffer[]) null, 1, 0);
fail("Should throw a NPE");
} catch (NullPointerException e) {
// expected
}
try {
client.write((ByteBuffer[]) null, 0, 1);
fail("Should throw a NPE");
} catch (NullPointerException e) {
// expected
}
try {
client.write((ByteBuffer[]) null, 1, 1);
fail("Should throw a NPE");
} catch (NullPointerException e) {
// expected
}
ByteBuffer[] buffers = new ByteBuffer[1];
buffers[0] = ByteBuffer.wrap("Hello ".getBytes("UTF-8"));
try {
client.write(buffers, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
client.write(buffers, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
client.write(buffers, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
client.write(buffers, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
client.write(null, 0, 0);
fail();
} catch (NullPointerException expected) {
}
// Tidy-up
worker.close();
client.close();
server.close();
}
use of java.nio.channels.SocketChannel in project robovm by robovm.
the class SocketChannelTest method test_socketChannel_write_ByteBuffer_posNotZero.
/**
* @tests SocketChannel#write(ByteBuffer) if position is not zero
*/
public void test_socketChannel_write_ByteBuffer_posNotZero() throws Exception {
// regression 5 for HARMONY-549
final String testStr = "Hello World";
ByteBuffer readBuf = ByteBuffer.allocate(11);
ByteBuffer buf = ByteBuffer.wrap(testStr.getBytes());
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr2);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr2);
buf.position(2);
ssc.accept().write(buf);
assertEquals(9, sc.read(readBuf));
buf.flip();
readBuf.flip();
byte[] read = new byte[9];
byte[] write = new byte[11];
buf.get(write);
readBuf.get(read);
for (int i = 0; i < 9; i++) {
assertEquals(read[i], write[i + 2]);
}
}
use of java.nio.channels.SocketChannel in project robovm by robovm.
the class SocketChannelTest method test_socketChannel_write_ByteBufferII.
/**
* @tests SocketChannel#write(ByteBuffer[], int, int)
*/
public void test_socketChannel_write_ByteBufferII() throws Exception {
// regression 2 for HARMONY-549
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(localAddr2);
SocketChannel sc = SocketChannel.open();
sc.connect(localAddr2);
SocketChannel sock = ssc.accept();
ByteBuffer[] buf = { ByteBuffer.allocate(10), null };
try {
sc.write(buf, 0, 2);
fail("should throw NPE");
} catch (NullPointerException e) {
// expected
}
ssc.close();
sc.close();
ByteBuffer target = ByteBuffer.allocate(10);
assertEquals(-1, sock.read(target));
}
Aggregations