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()));
}
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());
}
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()));
}
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();
}
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);
}
Aggregations