Search in sources :

Example 41 with SingleResourceBProgram

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

the class BProgramSyncSnapshotClonerTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    System.out.println("\nSTART Serialization test");
    BProgram bprog = new SingleResourceBProgram("BProgramSyncSnapshotClonerTest.js");
    BProgramSyncSnapshot cur = bprog.setup();
    ExecutorService exSvc = ExecutorServiceMaker.makeWithName("test");
    cur = cur.start(exSvc);
    cur.triggerEvent(cur.getStatements().stream().flatMap(s -> s.getRequest().stream()).findFirst().get(), exSvc, emptySet());
    BProgramSyncSnapshotIO io = new BProgramSyncSnapshotIO(bprog);
    byte[] out = io.serialize(cur);
    System.out.println("de-serializing\n");
    io.deserialize(out);
    System.out.println("END Serialization test\n");
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) VerificationResult(il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Collections.emptySet(java.util.Collections.emptySet) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) DfsBProgramVerifier(il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) Test(org.junit.Test) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) ExecutorService(java.util.concurrent.ExecutorService) ExecutorServiceMaker(il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker) 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) ExecutorService(java.util.concurrent.ExecutorService) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) Test(org.junit.Test)

Example 42 with SingleResourceBProgram

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

the class AddingBthreadsTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    final BEvent parentDone = new BEvent("parentDone");
    final BEvent kidADone = new BEvent("kidADone");
    final BEvent kidBDone = new BEvent("kidBDone");
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("AddingBthreads.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    EventSet kiddies = il.ac.bgu.cs.bp.bpjs.model.eventsets.ComposableEventSet.anyOf(kidADone, kidBDone);
    EventPattern expected = new EventPattern().append(kiddies).append(kiddies).append(parentDone).append(kiddies).append(kiddies).append(parentDone);
    System.out.println("Actual events:");
    eventLogger.getEvents().forEach(System.out::println);
    System.out.println("/Actual events");
    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) EventSet(il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet) 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 43 with SingleResourceBProgram

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

the class GetTimeTest method test.

@Test
public void test() throws InterruptedException {
    BProgram sut = new SingleResourceBProgram("getTimeTest.js");
    long timePre = System.currentTimeMillis();
    new BProgramRunner(sut).run();
    long timePost = System.currentTimeMillis();
    Long actual = sut.getFromGlobalScope("theTime", Long.class).get();
    assertTrue((actual >= timePre) && (actual <= timePost));
}
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 44 with SingleResourceBProgram

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

the class InterruptHandlerTest method echoEventTest.

@Test
public void echoEventTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("InterruptHandler.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
    sut.run();
    eventLogger.getEvents().forEach(e -> System.out.println(e));
    EventPattern expected = new EventPattern().append(new BEvent("boom")).append(new BEvent("boom")).append(new BEvent("internalValue"));
    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 45 with SingleResourceBProgram

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

the class InterruptHandlerTest method illegalBsyncTest.

@Test(expected = BProgramException.class)
public void illegalBsyncTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("InterruptHandler_illegal.js"));
    sut.addListener(new PrintBProgramRunnerListener());
    sut.run();
    fail("Program should have terminated in error.");
}
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) Test(org.junit.Test)

Aggregations

SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)45 Test (org.junit.Test)38 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)29 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)26 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)22 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)17 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)14 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)10 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)9 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)9 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)7 BriefPrintDfsVerifierListener (il.ac.bgu.cs.bp.bpjs.analysis.listeners.BriefPrintDfsVerifierListener)4 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)3 BProgramStateVisitedStateStore (il.ac.bgu.cs.bp.bpjs.analysis.BProgramStateVisitedStateStore)2 Node (il.ac.bgu.cs.bp.bpjs.analysis.Node)1 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)1 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)1 BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)1 FailedAssertion (il.ac.bgu.cs.bp.bpjs.model.FailedAssertion)1 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)1