Search in sources :

Example 1 with BProgramRunnerListenerAdapter

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()));
}
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 2 with BProgramRunnerListenerAdapter

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

Aggregations

BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)2 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)2 Test (org.junit.Test)2 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)1 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)1 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)1 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)1 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)1 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)1