Search in sources :

Example 1 with NonThreadScheduler

use of com.ociweb.pronghorn.stage.scheduling.NonThreadScheduler in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Ignore
public void testApp() {
    DeviceRuntime runtime = DeviceRuntime.test(new IoTApp());
    NonThreadScheduler scheduler = (NonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    int iterations = 10;
    while (--iterations >= 0) {
        scheduler.run();
    // test application here
    }
}
Also used : NonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.NonThreadScheduler) DeviceRuntime(com.ociweb.iot.maker.DeviceRuntime) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) Ignore(org.junit.Ignore)

Example 2 with NonThreadScheduler

use of com.ociweb.pronghorn.stage.scheduling.NonThreadScheduler 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

NonThreadScheduler (com.ociweb.pronghorn.stage.scheduling.NonThreadScheduler)2 TestHardware (com.ociweb.iot.hardware.impl.test.TestHardware)1 DeviceRuntime (com.ociweb.iot.maker.DeviceRuntime)1 ValveSchema (com.ociweb.iot.valveManifold.schema.ValveSchema)1 RawDataSchema (com.ociweb.pronghorn.pipe.RawDataSchema)1 GraphManager (com.ociweb.pronghorn.stage.scheduling.GraphManager)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1