test: shutdown okhttpclient
This commit is contained in:
@@ -17,7 +17,7 @@ public class ExecutionTest extends Connection {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Socket.class.getName());
|
||||
|
||||
final static int TIMEOUT = 100 * 1000;
|
||||
final static int TIMEOUT = 30 * 1000;
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void execConnection() throws InterruptedException, IOException {
|
||||
|
||||
@@ -2,13 +2,19 @@ package io.socket.engineio.client.executions;
|
||||
|
||||
import io.socket.emitter.Emitter;
|
||||
import io.socket.engineio.client.Socket;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class Connection {
|
||||
|
||||
public static void main(String[] args) throws URISyntaxException {
|
||||
final Socket socket = new Socket("http://localhost:" + System.getenv("PORT"));
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.webSocketFactory = client;
|
||||
opts.callFactory = client;
|
||||
|
||||
final Socket socket = new Socket("http://localhost:" + System.getenv("PORT"), opts);
|
||||
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
@@ -16,6 +22,12 @@ public class Connection {
|
||||
socket.close();
|
||||
}
|
||||
});
|
||||
socket.on(Socket.EVENT_CLOSE, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
client.dispatcher().executorService().shutdown();
|
||||
}
|
||||
});
|
||||
socket.open();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,21 @@ package io.socket.engineio.client.executions;
|
||||
|
||||
import io.socket.emitter.Emitter;
|
||||
import io.socket.engineio.client.Socket;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class ConnectionFailure {
|
||||
|
||||
public static void main(String[] args) throws URISyntaxException {
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.webSocketFactory = client;
|
||||
opts.callFactory = client;
|
||||
|
||||
int port = Integer.parseInt(System.getenv("PORT"));
|
||||
port++;
|
||||
final Socket socket = new Socket("http://localhost:" + port);
|
||||
final Socket socket = new Socket("http://localhost:" + port, opts);
|
||||
socket.on(Socket.EVENT_CLOSE, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
@@ -20,6 +26,7 @@ public class ConnectionFailure {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("error");
|
||||
client.dispatcher().executorService().shutdown();
|
||||
}
|
||||
});
|
||||
socket.open();
|
||||
|
||||
@@ -2,13 +2,19 @@ package io.socket.engineio.client.executions;
|
||||
|
||||
import io.socket.emitter.Emitter;
|
||||
import io.socket.engineio.client.Socket;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class ImmediateClose {
|
||||
|
||||
public static void main(String[] args) throws URISyntaxException {
|
||||
final Socket socket = new Socket("http://localhost:" + System.getenv("PORT"));
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
Socket.Options opts = new Socket.Options();
|
||||
opts.webSocketFactory = client;
|
||||
opts.callFactory = client;
|
||||
|
||||
final Socket socket = new Socket("http://localhost:" + System.getenv("PORT"), opts);
|
||||
socket.on(Socket.EVENT_OPEN, new Emitter.Listener() {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
@@ -18,6 +24,7 @@ public class ImmediateClose {
|
||||
@Override
|
||||
public void call(Object... args) {
|
||||
System.out.println("close");
|
||||
client.dispatcher().executorService().shutdown();
|
||||
}
|
||||
});
|
||||
socket.open();
|
||||
|
||||
Reference in New Issue
Block a user