use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.
the class TopologicalSortTest method testTopologicalSortSkip.
@Test
public void testTopologicalSortSkip() {
final CorrelationIdentifier a = CorrelationIdentifier.of("a");
final CorrelationIdentifier b = CorrelationIdentifier.of("b");
final CorrelationIdentifier c = CorrelationIdentifier.of("c");
final Map<CorrelationIdentifier, Set<CorrelationIdentifier>> dependencies = ImmutableMap.of();
final EnumeratingIterable<CorrelationIdentifier> topologicalPermutationIterable = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b, c), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutationIterable.iterator();
final ImmutableList.Builder<List<CorrelationIdentifier>> builder = ImmutableList.builder();
while (iterator.hasNext()) {
final List<CorrelationIdentifier> next = iterator.next();
builder.add(next);
if (next.get(0).equals(b) && next.get(1).equals(a)) {
iterator.skip(0);
}
}
final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = builder.build();
assertEquals(5, topologicalPermutations.size());
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, b, c)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, c, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(b, a, c)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, a, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, b, a)));
}
use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.
the class TopologicalSortTest method testTopologicalSortFullDependencies.
@Test
public void testTopologicalSortFullDependencies() {
final CorrelationIdentifier a = CorrelationIdentifier.of("a");
final CorrelationIdentifier b = CorrelationIdentifier.of("b");
final CorrelationIdentifier c = CorrelationIdentifier.of("c");
final Map<CorrelationIdentifier, Set<CorrelationIdentifier>> dependencies = ImmutableMap.of(b, ImmutableSet.of(a), c, ImmutableSet.of(b));
final EnumeratingIterable<CorrelationIdentifier> topologicalPermutationIterable = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b, c), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = ImmutableList.copyOf(topologicalPermutationIterable);
assertEquals(1, topologicalPermutations.size());
assertEquals(ImmutableList.of(a, b, c), topologicalPermutations.get(0));
}
use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.
the class TopologicalSortTest method testTopologicalSortSkipComplexError1.
@Test
public void testTopologicalSortSkipComplexError1() {
final CorrelationIdentifier a = CorrelationIdentifier.of("a");
final CorrelationIdentifier b = CorrelationIdentifier.of("b");
final EnumeratingIterable<CorrelationIdentifier> topologicalPermutations = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b), id -> ImmutableSet.of());
final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutations.iterator();
Assertions.assertThrows(UnsupportedOperationException.class, () -> iterator.skip(0));
}
use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.
the class TopologicalSortTest method testTopologicalSortSkip3.
@Test
public void testTopologicalSortSkip3() {
final CorrelationIdentifier a = CorrelationIdentifier.of("a");
final CorrelationIdentifier b = CorrelationIdentifier.of("b");
final CorrelationIdentifier c = CorrelationIdentifier.of("c");
final CorrelationIdentifier d = CorrelationIdentifier.of("d");
final Map<CorrelationIdentifier, Set<CorrelationIdentifier>> dependencies = ImmutableMap.of();
final EnumeratingIterable<CorrelationIdentifier> topologicalPermutationIterable = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b, c, d), id -> dependencies.getOrDefault(id, ImmutableSet.of()));
final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutationIterable.iterator();
final ImmutableList.Builder<List<CorrelationIdentifier>> builder = ImmutableList.builder();
while (iterator.hasNext()) {
final List<CorrelationIdentifier> next = iterator.next();
builder.add(next);
if (next.get(0).equals(b) && next.get(1).equals(a)) {
iterator.skip(0);
}
}
final ImmutableList<List<CorrelationIdentifier>> topologicalPermutations = builder.build();
assertEquals(19, topologicalPermutations.size());
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, b, c, d)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, b, d, c)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, c, b, d)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, c, d, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, d, b, c)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(a, d, c, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(b, a, c, d)));
assertFalse(topologicalPermutations.contains(ImmutableList.of(b, a, d, c)));
assertFalse(topologicalPermutations.contains(ImmutableList.of(b, c, a, d)));
assertFalse(topologicalPermutations.contains(ImmutableList.of(b, c, d, a)));
assertFalse(topologicalPermutations.contains(ImmutableList.of(b, d, a, c)));
assertFalse(topologicalPermutations.contains(ImmutableList.of(b, d, c, a)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, a, b, d)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, a, d, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, b, a, d)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, b, d, a)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, d, a, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(c, d, b, a)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(d, a, b, c)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(d, a, c, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(d, b, a, c)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(d, b, c, a)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(d, c, a, b)));
assertTrue(topologicalPermutations.contains(ImmutableList.of(d, c, b, a)));
}
use of com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier in project fdb-record-layer by FoundationDB.
the class TopologicalSortTest method testTopologicalSortSkipComplexError2.
@Test
public void testTopologicalSortSkipComplexError2() {
final CorrelationIdentifier a = CorrelationIdentifier.of("a");
final CorrelationIdentifier b = CorrelationIdentifier.of("b");
final EnumeratingIterable<CorrelationIdentifier> topologicalPermutations = TopologicalSort.topologicalOrderPermutations(ImmutableSet.of(a, b), id -> ImmutableSet.of());
final EnumeratingIterator<CorrelationIdentifier> iterator = topologicalPermutations.iterator();
iterator.next();
Assertions.assertThrows(IndexOutOfBoundsException.class, () -> iterator.skip(2));
}
Aggregations