@Test
  public void shouldAppendPartitionToVertex() {
    final Vertex v = g.addVertex("any", "thing");

    assertNotNull(v);
    assertEquals("thing", v.property("any").value());
    assertEquals("A", v.property(partition).value());
  }
  @Test
  public void shouldAppendPartitionToEdge() {
    final Vertex v1 = g.addVertex("any", "thing");
    final Vertex v2 = g.addVertex("some", "thing");
    final Edge e = v1.addEdge("connectsTo", v2, "every", "thing");

    assertNotNull(v1);
    assertEquals("thing", v1.property("any").value());
    assertEquals("A", v2.property(partition).value());

    assertNotNull(v2);
    assertEquals("thing", v2.property("some").value());
    assertEquals("A", v2.property(partition).value());

    assertNotNull(e);
    assertEquals("thing", e.property("every").value());
    assertEquals("connectsTo", e.label());
    assertEquals("A", e.property(partition).value());
  }
  @Test
  public void shouldWriteVerticesToMultiplePartitions() {
    final Vertex vA = g.addVertex("any", "a");
    final PartitionGraphStrategy strategy =
        (PartitionGraphStrategy) ((StrategyWrappedGraph) g).strategy().getGraphStrategy().get();
    strategy.setWritePartition("B");
    final Vertex vB = g.addVertex("any", "b");

    assertNotNull(vA);
    assertEquals("a", vA.property("any").value());
    assertEquals("A", vA.property(partition).value());

    assertNotNull(vB);
    assertEquals("b", vB.property("any").value());
    assertEquals("B", vB.property(partition).value());

    /* not applicable to SubgraphStrategy
    final GraphTraversal t = g.V();
    assertTrue(t.strategies().get().stream().anyMatch(o -> o.getClass().equals(PartitionGraphStrategy.PartitionGraphTraversalStrategy.class)));
    */

    g.V()
        .forEach(
            v -> {
              assertTrue(v instanceof StrategyWrappedVertex);
              assertEquals("a", v.property("any").value());
            });

    strategy.removeReadPartition("A");
    strategy.addReadPartition("B");

    g.V()
        .forEach(
            v -> {
              assertTrue(v instanceof StrategyWrappedVertex);
              assertEquals("b", v.property("any").value());
            });

    strategy.addReadPartition("A");
    assertEquals(new Long(2), g.V().count().next());
  }
  @Test
  public void shouldWrapProperties() {
    final Vertex v = g.addVertex("any", "a");
    final Edge e = v.addEdge("to", v, "all", "a");

    assertTrue(v.property("any") instanceof StrategyWrappedProperty);
    assertTrue(v.properties().get("any") instanceof StrategyWrappedProperty);

    assertTrue(e.property("all") instanceof StrategyWrappedProperty);
    assertTrue(e.properties().get("all") instanceof StrategyWrappedProperty);

    assertTrue(g.V().property("any").next() instanceof StrategyWrappedProperty);
    assertTrue(g.E().property("any").next() instanceof StrategyWrappedProperty);
  }
示例#5
0
 private static void createVertexProperty(
     final Graph graphToWriteTo,
     final Vertex v,
     final VertexProperty<Object> p,
     final boolean hidden) {
   final List<Object> propertyArgs = new ArrayList<>();
   if (graphToWriteTo.features().vertex().properties().supportsUserSuppliedIds())
     appendToArgList(propertyArgs, T.id, p.id());
   p.iterators()
       .propertyIterator()
       .forEachRemaining(it -> appendToArgList(propertyArgs, it.key(), it.value()));
   // p.iterators().hiddenPropertyIterator().forEachRemaining(it -> appendToArgList(propertyArgs,
   // Graph.Key.hide(it.key()), it.value()));
   v.property(hidden ? Graph.Key.hide(p.key()) : p.key(), p.value(), propertyArgs.toArray());
 }
示例#6
0
 @Override
 public UnaryOperator<Supplier<Void>> getRemoveElementStrategy(
     final Strategy.Context<? extends StrategyWrappedElement> ctx) {
   if (ctx.getCurrent() instanceof StrategyWrappedVertex) {
     return (t) ->
         () -> {
           Vertex v = ((StrategyWrappedVertex) ctx.getCurrent()).getBaseVertex();
           v.bothE().forEach(e -> e.remove());
           getDeletionVertex(ctx.getBaseGraph()).addEdge(UmlgGraph.DELETION_VERTEX, v);
           v.properties().values().forEach(p -> p.remove());
           v.property("_deleted", true);
           return null;
         };
   } else {
     return UnaryOperator.identity();
   }
 }