Search in sources :

Example 21 with BProgramRunner

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);
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) EventPattern(il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern) StringWriter(java.io.StringWriter) 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) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 22 with BProgramRunner

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");
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) JFrame(javax.swing.JFrame) 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) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)

Example 23 with BProgramRunner

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

Example 24 with BProgramRunner

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();
    }
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 25 with BProgramRunner

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();
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) Scriptable(org.mozilla.javascript.Scriptable) Before(org.junit.Before)

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