@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
public void shouldWriteToMultiplePartitions() {
final Vertex vA = g.addVertex("any", "a");
final Vertex vAA = g.addVertex("any", "aa");
final Edge eAtoAA = vA.addEdge("a->a", vAA);
final PartitionGraphStrategy strategy = (PartitionGraphStrategy) ((StrategyWrappedGraph) g).getStrategy().getGraphStrategy().get();
strategy.setWritePartition("B");
final Vertex vB = g.addVertex("any", "b");
vA.addEdge("a->b", vB);
strategy.setWritePartition("C");
final Vertex vC = g.addVertex("any", "c");
final Edge eBtovC = vB.addEdge("b->c", vC);
final Edge eAtovC = vA.addEdge("a->c", vC);
strategy.clearReadPartitions();
assertEquals(new Long(0), g.V().count().next());
assertEquals(new Long(0), g.E().count().next());
strategy.addReadPartition("A");
assertEquals(new Long(2), g.V().count().next());
assertEquals(new Long(1), g.E().count().next());
assertEquals(new Long(1), g.v(vA.id()).outE().count().next());
assertEquals(eAtoAA.id(), g.v(vA.id()).outE().next().id());
assertEquals(new Long(1), g.v(vA.id()).out().count().next());
assertEquals(vAA.id(), g.v(vA.id()).out().next().id());
strategy.addReadPartition("B");
assertEquals(new Long(3), g.V().count().next());
assertEquals(new Long(2), g.E().count().next());
strategy.addReadPartition("C");
assertEquals(new Long(4), g.V().count().next());
assertEquals(new Long(4), g.E().count().next());
strategy.removeReadPartition("A");
strategy.removeReadPartition("B");
assertEquals(new Long(1), g.V().count().next());
// two edges are in the "C" partition, but one each of their incident vertices are not
assertEquals(new Long(0), g.E().count().next());
assertEquals(new Long(0), g.v(vC.id()).inE().count().next());
assertEquals(new Long(0), g.v(vC.id()).in().count().next());
strategy.addReadPartition("B");
// only one edge in, due to excluded vertices; vA is not in {B,C}
assertEquals(new Long(1), g.v(vC.id()).inE().count().next());
assertEquals(new Long(1), g.v(vC.id()).in().count().next());
assertEquals(vC.id(), g.e(eBtovC.id()).inV().id().next());
assertEquals(vB.id(), g.e(eBtovC.id()).outV().id().next());
try {
g.e(eAtovC.id());
fail("Edge should not be in the graph because vA is not in partitions {B,C}");
} catch (Exception ex) {
assertTrue(ex instanceof NoSuchElementException);
}
}