Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.Traversal#iterate()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.Traversal#iterate() . 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: SubgraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(CREW)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS)
public void g_withSideEffectXsgX_V_hasXname_danielXout_capXsgX() throws Exception {
    final Configuration config = graphProvider.newGraphConfiguration("subgraph", this.getClass(), name.getMethodName(), CREW);
    graphProvider.clear(config);
    final Graph subgraph = graphProvider.openTestGraph(config);
    /////
    final Traversal<Vertex, Vertex> traversal = get_g_withSideEffectXsgX_V_hasXname_danielX_outE_subgraphXsgX_inV(subgraph);
    printTraversalForm(traversal);
    traversal.iterate();
    assertVertexEdgeCounts(subgraph, 3, 2);

    final List<String> locations = subgraph.traversal().V().has("name", "daniel").<String>values("location").toList();
    assertThat(locations, contains("spremberg", "kaiserslautern", "aachen"));

    graphProvider.clear(subgraph, config);
}
 
Example 2
Source File: TestIo.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void g_io_writeXjsonX() throws IOException {
    loadModern();
    final String fileToWrite = TestHelper.generateTempFile(WriteTest.class,"tinkerpop-modern-v3d0", ".json").getAbsolutePath().replace('\\', '/');

    final File f = new File(fileToWrite);
    assertThat(f.length() == 0, is(true));

    final Traversal<Object,Object> traversal =  this.sqlgGraph.traversal()
            .io(fileToWrite)
            .with(IO.writer, IO.graphson)
            .with(IO.registry, SqlgIoRegistryV3.instance())
            .write();
    printTraversalForm(traversal);
    traversal.iterate();

    assertThat(f.length() > 0, is(true));
}
 
Example 3
Source File: StandardVerificationStrategyTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBeVerified() {
    final Traversal copy = copyAndConfigureTraversal(traversal);

    if (legalTraversal) {
        copy.asAdmin().applyStrategies();

        // try to also apply strategies with iterate() so that a NoneStep is added - for consistency sake we want
        // to be able to run a profile and get no result back with this.
        final Traversal forIteration = copyAndConfigureTraversal(traversal);
        forIteration.iterate();
    } else {
        try {
            copy.asAdmin().applyStrategies();
            fail("The strategy should not allow traversal: " + this.traversal);
        } catch (IllegalStateException ise) {
            assertTrue(true);
        }
    }
}
 
Example 4
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_read_withXreader_gryoX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GryoResourceAccess.class, "tinkerpop-modern-v3d0.kryo", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_read_withXreader_gryoX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example 5
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void g_V_whereXinXcreatedX_count_isX1XX_name_profileXmetricsX() {
    final Traversal<Vertex, String> traversal = get_g_V_whereXinXcreatedX_count_isX1XX_name_profileXmetricsX();
    printTraversalForm(traversal);
    traversal.iterate();
    final TraversalMetrics traversalMetrics = traversal.asAdmin().getSideEffects().get(METRICS_KEY);
    validate_g_V_whereXinXcreatedX_count_isX1XX_name_profile(traversal, traversalMetrics);
}
 
Example 6
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void g_V_matchXa_created_b__b_in_count_isXeqX1XXX_selectXa_bX_profile() {
    final Traversal<Vertex, TraversalMetrics> traversal = get_g_V_matchXa_created_b__b_in_count_isXeqX1XXX_selectXa_bX_profile();
    printTraversalForm(traversal);
    traversal.iterate();
}
 
Example 7
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
@IgnoreEngine(TraversalEngine.Type.COMPUTER)
public void g_V_sideEffectXThread_sleepX10XX_sideEffectXThread_sleepX5XX_profileXmetricsX() {
    final Traversal<Vertex, Vertex> traversal = get_g_V_sideEffectXThread_sleepX10XX_sideEffectXThread_sleepX5XX_profileXmetricsX();
    printTraversalForm(traversal);
    traversal.iterate();

    // This assertion is really only meant for tinkergraph
    if (graph.getClass().getSimpleName().equals("TinkerGraph"))
        assertEquals("There should be 7 steps in this traversal (counting injected profile steps).", 7, traversal.asAdmin().getSteps().size());

    final TraversalMetrics traversalMetrics = traversal.asAdmin().getSideEffects().get(METRICS_KEY);
    validate_g_V_sideEffectXThread_sleepX10XX_sideEffectXThread_sleepX5XX_profile(traversalMetrics);
}
 
Example 8
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(GRATEFUL)
public void grateful_V_out_out_profileXmetricsX() {
    final Traversal<Vertex, Vertex> traversal = get_g_V_out_out_profileXmetricsX();
    printTraversalForm(traversal);
    traversal.iterate();
    final TraversalMetrics traversalMetrics = traversal.asAdmin().getSideEffects().get(METRICS_KEY);
    validate_g_V_out_out_profile_grateful(traversalMetrics);
}
 
Example 9
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void modern_V_out_out_profileXmetricsX() {
    final Traversal<Vertex, Vertex> traversal = get_g_V_out_out_profileXmetricsX();
    printTraversalForm(traversal);
    traversal.iterate();
    validate_g_V_out_out_profile_modern(traversal, traversal.asAdmin().getSideEffects().get(METRICS_KEY));
}
 
Example 10
Source File: TestIo.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void g_io_write_withXwrite_gryoX() throws IOException {
    loadModern();
    final String fileToWrite = TestHelper.generateTempFile(WriteTest.class, "tinkerpop-modern-v3d0", ".kryo").getAbsolutePath().replace('\\', '/');
    final File f = new File(fileToWrite);
    assertThat(f.length() == 0, is(true));
    final Traversal<Object, Object> traversal = this.sqlgGraph.traversal().io(fileToWrite)
            .with(IO.writer, IO.gryo)
            .with(IO.registry, SqlgIoRegistryV3.instance())
            .write();
    printTraversalForm(traversal);
    traversal.iterate();
    assertThat(f.length() > 0, is(true));
}
 
Example 11
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_read_withXreader_graphsonX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphSONResourceAccess.class, "tinkerpop-modern-v3d0.json", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_read_withXreader_graphsonX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example 12
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_readXkryoX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GryoResourceAccess.class, "tinkerpop-modern-v3d0.kryo", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_readXkryoX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example 13
Source File: WriteTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_WRITE)
public void g_io_writeXxmlX() throws IOException {
    final String fileToWrite = TestHelper.generateTempFile(WriteTest.class,"tinkerpop-modern", ".xml").getAbsolutePath().replace('\\', '/');

    final File f = new File(fileToWrite);
    assertThat(f.length() == 0, is(true));

    final Traversal<Object,Object> traversal = get_g_io_writeXxmlX(fileToWrite);
    printTraversalForm(traversal);
    traversal.iterate();

    assertThat(f.length() > 0, is(true));
}
 
Example 14
Source File: WriteTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_WRITE)
public void g_io_write_withXwriter_graphsonX() throws IOException {
    final String fileToWrite = TestHelper.generateTempFile(WriteTest.class,"tinkerpop-modern-v3d0", ".json").getAbsolutePath().replace('\\', '/');

    final File f = new File(fileToWrite);
    assertThat(f.length() == 0, is(true));

    final Traversal<Object,Object> traversal = get_g_io_write_withXwriter_graphsonX(fileToWrite);
    printTraversalForm(traversal);
    traversal.iterate();

    assertThat(f.length() > 0, is(true));
}
 
Example 15
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void testProfileStrategyCallbackSideEffect() {
    final Traversal<Vertex, Vertex> t = get_g_V_out_out_profileXmetricsX();
    MockStep mockStep = new MockStep(t.asAdmin());
    t.asAdmin().addStep(3, mockStep);
    t.iterate();
    assertTrue(mockStep.callbackCalled);

    if (!onGraphComputer(t.asAdmin())) {
        final TraversalMetrics traversalMetrics = t.asAdmin().getSideEffects().get(METRICS_KEY);
        assertEquals(100, traversalMetrics.getMetrics(3).getCount("bogusCount").longValue());
    }
}
 
Example 16
Source File: WriteTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_WRITE)
public void g_io_write_withXwrite_gryoX() throws IOException {
    final String fileToWrite = TestHelper.generateTempFile(WriteTest.class, "tinkerpop-modern-v3d0", ".kryo").getAbsolutePath().replace('\\', '/');

    final File f = new File(fileToWrite);
    assertThat(f.length() == 0, is(true));

    final Traversal<Object,Object> traversal = get_g_io_write_withXwriter_gryoX(fileToWrite);
    printTraversalForm(traversal);
    traversal.iterate();

    assertThat(f.length() > 0, is(true));
}
 
Example 17
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void g_V_matchXa_created_b__b_in_count_isXeqX1XXX_selectXa_bX_profileXmetricsX() {
    final Traversal<Vertex, Map<String, String>> traversal = get_g_V_matchXa_created_b__b_in_count_isXeqX1XXX_selectXa_bX_profileXmetricsX();
    printTraversalForm(traversal);
    traversal.iterate();
}
 
Example 18
Source File: MatchTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@LoadGraphWith(MODERN)
public void g_V_out_asXcX_matchXb_knows_a__c_created_eX_selectXcX() throws Exception {
    final Traversal<Vertex, String> traversal = get_g_V_out_asXcX_matchXb_knows_a__c_created_eX_selectXcX();
    try {
        printTraversalForm(traversal);
        traversal.iterate();
        fail("Should have tossed an exception because match pattern is not solvable");
    } catch (Exception ex) {
        //final Throwable root = ExceptionUtils.getRootCause(ex);
        //assertThat(root.getMessage(), startsWith("The provided match pattern is unsolvable:"));
    }
}
 
Example 19
Source File: HasTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(MODERN)
public void g_VXv4X_hasXage_gt_30X() {
    final Traversal<Vertex, Vertex> traversalJosh = get_g_VXv1X_hasXage_gt_30X(convertToVertex(graph,"josh"));
    printTraversalForm(traversalJosh);
    assertTrue(traversalJosh.hasNext());
    traversalJosh.iterate();
}
 
Example 20
Source File: MatchTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@LoadGraphWith(MODERN)
public void g_V_matchXa_knows_b__c_knows_bX() {
    final Traversal<Vertex, Map<String, Vertex>> traversal = get_g_V_matchXa_knows_b__c_knows_bX();
    try {
        printTraversalForm(traversal);
        traversal.iterate();
        fail("Should have tossed an exception because match pattern is not solvable");
    } catch (Exception ex) {
        //final Throwable root = ExceptionUtils.getRootCause(ex);
        //assertThat(root.getMessage(), startsWith("The provided match pattern is unsolvable:"));
    }
}