use of java.net.Socket in project flink by apache.
the class SocketClientSinkTest method testSinkAutoFlush.
@Test
public void testSinkAutoFlush() throws Exception {
final ServerSocket server = new ServerSocket(0);
final int port = server.getLocalPort();
final SocketClientSink<String> simpleSink = new SocketClientSink<>(host, port, simpleSchema, 0, true);
simpleSink.open(new Configuration());
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
Thread sinkRunner = new Thread("Test sink runner") {
@Override
public void run() {
try {
// need two messages here: send a fin to cancel the client state:FIN_WAIT_2 while the server is CLOSE_WAIT
simpleSink.invoke(TEST_MESSAGE + '\n');
} catch (Throwable t) {
error.set(t);
}
}
};
sinkRunner.start();
Socket sk = server.accept();
BufferedReader rdr = new BufferedReader(new InputStreamReader(sk.getInputStream()));
String value = rdr.readLine();
sinkRunner.join();
simpleSink.close();
server.close();
if (error.get() != null) {
Throwable t = error.get();
t.printStackTrace();
fail("Error in spawned thread: " + t.getMessage());
}
assertEquals(TEST_MESSAGE, value);
}
use of java.net.Socket in project flink by apache.
the class SocketTextStreamFunctionTest method testSocketSourceOutputInfiniteRetries.
@Test
public void testSocketSourceOutputInfiniteRetries() throws Exception {
ServerSocket server = new ServerSocket(0);
Socket channel = null;
try {
SocketTextStreamFunction source = new SocketTextStreamFunction(LOCALHOST, server.getLocalPort(), "\n", -1, 100);
SocketSourceThread runner = new SocketSourceThread(source, "test1", "check");
runner.start();
// first connection: nothing
channel = server.accept();
channel.close();
// second connection: first string
channel = server.accept();
OutputStreamWriter writer = new OutputStreamWriter(channel.getOutputStream());
writer.write("test1\n");
writer.close();
channel.close();
// third connection: nothing
channel = server.accept();
channel.close();
// forth connection: second string
channel = server.accept();
writer = new OutputStreamWriter(channel.getOutputStream());
writer.write("check\n");
writer.flush();
runner.waitForNumElements(2);
runner.cancel();
runner.waitUntilDone();
} finally {
if (channel != null) {
IOUtils.closeQuietly(channel);
}
IOUtils.closeQuietly(server);
}
}
use of java.net.Socket in project flink by apache.
the class SocketTextStreamFunctionTest method testSocketSourceOutputAcrossRetries.
@Test
public void testSocketSourceOutputAcrossRetries() throws Exception {
ServerSocket server = new ServerSocket(0);
Socket channel = null;
try {
SocketTextStreamFunction source = new SocketTextStreamFunction(LOCALHOST, server.getLocalPort(), "\n", 10, 100);
SocketSourceThread runner = new SocketSourceThread(source, "test1", "check1", "check2");
runner.start();
// first connection: nothing
channel = server.accept();
channel.close();
// second connection: first string
channel = server.accept();
OutputStreamWriter writer = new OutputStreamWriter(channel.getOutputStream());
writer.write("te");
writer.close();
channel.close();
// third connection: nothing
channel = server.accept();
channel.close();
// forth connection: second string
channel = server.accept();
writer = new OutputStreamWriter(channel.getOutputStream());
writer.write("st1\n");
writer.write("check1\n");
writer.write("check2\n");
writer.flush();
runner.waitForNumElements(2);
runner.cancel();
runner.waitUntilDone();
} finally {
if (channel != null) {
IOUtils.closeQuietly(channel);
}
IOUtils.closeQuietly(server);
}
}
use of java.net.Socket in project flink by apache.
the class SocketTextStreamFunctionTest method testSocketSourceSimpleOutput.
@Test
public void testSocketSourceSimpleOutput() throws Exception {
ServerSocket server = new ServerSocket(0);
Socket channel = null;
try {
SocketTextStreamFunction source = new SocketTextStreamFunction(LOCALHOST, server.getLocalPort(), "\n", 0);
SocketSourceThread runner = new SocketSourceThread(source, "test1", "check");
runner.start();
channel = server.accept();
OutputStreamWriter writer = new OutputStreamWriter(channel.getOutputStream());
writer.write("test1\n");
writer.write("check\n");
writer.flush();
runner.waitForNumElements(2);
runner.cancel();
runner.interrupt();
runner.waitUntilDone();
channel.close();
} finally {
if (channel != null) {
IOUtils.closeQuietly(channel);
}
IOUtils.closeQuietly(server);
}
}
use of java.net.Socket in project flink by apache.
the class TestingFailingBlobServer method run.
@Override
public void run() {
// we do properly the first operation (PUT)
try {
new BlobServerConnection(getServerSocket().accept(), this).start();
} catch (Throwable t) {
t.printStackTrace();
}
// do some failing operations
for (int num = 0; num < numFailures && !isShutdown(); num++) {
Socket socket = null;
try {
socket = getServerSocket().accept();
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
// just abort everything
is.close();
os.close();
socket.close();
} catch (IOException e) {
} finally {
if (socket != null) {
try {
socket.close();
} catch (Throwable t) {
}
}
}
}
// regular runs
super.run();
}
Aggregations