Search in sources :

Example 11 with PipedInputStream

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);
}
Also used : HystrixStream(com.netflix.hystrix.contrib.metrics.HystrixStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Example 12 with PipedInputStream

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);
}
Also used : HystrixStream(com.netflix.hystrix.contrib.metrics.HystrixStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream)

Example 13 with PipedInputStream

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());
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.Test)

Example 14 with PipedInputStream

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();
}
Also used : PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectStreamClass(java.io.ObjectStreamClass) ObjectInputStream(java.io.ObjectInputStream)

Example 15 with PipedInputStream

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);
}
Also used : HashMap(java.util.HashMap) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

PipedInputStream (java.io.PipedInputStream)122 PipedOutputStream (java.io.PipedOutputStream)118 IOException (java.io.IOException)38 Test (org.junit.Test)33 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)21 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)21 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)17 TypeToken (com.google.common.reflect.TypeToken)17 DataInputStream (java.io.DataInputStream)13 DataOutputStream (java.io.DataOutputStream)13 InputStream (java.io.InputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Before (org.junit.Before)10 OutputStream (java.io.OutputStream)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 PrintStream (java.io.PrintStream)7 InputStreamReader (java.io.InputStreamReader)6 ImmutableList (com.google.common.collect.ImmutableList)5 List (java.util.List)5 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)5