Search in sources :

Example 1 with BProgramRunner

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

the class BEventsJsTest method setUp.

@Before
public void setUp() throws InterruptedException {
    prog = new BProgram() {

        @Override
        protected void setupProgramScope(Scriptable aScope) {
            aScope.put("events", aScope, Context.javaToJS(events, aScope));
            evaluate("events.put('nameOnly1',     bp.Event('nameOnly'));\n" + "events.put('nameOnly2',     bp.Event('nameOnly'));\n" + "events.put('nameOnly-diff', bp.Event('nameOnly-diff'));\n" + "events.put('withData1',           bp.Event('withData',{a:'a',b:'b',c:700}));\n" + "events.put('withData2',           bp.Event('withData',{a:'a',b:'b',c:700}));\n" + "events.put('withData2-reordered', bp.Event('withData',{b:'b',a:'a',c:700}));\n" + "events.put('withData-diff1', bp.Event('withDataX',{a:'a',b:'b',c:700}));\n" + "events.put('withData-diff2', bp.Event('withData',{b:'b',c:700}));\n" + "events.put('withData-diff3', bp.Event('withData',{a:'a',b:'b',c:700,d:'x'}));\n" + "events.put('withData-diff4', bp.Event('withData',{a:'x',b:'b',c:700}));\n" + "events.put('withData-rec',   bp.Event('withData',{a:'x',b:'b',child:{a:2,b:'b'}}));\n" + "events.put('withData-rec2',  bp.Event('withData',{a:'x',b:'b',child:{a:2,b:'b'}}));\n" + "events.put('withPrimitiveData1',      bp.Event('withPrimitiveData',12));\n" + "events.put('withPrimitiveData2',      bp.Event('withPrimitiveData',12));\n" + "events.put('withPrimitiveData-diff1', bp.Event('withPrimitiveData',13));\n" + "events.put('withPrimitiveData-diff2', bp.Event('withPrimitiveData','string'));\n" + "events.put('withPrimitiveData-diff3', bp.Event('withPrimitiveData',{}));\n" + "events.put('withPrimitiveData-diff4', bp.Event('withPrimitiveData',function(p){return p;}));\n" + "events.put('e', bp.Event('e'));\n" + "events.put('m1d', bp.Event('metaE',bp.Event('e')));\n" + "events.put('m2d', bp.Event('metaE',bp.Event('e')));\n" + "events.put('m1i', bp.Event('metaE',{e:bp.Event('e'), v:'js-string'}));\n" + "events.put('m2i', bp.Event('metaE',{e:bp.Event('e'), v:'js-string'}));", "inline script");
        }
    };
    new BProgramRunner(prog).run();
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) Scriptable(org.mozilla.javascript.Scriptable) Before(org.junit.Before)

Example 2 with BProgramRunner

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

the class BProgramTest method testIllegalPrepend.

@Test(expected = IllegalStateException.class)
public void testIllegalPrepend() 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');";
    BProgram sut = new StringBProgram(coreSource);
    BProgramRunner rnr = new BProgramRunner(sut);
    rnr.run();
    sut.prependSource("bp.log.info('grrr');");
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) Test(org.junit.Test)

Example 3 with BProgramRunner

use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner 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 4 with BProgramRunner

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

the class BProgramTest method testIllegalAppend.

@Test(expected = IllegalStateException.class)
public void testIllegalAppend() 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');";
    BProgram sut = new StringBProgram(coreSource);
    BProgramRunner rnr = new BProgramRunner(sut);
    rnr.run();
    sut.appendSource("bp.log.info('grrr');");
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) Test(org.junit.Test)

Example 5 with BProgramRunner

use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner 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)

Aggregations

BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)43 Test (org.junit.Test)38 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)30 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)29 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)26 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)10 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)4 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)4 Scriptable (org.mozilla.javascript.Scriptable)3 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)2 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2 Before (org.junit.Before)2 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 JsEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1