Search in sources :

Example 16 with InMemoryEventLoggingListener

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

the class BProgramTest method testPrependAndAppendSource.

@Test
public void testPrependAndAppendSource() throws InterruptedException {
    System.out.println("\n\ntestPrependAndAppendSource");
    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');\n" + "var o1=1; var o2=1; var o3=1;";
    String coreSource = "bp.registerBThread(function() {\n" + "    bsync( {request: e1} );\n" + "    bsync( {request: e2} );\n" + "    bsync( {request: e3} );\n" + "});" + "bp.log.info('main code evaluated');\n" + "var o2=2; var o3=2;";
    String appendedSource = "bp.registerBThread(function(){\n" + "   bsync({waitFor: e2});\n" + "   bsync({request: bp.Event(\"2a\"),\n" + "            block: e3});\n" + "});\n" + "bp.log.info('appended code evaluated');\n" + "var o3=3;";
    BProgramRunner rnr = new BProgramRunner();
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener el = rnr.addListener(new InMemoryEventLoggingListener());
    BProgram sut = new StringBProgram(coreSource);
    sut.prependSource(prependedCode);
    sut.appendSource(appendedSource);
    rnr.setBProgram(sut);
    rnr.run();
    assertEquals(asList("1", "2", "2a", "3"), el.getEvents().stream().map(BEvent::getName).collect(toList()));
    assertEquals(Optional.of(1.0), sut.getFromGlobalScope("o1", Number.class));
    assertEquals(Optional.of(2.0), sut.getFromGlobalScope("o2", Number.class));
    assertEquals(Optional.of(3.0), sut.getFromGlobalScope("o3", Number.class));
    System.out.println("-- testPrependAndAppendSource DONE");
}
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)

Example 17 with InMemoryEventLoggingListener

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

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

the class BSyncDataPassingTest method priorityDataTest_noBlocking.

@Test
public void priorityDataTest_noBlocking() {
    BProgram bp = new SingleResourceBProgram("BSyncDataPassingTest.js");
    bp.putInGlobalScope("block30", false);
    bp.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
    BProgramRunner rnr = new BProgramRunner(bp);
    InMemoryEventLoggingListener eventsLogger = rnr.addListener(new InMemoryEventLoggingListener());
    rnr.addListener(new PrintBProgramRunnerListener());
    rnr.run();
    assertEquals(Arrays.asList("p30", "p20", "p10", "p3", "p2", "p1"), eventsLogger.eventNames());
}
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) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy) Test(org.junit.Test)

Example 19 with InMemoryEventLoggingListener

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

the class BSyncDataPassingTest method priorityDataTest_blocking.

@Test
public void priorityDataTest_blocking() {
    BProgram bp = new SingleResourceBProgram("BSyncDataPassingTest.js");
    bp.putInGlobalScope("block30", true);
    bp.setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy(17));
    BProgramRunner rnr = new BProgramRunner(bp);
    InMemoryEventLoggingListener eventsLogger = rnr.addListener(new InMemoryEventLoggingListener());
    rnr.addListener(new PrintBProgramRunnerListener());
    rnr.run();
    assertEquals(Arrays.asList("p20", "p10", "p3", "p2", "p1"), eventsLogger.eventNames());
}
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) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy) Test(org.junit.Test)

Example 20 with InMemoryEventLoggingListener

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

the class EventsArraysTest method testEventsWithData.

@Test
public void testEventsWithData() throws Exception {
    BProgramRunner bpr = new BProgramRunner(new SingleResourceBProgram("EventArrays.js"));
    bpr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener events = bpr.addListener(new InMemoryEventLoggingListener());
    bpr.run();
    assertEquals(Arrays.asList("e11", "e21"), events.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) 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

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