compatible with engine.io-client 1.2.2
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package com.github.nkzawa.engineio.client;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public abstract class Connection {
|
||||
|
||||
final static int TIMEOUT = 3000;
|
||||
final static int PORT = 3000;
|
||||
|
||||
private Process serverProcess;
|
||||
private ExecutorService serverService;
|
||||
private Future serverOutout;
|
||||
private Future serverError;
|
||||
|
||||
@Before
|
||||
public void startServer() throws IOException, InterruptedException {
|
||||
System.out.println("Starting server ...");
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
serverProcess = Runtime.getRuntime().exec(
|
||||
"node src/test/resources/index.js " + PORT, new String[] {"DEBUG=engine*"});
|
||||
serverService = Executors.newCachedThreadPool();
|
||||
serverOutout = serverService.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(serverProcess.getInputStream()));
|
||||
String line;
|
||||
try {
|
||||
line = reader.readLine();
|
||||
latch.countDown();
|
||||
do {
|
||||
System.out.println("SERVER OUT: " + line);
|
||||
} while ((line = reader.readLine()) != null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
serverError = serverService.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(serverProcess.getErrorStream()));
|
||||
String line;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.err.println("SERVER ERR: " + line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
latch.await(3000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopServer() throws InterruptedException {
|
||||
System.out.println("Stopping server ...");
|
||||
serverProcess.destroy();
|
||||
serverOutout.cancel(true);
|
||||
serverError.cancel(true);
|
||||
serverService.shutdown();
|
||||
serverService.awaitTermination(3000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user