Search in sources :

Example 1 with ValveSchema

use of com.ociweb.iot.valveManifold.schema.ValveSchema 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)

Aggregations

ValveSchema (com.ociweb.iot.valveManifold.schema.ValveSchema)1 RawDataSchema (com.ociweb.pronghorn.pipe.RawDataSchema)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 Test (org.junit.Test)1