Java Code Examples for org.apache.tinkerpop.gremlin.driver.ResultSet#iterator()

The following examples show how to use org.apache.tinkerpop.gremlin.driver.ResultSet#iterator() . 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: GremlinDriverIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIterate() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();

    final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
    final Iterator<Result> itty = results.iterator();
    final AtomicInteger counter = new AtomicInteger(0);
    while (itty.hasNext()) {
        counter.incrementAndGet();
        assertEquals(counter.get(), itty.next().getInt());
    }

    assertEquals(9, counter.get());
    assertThat(results.allItemsAvailable(), is(true));

    // can't stream it again
    assertThat(results.iterator().hasNext(), is(false));

    cluster.close();
}
 
Example 2
Source File: DriverRemoteTraversal.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public DriverRemoteTraversal(final ResultSet rs, final Client client, final boolean attach, final Optional<Configuration> conf) {
    // attaching is really just for testing purposes. it doesn't make sense in any real-world scenario as it would
    // require that the client have access to the Graph instance that produced the result. tests need that
    // attachment process to properly execute in full hence this little hack.
    if (attach) {
        if (!conf.isPresent()) throw new IllegalStateException("Traverser can't be reattached for testing");
        final Graph graph = ((Supplier<Graph>) conf.get().getProperty(GREMLIN_REMOTE + "attachment")).get();
        this.traversers = new AttachingTraverserIterator<>(rs.iterator(), graph);
    } else {
        this.traversers = new TraverserIterator<>(rs.iterator());
    }
}