Search in sources :

Example 41 with BProgramRunner

use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.

the class GetTimeTest method test.

@Test
public void test() throws InterruptedException {
    BProgram sut = new SingleResourceBProgram("getTimeTest.js");
    long timePre = System.currentTimeMillis();
    new BProgramRunner(sut).run();
    long timePost = System.currentTimeMillis();
    Long actual = sut.getFromGlobalScope("theTime", Long.class).get();
    assertTrue((actual >= timePre) && (actual <= timePost));
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 42 with BProgramRunner

use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.

the class InterruptHandlerTest method echoEventTest.

@Test
public void echoEventTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("InterruptHandler.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    eventLogger.getEvents().forEach(e -> System.out.println(e));
    EventPattern expected = new EventPattern().append(new BEvent("boom")).append(new BEvent("boom")).append(new BEvent("internalValue"));
    assertTrue(expected.matches(eventLogger.getEvents()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) EventPattern(il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 43 with BProgramRunner

use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.

the class InterruptHandlerTest method illegalBsyncTest.

@Test(expected = BProgramException.class)
public void illegalBsyncTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("InterruptHandler_illegal.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    sut.run();
    fail("Program should have terminated in error.");
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Aggregations

BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)43 Test (org.junit.Test)38 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)30 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)29 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)26 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)13 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)10 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)10 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)4 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)4 Scriptable (org.mozilla.javascript.Scriptable)3 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)2 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2 Before (org.junit.Before)2 FailedAssertion (il.ac.bgu.cs.bp.bpjs.model.FailedAssertion)1 EventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.EventSelectionStrategy)1 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)1 JsEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1