use of il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter 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.execution.listeners.BProgramRunnerListenerAdapter in project BPjs by bThink-BGU.
the class PutInContextTest method testPutInContext_midRun.
@Test
public void testPutInContext_midRun() throws InterruptedException {
final String program = "bp.registerBThread(function(){\n" + "bsync({request:bp.Event('A')});\n" + "bp.log.info(obj);var len=obj.length;\n" + "bsync({request:bp.Event(String(len))});\n" + "});";
final String outsideObject = "I'm an outside object";
BProgram sut = new StringBProgram(program);
BProgramRunner runner = new BProgramRunner(sut);
runner.addListener(new BProgramRunnerListenerAdapter() {
int counter = 0;
@Override
public void eventSelected(BProgram bp, BEvent theEvent) {
switch(counter) {
case 0:
sut.putInGlobalScope("obj", outsideObject);
break;
case 1:
assertEquals(theEvent.getName(), Long.toString(outsideObject.length()));
break;
}
counter++;
}
});
runner.run();
}
Aggregations