Search in sources :

Example 1 with StreamingReadVisitorToJSON

use of com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON in project PronghornPipes by oci-pronghorn.

the class StreamingConsumerTest method sequenceFragmentWriteRead.

@Test
public void sequenceFragmentWriteRead() {
    Pipe<MessageSchemaDynamic> ring = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    ring.initBuffers();
    int testSize = 5;
    // in this method we write two sequence members but only record the count after writing the members
    populateRingBufferWithSequence(ring, testSize);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    StreamingReadVisitor visitor = new StreamingReadVisitorToJSON(ps);
    // new StreamingReadVisitorDebugDelegate(visitor) );
    StreamingVisitorReader reader = new StreamingVisitorReader(ring, visitor);
    // ring is fully populated so we should not need to call this run again
    while (Pipe.contentRemaining(ring) > 0) {
        reader.run();
    }
    ps.close();
    String results = new String(baos.toByteArray());
    // spot check the produced JSON
    assertTrue(results, results.indexOf("\"TruckId\":10") > 0);
    assertTrue(results, results.indexOf("{\"AThing\":7}") > 0);
    assertTrue(results, results.indexOf("{\"JustOneMoreQuestion\":42}") > 0);
}
Also used : PrintStream(java.io.PrintStream) StreamingReadVisitorToJSON(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON) StreamingReadVisitor(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor) StreamingVisitorReader(com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with StreamingReadVisitorToJSON

use of com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON in project PronghornPipes by oci-pronghorn.

the class StreamingConsumerTest method generatorTest.

@Test
public void generatorTest() {
    final int seed = 2;
    // hard coded value that comes from this seed 2
    final long aLongValue = 2945688134060370505l;
    // hard coded value that comes from this seed 2
    final int aNegIntValue = -29;
    Pipe<MessageSchemaDynamic> ring = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), 50, 30));
    ring.initBuffers();
    StreamingWriteVisitorGenerator swvg = new StreamingWriteVisitorGenerator(FROM, new Random(seed), 30, 30);
    StreamingVisitorWriter svw = new StreamingVisitorWriter(ring, swvg);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);
    // PrintStream ps = System.out;
    StreamingReadVisitor visitor = new StreamingReadVisitorToJSON(ps);
    // , new StreamingReadVisitorDebugDelegate(visitor) );
    StreamingVisitorReader reader = new StreamingVisitorReader(ring, visitor);
    svw.startup();
    reader.startup();
    do {
        svw.run();
    } while (!svw.isAtBreakPoint());
    reader.run();
    svw.shutdown();
    reader.shutdown();
    byte[] byteArray = baos.toByteArray();
    assertTrue("No JSON was produced", byteArray.length > 0);
    String results = new String(byteArray);
    // spot check the produced JSON
    assertTrue(results, results.indexOf("\"Trucks\":") > 0);
    assertTrue(results, results.indexOf("{\"Squad\":") > 0);
    assertTrue(results, results.indexOf(Long.toString(aLongValue)) > 0);
    assertTrue(results, results.indexOf(Integer.toString(aNegIntValue)) > 0);
}
Also used : PrintStream(java.io.PrintStream) StreamingWriteVisitorGenerator(com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator) StreamingVisitorWriter(com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter) Pipe(com.ociweb.pronghorn.pipe.Pipe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamingReadVisitorToJSON(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON) Random(java.util.Random) StreamingReadVisitor(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor) StreamingVisitorReader(com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) Test(org.junit.Test)

Aggregations

MessageSchemaDynamic (com.ociweb.pronghorn.pipe.MessageSchemaDynamic)2 Pipe (com.ociweb.pronghorn.pipe.Pipe)2 StreamingReadVisitor (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor)2 StreamingReadVisitorToJSON (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorToJSON)2 StreamingVisitorReader (com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 Test (org.junit.Test)2 StreamingVisitorWriter (com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter)1 StreamingWriteVisitorGenerator (com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator)1 Random (java.util.Random)1