use of java.io.PipedInputStream in project Hystrix by Netflix.
the class StreamingOutputProviderTest method testInfiniteOnNextStream.
@Test
public void testInfiniteOnNextStream() throws Exception {
final PipedInputStream is = new PipedInputStream();
final PipedOutputStream os = new PipedOutputStream(is);
final AtomicInteger writes = new AtomicInteger(0);
final HystrixStream stream = new HystrixStream(streamOfOnNexts, 100, new AtomicInteger(1));
Thread streamingThread = startStreamingThread(stream, os);
verifyStream(is, writes);
// Let the provider stream for some time.
Thread.sleep(1000);
// Stop streaming
streamingThread.interrupt();
os.close();
is.close();
System.out.println("Total lines:" + writes.get());
// Observable is configured to emit events in every 100 ms. So expect at least 9 in a second.
assertTrue(writes.get() >= 9);
// Provider is expected to decrement connection count when streaming process is terminated.
assertTrue(stream.getConcurrentConnections().get() == 0);
}
use of java.io.PipedInputStream in project Hystrix by Netflix.
the class StreamingOutputProviderTest method testStreamOnce.
private void testStreamOnce(Observable<String> observable) throws Exception {
final PipedInputStream is = new PipedInputStream();
final PipedOutputStream os = new PipedOutputStream(is);
final AtomicInteger writes = new AtomicInteger(0);
final HystrixStream stream = new HystrixStream(observable, 100, new AtomicInteger(1));
startStreamingThread(stream, os);
verifyStream(is, writes);
Thread.sleep(1000);
os.close();
is.close();
System.out.println("Total lines:" + writes.get());
assertTrue(writes.get() == 1);
assertTrue(stream.getConcurrentConnections().get() == 0);
}
use of java.io.PipedInputStream in project netty by netty.
the class CompactObjectSerializationTest method testInterfaceSerialization.
@Test
public void testInterfaceSerialization() throws Exception {
PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut);
CompactObjectOutputStream out = new CompactObjectOutputStream(pipeOut);
CompactObjectInputStream in = new CompactObjectInputStream(pipeIn, ClassResolvers.cacheDisabled(null));
out.writeObject(List.class);
Assert.assertSame(List.class, in.readObject());
}
use of java.io.PipedInputStream in project robovm by robovm.
the class Test method test_readObject_replacedClassDescriptor.
// Regression test for HARMONY-4996
public void test_readObject_replacedClassDescriptor() throws Exception {
ObjectStreamClass[] objs = new ObjectStreamClass[1000];
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
ObjectOutputStream oout = new TestObjectOutputStream(pout, objs);
oout.writeObject(new TestExtObject());
oout.writeObject("test");
oout.close();
ObjectInputStream oin = new TestObjectInputStream(pin, objs);
oin.readObject();
oin.readObject();
}
use of java.io.PipedInputStream in project robovm by robovm.
the class Test method test_readClassDescriptor_1.
/*
* Testing classDescriptor replacement with the value generated by
* ObjectStreamClass.lookup() method.
* Regression test for HARMONY-4638
*/
public void test_readClassDescriptor_1() throws IOException, ClassNotFoundException {
A a = new A();
a.name = "It's a test";
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
ObjectOutputStream out = new ObjectOutputStream(pout);
ObjectInputStream in = new ObjectIutputStreamWithReadDesc2(pin, A.class);
// test single object
out.writeObject(a);
A a1 = (A) in.readObject();
assertEquals("Single case: incorrectly read the field of A", a.name, a1.name);
// test cyclic reference
HashMap m = new HashMap();
a = new A();
a.name = "It's a test 0";
a1 = new A();
a1.name = "It's a test 1";
m.put("0", a);
m.put("1", a1);
out.writeObject(m);
HashMap m1 = (HashMap) in.readObject();
assertEquals("Incorrectly read the field of A", a.name, ((A) m1.get("0")).name);
assertEquals("Incorrectly read the field of A1", a1.name, ((A) m1.get("1")).name);
}
Aggregations