add tests for termination
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.github.nkzawa.engineio.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ExecutionTest extends Connection {
|
||||
|
||||
final static int TIMEOUT = 30 * 1000;
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void execConnection() throws InterruptedException, IOException {
|
||||
exec("com.github.nkzawa.engineio.client.executions.Connection");
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void execConnectionFailure() throws InterruptedException, IOException {
|
||||
exec("com.github.nkzawa.engineio.client.executions.ConnectionFailure");
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void execImmediateClose() throws InterruptedException, IOException {
|
||||
exec("com.github.nkzawa.engineio.client.executions.ImmediateClose");
|
||||
}
|
||||
|
||||
private void exec(String mainClass) throws InterruptedException, IOException {
|
||||
Process process = Runtime.getRuntime().exec(String.format("mvn --quiet exec:java" +
|
||||
" -Dexec.mainClass=%s -Dexec.classpathScope=test", mainClass), createEnv());
|
||||
BufferedReader input = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = input.readLine()) != null) {
|
||||
System.out.println("EXEC OUT: " + line);
|
||||
}
|
||||
process.waitFor();
|
||||
assertThat(process.exitValue(), is(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.github.nkzawa.engineio.client.executions;
|
||||
|
||||
import com.github.nkzawa.emitter.Emitter;
|
||||
import com.github.nkzawa.engineio.client.Socket;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
public class Connection {
|
||||
|
||||
public static void main(String[] args) throws URISyntaxException {
|
||||
Map<String, String> env = System.getenv();
|
||||
final Socket socket = new Socket("http://localhost:" + env.get("PORT"));
|
||||
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("open");
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
socket.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.github.nkzawa.engineio.client.executions;
|
||||
|
||||
import com.github.nkzawa.emitter.Emitter;
|
||||
import com.github.nkzawa.engineio.client.Socket;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConnectionFailure {
|
||||
|
||||
public static void main(String[] args) throws URISyntaxException {
|
||||
Map<String, String> env = System.getenv();
|
||||
int port = Integer.parseInt(env.get("PORT"));
|
||||
port++;
|
||||
final Socket socket = new Socket("http://localhost:" + port);
|
||||
socket.on(Socket.EVENT_CLOSE, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("close");
|
||||
}
|
||||
}).on(Socket.EVENT_ERROR, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("error");
|
||||
}
|
||||
});
|
||||
socket.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.github.nkzawa.engineio.client.executions;
|
||||
|
||||
import com.github.nkzawa.emitter.Emitter;
|
||||
import com.github.nkzawa.engineio.client.Socket;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImmediateClose {
|
||||
|
||||
public static void main(String[] args) throws URISyntaxException {
|
||||
Map<String, String> env = System.getenv();
|
||||
final Socket socket = new Socket("http://localhost:" + env.get("PORT"));
|
||||
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("open");
|
||||
}
|
||||
}).on(Socket.EVENT_CLOSE, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("close");
|
||||
}
|
||||
});
|
||||
socket.open();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user