Search in sources :

Example 11 with BProgram

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

the class BProgramRunnerTest method testRun.

/**
 * Test of start method, of class BProgramRunner.
 * @throws java.lang.Exception
 */
@Test
public void testRun() throws Exception {
    BProgram bprog = new SingleResourceBProgram("HotNCold.js");
    BProgramRunner sut = new BProgramRunner(bprog);
    sut.addListener(new PrintBProgramRunnerListener());
    sut.run();
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 12 with BProgram

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

the class BProgramRunnerTest method testExecutorName.

@Test
public void testExecutorName() throws InterruptedException {
    BProgram bprog = new StringBProgram("var exName = 'initial value'\n" + "bp.registerBThread( function(){\n" + "  exName = bp.getJavaThreadName();\n" + "});");
    new BProgramRunner(bprog).run();
    String exName = bprog.getFromGlobalScope("exName", String.class).get();
    assertTrue("Java executor name is wrong (got:'" + exName + "')", exName.startsWith("BProgramRunner-"));
}
Also used : SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 13 with BProgram

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

the class BProgramJsProxyTest method randomProxyText.

@Test
public void randomProxyText() throws InterruptedException {
    BProgram sut = new SingleResourceBProgram("RandomProxy.js");
    new BProgramRunner(sut).run();
    Double boolCount = sut.getFromGlobalScope("boolCount", Double.class).get();
    assertEquals(500.0, boolCount, 100);
    Double intCount = sut.getFromGlobalScope("intCount", Double.class).get();
    assertEquals(500.0, intCount, 100);
    Double floatCount = sut.getFromGlobalScope("floatCount", Double.class).get();
    assertEquals(500.0, floatCount, 100);
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) 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) Test(org.junit.Test)

Example 14 with BProgram

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

the class BProgramJsProxyTest method logLevelProxyText.

@Test
public void logLevelProxyText() throws InterruptedException {
    BProgram sut = new SingleResourceBProgram("RandomProxy.js");
    new BProgramRunner(sut).run();
    String logLevel1 = sut.getFromGlobalScope("logLevel1", String.class).get();
    assertEquals(BProgramJsProxy.LogLevel.Off.name(), logLevel1);
    String logLevel2 = sut.getFromGlobalScope("logLevel2", String.class).get();
    assertEquals(BProgramJsProxy.LogLevel.Warn.name(), logLevel2);
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) 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) Test(org.junit.Test)

Example 15 with BProgram

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

the class JsEventSetTest method testJsSetData.

@Test
public void testJsSetData() throws InterruptedException, URISyntaxException {
    try {
        Context.enter();
        BProgram bpr = new StringBProgram("Eventset", "var es=bp.EventSet('a',function(e){return e.name=='a';});\n");
        new BProgramRunner(bpr).run();
        NativeJavaObject sut = (NativeJavaObject) bpr.getGlobalScope().get("es", bpr.getGlobalScope());
        JsEventSet jsSut = (JsEventSet) Context.jsToJava(sut, JsEventSet.class);
        assertEquals("a", jsSut.getName());
        assertTrue(jsSut.toString().contains("a"));
        assertTrue(jsSut.toString().contains("JsEventSet"));
        assertTrue(jsSut.contains(BEvent.named("a")));
        assertFalse(jsSut.contains(BEvent.named("b")));
    } finally {
        Context.exit();
    }
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) JsEventSet(il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Aggregations

BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)36 Test (org.junit.Test)29 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)23 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)21 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)11 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)10 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)9 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)8 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)7 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)5 Scriptable (org.mozilla.javascript.Scriptable)5 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)4 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)3 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)3 BPjsCodeEvaluationException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsCodeEvaluationException)2 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)2 EventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.EventSelectionStrategy)2 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2