Search in sources :

Example 11 with InMemoryEventLoggingListener

use of il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener 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()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) EventPattern(il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern) 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) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 12 with InMemoryEventLoggingListener

use of il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener 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());
}
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) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 13 with InMemoryEventLoggingListener

use of il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener 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 14 with InMemoryEventLoggingListener

use of il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener 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 15 with InMemoryEventLoggingListener

use of il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener in project BPjs by bThink-BGU.

the class BProgramTest method testPrependSource.

@Test
public void testPrependSource() throws InterruptedException {
    String prependedCode = "var e1=bp.Event(\"1\");\n" + "var e2=bp.Event(\"2\");\n" + "var e3=bp.Event(\"3\");\n" + "bp.log.info('Prepended code evaluated');";
    String coreSource = "bp.registerBThread(function() {\n" + "    bsync( {request: e1} );\n" + "    bsync( {request: e2} );\n" + "    bsync( {request: e3} );\n" + "});" + "bp.log.info('Source code evaluated');";
    BProgramRunner rnr = new BProgramRunner();
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener el = rnr.addListener(new InMemoryEventLoggingListener());
    BProgram sut = new StringBProgram(coreSource);
    sut.prependSource(prependedCode);
    rnr.setBProgram(sut);
    rnr.run();
    assertEquals(asList("1", "2", "3"), el.getEvents().stream().map(BEvent::getName).collect(toList()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) Test(org.junit.Test)

Aggregations

BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)26 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)26 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)26 Test (org.junit.Test)26 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)21 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)3 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)3 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)2 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)1 FailedAssertion (il.ac.bgu.cs.bp.bpjs.model.FailedAssertion)1 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)1 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)1 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashSet (java.util.HashSet)1