Search in sources :

Example 16 with SingleResourceBProgram

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

the class HotNColdTest method superStepTest.

@Test
public void superStepTest() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("HotNCold.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(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(allDoneEvent);
    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) Test(org.junit.Test)

Example 17 with SingleResourceBProgram

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

the class LoggingTest method testLogLevels.

@Test
public void testLogLevels() throws InterruptedException, UnsupportedEncodingException {
    PrintStream originalOut = System.out;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (PrintStream myOut = new PrintStream(baos)) {
        System.setOut(myOut);
        new BProgramRunner(new SingleResourceBProgram("loggingTest.js")).run();
        myOut.flush();
    }
    String result = baos.toString(StandardCharsets.UTF_8.name());
    System.setOut(originalOut);
    System.out.println("result:");
    System.out.println(result);
    org.junit.Assert.assertEquals(6l, (long) result.split("\n").length);
}
Also used : PrintStream(java.io.PrintStream) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 18 with SingleResourceBProgram

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

the class PushingExternalEventTest method externalEventsFromABthread.

@Test
public void externalEventsFromABthread() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("PushingExternalEvent.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("start")).append(new BEvent("external")).append(new BEvent("done"));
    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 19 with SingleResourceBProgram

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

the class PushingExternalEventTest method topLevelExternalEvents.

@Test
public void topLevelExternalEvents() throws InterruptedException {
    BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("TopLevelExternalEvents.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("ext1")).append(new BEvent("ext2")).append(new BEvent("ext3")).append(new BEvent("internal"));
    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 20 with SingleResourceBProgram

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

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