Search in sources :

Example 1 with ScriptedNonThreadScheduler

use of com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler in project GreenLightning by oci-pronghorn.

the class GreenRuntime method test.

private static ScriptedNonThreadScheduler test(GreenApp app, GreenRuntime runtime) {
    // force hardware to TestHardware regardless of where or what platform its run on.
    // this is done because this is the test() method and must behave the same everywhere.
    runtime.builder = new BuilderImpl(runtime.gm, runtime.args);
    // lowered for tests, we want tests to run faster, tests probably run on bigger systems.
    runtime.builder.setDefaultRate(10_000);
    app.declareConfiguration(runtime.builder);
    GraphManager.addDefaultNota(runtime.gm, GraphManager.SCHEDULE_RATE, runtime.builder.getDefaultSleepRateNS());
    runtime.declareBehavior(app);
    runtime.builder.buildStages(runtime);
    runtime.logStageScheduleRates();
    TelemetryConfig telemetryConfig = runtime.builder.getTelemetryConfig();
    if (telemetryConfig != null) {
        runtime.gm.enableTelemetry(telemetryConfig.getPort());
    }
    // exportGraphDotFile();
    boolean reverseOrder = false;
    StageVisitor badPlayers = new StageVisitor() {

        byte[] seen = new byte[GraphManager.countStages(runtime.gm) + 1];

        @Override
        public void visit(PronghornStage stage) {
            if (0 == seen[stage.stageId]) {
                seen[stage.stageId] = 1;
                logger.warn("Slow or blocking stage detected, investigation required: {}", stage);
            }
        }
    };
    runtime.setScheduler(new ScriptedNonThreadScheduler(runtime.gm, reverseOrder, badPlayers, null));
    return (ScriptedNonThreadScheduler) runtime.getScheduler();
}
Also used : BuilderImpl(com.ociweb.gl.impl.BuilderImpl) ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) StageVisitor(com.ociweb.pronghorn.stage.scheduling.StageVisitor) PronghornStage(com.ociweb.pronghorn.stage.PronghornStage)

Example 2 with ScriptedNonThreadScheduler

use of com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler in project GreenLightning by oci-pronghorn.

the class GreenRuntime method testUntilShutdownRequested.

public static boolean testUntilShutdownRequested(GreenApp app, long timeoutMS) {
    GreenRuntime runtime = new GreenRuntime(app.getClass().getSimpleName());
    ScriptedNonThreadScheduler s = test(app, runtime);
    long limit = System.nanoTime() + (timeoutMS * 1_000_000L);
    boolean result = true;
    s.startup();
    while (!ScriptedNonThreadScheduler.isShutdownRequested(s)) {
        s.run();
        if (System.nanoTime() > limit) {
            System.err.println("exit due to timeout");
            result = false;
            break;
        }
    }
    return result;
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler)

Example 3 with ScriptedNonThreadScheduler

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

the class AppTest method testApp.

@Test
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp(false));
    TestHardware hardware = (TestHardware) runtime.getHardware();
    TestI2CBacking backing = (TestI2CBacking) hardware.getI2CBacking();
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    hardware.clearI2CWriteCount();
    hardware.write(IoTApp.ANGLE_SENSOR_PORT, 512);
    hardware.write(IoTApp.LIGHT_SENSOR_PORT, 300);
// scheduler.run();
// 
// int i = hardware.getI2CWriteCount();
// while (i>0) {
// 
// hardware.outputLastI2CWrite(System.out,i--);
// 
// }
// need ring of commands so it can be checked.
// assertEquals(Grove_LCD_RGB.RGB_ADDRESS, backing.lastWriteAddress);
// TODO: must ask I2C LCD for its brightness.
// test application here
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestI2CBacking(com.ociweb.iot.hardware.impl.test.TestI2CBacking) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 4 with ScriptedNonThreadScheduler

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

the class AppTest method testApp.

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

Example 5 with ScriptedNonThreadScheduler

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

the class AppTest method testApp.

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

Aggregations

ScriptedNonThreadScheduler (com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler)13 TestHardware (com.ociweb.iot.hardware.impl.test.TestHardware)11 FogRuntime (com.ociweb.iot.maker.FogRuntime)11 Test (org.junit.Test)8 Ignore (org.junit.Ignore)3 BasicTestPortReader (com.ociweb.iot.hardware.impl.test.BasicTestPortReader)2 BuilderImpl (com.ociweb.gl.impl.BuilderImpl)1 TestI2CBacking (com.ociweb.iot.hardware.impl.test.TestI2CBacking)1 PronghornStage (com.ociweb.pronghorn.stage.PronghornStage)1 StageVisitor (com.ociweb.pronghorn.stage.scheduling.StageVisitor)1