use of il.ac.bgu.cs.bp.bpjs.model.BEvent in project BPjs by bThink-BGU.
the class EventSelectionResultTest method testEquality.
@Test
public void testEquality() {
EventSelectionResult esrA = new EventSelectionResult(new BEvent("a"));
EventSelectionResult esrA1 = new EventSelectionResult(new BEvent("a"), new HashSet<>(Arrays.asList(1)));
EventSelectionResult esrA2 = new EventSelectionResult(new BEvent("a"), new HashSet<>(Arrays.asList(2)));
EventSelectionResult esrB = new EventSelectionResult(new BEvent("b"));
assertEquals(esrA, esrA);
assertNotEquals(esrA, esrB);
assertNotEquals(esrA, esrA1);
assertNotEquals(esrA2, esrA1);
assertNotEquals(esrA, null);
assertNotEquals(esrA, "hello");
Set<EventSelectionResult> ess = new HashSet<>();
ess.add(esrA);
ess.add(esrA);
ess.add(esrA1);
ess.add(esrA1);
ess.add(esrA2);
ess.add(esrA2);
assertEquals(3, ess.size());
}
use of il.ac.bgu.cs.bp.bpjs.model.BEvent in project BPjs by bThink-BGU.
the class EventSetsTest method testAllExcept.
/**
* Test of allExcept method, of class EventSets.
*/
@Test
public void testAllExcept() {
BEvent evtIn = new BEvent("In");
BEvent evtOut = new BEvent("Out");
EventSet es = EventSets.allExcept(evtOut);
assertFalse(es.contains(evtOut));
assertTrue(es.contains(evtIn));
}
use of il.ac.bgu.cs.bp.bpjs.model.BEvent in project BPjs by bThink-BGU.
the class OrderedEventSelectionStrategy method selectableEvents.
@Override
public Set<BEvent> selectableEvents(Set<BSyncStatement> statements, List<BEvent> externalEvents) {
if (statements.isEmpty()) {
// Corner case, not sure this is even possible.
return externalEvents.isEmpty() ? emptySet() : singleton(externalEvents.get(0));
}
EventSet blocked = ComposableEventSet.anyOf(statements.stream().filter(stmt -> stmt != null).map(BSyncStatement::getBlock).filter(r -> r != EventSets.none).collect(toSet()));
Set<BEvent> requested = statements.stream().filter(stmt -> stmt != null).map(stmt -> (BEvent) (stmt.getRequest().stream().filter(e -> !blocked.contains(e)).findFirst().orElse(null))).filter(e -> e != null).collect(toSet());
// Let's see what internal events are requested and not blocked (if any).
try {
Context.enter();
Set<BEvent> requestedAndNotBlocked = requested.stream().filter(req -> !blocked.contains(req)).collect(toSet());
return requestedAndNotBlocked.isEmpty() ? // No internal events requested, defer to externals.
externalEvents.stream().filter(e -> !blocked.contains(e)).findFirst().map(e -> singleton(e)).orElse(emptySet()) : requestedAndNotBlocked;
} finally {
Context.exit();
}
}
use of il.ac.bgu.cs.bp.bpjs.model.BEvent in project BPjs by bThink-BGU.
the class PrioritizedBThreadsEventSelectionStrategy method selectableEvents.
@Override
public Set<BEvent> selectableEvents(Set<BSyncStatement> statements, List<BEvent> externalEvents) {
if (statements.isEmpty()) {
// Corner case, not sure this is even possible.
return externalEvents.isEmpty() ? emptySet() : singleton(externalEvents.get(0));
}
final EventSet blocked = ComposableEventSet.anyOf(statements.stream().filter(stmt -> stmt != null).map(BSyncStatement::getBlock).filter(r -> r != EventSets.none).collect(toSet()));
Set<Pair<BEvent, Integer>> requested = statements.stream().filter(stmt -> stmt != null).flatMap(stmt -> eventsToPrioritizedPairs(stmt)).collect(Collectors.toSet());
// Let's see what internal events are requested and not blocked (if any).
try {
Context.enter();
Set<Pair<BEvent, Integer>> requestedAndNotBlockedWithPriorities = requested.stream().filter(req -> !blocked.contains(req.getLeft())).collect(toSet());
Integer highestPriority = requestedAndNotBlockedWithPriorities.stream().map(p -> p.getRight()).max(Integer::max).get();
Set<BEvent> requestedAndNotBlocked = requestedAndNotBlockedWithPriorities.stream().filter(p -> p.getRight().intValue() == highestPriority.intValue()).map(p -> p.getLeft()).collect(toSet());
return requestedAndNotBlocked.isEmpty() ? // No internal events requested, defer to externals.
externalEvents.stream().filter(e -> !blocked.contains(e)).findFirst().map(e -> singleton(e)).orElse(emptySet()) : requestedAndNotBlocked;
} finally {
Context.exit();
}
}
use of il.ac.bgu.cs.bp.bpjs.model.BEvent 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()));
}
Aggregations