Search in sources :

Example 6 with EventPattern

use of il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern 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 7 with EventPattern

use of il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern 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 8 with EventPattern

use of il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern in project BPjs by bThink-BGU.

the class NamedArgsHotNColdTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("NamedArgsHotNCold.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    eventLogger.getEvents().forEach(e -> System.out.println(e));
    final BEvent hotEvent = new BEvent("hotEvent");
    final BEvent coldEvent = new BEvent("coldEvent");
    final BEvent allDoneEvent = new BEvent("allDone");
    EventPattern expected = new EventPattern().append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(allDoneEvent);
    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 9 with EventPattern

use of il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern in project BPjs by bThink-BGU.

the class AddingBthreadsTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    final BEvent parentDone = new BEvent("parentDone");
    final BEvent kidADone = new BEvent("kidADone");
    final BEvent kidBDone = new BEvent("kidBDone");
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("AddingBthreads.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    EventSet kiddies = il.ac.bgu.cs.bp.bpjs.model.eventsets.ComposableEventSet.anyOf(kidADone, kidBDone);
    EventPattern expected = new EventPattern().append(kiddies).append(kiddies).append(parentDone).append(kiddies).append(kiddies).append(parentDone);
    System.out.println("Actual events:");
    eventLogger.getEvents().forEach(System.out::println);
    System.out.println("/Actual events");
    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) EventSet(il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet) 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 10 with EventPattern

use of il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern in project BPjs by bThink-BGU.

the class InterruptHandlerTest method echoEventTest.

@Test
public void echoEventTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("InterruptHandler.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("boom")).append(new BEvent("boom")).append(new BEvent("internalValue"));
    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)

Aggregations

EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)10 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)10 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)10 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)10 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)10 Test (org.junit.Test)10 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)8 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)1 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)1 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)1 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1