org.apache.tinkerpop.gremlin.FeatureRequirement Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.FeatureRequirement. 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: FeatureSupportTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
public void shouldSupportUserSuppliedIdsOfTypeUuid() throws Exception {
    final UUID id = UUID.randomUUID();

    // a graph can "allow" an id without internally supporting it natively and therefore doesn't need
    // to throw the exception
    assumeFalse(graph.features().edge().willAllowId(id));

    try {
        final Vertex v = graph.addVertex();
        v.addEdge("test", v, T.id, id);
        fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_UUID_IDS));
    } catch (Exception e) {
        validateException(Edge.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), e);
    }
}
 
Example #2
Source File: AddEdgeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
public void g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X() {
    final Vertex a = g.V().has("name", "marko").next();
    final Vertex b = g.V().has("name", "peter").next();

    final Traversal<Vertex, Edge> traversal = get_g_withSideEffectXb_bX_VXaX_addEXknowsX_toXbX_propertyXweight_0_5X(a, b);
    final Edge edge = traversal.next();
    assertFalse(traversal.hasNext());
    assertEquals(edge.outVertex(), convertToVertex(graph, "marko"));
    assertEquals(edge.inVertex(), convertToVertex(graph, "peter"));
    assertEquals("knows", edge.label());
    assertEquals(1, g.E(edge).properties().count().next().intValue());
    assertEquals(0.5d, g.E(edge).<Double>values("weight").next(), 0.1d);
    assertEquals(6L, g.V().count().next().longValue());
    assertEquals(7L, g.E().count().next().longValue());
}
 
Example #3
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
public void shouldTransformGraphMLV2ToV3ViaXSLT() throws Exception {
    final InputStream stylesheet = Thread.currentThread().getContextClassLoader().getResourceAsStream("tp2-to-tp3-graphml.xslt");
    final InputStream datafile = getResourceAsStream(GraphMLResourceAccess.class, "tinkerpop-classic-tp2.xml");
    final ByteArrayOutputStream output = new ByteArrayOutputStream();

    final TransformerFactory tFactory = TransformerFactory.newInstance();
    final StreamSource stylesource = new StreamSource(stylesheet);
    final Transformer transformer = tFactory.newTransformer(stylesource);

    final StreamSource source = new StreamSource(datafile);
    final StreamResult result = new StreamResult(output);
    transformer.transform(source, result);

    final GraphReader reader = GraphMLReader.build().create();
    reader.readGraph(new ByteArrayInputStream(output.toByteArray()), graph);
    assertClassicGraph(graph, false, true);
}
 
Example #4
Source File: TransactionTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE)
public void shouldCommitOnCloseWhenConfigured() throws Exception {
    final AtomicReference<Object> oid = new AtomicReference<>();
    final Thread t = new Thread(() -> {
        final Vertex v1 = graph.addVertex("name", "marko");
        g.tx().onClose(Transaction.CLOSE_BEHAVIOR.COMMIT);
        oid.set(v1.id());
        graph.tx().close();
    });
    t.start();
    t.join();

    final Vertex v2 = graph.vertices(oid.get()).next();
    assertEquals("marko", v2.<String>value("name"));
}
 
Example #5
Source File: FeatureSupportTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_ANY_IDS, supported = false)
public void shouldSupportUserSuppliedIdsOfTypeAny() throws Exception {
    final Date id = new Date();

    // a graph can "allow" an id without internally supporting it natively and therefore doesn't need
    // to throw the exception
    assumeFalse(graph.features().vertex().properties().willAllowId(id));

    try {
        final Vertex v = graph.addVertex();
        v.property(VertexProperty.Cardinality.single, "test", "me", T.id, id);
        fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), FEATURE_ANY_IDS));
    } catch (Exception ex) {
        validateException(VertexProperty.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), ex);
    }
}
 
Example #6
Source File: TransactionTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
public void shouldAllowReferenceOfEdgeIdOutsideOfOriginalThreadManual() throws Exception {
    g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL);
    g.tx().open();
    final Vertex v1 = graph.addVertex();
    final Edge e = v1.addEdge("self", v1, "weight", 0.5d);

    final AtomicReference<Object> id = new AtomicReference<>();
    final Thread t = new Thread(() -> {
        g.tx().open();
        id.set(e.id());
    });

    t.start();
    t.join();

    assertEquals(e.id(), id.get());

    g.tx().rollback();
}
 
Example #7
Source File: FeatureSupportTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
public void shouldSupportUserSuppliedIdsOfTypeUuid() throws Exception {
    final UUID id = UUID.randomUUID();

    // a graph can "allow" an id without internally supporting it natively and therefore doesn't need
    // to throw the exception
    assumeFalse(graph.features().vertex().properties().willAllowId(id));

    try {
        final Vertex v = graph.addVertex();
        v.property(VertexProperty.Cardinality.single, "test", "me", T.id, id);
        fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexPropertyFeatures.class.getSimpleName(), FEATURE_UUID_IDS));
    } catch (Exception ex) {
        validateException(VertexProperty.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), ex);
    }
}
 
Example #8
Source File: FeatureSupportTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_ANY_IDS, supported = false)
public void shouldSupportUserSuppliedIdsOfTypeAny() throws Exception {
    final Date id = new Date();

    // a graph can "allow" an id without internally supporting it natively and therefore doesn't need
    // to throw the exception
    assumeFalse(graph.features().edge().willAllowId(id));

    try {
        final Vertex v = graph.addVertex();
        v.addEdge("test", v, T.id, id);
        fail(String.format(INVALID_FEATURE_SPECIFICATION, EdgeFeatures.class.getSimpleName(), FEATURE_ANY_IDS));
    } catch (Exception e) {
        validateException(Edge.Exceptions.userSuppliedIdsOfThisTypeNotSupported(), e);
    }
}
 
Example #9
Source File: IoGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteModern() throws Exception {
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        final GraphWriter writer = graph.io(ioBuilderToTest).writer().create();
        writer.writeGraph(os, graph);

        final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
        graphProvider.clear(configuration);
        final Graph g1 = graphProvider.openTestGraph(configuration);
        final GraphReader reader = graph.io(ioBuilderToTest).reader().create();
        try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
            reader.readGraph(bais, g1);
        }

        // modern uses double natively so always assert as such
        IoTest.assertModernGraph(g1, true, lossyForId);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #10
Source File: VertexTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_UPSERT, supported = false)
public void shouldHaveExceptionConsistencyWhenAssigningSameIdOnEdge() {
    final Vertex v = graph.addVertex();
    final Object o = graphProvider.convertId("1", Edge.class);
    v.addEdge("self", v, T.id, o, "weight", 1);

    try {
        v.addEdge("self", v, T.id, o, "weight", 1);
        fail("Assigning the same ID to an Element should throw an exception");
    } catch (Exception ex) {
        validateException(Graph.Exceptions.edgeWithIdAlreadyExists(o), ex);
    }
}
 
Example #11
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteSelfLoopingEdges() throws Exception {
    final Graph source = graph;
    final Vertex v1 = source.addVertex();
    final Vertex v2 = source.addVertex();
    v1.addEdge("CONTROL", v2);
    v1.addEdge("SELFLOOP", v1);

    final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null);
    final Graph target = graphProvider.openTestGraph(targetConf);
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        source.io(IoCore.graphml()).writer().create().writeGraph(os, source);
        try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
            target.io(IoCore.graphml()).reader().create().readGraph(is, target);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
    assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
}
 
Example #12
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteModernWrappedInJsonObject() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V2_0).create();
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        final GraphWriter writer = graph.io(graphson()).writer().wrapAdjacencyList(true).mapper(mapper).create();
        writer.writeGraph(os, graph);

        final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
        graphProvider.clear(configuration);
        final Graph g1 = graphProvider.openTestGraph(configuration);
        final GraphReader reader = graph.io(graphson()).reader().mapper(mapper).unwrapAdjacencyList(true).create();
        try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
            reader.readGraph(bais, g1);
        }

        // modern uses double natively so always assert as such
        IoTest.assertModernGraph(g1, true, true);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #13
Source File: EdgeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldNotGetConcurrentModificationException() {
    for (int i = 0; i < 25; i++) {
        final Vertex v = graph.addVertex();
        v.addEdge("friend", v);
    }

    tryCommit(graph, getAssertVertexEdgeCounts(25, 25));

    for (Edge e : g.E().toList()) {
        e.remove();
        tryCommit(graph);
    }

    tryCommit(graph, getAssertVertexEdgeCounts(25, 0));
}
 
Example #14
Source File: VariablesTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = Graph.Features.VariableFeatures.FEATURE_VARIABLES)
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = Graph.Features.VariableFeatures.FEATURE_INTEGER_VALUES)
public void shouldHoldVariableInteger() {
    final Graph.Variables variables = graph.variables();
    variables.set("test1", 1);
    variables.set("test2", 2);
    variables.set("test3", 3);

    tryCommit(graph, graph -> {
        final Map<String, Object> m = variables.asMap();
        assertEquals(1, m.get("test1"));
        assertEquals(2, m.get("test2"));
        assertEquals(3, m.get("test3"));
    });
}
 
Example #15
Source File: TransactionTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
public void shouldAllowReferenceOfVertexOutsideOfOriginalTransactionalContextManual() {
    g.tx().onReadWrite(Transaction.READ_WRITE_BEHAVIOR.MANUAL);
    g.tx().open();
    final Vertex v1 = graph.addVertex("name", "stephen");
    g.tx().commit();

    g.tx().open();
    assertEquals("stephen", v1.value("name"));

    g.tx().rollback();
    g.tx().open();
    assertEquals("stephen", v1.value("name"));
    g.tx().close();
}
 
Example #16
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers.
 */
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldWriteNormalizedGraphML() throws Exception {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        final GraphMLWriter w = GraphMLWriter.build().normalize(true).create();
        w.writeGraph(bos, graph);
        final String expected = streamToString(getResourceAsStream(GraphMLResourceAccess.class, "tinkerpop-classic-normalized.xml"));
        assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
    }
}
 
Example #17
Source File: TestGraphProvider.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
private static boolean customizedId(Class<?> test, String testMethod) {
    Method method;
    try {
        method = test.getDeclaredMethod(testMethod);
    } catch (NoSuchMethodException ignored) {
        return false;
    }
    FeatureRequirements features =
                        method.getAnnotation(FeatureRequirements.class);
    if (features == null) {
        return false;
    }
    for (FeatureRequirement feature : features.value()) {
        if (feature.featureClass() == Graph.Features.VertexFeatures.class &&
            ID_TYPES.contains(feature.feature())) {
            // Expect CUSTOMIZED_ID if want to pass id to create vertex
            return true;
        }
    }
    return false;
}
 
Example #18
Source File: AddEdgeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
public void g_V_asXaX_inXcreatedX_addEXcreatedByX_fromXaX_propertyXyear_2009X_propertyXacl_publicX() {
    final Traversal<Vertex, Edge> traversal = get_g_V_asXaX_inXcreatedX_addEXcreatedByX_fromXaX_propertyXyear_2009X_propertyXacl_publicX();
    printTraversalForm(traversal);
    int count = 0;
    while (traversal.hasNext()) {
        final Edge edge = traversal.next();
        assertEquals("createdBy", edge.label());
        assertEquals(2009, g.E(edge).values("year").next());
        assertEquals("public", g.E(edge).values("acl").next());
        assertEquals(2, g.E(edge).properties().count().next().intValue());
        assertEquals("person", g.E(edge).inV().label().next());
        assertEquals("software", g.E(edge).outV().label().next());
        if (g.E(edge).outV().values("name").next().equals("ripple"))
            assertEquals("josh", g.E(edge).inV().values("name").next());
        count++;

    }
    assertEquals(4, count);
    assertEquals(10, IteratorUtils.count(g.E()));
    assertEquals(6, IteratorUtils.count(g.V()));
}
 
Example #19
Source File: StarGraphTest.java    From tinkerpop with Apache License 2.0 6 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 shouldAttachWithCreateMethod() {
    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 Vertex createdVertex = starGraph.getStarVertex().attach(Attachable.Method.create(graph));
    starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(edge -> ((Attachable<Edge>) edge).attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex)));
    TestHelper.validateEquality(starVertex, createdVertex);
}
 
Example #20
Source File: AddVertexTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NULL_PROPERTY_VALUES, supported = false)
public void g_V_hasLabelXpersonX_propertyXname_nullX() {
    final Traversal<Vertex, Vertex> traversal = get_g_V_hasLabelXpersonX_propertyXname_nullX();
    printTraversalForm(traversal);
    traversal.forEachRemaining(v -> assertThat(v.properties("name").hasNext(), is(false)));
}
 
Example #21
Source File: VertexTest.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_ADD_VERTICES)
public void shouldValidateEquality() {
    final Vertex v1 = graph.addVertex();
    final Vertex v2 = graph.addVertex();

    assertEquals(v1, v1);
    assertEquals(v2, v2);
    assertNotEquals(v1, v2);
}
 
Example #22
Source File: EventStrategyProcessTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
public void shouldReferencePropertyOfVertexPropertyWhenNew() {
    final AtomicBoolean triggered = new AtomicBoolean(false);
    final Vertex v = graph.addVertex();
    final VertexProperty vp = v.property("xxx","blah");
    final String label = vp.label();
    final Object value = vp.value();
    vp.property("to-change", "dah");

    final MutationListener listener = new AbstractMutationListener() {
        @Override
        public void vertexPropertyPropertyChanged(final VertexProperty element, final Property oldValue, final Object setValue) {
            assertThat(element, instanceOf(ReferenceVertexProperty.class));
            assertEquals(label, element.label());
            assertEquals(value, element.value());
            assertThat(oldValue, instanceOf(KeyedProperty.class));
            assertEquals("new", oldValue.key());
            assertEquals("yay!", setValue);
            triggered.set(true);
        }
    };
    final EventStrategy.Builder builder = EventStrategy.build().addListener(listener).detach(EventStrategy.Detachment.REFERENCE);

    if (graph.features().graph().supportsTransactions())
        builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));

    final EventStrategy eventStrategy = builder.create();
    final GraphTraversalSource gts = create(eventStrategy);

    gts.V(v).properties("xxx").property("new","yay!").iterate();
    tryCommit(graph);

    assertEquals(1, IteratorUtils.count(g.V(v).properties()));
    assertEquals(2, IteratorUtils.count(g.V(v).properties().properties()));
    assertThat(triggered.get(), is(true));
}
 
Example #23
Source File: GraphTest.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_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_UUID_IDS)
public void shouldIterateVerticesWithUuidIdSupportUsingVertexId() {
    // if the graph supports id assigned, it should allow it.  if the graph does not, it will generate one
    final Vertex v1 = graph.features().vertex().supportsUserSuppliedIds() ? graph.addVertex(T.id, UUID.randomUUID()) : graph.addVertex();
    graph.addVertex();
    tryCommit(graph, graph -> {
        final Vertex v = graph.vertices(v1.id()).next();
        assertEquals(v1.id(), v.id());
    });
}
 
Example #24
Source File: FeatureSupportTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_THREADED_TRANSACTIONS, supported = false)
public void shouldThrowOnThreadedTransactionNotSupported() {
    try {
        graph.tx().createThreadedTx();
        fail("An exception should be thrown since the threaded transaction feature is not supported");
    } catch (Exception e) {
        validateException(Transaction.Exceptions.threadedTransactionsNotSupported(), e);
    }
}
 
Example #25
Source File: PropertyTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_NULL_PROPERTY_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
public void shouldAllowNullAddVertexProperty() throws Exception {
    final Vertex v = this.graph.addVertex("person");
    final VertexProperty vp = v.property("location", "santa fe", "startTime", 1995, "endTime", null);
    assertEquals(1995, (int) vp.value("startTime"));
    assertNull(vp.value("endTime"));
}
 
Example #26
Source File: VertexTest.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_ADD_VERTICES)
public void shouldHaveExceptionConsistencyWhenUsingSystemVertexLabel() {
    final String label = Graph.Hidden.hide("systemLabel");
    try {
        graph.addVertex(T.label, label);
        fail("Call to Graph.addVertex() should throw an exception when label is a system key");
    } catch (Exception ex) {
        validateException(Element.Exceptions.labelCanNotBeAHiddenKey(label), ex);
    }
}
 
Example #27
Source File: CommunityGeneratorTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_INTEGER_VALUES)
public void shouldGenerateDifferentGraph() throws Exception {
    final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
    final Graph graph1 = graphProvider.openTestGraph(configuration);

    try {
        communityGeneratorTest(graph, () -> 123456789l);

        afterLoadGraphWith(graph1);
        communityGeneratorTest(graph1, () -> 987654321l);

        final GraphTraversalSource g = graph.traversal();
        final GraphTraversalSource g1 = graph1.traversal();

        assertTrue(g.E().count().next() > 0);
        assertTrue(g.V().count().next() > 0);
        assertTrue(g1.E().count().next() > 0);
        assertTrue(g1.V().count().next() > 0);

        // don't assert counts of edges...those may be the same, just ensure that not every vertex has the
        // same number of edges between graphs.  that should make it harder for the test to fail.
        assertFalse(same(graph, graph1));
    } catch (Exception ex) {
        throw ex;
    } finally {
        graphProvider.clear(graph1, configuration);
    }

    assertFalse(failures.get() >= ultimateFailureThreshold);
}
 
Example #28
Source File: FeatureSupportTest.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_ADD_VERTICES)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_UUID_IDS, supported = false)
public void shouldSupportUuidIdsIfUuidIdsAreGeneratedFromTheGraph() throws Exception {
    final Vertex v = graph.addVertex();
    if (v.id() instanceof UUID)
        fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_UUID_IDS));
}
 
Example #29
Source File: GraphTest.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_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
public void shouldIterateVerticesWithCustomIdSupportUsingStringRepresentations() {
    final Vertex v1 = graph.addVertex();
    final Vertex v2 = graph.addVertex();
    graph.addVertex();
    tryCommit(graph, graph -> {
        assertEquals(2, IteratorUtils.count(graph.vertices(v1.id().toString(), v2.id().toString())));
    });
}
 
Example #30
Source File: DropTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_PROPERTY)
public void g_E_propertiesXweightX_drop() {
    final Traversal<Edge, ? extends Property<Object>> traversal = get_g_E_propertiesXweightX_drop();
    printTraversalForm(traversal);
    assertFalse(traversal.hasNext());
    g.E().forEachRemaining(edge -> assertEquals(0, IteratorUtils.count(edge.properties())));
}