Search in sources :

Example 11 with BEvent

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

the class PushingExternalEventTest method topLevelExternalEvents.

@Test
public void topLevelExternalEvents() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("TopLevelExternalEvents.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("ext1")).append(new BEvent("ext2")).append(new BEvent("ext3")).append(new BEvent("internal"));
    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 12 with BEvent

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

the class JsEventSetTest method testRun.

@Test
public void testRun() throws InterruptedException, URISyntaxException {
    BProgramRunner bpr = new BProgramRunner(new SingleResourceBProgram("JsEventSet.js"));
    bpr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = bpr.addListener(new InMemoryEventLoggingListener());
    bpr.run();
    assertEquals(Arrays.asList(new BEvent("1stEvent"), new BEvent("2ndEvent")), eventLogger.getEvents());
}
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) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 13 with BEvent

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

the class StatementsWithDataTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    SingleResourceBProgram bprog = new SingleResourceBProgram("StatementsWithData.js");
    BProgramRunner sut = new BProgramRunner();
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.setBProgram(bprog);
    sut.getBProgram().setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
    sut.addListener(new BProgramRunnerListenerAdapter() {
    });
    sut.run();
    eventLogger.getEvents().forEach(e -> System.out.println(e));
    EventPattern expected = new EventPattern().append(new BEvent("1")).append(new BEvent("2")).append(new BEvent("3"));
    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) BProgramRunnerListenerAdapter(il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter) 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) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 14 with BEvent

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

the class BEventSetsJsTest method testContains_Name.

@Test
public void testContains_Name() throws InterruptedException {
    BEvent eName = events.get("eName");
    BEvent eNotName = events.get("eNotName");
    EventSet esName = eventSets.get("esName");
    Context.enter();
    assertTrue(esName.contains(eName));
    assertFalse(esName.contains(eNotName));
    Context.exit();
}
Also used : BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 15 with BEvent

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

the class BProgramJsProxy method sync.

public void sync(NativeObject jsRWB, Object data) {
    Map<String, Object> jRWB = (Map) Context.jsToJava(jsRWB, Map.class);
    BSyncStatement stmt = BSyncStatement.make();
    Object req = jRWB.get("request");
    if (req != null) {
        if (req instanceof BEvent) {
            stmt = stmt.request((BEvent) req);
        } else if (req instanceof NativeArray) {
            NativeArray arr = (NativeArray) req;
            stmt = stmt.request(Arrays.asList(arr.getIndexIds()).stream().map(i -> (BEvent) arr.get(i)).collect(toList()));
        }
    }
    stmt = stmt.waitFor(convertToEventSet(jRWB.get("waitFor"))).block(convertToEventSet(jRWB.get("block"))).interrupt(convertToEventSet(jRWB.get("interrupt"))).data(data);
    captureBThreadState(stmt);
}
Also used : NativeArray(org.mozilla.javascript.NativeArray) BSyncStatement(il.ac.bgu.cs.bp.bpjs.model.BSyncStatement) NativeObject(org.mozilla.javascript.NativeObject) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Map(java.util.Map)

Aggregations

BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)37 Test (org.junit.Test)25 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)16 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)13 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)13 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)13 BSyncStatement (il.ac.bgu.cs.bp.bpjs.model.BSyncStatement)9 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)8 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)8 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)7 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)6 Context (org.mozilla.javascript.Context)6 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)5 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Set (java.util.Set)5 ComposableEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.ComposableEventSet)4 EventSets (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSets)4 Collections.emptySet (java.util.Collections.emptySet)4