use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class DynamicBThreadAdditionTest method test.
@Test
public void test() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("dynamicBthreadAddition.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.run();
Set<String> expected = new HashSet<>(Arrays.asList("e0", "e1", "e2", "e3"));
assertEquals(expected, eventLogger.getEvents().stream().map(BEvent::getName).collect(toSet()));
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class EventsWithDataTest method testEventsWithData.
@Test
public void testEventsWithData() throws Exception {
BProgram bpr = new SingleResourceBProgram("EventsWithData.js", "programName", new SimpleEventSelectionStrategy(99l));
BProgramRunner rnr = new BProgramRunner(bpr);
rnr.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener events = rnr.addListener(new InMemoryEventLoggingListener());
rnr.run();
assertEquals(Arrays.asList("e1", "e2", "e1e2"), events.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 ExternalEventsTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
final BEvent in1a = new BEvent("in1a");
final BEvent ext1 = new BEvent("ext1");
final BEvent in1b = new BEvent("in1b");
final SingleResourceBProgram bprog = new SingleResourceBProgram("ExternalEvents.js");
bprog.setEventSelectionStrategy(new LoggingEventSelectionStrategyDecorator(bprog.getEventSelectionStrategy()));
final BProgramRunner sut = new BProgramRunner(bprog);
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.getBProgram().enqueueExternalEvent(ext1);
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(in1a).append(ext1).append(in1b);
assertTrue(expected.matches(eventLogger.getEvents()));
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class BpSyncTests method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("bp-sync.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
assertEquals("hello,world", TestUtils.eventNamesString(eventLogger.getEvents(), ","));
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class ExternalEventsDaemonTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("ExternalEventsDaemon.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
new Thread(() -> {
try {
for (int i = 0; i < 4; i++) {
Thread.sleep(500);
sut.getBProgram().enqueueExternalEvent(new BEvent("ext1"));
}
} catch (InterruptedException ex) {
Logger.getLogger(ExternalEventsDaemonTest.class.getName()).log(Level.SEVERE, null, ex);
}
}).start();
sut.run();
assertTrue(sut.getBProgram().getFromGlobalScope("internalDaemonMode", Boolean.class).get());
eventLogger.getEvents().forEach(e -> System.out.println(e));
final BEvent in1a = new BEvent("in1a");
final BEvent in1b = new BEvent("in1b");
final BEvent ext1 = new BEvent("ext1");
EventPattern expected = new EventPattern().append(ext1).append(in1a).append(in1b).append(ext1).append(in1a).append(in1b).append(ext1).append(in1a).append(in1b);
assertTrue(expected.matches(eventLogger.getEvents()));
}
Aggregations