use of java.net.InetSocketAddress in project flink by apache.
the class BlobServerGetTest method testGetFailsDuringStreaming.
@Test
public void testGetFailsDuringStreaming() {
BlobServer server = null;
BlobClient client = null;
try {
Configuration config = new Configuration();
server = new BlobServer(config);
InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
client = new BlobClient(serverAddress, config);
byte[] data = new byte[5000000];
rnd.nextBytes(data);
// put content addressable (like libraries)
BlobKey key = client.put(data);
assertNotNull(key);
// issue a GET request that succeeds
InputStream is = client.get(key);
byte[] receiveBuffer = new byte[50000];
BlobUtils.readFully(is, receiveBuffer, 0, receiveBuffer.length, null);
BlobUtils.readFully(is, receiveBuffer, 0, receiveBuffer.length, null);
// shut down the server
for (BlobServerConnection conn : server.getCurrentActiveConnections()) {
conn.close();
}
try {
byte[] remainder = new byte[data.length - 2 * receiveBuffer.length];
BlobUtils.readFully(is, remainder, 0, remainder.length, null);
// we tolerate that this succeeds, as the receiver socket may have buffered
// everything already
} catch (IOException e) {
// expected
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (client != null) {
try {
client.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
if (server != null) {
server.shutdown();
}
}
}
use of java.net.InetSocketAddress in project flink by apache.
the class BlobServerPutTest method testPutChunkedStreamSuccessful.
@Test
public void testPutChunkedStreamSuccessful() {
BlobServer server = null;
BlobClient client = null;
try {
Configuration config = new Configuration();
server = new BlobServer(config);
InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
client = new BlobClient(serverAddress, config);
byte[] data = new byte[2000000];
rnd.nextBytes(data);
// put content addressable (like libraries)
{
BlobKey key1 = client.put(new ChunkedInputStream(data, 19));
assertNotNull(key1);
}
// put under job and name scope
{
JobID jid = new JobID();
String stringKey = "my test key";
client.put(jid, stringKey, new ChunkedInputStream(data, 17));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (client != null) {
try {
client.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
if (server != null) {
server.shutdown();
}
}
}
use of java.net.InetSocketAddress in project flink by apache.
the class BlobServerPutTest method testPutBufferFails.
@Test
public void testPutBufferFails() {
//setWritable doesn't work on Windows.
assumeTrue(!OperatingSystem.isWindows());
BlobServer server = null;
BlobClient client = null;
File tempFileDir = null;
try {
Configuration config = new Configuration();
server = new BlobServer(config);
// make sure the blob server cannot create any files in its storage dir
tempFileDir = server.createTemporaryFilename().getParentFile().getParentFile();
assertTrue(tempFileDir.setExecutable(true, false));
assertTrue(tempFileDir.setReadable(true, false));
assertTrue(tempFileDir.setWritable(false, false));
InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
client = new BlobClient(serverAddress, config);
byte[] data = new byte[2000000];
rnd.nextBytes(data);
// put content addressable (like libraries)
try {
client.put(data);
fail("This should fail.");
} catch (IOException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Server side error"));
}
try {
client.put(data);
fail("Client should be closed");
} catch (IllegalStateException e) {
// expected
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
// set writable again to make sure we can remove the directory
if (tempFileDir != null) {
tempFileDir.setWritable(true, false);
}
if (client != null) {
try {
client.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
if (server != null) {
server.shutdown();
}
}
}
use of java.net.InetSocketAddress in project flink by apache.
the class BlobServerPutTest method testPutStreamSuccessful.
@Test
public void testPutStreamSuccessful() {
BlobServer server = null;
BlobClient client = null;
try {
Configuration config = new Configuration();
server = new BlobServer(config);
InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
client = new BlobClient(serverAddress, config);
byte[] data = new byte[2000000];
rnd.nextBytes(data);
// put content addressable (like libraries)
{
BlobKey key1 = client.put(new ByteArrayInputStream(data));
assertNotNull(key1);
}
// put under job and name scope
{
JobID jid = new JobID();
String stringKey = "my test key";
client.put(jid, stringKey, new ByteArrayInputStream(data));
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (client != null) {
try {
client.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
if (server != null) {
server.shutdown();
}
}
}
use of java.net.InetSocketAddress in project flink by apache.
the class BlobServerPutTest method testPutNamedBufferFails.
@Test
public void testPutNamedBufferFails() {
//setWritable doesn't work on Windows.
assumeTrue(!OperatingSystem.isWindows());
BlobServer server = null;
BlobClient client = null;
File tempFileDir = null;
try {
Configuration config = new Configuration();
server = new BlobServer(config);
// make sure the blob server cannot create any files in its storage dir
tempFileDir = server.createTemporaryFilename().getParentFile().getParentFile();
assertTrue(tempFileDir.setExecutable(true, false));
assertTrue(tempFileDir.setReadable(true, false));
assertTrue(tempFileDir.setWritable(false, false));
InetSocketAddress serverAddress = new InetSocketAddress("localhost", server.getPort());
client = new BlobClient(serverAddress, config);
byte[] data = new byte[2000000];
rnd.nextBytes(data);
// put under job and name scope
try {
JobID jid = new JobID();
String stringKey = "my test key";
client.put(jid, stringKey, data);
fail("This should fail.");
} catch (IOException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Server side error"));
}
try {
JobID jid = new JobID();
String stringKey = "another key";
client.put(jid, stringKey, data);
fail("Client should be closed");
} catch (IllegalStateException e) {
// expected
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
// set writable again to make sure we can remove the directory
if (tempFileDir != null) {
tempFileDir.setWritable(true, false);
}
if (client != null) {
try {
client.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
if (server != null) {
server.shutdown();
}
}
}
Aggregations