use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class LoggingEventSelectionStrategyDecoratorTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException, IOException {
StringWriter strOut = new StringWriter();
try (PrintWriter outWriter = new PrintWriter(strOut)) {
LoggingEventSelectionStrategyDecorator sut = new LoggingEventSelectionStrategyDecorator(new SimpleEventSelectionStrategy(), outWriter);
SingleResourceBProgram bp = new SingleResourceBProgram("HotNCold.js");
bp.setEventSelectionStrategy(sut);
BProgramRunner runner = new BProgramRunner(bp);
runner.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = runner.addListener(new InMemoryEventLoggingListener());
runner.run();
EventPattern expected = new EventPattern().append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(allDoneEvent);
assertTrue(expected.matches(eventLogger.getEvents()));
outWriter.flush();
}
strOut.flush();
strOut.close();
String output = strOut.toString();
System.out.println("output = " + output);
int selectableEventsLogs = Arrays.stream(output.split("\n")).filter(s -> s.contains("== Choosing Selectable Events ==")).collect(toList()).size();
assertEquals(7, selectableEventsLogs);
int eventSelections = Arrays.stream(output.split("\n")).filter(s -> s.contains("== Actual Event Selection ======")).collect(toList()).size();
assertEquals(7, eventSelections);
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class TTTButton method main.
public static void main(String[] args) throws InterruptedException {
// Create a program
BProgram bprog = new SingleResourceBProgram("BPJSTicTacToe.js");
bprog.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
bprog.setDaemonMode(true);
JFrame f = new TicTacToeGameMain();
BProgramRunner rnr = new BProgramRunner(bprog);
rnr.addListener(new PrintBProgramRunnerListener());
TTTdisplayGame = new TTTDisplayGame(bprog, rnr);
rnr.run();
System.out.println("end of run");
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class Mazes method run.
public void run() throws InterruptedException {
SingleResourceBProgram bprog = prepareProgram();
BProgramRunner rnr = new BProgramRunner(bprog);
rnr.addListener(new PrintBProgramRunnerListener());
rnr.run();
printMaze(getMaze(bprog));
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class PriorityBasedSelectionTest method testBadPredicate.
@Test
public void testBadPredicate() {
try {
StringBProgram bProgram = new StringBProgram(//
"" + //
"bp.registerBThread('bt1',function(){" + //
" bsync({request:bp.Event('X')});" + //
"});" + //
"bp.registerBThread('bt2',function(){" + //
" bsync({request:bp.Event('Y')});" + //
"});");
PrioritizedBThreadsEventSelectionStrategy eventSelectionStrategy = new PrioritizedBThreadsEventSelectionStrategy();
eventSelectionStrategy.setPriority("bt1", 1);
bProgram.setEventSelectionStrategy(eventSelectionStrategy);
BProgramRunner bpr = new BProgramRunner(bProgram);
bpr.run();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class BEventSetsJsTest method setUp.
@Before
public void setUp() throws InterruptedException {
prog = new BProgram() {
@Override
protected void setupProgramScope(Scriptable aScope) {
aScope.put("events", aScope, Context.javaToJS(events, aScope));
aScope.put("eventSets", aScope, Context.javaToJS(eventSets, aScope));
aScope.put("test", aScope, Context.javaToJS(BEventSetsJsTest.this, aScope));
evaluate("eventSets.put(\"esName\", bp.EventSet( 'x', function(e){ " + "bp.log.info('esName');\n" + "bp.log.info(e);\n" + "bp.log.info(e.name);\n" + "bp.log.info( e.name==='Name' );\n" + "return e.name=='Name'; }) );\n" + "eventSets.put(\"esDataObjVizIsViz\", bp.EventSet( 'x', function(e){ " + "bp.log.info('esDataObjVizIsViz');\n" + "bp.log.info(e);\n" + "return (e.data) ? e.data.viz=='viz' : false; }) );\n" + "eventSets.put(\"esDataIsViz\", bp.EventSet( 'x', function(e){ " + "bp.log.info('esDataIsViz');\n" + "bp.log.info(e);\n" + "bp.log.info(e.data);\n" + "return e.data==\"viz\"; }) );\n" + "events.put( \"eName\", bp.Event(\"Name\") );\n" + "events.put( \"eNotName\", bp.Event(\"NotName\") );\n" + "events.put( \"eVizObj\", bp.Event(\"aName\", {viz:\"viz\"}) );\n" + "events.put( \"eViz\", bp.Event('aName', 'viz') );", "inline script");
}
};
new BProgramRunner(prog).run();
}
Aggregations