remoteProxy = (T) ServiceEndpoints.toServiceObject(remoteEndpoint, (Collection<Class<?>>) (Object) remoteInterfaces, classLoader); StreamMessageProducer reader = new StreamMessageProducer(input, jsonHandler, remoteEndpoint); MessageConsumer messageConsumer = wrapMessageConsumer(remoteEndpoint); ExecutorService execService = executorService != null ? executorService : Executors.newCachedThreadPool();
StreamMessageProducer reader = new StreamMessageProducer(input, jsonHandler, remoteEndpoint); MessageConsumer messageConsumer = wrapMessageConsumer(remoteEndpoint); ExecutorService execService = executorService != null ? executorService : Executors.newCachedThreadPool();
@Test public void testStopOnSocketClosed() throws Throwable { executorService.submit(() -> { InputStream input = new InputStream() { @Override public int read() throws IOException { throw new SocketException("Socket closed"); } }; MessageJsonHandler jsonHandler = new MessageJsonHandler(Collections.emptyMap()); StreamMessageProducer messageProducer = new StreamMessageProducer(input, jsonHandler); messageProducer.listen(message -> {}); messageProducer.close(); }).get(TIMEOUT, TimeUnit.MILLISECONDS); }
@Test public void testStopOnInterrrupt() throws Exception { executorService.submit(() -> { InputStream input = new InputStream() { @Override public int read() throws IOException { throw new InterruptedIOException(); } }; MessageJsonHandler jsonHandler = new MessageJsonHandler(Collections.emptyMap()); StreamMessageProducer messageProducer = new StreamMessageProducer(input, jsonHandler); messageProducer.listen(message -> {}); messageProducer.close(); }).get(TIMEOUT, TimeUnit.MILLISECONDS); }
@Test public void testStopOnChannelClosed() throws Exception { executorService.submit(() -> { InputStream input = new InputStream() { @Override public int read() throws IOException { throw new ClosedChannelException(); } }; MessageJsonHandler jsonHandler = new MessageJsonHandler(Collections.emptyMap()); StreamMessageProducer messageProducer = new StreamMessageProducer(input, jsonHandler); messageProducer.listen(message -> {}); messageProducer.close(); }).get(TIMEOUT, TimeUnit.MILLISECONDS); }
@Test(expected=JsonRpcException.class) public void testIOException() throws Throwable { try { executorService.submit(() -> { InputStream input = new InputStream() { @Override public int read() throws IOException { throw new SocketException("Permission denied: connect"); } }; MessageJsonHandler jsonHandler = new MessageJsonHandler(Collections.emptyMap()); StreamMessageProducer messageProducer = new StreamMessageProducer(input, jsonHandler); messageProducer.listen(message -> {}); messageProducer.close(); }).get(TIMEOUT, TimeUnit.MILLISECONDS); } catch (ExecutionException e) { throw e.getCause(); } }