Search in sources :

Example 21 with Pipe

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

the class JSONParserTest method arrayTest.

@Test
public void arrayTest() {
    String json = " [ { \"key\" : \"value\" } , \n { \"key\" : \"value\" }     ] ";
    Pipe pipe = buildPopulatedPipe(json);
    TrieParserReader reader = JSONParser.newReader();
    StringBuilder target = new StringBuilder();
    JSONVisitor visitor = new JSONVisitorCapture(target);
    int msgIdx = Pipe.takeMsgIdx(pipe);
    JSONParser.parse(pipe, reader, visitor);
    assertEquals("[{key:value},{key:value}]", target.toString());
}
Also used : JSONVisitor(com.ociweb.pronghorn.util.parse.JSONVisitor) JSONVisitorCapture(com.ociweb.pronghorn.util.parse.JSONVisitorCapture) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 22 with Pipe

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

the class JSONParserTest method streamingArrayTest.

@Test
public void streamingArrayTest() {
    String json = " [ { \"key\" : \"value\" } , \n { \"key\" : \"value\" }     ] ";
    Pipe pipe = buildPopulatedPipe(json);
    TrieParserReader reader = new TrieParserReader(2);
    int msgIdx = Pipe.takeMsgIdx(pipe);
    TrieParserReader.parseSetup(reader, pipe);
    StringBuilder target = new StringBuilder();
    JSONStreamVisitor visitor = new JSONStreamVisitorCapture(target);
    Pipe.takeMsgIdx(pipe);
    JSONStreamParser parser = new JSONStreamParser();
    parser.parse(reader, visitor);
    assertEquals(target.toString().replaceAll("\n", "\\n"), "[{\n    \"key\":\"value\"}\n,\n{\n    \"key\":\"value\"}\n]", target.toString());
}
Also used : JSONStreamVisitor(com.ociweb.pronghorn.util.parse.JSONStreamVisitor) JSONStreamParser(com.ociweb.pronghorn.util.parse.JSONStreamParser) Pipe(com.ociweb.pronghorn.pipe.Pipe) JSONStreamVisitorCapture(com.ociweb.pronghorn.util.parse.JSONStreamVisitorCapture) Test(org.junit.Test)

Example 23 with Pipe

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

the class JSONParserTest method simpleTest.

@Test
public void simpleTest() {
    String json = " { \"key\" : \"value\" }  ";
    Pipe pipe = buildPopulatedPipe(json);
    TrieParserReader reader = JSONParser.newReader();
    StringBuilder target = new StringBuilder();
    JSONVisitor visitor = new JSONVisitorCapture(target);
    int msgIdx = Pipe.takeMsgIdx(pipe);
    JSONParser.parse(pipe, reader, visitor);
    assertEquals("{key:value}", target.toString());
}
Also used : JSONVisitor(com.ociweb.pronghorn.util.parse.JSONVisitor) JSONVisitorCapture(com.ociweb.pronghorn.util.parse.JSONVisitorCapture) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Example 24 with Pipe

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

the class JSONParserTest method buildPopulatedPipe.

private Pipe buildPopulatedPipe(String json) {
    Pipe pipe = new Pipe(new PipeConfig(RawDataSchema.instance));
    pipe.initBuffers();
    int size = Pipe.addMsgIdx(pipe, 0);
    DataOutputBlobWriter output = pipe.outputStream(pipe);
    output.openField();
    output.append(json);
    output.closeLowLevelField();
    Pipe.confirmLowLevelWrite(pipe, size);
    Pipe.publishWrites(pipe);
    return pipe;
}
Also used : PipeConfig(com.ociweb.pronghorn.pipe.PipeConfig) DataOutputBlobWriter(com.ociweb.pronghorn.pipe.DataOutputBlobWriter) Pipe(com.ociweb.pronghorn.pipe.Pipe)

Example 25 with Pipe

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

the class JSONParserTest method complexTest.

@Test
public void complexTest() {
    String json = " { \"key\" : \"value\" \n, \"key2\" : \"value2\"}  ";
    Pipe pipe = buildPopulatedPipe(json);
    TrieParserReader reader = JSONParser.newReader();
    StringBuilder target = new StringBuilder();
    JSONVisitor visitor = new JSONVisitorCapture(target);
    int msgIdx = Pipe.takeMsgIdx(pipe);
    JSONParser.parse(pipe, reader, visitor);
    assertEquals("{key:value,key2:value2}", target.toString());
}
Also used : JSONVisitor(com.ociweb.pronghorn.util.parse.JSONVisitor) JSONVisitorCapture(com.ociweb.pronghorn.util.parse.JSONVisitorCapture) Pipe(com.ociweb.pronghorn.pipe.Pipe) Test(org.junit.Test)

Aggregations

Pipe (com.ociweb.pronghorn.pipe.Pipe)42 PipeConfig (com.ociweb.pronghorn.pipe.PipeConfig)19 Test (org.junit.Test)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Ignore (org.junit.Ignore)7 MessageSchemaDynamic (com.ociweb.pronghorn.pipe.MessageSchemaDynamic)5 IOException (java.io.IOException)5 StreamingVisitorReader (com.ociweb.pronghorn.pipe.stream.StreamingVisitorReader)4 StreamingVisitorWriter (com.ociweb.pronghorn.pipe.stream.StreamingVisitorWriter)4 StreamingWriteVisitorGenerator (com.ociweb.pronghorn.pipe.stream.StreamingWriteVisitorGenerator)4 Random (java.util.Random)4 RingInputStream (com.ociweb.pronghorn.pipe.stream.RingInputStream)3 JSONVisitor (com.ociweb.pronghorn.util.parse.JSONVisitor)3 JSONVisitorCapture (com.ociweb.pronghorn.util.parse.JSONVisitorCapture)3 NetPayloadSchema (com.ociweb.pronghorn.network.schema.NetPayloadSchema)2 DataOutputBlobWriter (com.ociweb.pronghorn.pipe.DataOutputBlobWriter)2 RawDataSchema (com.ociweb.pronghorn.pipe.RawDataSchema)2 RingOutputStream (com.ociweb.pronghorn.pipe.stream.RingOutputStream)2 StreamingReadVisitor (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitor)2 StreamingReadVisitorMatcher (com.ociweb.pronghorn.pipe.stream.StreamingReadVisitorMatcher)2