Java Code Examples for org.apache.tinkerpop.gremlin.structure.Graph#Features

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Graph#Features . 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: StringFactory.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static String featureString(final Graph.Features features) {
    final StringBuilder sb = new StringBuilder("FEATURES");
    final Predicate<Method> supportMethods = (m) -> m.getModifiers() == Modifier.PUBLIC && m.getName().startsWith(featuresStartWith) && !m.getName().equals(featuresStartWith);
    sb.append(LINE_SEPARATOR);

    Stream.of(Pair.with(Graph.Features.GraphFeatures.class, features.graph()),
            Pair.with(Graph.Features.VariableFeatures.class, features.graph().variables()),
            Pair.with(Graph.Features.VertexFeatures.class, features.vertex()),
            Pair.with(Graph.Features.VertexPropertyFeatures.class, features.vertex().properties()),
            Pair.with(Graph.Features.EdgeFeatures.class, features.edge()),
            Pair.with(Graph.Features.EdgePropertyFeatures.class, features.edge().properties())).forEach(p -> {
        printFeatureTitle(p.getValue0(), sb);
        Stream.of(p.getValue0().getMethods())
                .filter(supportMethods)
                .map(createTransform(p.getValue1()))
                .forEach(sb::append);
    });

    return sb.toString();
}
 
Example 2
Source File: ElementHelperTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAttachPropertiesButNotLabelsOrId() {
    final Element mockElement = mock(Element.class);
    final Graph mockGraph = mock(Graph.class);
    final Graph.Features mockGraphFeatures = mock(Graph.Features.class);
    final Graph.Features.VertexFeatures mockVertexFeatures = mock(Graph.Features.VertexFeatures.class);
    final Graph.Features.VertexPropertyFeatures mockVertexPropertyFeatures = mock(Graph.Features.VertexPropertyFeatures.class);
    when(mockElement.graph()).thenReturn(mockGraph);
    when(mockGraph.features()).thenReturn(mockGraphFeatures);
    when(mockGraphFeatures.vertex()).thenReturn(mockVertexFeatures);
    when(mockVertexFeatures.properties()).thenReturn(mockVertexPropertyFeatures);
    when(mockVertexPropertyFeatures.supportsNullPropertyValues()).thenReturn(true);
    ElementHelper.attachProperties(mockElement, "test", 123, T.id, 321, T.label, "friends");
    verify(mockElement, times(1)).property("test", 123);
    verify(mockElement, times(0)).property(T.id.getAccessor(), 321);
    verify(mockElement, times(0)).property(T.label.getAccessor(), "friends");
}
 
Example 3
Source File: ElementHelperTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAttachPropertiesWithCardinalityButNotLabelsOrId() {
    final Vertex mockElement = mock(Vertex.class);
    final Graph mockGraph = mock(Graph.class);
    final Graph.Features mockGraphFeatures = mock(Graph.Features.class);
    final Graph.Features.VertexFeatures mockVertexFeatures = mock(Graph.Features.VertexFeatures.class);
    final Graph.Features.VertexPropertyFeatures mockVertexPropertyFeatures = mock(Graph.Features.VertexPropertyFeatures.class);
    when(mockElement.graph()).thenReturn(mockGraph);
    when(mockGraph.features()).thenReturn(mockGraphFeatures);
    when(mockGraphFeatures.vertex()).thenReturn(mockVertexFeatures);
    when(mockVertexFeatures.properties()).thenReturn(mockVertexPropertyFeatures);
    when(mockVertexPropertyFeatures.supportsNullPropertyValues()).thenReturn(true);
    ElementHelper.attachProperties(mockElement, VertexProperty.Cardinality.single, "test", 123, T.id, 321, T.label, "friends");
    verify(mockElement, times(1)).property(VertexProperty.Cardinality.single, "test", 123);
    verify(mockElement, times(0)).property(VertexProperty.Cardinality.single, T.id.getAccessor(), 321);
    verify(mockElement, times(0)).property(VertexProperty.Cardinality.single, T.label.getAccessor(), "friends");
}
 
Example 4
Source File: AbstractGremlinTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private static void assumeRequirementsAreMetForTest(final Set<FeatureRequirement> featureRequirementSet,
                                                    final Graph.Features features, final boolean staticCheck)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    for (FeatureRequirement fr : featureRequirementSet) {
        try {
            assumeThat(String.format("Features of the graph do not support all of the features required by this test so it will be ignored: %s.%s=%s",
                    fr.featureClass().getSimpleName(), fr.feature(), fr.supported()),
                    features.supports(fr.featureClass(), fr.feature()), is(fr.supported()));
        } catch (NoSuchMethodException nsme) {
            throw new NoSuchMethodException(String.format("[supports%s] is not a valid feature on %s", fr.feature(), fr.featureClass()));
        } catch (UnsupportedOperationException uoe) {
            // no worries if this is a check of static features - it just means that we can't use the cache to
            // support this check and will have to incur the cost of instantiating a graph instance directly. but,
            // if this is not a static check then something else is amiss and we should throw.
            if (staticCheck) throw uoe;
        }
    }
}
 
Example 5
Source File: ElementHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test(expected = ClassCastException.class)
public void shouldFailTryingToAttachPropertiesNonStringKey() {
    final Element mockElement = mock(Element.class);
    final Graph mockGraph = mock(Graph.class);
    final Graph.Features mockGraphFeatures = mock(Graph.Features.class);
    final Graph.Features.VertexFeatures mockVertexFeatures = mock(Graph.Features.VertexFeatures.class);
    final Graph.Features.VertexPropertyFeatures mockVertexPropertyFeatures = mock(Graph.Features.VertexPropertyFeatures.class);
    when(mockElement.graph()).thenReturn(mockGraph);
    when(mockGraph.features()).thenReturn(mockGraphFeatures);
    when(mockGraphFeatures.vertex()).thenReturn(mockVertexFeatures);
    when(mockVertexFeatures.properties()).thenReturn(mockVertexPropertyFeatures);
    when(mockVertexPropertyFeatures.supportsNullPropertyValues()).thenReturn(true);
    ElementHelper.attachProperties(mockElement, "test", 123, 321, "test");
}
 
Example 6
Source File: ElementHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test(expected = ClassCastException.class)
public void shouldFailTryingToAttachPropertiesWithCardinalityNonStringKey() {
    final Element mockElement = mock(Vertex.class);
    final Graph mockGraph = mock(Graph.class);
    final Graph.Features mockGraphFeatures = mock(Graph.Features.class);
    final Graph.Features.VertexFeatures mockVertexFeatures = mock(Graph.Features.VertexFeatures.class);
    final Graph.Features.VertexPropertyFeatures mockVertexPropertyFeatures = mock(Graph.Features.VertexPropertyFeatures.class);
    when(mockElement.graph()).thenReturn(mockGraph);
    when(mockGraph.features()).thenReturn(mockGraphFeatures);
    when(mockGraphFeatures.vertex()).thenReturn(mockVertexFeatures);
    when(mockVertexFeatures.properties()).thenReturn(mockVertexPropertyFeatures);
    when(mockVertexPropertyFeatures.supportsNullPropertyValues()).thenReturn(true);
    ElementHelper.attachProperties(mockElement, VertexProperty.Cardinality.single, "test", 123, 321, "test");
}
 
Example 7
Source File: PartitionStrategyTraverseTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static GraphTraversal create(final Class<? extends Element> clazz) {
    final Graph mockedGraph = mock(Graph.class);
    final Graph.Features features = mock(Graph.Features.class);
    final Graph.Features.VertexFeatures vertexFeatures = mock(Graph.Features.VertexFeatures.class);
    when(mockedGraph.features()).thenReturn(features);
    when(features.vertex()).thenReturn(vertexFeatures);
    when(vertexFeatures.getCardinality(any())).thenReturn(VertexProperty.Cardinality.single);
    final DefaultGraphTraversal t = new DefaultGraphTraversal<>(mockedGraph);
    if (clazz != null) t.asAdmin().addStep(new GraphStep<>(t.asAdmin(), clazz, true));
    return t;
}
 
Example 8
Source File: BitsyGraph.java    From bitsy with Apache License 2.0 4 votes vote down vote up
@Override
public Graph.Features features() {
    return bitsyFeatures;
}
 
Example 9
Source File: BitsyAutoReloadingGraph.java    From bitsy with Apache License 2.0 4 votes vote down vote up
@Override
public Graph.Features features() {
    return graph.features();
}
 
Example 10
Source File: StandardJanusGraph.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
public Graph.Features features() {
    return JanusGraphFeatures.getFeatures(this, backend.getStoreFeatures());
}
 
Example 11
Source File: AbstractGremlinTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    final Method testMethod = this.getClass().getMethod(cleanMethodName(name.getMethodName()));
    final LoadGraphWith[] loadGraphWiths = testMethod.getAnnotationsByType(LoadGraphWith.class);
    final LoadGraphWith loadGraphWith = loadGraphWiths.length == 0 ? null : loadGraphWiths[0];
    final LoadGraphWith.GraphData loadGraphWithData = null == loadGraphWith ? null : loadGraphWith.value();
    final Set<FeatureRequirement> featureRequirementSet = getFeatureRequirementsForTest(testMethod, loadGraphWiths);

    graphProvider = GraphManager.getGraphProvider();

    // pre-check if available from graph provider to avoid graph creation
    final Optional<Graph.Features> staticFeatures = graphProvider.getStaticFeatures();
    if (staticFeatures.isPresent()) {
        assumeRequirementsAreMetForTest(featureRequirementSet, staticFeatures.get(), true);
    }

    graphProvider.getTestListener().ifPresent(l -> l.onTestStart(this.getClass(), name.getMethodName()));

    // Reset the counter for open iterators by this test
    StoreIteratorCounter.INSTANCE.reset();

    config = graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), loadGraphWithData);

    // this should clear state from a previously unfinished test. since the graph does not yet exist,
    // persisted graphs will likely just have their directories removed
    graphProvider.clear(config);

    graph = graphProvider.openTestGraph(config);
    g = graphProvider.traversal(graph);

    // even if we checked static features earlier it's of little cost to recheck again with the real graph
    // once it is instantiated. the real cost savings is preventing graph creation in the first place so
    // let's double check that all is legit.
    assumeRequirementsAreMetForTest(featureRequirementSet, graph.features(), false);

    beforeLoadGraphWith(graph);

    // load a graph with sample data if the annotation is present on the test
    graphProvider.loadGraphData(graph, loadGraphWith, this.getClass(), name.getMethodName());

    afterLoadGraphWith(graph);
}
 
Example 12
Source File: GraphManager.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Optional<Graph.Features> getStaticFeatures() {
    return innerGraphProvider.getStaticFeatures();
}
 
Example 13
Source File: AbstractNeo4jGraphProvider.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Optional<Graph.Features> getStaticFeatures() {
    return Optional.ofNullable(features);
}
 
Example 14
Source File: GraphProvider.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Gets a {@link Graph.Features} implementation that contains graph feature configuration that will never change
 * from execution to execution of the tests given this current {@code GraphProvider} implementation. Implementing
 * this method will allow the test suite to avoid creation of a {@link Graph} instance and thus speed up the
 * execution of tests if that creation process is expensive. It is important that this static set of features be
 * representative of what the {@link Graph} instance produced by this {@code GraphProvider} can actually do or
 * else the cost of {@link Graph} instantiation will be incurred when it doesn't need to be. It is also important
 * that this method be faster than the cost of {@link Graph} creation in the first place or there really won't be
 * any difference in execution speed. In cases where some features are static and others are not, simply throw
 * an {@code UnsupportedOperationException} from those features to let the test suite know that it cannot rely
 * on them and the test suite will revert to using a constructed {@link Graph} instance.
 */
public default Optional<Graph.Features> getStaticFeatures() {
    return Optional.empty();
}