@Test public void shouldThrowExceptionOnvInDifferentPartition() { final Vertex vA = g.addVertex("any", "a"); assertEquals(vA.id(), g.v(vA.id()).id()); final PartitionGraphStrategy strategy = (PartitionGraphStrategy) ((StrategyWrappedGraph) g).strategy().getGraphStrategy().get(); strategy.clearReadPartitions(); try { g.v(vA.id()); } catch (Exception ex) { final Exception expected = Graph.Exceptions.elementNotFound(Vertex.class, vA.id()); assertEquals(expected.getClass(), ex.getClass()); assertEquals(expected.getMessage(), ex.getMessage()); } }
@Before public void setup() { final Vertex v = mock(Vertex.class); when(v.id()).thenReturn("1"); when(v.label()).thenReturn("l"); this.mv = DetachedVertex.detach(v); }
@Test public void shouldNotEvaluateToEqualDifferentId() { final Vertex v = mock(Vertex.class); when(v.id()).thenReturn("2"); when(v.label()).thenReturn("l"); final DetachedVertex mv1 = DetachedVertex.detach(v); assertFalse(mv1.equals(this.mv)); }
@Test 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).strategy().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); /* not applicable to SubgraphStrategy final GraphTraversal t = g.V(); assertTrue(t.strategies().get().stream().anyMatch(o -> o.getClass().equals(PartitionGraphStrategy.PartitionGraphTraversalStrategy.class))); */ 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()); assertEquals(vC.id(), g.e(eAtovC.id()).inV().id().next()); assertFalse(g.e(eAtovC.id()).outV().hasNext()); /* not applicable to SubgraphStrategy strategy.addReadPartition("A"); g.v(vA.id()).out().out().forEach(v -> { assertTrue(v instanceof StrategyWrapped); assertFalse(((StrategyWrappedElement) v).getBaseElement() instanceof StrategyWrapped); }); g.v(vA.id()).outE().inV().outE().forEach(e -> { assertTrue(e instanceof StrategyWrapped); assertFalse(((StrategyWrappedElement) e).getBaseElement() instanceof StrategyWrapped); }); */ }