/** Test the "local-write remote-read" pipe. */ public void testLocalWrite() throws Exception { Pipe p = Pipe.createLocalToRemote(); Future<Integer> f = channel.callAsync(new ReadingCallable(p)); write(p); int r = f.get(); System.out.println("result=" + r); assertEquals(5, r); }
public void testLocalWrite2() throws Exception { Pipe p = Pipe.createLocalToRemote(); Future<Integer> f = channel.callAsync(new ReadingCallable(p)); Thread.sleep(2000); // wait for remote to connect to local. write(p); int r = f.get(); System.out.println("result=" + r); assertEquals(5, r); }
/** Writer end closes even before the remote computation kicks in. */ public void testQuickBurstWrite() throws Exception { final Pipe p = Pipe.createLocalToRemote(); Future<Integer> f = channel.callAsync( new Callable<Integer, IOException>() { public Integer call() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(p.getIn(), baos); return baos.size(); } }); OutputStream os = p.getOut(); os.write(1); os.close(); // at this point the async executable kicks in. // TODO: introduce a lock to ensure the ordering. assertEquals(1, (int) f.get()); }
public void testSaturation() throws Exception { if (channelRunner instanceof InProcessCompatibilityMode) return; // can't do this test without the throttling support. final Pipe p = Pipe.createLocalToRemote(); Thread writer = new Thread() { @Override public void run() { OutputStream os = p.getOut(); try { byte[] buf = new byte[Channel.PIPE_WINDOW_SIZE * 2 + 1]; os.write(buf); } catch (IOException e) { e.printStackTrace(); } } }; // 1. wait until the receiver sees the first byte. at this point the pipe should be completely // clogged // 2. make sure the writer thread is still alive, blocking // 3. read the rest ISaturationTest target = channel.call(new CreateSaturationTestProxy(p)); // make sure the pipe is connected target.ensureConnected(); writer.start(); // make sure that some data arrived to the receiver // at this point the pipe should be fully clogged assertEquals(0, target.readFirst()); // the writer should be still blocked Thread.sleep(1000); assertTrue(writer.isAlive()); target.readRest(); }