@Test public void testClosingIterables() throws IOException { graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareVertex("v2", VISIBILITY_A) .addPropertyValue("k1", "name", "matt", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); // Ensure that closing doesn't cause an error if we haven't iterated yet Iterable<Vertex> vertices1 = graph.getVertices(AUTHORIZATIONS_A); if (vertices1 instanceof Closeable) { ((Closeable) vertices1).close(); } // Ensure that closing doesn't cause an error if the iterable was fully traversed vertices1 = graph.getVertices(AUTHORIZATIONS_A); toList(vertices1); if (vertices1 instanceof Closeable) { ((Closeable) vertices1).close(); } // Ensure that closing query results doesn't cause an error if we haven't iterated yet QueryResultsIterable<Vertex> queryResults = graph.query(AUTHORIZATIONS_A).hasId("v1").vertices(); queryResults.close(); // Ensure that closing query results doesn't cause an error if the iterable was fully traversed queryResults = graph.query(AUTHORIZATIONS_A).hasId("v1").vertices(); toList(queryResults); queryResults.close(); }
@Test public void testClosingIterables() throws IOException { graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareVertex("v2", VISIBILITY_A) .addPropertyValue("k1", "name", "matt", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); // Ensure that closing doesn't cause an error if we haven't iterated yet Iterable<Vertex> vertices1 = graph.getVertices(AUTHORIZATIONS_A); if (vertices1 instanceof Closeable) { ((Closeable) vertices1).close(); } // Ensure that closing doesn't cause an error if the iterable was fully traversed vertices1 = graph.getVertices(AUTHORIZATIONS_A); toList(vertices1); if (vertices1 instanceof Closeable) { ((Closeable) vertices1).close(); } // Ensure that closing query results doesn't cause an error if we haven't iterated yet QueryResultsIterable<Vertex> queryResults = graph.query(AUTHORIZATIONS_A).hasId("v1").vertices(); queryResults.close(); // Ensure that closing query results doesn't cause an error if the iterable was fully traversed queryResults = graph.query(AUTHORIZATIONS_A).hasId("v1").vertices(); toList(queryResults); queryResults.close(); }
@Test public void testExtendedDataEdgeQuery() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row2", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareVertex("v2", VISIBILITY_A) .addExtendedData("table1", "row3", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row4", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A) .addExtendedData("table1", "row5", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row6", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Edge e1 = graph.getEdge("e1", AUTHORIZATIONS_A); List<ExtendedDataRow> searchResultsList = toList( getGraph().query("*", AUTHORIZATIONS_A) .hasExtendedData(ElementType.EDGE, e1.getId(), "table1") .extendedDataRows() ); assertRowIdsAnyOrder(Lists.newArrayList("row5", "row6"), searchResultsList); QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).hasId("e1").extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A).hasId("v1", "e1").extendedDataRows(); assertResultsCount(4, 4, rows); }
@Test public void testExtendedDataEdgeQuery() { graph.prepareVertex("v1", VISIBILITY_A) .addExtendedData("table1", "row1", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row2", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareVertex("v2", VISIBILITY_A) .addExtendedData("table1", "row3", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row4", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.prepareEdge("e1", "v1", "v2", LABEL_LABEL1, VISIBILITY_A) .addExtendedData("table1", "row5", "name", "value 1", VISIBILITY_A) .addExtendedData("table1", "row6", "name", "value 2", VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); Edge e1 = graph.getEdge("e1", AUTHORIZATIONS_A); List<ExtendedDataRow> searchResultsList = toList( getGraph().query("*", AUTHORIZATIONS_A) .hasExtendedData(ElementType.EDGE, e1.getId(), "table1") .extendedDataRows() ); assertRowIdsAnyOrder(Lists.newArrayList("row5", "row6"), searchResultsList); QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).hasId("e1").extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A).hasId("v1", "e1").extendedDataRows(); assertResultsCount(4, 4, rows); }
assertRowIdsAnyOrder(Lists.newArrayList("row3", "row4", "row5", "row6"), searchResultsList); QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).hasId("v1").extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A).hasId("v1", "v2").extendedDataRows(); assertResultsCount(4, 4, rows);
assertRowIdsAnyOrder(Lists.newArrayList("row3", "row4", "row5", "row6"), searchResultsList); QueryResultsIterable<ExtendedDataRow> rows = graph.query(AUTHORIZATIONS_A).hasId("v1").extendedDataRows(); assertResultsCount(2, 2, rows); rows = graph.query(AUTHORIZATIONS_A).hasId("v1", "v2").extendedDataRows(); assertResultsCount(4, 4, rows);
assertResultsCount(2, 2, vertices); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1").vertices(); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1", "v2").vertices(); assertResultsCount(2, 2, vertices); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1", "v2").hasId("v1").vertices(); assertResultsCount(1, 1, vertices); assertVertexIds(vertices, "v1"); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1").hasId("v2").vertices(); assertResultsCount(0, 0, vertices); edges = graph.query(AUTHORIZATIONS_A).hasId("e1").edges(); assertResultsCount(1, 1, edges); edges = graph.query(AUTHORIZATIONS_A).hasId("e1", "e2").edges(); assertResultsCount(2, 2, edges);
assertResultsCount(2, 2, vertices); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1").vertices(); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1", "v2").vertices(); assertResultsCount(2, 2, vertices); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1", "v2").hasId("v1").vertices(); assertResultsCount(1, 1, vertices); assertVertexIds(vertices, "v1"); vertices = graph.query(AUTHORIZATIONS_A).hasId("v1").hasId("v2").vertices(); assertResultsCount(0, 0, vertices); edges = graph.query(AUTHORIZATIONS_A).hasId("e1").edges(); assertResultsCount(1, 1, edges); edges = graph.query(AUTHORIZATIONS_A).hasId("e1", "e2").edges(); assertResultsCount(2, 2, edges);