Search in sources :

Example 6 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)

Example 7 with ScriptedNonThreadScheduler

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

the class AppTest method testApp.

@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 8 with ScriptedNonThreadScheduler

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

the class AppTest method testApp.

// this test reqires network connectivity of some kind
// HZ  may end up hanging this test if it can not find what it is lookoing for.
@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 9 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();
    hardware.portReader = new BasicTestPortReader();
    int iterations = 4;
    boolean isFirst = true;
    int expected = 0;
    long lastTime = 0;
    while (iterations > 0) {
        scheduler.run();
        long time = hardware.getLastTime(IoTApp.LED_PORT);
        if (0 != time) {
            iterations--;
            assertEquals(expected, 1 & hardware.read(IoTApp.LED_PORT));
            expected = 1 & (expected + 1);
            if (0 != lastTime) {
                long durationMs = (time - lastTime);
                if (!isFirst) {
                    assertTrue(Long.toString(durationMs), // first difference may be short because first transition is later due to startup.
                    durationMs >= 400);
                } else {
                    isFirst = false;
                }
                assertTrue(durationMs <= 750);
            }
            lastTime = time;
            hardware.clearCaputuredLastTimes();
            hardware.clearCaputuredHighs();
        }
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) BasicTestPortReader(com.ociweb.iot.hardware.impl.test.BasicTestPortReader) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 10 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() {
    // 1 SEC
    IoTApp.RED_MS = 1000;
    // .8 SEC
    IoTApp.GREEN_MS = 800;
    // .2 SEC
    IoTApp.YELLOW_MS = 200;
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    scheduler.startup();
    long next = System.currentTimeMillis() + 5_000;
    while (System.currentTimeMillis() < next) {
        scheduler.run();
        Thread.yield();
    }
    scheduler.shutdown();
}
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