Search in sources :

Example 1 with StreamingWriteVisitorGenerator

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

the class GenerativeTest method buildPopulatedRing.

public Pipe buildPopulatedRing(FieldReferenceOffsetManager from, PipeConfig rbConfig, int commonSeed, int iterations) {
    int i;
    Pipe ring2 = new Pipe(rbConfig);
    ring2.initBuffers();
    StreamingWriteVisitorGenerator swvg2 = new StreamingWriteVisitorGenerator(from, new Random(commonSeed), varLength, varLength);
    StreamingVisitorWriter svw2 = new StreamingVisitorWriter(ring2, swvg2);
    svw2.startup();
    i = iterations;
    while (--i > 0) {
        svw2.run();
    }
    return ring2;
}
Also used : StreamingWriteVisitorGenerator(com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator) StreamingVisitorWriter(com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter) Random(java.util.Random) Pipe(com.ociweb.pronghorn.pipe.Pipe)

Example 2 with StreamingWriteVisitorGenerator

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

the class StreamingConsumerTest method matchingTestPositive.

@Test
public void matchingTestPositive() {
    Pipe<MessageSchemaDynamic> ring1 = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    Pipe<MessageSchemaDynamic> ring2 = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    ring1.initBuffers();
    ring2.initBuffers();
    int commonSeed = 100;
    StreamingWriteVisitorGenerator swvg1 = new StreamingWriteVisitorGenerator(FROM, new Random(commonSeed), 30, 30);
    StreamingVisitorWriter svw1 = new StreamingVisitorWriter(ring1, swvg1);
    StreamingWriteVisitorGenerator swvg2 = new StreamingWriteVisitorGenerator(FROM, new Random(commonSeed), 30, 30);
    StreamingVisitorWriter svw2 = new StreamingVisitorWriter(ring2, swvg2);
    svw1.startup();
    svw2.startup();
    svw1.run();
    svw2.run();
    svw1.run();
    svw2.run();
    // confirm that both rings contain the exact same thing
    assertTrue(Arrays.equals(Pipe.primaryBuffer(ring1), Pipe.primaryBuffer(ring2)));
    assertTrue(Arrays.equals(Pipe.byteBuffer(ring1), Pipe.byteBuffer(ring2)));
    // now use matcher to confirm the same.
    StreamingReadVisitorMatcher srvm = new StreamingReadVisitorMatcher(ring1);
    // new StreamingReadVisitorDebugDelegate(srvm) );
    StreamingVisitorReader svr = new StreamingVisitorReader(ring2, srvm);
    svr.startup();
    try {
        svr.run();
    } catch (Throwable t) {
        t.printStackTrace();
        fail(t.getMessage());
    }
    svr.shutdown();
    svw1.shutdown();
    svw2.shutdown();
}
Also used : StreamingWriteVisitorGenerator(com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator) StreamingVisitorWriter(com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter) Random(java.util.Random) StreamingVisitorReader(com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) StreamingReadVisitorMatcher(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorMatcher) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 3 with StreamingWriteVisitorGenerator

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

the class StreamingConsumerTest method matchingTestNegative.

@Test
public void matchingTestNegative() {
    Pipe<MessageSchemaDynamic> ring1 = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), 1 << primaryRingSizeInBits, 1 << byteRingSizeInBits));
    Pipe<MessageSchemaDynamic> ring2 = new Pipe<MessageSchemaDynamic>(new PipeConfig<MessageSchemaDynamic>(new MessageSchemaDynamic(FROM), primaryRingSizeInBits, byteRingSizeInBits));
    ring1.initBuffers();
    ring2.initBuffers();
    int commonSeed = 300;
    StreamingWriteVisitorGenerator swvg1 = new StreamingWriteVisitorGenerator(FROM, new Random(commonSeed), 30, 30);
    StreamingVisitorWriter svw1 = new StreamingVisitorWriter(ring1, swvg1);
    StreamingWriteVisitorGenerator swvg2 = new StreamingWriteVisitorGenerator(FROM, new Random(commonSeed + 1), 30, 30);
    StreamingVisitorWriter svw2 = new StreamingVisitorWriter(ring2, swvg2);
    svw1.startup();
    svw2.startup();
    svw1.run();
    svw2.run();
    svw1.run();
    svw2.run();
    StreamingReadVisitorMatcher srvm = new StreamingReadVisitorMatcher(ring1);
    StreamingVisitorReader svr = new StreamingVisitorReader(ring2, srvm);
    svr.startup();
    try {
        svr.run();
        fail("expected exception");
    } catch (Throwable t) {
    // success
    // t.printStackTrace();
    }
    svr.shutdown();
    svw1.shutdown();
    svw2.shutdown();
}
Also used : StreamingWriteVisitorGenerator(com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator) StreamingVisitorWriter(com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter) Random(java.util.Random) StreamingVisitorReader(com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader) MessageSchemaDynamic(com.ociweb.pronghorn.pipe.MessageSchemaDynamic) StreamingReadVisitorMatcher(com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorMatcher) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 4 with StreamingWriteVisitorGenerator

use of com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator 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)

Example 5 with StreamingWriteVisitorGenerator

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

the class PipeMultiTemplateTest method buildPopulatedRing.

public Pipe buildPopulatedRing(FieldReferenceOffsetManager from, PipeConfig rbConfig, int commonSeed, int iterations, int varLength) {
    int i;
    Pipe ring2 = new Pipe(rbConfig);
    ring2.initBuffers();
    StreamingWriteVisitorGenerator swvg2 = new StreamingWriteVisitorGenerator(from, new Random(commonSeed), varLength, varLength);
    StreamingVisitorWriter svw2 = new StreamingVisitorWriter(ring2, swvg2);
    svw2.startup();
    i = iterations;
    while (--i >= 0 || !svw2.isAtBreakPoint()) {
        svw2.run();
    }
    svw2.shutdown();
    return ring2;
}
Also used : StreamingWriteVisitorGenerator(com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator) StreamingVisitorWriter(com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter) Random(java.util.Random)

Aggregations

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