Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions test/org/rascalmpl/test/rpc/IValueOverJsonTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -72,6 +73,7 @@ public class IValueOverJsonTests {
private JsonRpcTestInterface testServer;
private final PipedInputStream is0, is1;
private final PipedOutputStream os0, os1;
private final ExecutorService exec = Executors.newCachedThreadPool();

@Parameters(name="{0}")
public static Iterable<Object[]> modesAndConfig() {
Expand All @@ -92,7 +94,7 @@ public IValueOverJsonTests(ComplexTypeMode complexTypeMode, Consumer<GsonBuilder
os0 = new PipedOutputStream();
is1 = new PipedInputStream(os0);
os1 = new PipedOutputStream(is0);
new TestThread(is0, os0, gsonConfig).start();
new TestThread(is0, os0, gsonConfig, exec).start();
new TestClient(is1, os1, gsonConfig);
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -101,6 +103,7 @@ public IValueOverJsonTests(ComplexTypeMode complexTypeMode, Consumer<GsonBuilder

@After
public void teardown() throws IOException {
exec.shutdown();
if (is0 != null) {
is0.close();
}
Expand All @@ -118,12 +121,16 @@ public void teardown() throws IOException {
class TestClient {
public TestClient(InputStream is, OutputStream os, Consumer<GsonBuilder> gsonConfig) {
Launcher<JsonRpcTestInterface> clientLauncher = new Launcher.Builder<JsonRpcTestInterface>()
.setRemoteInterface(JsonRpcTestInterface.class)
.setLocalService(this)
.setRemoteInterface(JsonRpcTestInterface.class)
.setInput(is)
.setOutput(os)
.configureGson(gsonConfig)
.setExecutorService(Executors.newCachedThreadPool())
.setExceptionHandler(e -> {
System.err.println(e);
return new ResponseError(ResponseErrorCode.InternalError, e.getMessage(), e);
})
.setExecutorService(exec)
.create();

clientLauncher.startListening();
Expand All @@ -135,11 +142,13 @@ static class TestThread extends Thread {
private final InputStream is;
private final OutputStream os;
private final Consumer<GsonBuilder> gsonConfig;
private final ExecutorService exec;

public TestThread(InputStream is, OutputStream os, Consumer<GsonBuilder> gsonConfig) {
public TestThread(InputStream is, OutputStream os, Consumer<GsonBuilder> gsonConfig, ExecutorService exec) {
this.is = is;
this.os = os;
this.gsonConfig = gsonConfig;
this.exec = exec;
this.setDaemon(true);
}

Expand All @@ -155,13 +164,14 @@ public void run() {
System.err.println(e);
return new ResponseError(ResponseErrorCode.InternalError, e.getMessage(), e);
})
.setExecutorService(exec)
.create();

serverLauncher.startListening();
}
}

private static Set<ComplexTypeMode> asJsonObjectOrNotSupported = new HashSet<>(Arrays.asList(ComplexTypeMode.ENCODE_AS_JSON_OBJECT, ComplexTypeMode.NOT_SUPPORTED));
private static final Set<ComplexTypeMode> asJsonObjectOrNotSupported = new HashSet<>(Arrays.asList(ComplexTypeMode.ENCODE_AS_JSON_OBJECT, ComplexTypeMode.NOT_SUPPORTED));

private <T extends IValue> void runTestForPrimitiveType(String type, Supplier<T> supplier, Function<T, CompletableFuture<T>> function) {
expectSuccessful(type, supplier, function);
Expand Down
Loading