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