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();
}
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');");
}
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()));
}
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');");
}
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()));
}
Aggregations