Search in sources :

Example 6 with RawDataSchema

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

the class JSONParseTest method simple2DArrayParseTest.

@Test
public void simple2DArrayParseTest() {
    Pipe<RawDataSchema> targetData = parseJSON(simple2DArrayExample, simple2DArrayExtractor);
    // confirm data on the pipe is good...
    Pipe.takeMsgIdx(targetData);
    ChannelReader dataStream = (ChannelReader) Pipe.openInputStream(targetData);
    long header = dataStream.readPackedLong();
    assertEquals(0, header);
    assertEquals(2, dataStream.readPackedInt());
    assertEquals(5, dataStream.readPackedInt());
    assertEquals(2, dataStream.readPackedInt());
    assertEquals("one", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("two", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("three", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("four", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("five", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("six", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("seven", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals(2, dataStream.readPackedInt());
    assertEquals(5, dataStream.readPackedInt());
    assertEquals(2, dataStream.readPackedInt());
    assertEquals(1, dataStream.readPackedLong());
    assertEquals(2, dataStream.readPackedLong());
    assertEquals(3, dataStream.readPackedLong());
    assertEquals(4, dataStream.readPackedLong());
    assertEquals(5, dataStream.readPackedLong());
    assertEquals(6, dataStream.readPackedLong());
    assertEquals(7, dataStream.readPackedLong());
    assertEquals(0, dataStream.available());
}
Also used : RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) ChannelReader(com.ociweb.pronghorn.pipe.ChannelReader) Test(org.junit.Test)

Example 7 with RawDataSchema

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

the class TrieParserTest method testwriteCapturedUTF8ToPipe.

@Test
public void testwriteCapturedUTF8ToPipe() throws IOException {
    TrieParserReader reader = new TrieParserReader(3);
    TrieParser map = new TrieParser(16);
    // map.setValue(wrapping(dataBytesExtractStart,4), 0,
    // dataBytesExtractStart.length, 15, value2);
    map.setUTF8Value("%b1234", 33);
    CharSequence test1 = "abcd1234";
    reader.query(map, test1);
    Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64);
    pipe.initBuffers();
    int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1);
    DataOutputBlobWriter x = Pipe.outputStream(pipe);
    DataOutputBlobWriter.openField(x);
    // just like in test above, will return the number of captured bytes 4
    // in this case(abcd).
    int num = TrieParserReader.writeCapturedUTF8ToPipe(reader, pipe, 0, RawDataSchema.MSG_CHUNKEDSTREAM_1_FIELD_BYTEARRAY_2);
    x.closeLowLevelField();
    Pipe.confirmLowLevelWrite(pipe, size);
    Pipe.publishWrites(pipe);
    // /////////
    int msg = Pipe.takeMsgIdx(pipe);
    assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg);
    DataInputBlobReader y = Pipe.inputStream(pipe);
    y.openLowLevelAPIField();
    StringBuilder str = new StringBuilder();
    y.readUTFOfLength(y.available(), str);
    Pipe.confirmLowLevelRead(pipe, size);
    Pipe.releaseReadLock(pipe);
    assertEquals(num, 4);
}
Also used : RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) DataInputBlobReader(com.ociweb.pronghorn.pipe.DataInputBlobReader) DataOutputBlobWriter(com.ociweb.pronghorn.pipe.DataOutputBlobWriter) Test(org.junit.Test)

Example 8 with RawDataSchema

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

the class TrieParserTest method testwriteCapturedUTF8.

@Test
public void testwriteCapturedUTF8() {
    TrieParserReader reader = new TrieParserReader(3);
    TrieParser map = new TrieParser(16);
    map.setUTF8Value("12%b1234", 33);
    CharSequence test = "12abcd1234";
    // query holds most recent thing
    reader.query(map, test);
    Pipe<RawDataSchema> pipe = RawDataSchema.instance.newPipe(2, 64);
    pipe.initBuffers();
    int size = Pipe.addMsgIdx(pipe, RawDataSchema.MSG_CHUNKEDSTREAM_1);
    DataOutputBlobWriter x = Pipe.outputStream(pipe);
    DataOutputBlobWriter.openField(x);
    // will append "abcd" to blobWriter
    int val = TrieParserReader.writeCapturedUTF8(reader, 0, x);
    x.closeLowLevelField();
    Pipe.confirmLowLevelWrite(pipe, size);
    Pipe.publishWrites(pipe);
    // /////////
    int msg = Pipe.takeMsgIdx(pipe);
    assertEquals(RawDataSchema.MSG_CHUNKEDSTREAM_1, msg);
    DataInputBlobReader y = Pipe.inputStream(pipe);
    y.openLowLevelAPIField();
    StringBuilder str = new StringBuilder();
    y.readUTFOfLength(y.available(), str);
    // value of blobwriter sent to stringbuilder to sompare with other
    // string
    assertEquals(str.toString().trim(), "abcd");
}
Also used : RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) DataInputBlobReader(com.ociweb.pronghorn.pipe.DataInputBlobReader) DataOutputBlobWriter(com.ociweb.pronghorn.pipe.DataOutputBlobWriter) Test(org.junit.Test)

Example 9 with RawDataSchema

use of com.ociweb.pronghorn.pipe.RawDataSchema in project FogLight-Examples by oci-pronghorn.

the class UARTDataParserTest method ParserStageTest.

@Test
public void ParserStageTest() {
    GraphManager gm = new GraphManager();
    Pipe<RawDataSchema> input = RawDataSchema.instance.newPipe(4, 512);
    Pipe<ValveSchema> filter = ValveSchema.instance.newPipe(64, 128);
    Pipe<ValveSchema> output = ValveSchema.instance.newPipe(64, 128);
    ByteArrayOutputStream results = new ByteArrayOutputStream();
    ValveDataParserStage.newInstance(gm, input, filter);
    FilterStage.newInstance(gm, filter, output);
    ConsoleJSONDumpStage.newInstance(gm, output, new PrintStream(results));
    // MonitorConsoleStage.attach(gm);
    NonThreadScheduler scheduler = new NonThreadScheduler(gm);
    scheduler.startup();
    // ////////////////
    // //setup the test data
    // ////////////////
    Pipe.addMsgIdx(input, RawDataSchema.MSG_CHUNKEDSTREAM_1);
    String message = "587lf5pf\"L\"vf0sp55] [" + "st1" + "sn100100" + "pn\"NX-DCV-SM-BLU-1-1-VO-L1-SO-OO\"" + "lr-100" + "cc184587" + "lf0" + "pf\"L\"" + "vf0" + "sp80" + "vf0" + "sp42" + "]";
    Pipe.addUTF8(message, input);
    Pipe.confirmLowLevelWrite(input, Pipe.sizeOf(input, RawDataSchema.MSG_CHUNKEDSTREAM_1));
    Pipe.publishWrites(input);
    // ////////////////
    int i = 1000;
    while (--i >= 0) {
        scheduler.run();
    }
    scheduler.shutdown();
    // //////////////
    // /confirm the results
    // //////////////
    String stringResults = new String(results.toByteArray());
    // for debug to inspect the values
    System.err.println(stringResults);
    assertFalse(stringResults.contains("55"));
    assertTrue(stringResults.contains("{\"PartNumber\":\"NX-DCV-SM-BLU-1-1-VO-L1-SO-OO\"}"));
    assertTrue(stringResults.contains("{\"ResidualOfDynamicAnalysis\":4294967196}"));
    int firstSP = stringResults.indexOf("{\"SupplyPressure\":80}");
    assertTrue(firstSP != -1);
    int secondSP = stringResults.indexOf("{\"SupplyPressure\":42}", firstSP + 1);
    assertTrue(secondSP != -1);
    int firstVP = stringResults.indexOf("{\"ValveFault\":0}");
    assertTrue(firstVP != -1);
    int secondVP = stringResults.indexOf("{\"ValveFault\":0}", firstVP + 1);
    assertTrue(secondVP == -1);
}
Also used : PrintStream(java.io.PrintStream) NonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.NonThreadScheduler) RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) GraphManager(com.ociweb.pronghorn.stage.scheduling.GraphManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ValveSchema(com.ociweb.iot.valveManifold.schema.ValveSchema) Test(org.junit.Test)

Example 10 with RawDataSchema

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

the class JSONParseTest method simpleArrayNullParseTest.

@Test
public void simpleArrayNullParseTest() {
    Pipe<RawDataSchema> targetData = parseJSON(simpleArrayNullExample, simpleArrayExtractor);
    // confirm data on the pipe is good...
    Pipe.takeMsgIdx(targetData);
    ChannelReader dataStream = (ChannelReader) Pipe.openInputStream(targetData);
    long header = dataStream.readPackedLong();
    assertEquals(0, header);
    assertEquals(5, dataStream.readPackedInt());
    // these are 19 bytes plus 10, 29
    assertEquals("one", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals(null, dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals(null, dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("four", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals("five", dataStream.readUTFOfLength(dataStream.readPackedInt()));
    assertEquals(5, dataStream.readPackedInt());
    assertEquals(1, dataStream.readPackedLong());
    assertEquals(0, dataStream.readPackedLong());
    assertTrue(dataStream.wasPackedNull());
    assertEquals(3, dataStream.readPackedLong());
    assertEquals(4, dataStream.readPackedLong());
    assertEquals(5, dataStream.readPackedLong());
    assertEquals(0, dataStream.available());
}
Also used : RawDataSchema(com.ociweb.pronghorn.pipe.RawDataSchema) ChannelReader(com.ociweb.pronghorn.pipe.ChannelReader) Test(org.junit.Test)

Aggregations

RawDataSchema (com.ociweb.pronghorn.pipe.RawDataSchema)19 Test (org.junit.Test)17 ChannelReader (com.ociweb.pronghorn.pipe.ChannelReader)10 DataInputBlobReader (com.ociweb.pronghorn.pipe.DataInputBlobReader)6 DataOutputBlobWriter (com.ociweb.pronghorn.pipe.DataOutputBlobWriter)6 Pipe (com.ociweb.pronghorn.pipe.Pipe)2 TrieParserReader (com.ociweb.pronghorn.util.TrieParserReader)2 ValveSchema (com.ociweb.iot.valveManifold.schema.ValveSchema)1 GraphManager (com.ociweb.pronghorn.stage.scheduling.GraphManager)1 NonThreadScheduler (com.ociweb.pronghorn.stage.scheduling.NonThreadScheduler)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1