Search in sources :

Example 1 with PrintBProgramRunnerListener

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

the class BProgramTest method testAppendSource.

@Test
public void testAppendSource() throws InterruptedException {
    String coreSource = "bp.registerBThread(function() {\n" + "    bsync( {request: bp.Event(\"1\")} );\n" + "    bsync( {request: bp.Event(\"2\")} );\n" + "    bsync( {request: bp.Event(\"3\")} );\n" + "});" + "bp.log.info('Source code evaluated');";
    String additionalSource = "bp.registerBThread(function(){\n" + "   bsync({waitFor: bp.Event(\"2\")});\n" + "   bsync({request: bp.Event(\"2a\"),\n" + "            block: bp.Event(\"3\")});\n" + "});\n" + "bp.log.info('Additional code evaluated');";
    BProgram sanitySut = new StringBProgram(coreSource);
    BProgramRunner rnr = new BProgramRunner(sanitySut);
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener el = rnr.addListener(new InMemoryEventLoggingListener());
    System.out.println("Sanity run");
    rnr.run();
    System.out.println("/Sanity run");
    System.out.println("");
    assertEquals(asList("1", "2", "3"), el.getEvents().stream().map(BEvent::getName).collect(toList()));
    System.out.println("Test Run");
    BProgram sut = new StringBProgram(coreSource);
    sut.appendSource(additionalSource);
    rnr.setBProgram(sut);
    rnr.run();
    assertEquals(asList("1", "2", "2a", "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)

Example 2 with PrintBProgramRunnerListener

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

the class BProgramSyncSnapshotClonerTest method testProgramIsOk.

@Test
public void testProgramIsOk() throws InterruptedException {
    BProgramRunner bpr = new BProgramRunner(new SingleResourceBProgram("BProgramSyncSnapshotClonerTest.js"));
    bpr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener events = bpr.addListener(new InMemoryEventLoggingListener());
    bpr.run();
    events.getEvents().forEach(e -> System.out.println(e.toString()));
}
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) Test(org.junit.Test)

Example 3 with PrintBProgramRunnerListener

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

the class DynamicBThreadAdditionTest method test.

@Test
public void test() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("dynamicBthreadAddition.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    Set<String> expected = new HashSet<>(Arrays.asList("e0", "e1", "e2", "e3"));
    assertEquals(expected, eventLogger.getEvents().stream().map(BEvent::getName).collect(toSet()));
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with PrintBProgramRunnerListener

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

the class EventsWithDataTest method testEventsWithData.

@Test
public void testEventsWithData() throws Exception {
    BProgram bpr = new SingleResourceBProgram("EventsWithData.js", "programName", new SimpleEventSelectionStrategy(99l));
    BProgramRunner rnr = new BProgramRunner(bpr);
    rnr.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener events = rnr.addListener(new InMemoryEventLoggingListener());
    rnr.run();
    assertEquals(Arrays.asList("e1", "e2", "e1e2"), 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) SimpleEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy) 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) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 5 with PrintBProgramRunnerListener

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

the class ExternalEventsTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    final BEvent in1a = new BEvent("in1a");
    final BEvent ext1 = new BEvent("ext1");
    final BEvent in1b = new BEvent("in1b");
    final SingleResourceBProgram bprog = new SingleResourceBProgram("ExternalEvents.js");
    bprog.setEventSelectionStrategy(new LoggingEventSelectionStrategyDecorator(bprog.getEventSelectionStrategy()));
    final BProgramRunner sut = new BProgramRunner(bprog);
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.getBProgram().enqueueExternalEvent(ext1);
    sut.run();
    eventLogger.getEvents().forEach(e -> System.out.println(e));
    EventPattern expected = new EventPattern().append(in1a).append(ext1).append(in1b);
    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) LoggingEventSelectionStrategyDecorator(il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator) 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

PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)31 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)30 Test (org.junit.Test)28 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)26 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)25 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)6 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)4 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)3 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)1 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 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1