Java Code Examples for org.apache.tinkerpop.gremlin.structure.util.star.StarGraph#addVertex()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.star.StarGraph#addVertex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertexWritableTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHashAndEqualCorrectly() {
    final StarGraph graph = StarGraph.open();
    final Vertex v = graph.addVertex(T.id, 1, T.label, Vertex.DEFAULT_LABEL);
    final Set<VertexWritable> set = new HashSet<>();
    for (int i = 0; i < 100; i++) {
        set.add(new VertexWritable(v));
    }
    assertEquals(1, set.size());
}
 
Example 2
Source File: VertexWritableTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHaveEqualVertexWritableAndInternalVertex() throws Exception {
    final StarGraph graph = StarGraph.open();
    final Vertex v = graph.addVertex(T.id, 1, T.label, Vertex.DEFAULT_LABEL);
    final VertexWritable vw = new VertexWritable(v);
    assertEquals(vw, vw);
    assertEquals(vw, byteClone(vw));
    assertEquals(v, byteClone(vw).get());
}
 
Example 3
Source File: VertexWritableTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldConstructVertexWritableWithCorrectByteRepresentation() {
    final StarGraph graph = StarGraph.open();
    final Vertex v = graph.addVertex(T.id, 1, T.label, Vertex.DEFAULT_LABEL, "test", "123");
    v.property(VertexProperty.Cardinality.list, "name", "marko", "acl", "private");
    final VertexWritable vw = byteClone(new VertexWritable(v));

    assertEquals(v.id(), vw.get().id());
    assertEquals(v.label(), vw.get().label());
    assertEquals("123", vw.get().value("test"));
    assertEquals(2, IteratorUtils.count(vw.get().properties()));
    assertEquals("marko", vw.get().value("name"));
    assertEquals("private", vw.get().property("name").value("acl"));
}
 
Example 4
Source File: DetachedGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
public void testAttachableCreateMethod() {
    final Random random = TestHelper.RANDOM;
    StarGraph starGraph = StarGraph.open();
    Vertex starVertex = starGraph.addVertex(T.label, "person", "name", "stephen", "name", "spmallete");
    starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko");
    for (int i = 0; i < 100; i++) {
        starVertex.addEdge("knows", starGraph.addVertex("person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong()));
        starGraph.addVertex(T.label, "project").addEdge("developedBy", starVertex, "public", random.nextBoolean());
    }
    final DetachedVertex detachedVertex = DetachedFactory.detach(starGraph.getStarVertex(), true);
    final Vertex createdVertex = detachedVertex.attach(Attachable.Method.create(graph));
    TestHelper.validateVertexEquality(detachedVertex, createdVertex, false);
    TestHelper.validateVertexEquality(detachedVertex, starVertex, false);

    starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(starEdge -> {
        final DetachedEdge detachedEdge = DetachedFactory.detach(starEdge, true);
        final Edge createdEdge = detachedEdge.attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex));
        TestHelper.validateEdgeEquality(detachedEdge, starEdge);
        TestHelper.validateEdgeEquality(detachedEdge, createdEdge);
    });

}
 
Example 5
Source File: AbstractIoRegistryCheck.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private void validateIoRegistryGraph(final HadoopGraph graph,
                                     final Class<? extends GraphComputer> graphComputerClass,
                                     final RecordWriter<NullWritable, VertexWritable> writer) throws Exception {


    for (int i = 0; i < NUMBER_OF_VERTICES; i++) {
        final StarGraph starGraph = StarGraph.open();
        Vertex vertex = starGraph.addVertex(T.label, "place", T.id, i, "point", new ToyPoint(i, i * 10), "message", "I'm " + i, "triangle", new ToyTriangle(i, i * 10, i * 100));
        vertex.addEdge("connection", starGraph.addVertex(T.id, i > 0 ? i - 1 : NUMBER_OF_VERTICES - 1));
        writer.write(NullWritable.get(), new VertexWritable(starGraph.getStarVertex()));
    }
    writer.close(new TaskAttemptContextImpl(ConfUtil.makeHadoopConfiguration(graph.configuration()), new TaskAttemptID()));

    // OLAP TESTING //
    validatePointTriangles(graph.traversal().withComputer(graphComputerClass).V().project("point", "triangle").by("point").by("triangle").toList());
    validatePointTriangles(graph.traversal().withComputer(graphComputerClass).V().out().project("point", "triangle").by("point").by("triangle").toList());
    validatePointTriangles(graph.traversal().withComputer(graphComputerClass).V().out().out().project("point", "triangle").by("point").by("triangle").toList());
    // OLTP TESTING //
    validatePointTriangles(graph.traversal().V().project("point", "triangle").by("point").by("triangle").toList());
    // HDFS TESTING //
    /*validatePointTriangles(IteratorUtils.<Map<String, Object>>asList(IteratorUtils.<Vertex, Map<String, Object>>map(FileSystemStorage.open(ConfUtil.makeHadoopConfiguration(graph.configuration())).head(graph.configuration().getInputLocation(), graph.configuration().getGraphReader()),
            vertex -> {
                return new HashMap<String, Object>() {{
                    put("point", vertex.value("point"));
                    put("triangle", vertex.value("triangle"));
                }};
            })));*/
}
 
Example 6
Source File: SparkMessengerTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void testSparkMessenger() throws Exception {
    // Define scopes
    final MessageScope.Local<String> orderSrcMessageScope = MessageScope.Local
            .of(__::inE, (message, edge) -> {
                if ("mocked_edge_label1".equals(edge.label())) {
                    return message;
                }
                return null;
            });

    // Define star graph
    final StarGraph starGraph = StarGraph.open();
    Object[] vertex0Array = new Object[]{T.id, 0, T.label, "mocked_vertex_label1"};
    Object[] vertex1Array = new Object[]{T.id, 1, T.label, "mocked_vertex_label2"};
    Object[] vertex2Array = new Object[]{T.id, 2, T.label, "mocked_vertex_label2"};
    Vertex vertex0 = starGraph.addVertex(vertex0Array);
    Vertex vertex1 = starGraph.addVertex(vertex1Array);
    Vertex vertex2 = starGraph.addVertex(vertex2Array);
    vertex1.addEdge("mocked_edge_label1", vertex0);
    vertex2.addEdge("mocked_edge_label2", vertex0);

    // Create Spark Messenger
    final SparkMessenger<String> messenger = new SparkMessenger<>();
    final List<String> incomingMessages = Arrays.asList("a", "b", "c");
    messenger.setVertexAndIncomingMessages(vertex0, incomingMessages);

    messenger.sendMessage(orderSrcMessageScope, "a");
    List<Tuple2<Object, String>> outgoingMessages0 = messenger.getOutgoingMessages();

    Assert.assertEquals("a", outgoingMessages0.get(0)._2());
    Assert.assertNull(outgoingMessages0.get(1)._2());
}