Refine search
resultgraph = graph.newTransaction(); for (Map.Entry<Long, Map<String, Object>> vprop : mutatedProperties.entrySet()) { Vertex v = resultgraph.vertices(vprop.getKey()).next(); for (Map.Entry<String, Object> prop : vprop.getValue().entrySet()) { v.property(VertexProperty.Cardinality.single, prop.getKey(), prop.getValue());
@Override public void run() { final long gCounter = IteratorUtils.count(graph.vertices()); assertEquals(1l, gCounter); final long g1Counter = IteratorUtils.count(g1.vertices()); assertEquals(0l, g1Counter); } };
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) public void shouldEvaluateEquivalentVerticesWithNoSuppliedIds() { final Vertex v = graph.addVertex(); assertNotNull(v); final Vertex u = graph.vertices(v.id()).next(); assertNotNull(u); assertEquals(v, u); assertEquals(graph.vertices(u.id()).next(), graph.vertices(u.id()).next()); assertEquals(graph.vertices(v.id()).next(), graph.vertices(u.id()).next()); assertEquals(graph.vertices(v.id()).next(), graph.vertices(v.id()).next()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) public void shouldCreateVertex() { final DetachedVertex detachedVertex = new DetachedVertex(23, "dog", Collections.emptyMap()); detachedVertex.attach(Attachable.Method.create(graph)); assertEquals(7, IteratorUtils.count(graph.vertices())); final AtomicInteger dogTimes = new AtomicInteger(0); graph.vertices().forEachRemaining(vertex -> { if (vertex.label().equals("dog")) { dogTimes.incrementAndGet(); } }); assertEquals(1, dogTimes.get()); }
@Test public void shouldHaveExceptionConsistencyWhenFindVertexByIdThatIsNonExistentViaIterator() { try { graph.vertices(graphProvider.convertId(10000l, Vertex.class)).next(); fail("Call to g.vertices(10000l) should throw an exception"); } catch (Exception ex) { assertThat(ex, IsInstanceOf.instanceOf(NoSuchElementException.class)); } }
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS) public void shouldEvaluateEquivalentVertexHashCodeWithSuppliedIds() { final Vertex v = graph.addVertex(T.id, graphProvider.convertId("1", Vertex.class)); final Vertex u = graph.vertices(graphProvider.convertId("1", Vertex.class)).next(); assertEquals(v, u); final Set<Vertex> set = new HashSet<>(); set.add(v); set.add(v); set.add(u); set.add(u); set.add(graph.vertices(graphProvider.convertId("1", Vertex.class)).next()); set.add(graph.vertices(graphProvider.convertId("1", Vertex.class)).next()); assertEquals(1, set.size()); assertEquals(v.hashCode(), u.hashCode()); }
@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_ANY_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS) public void shouldNotMixTypesForGettingSpecificVerticesWithStringFirst() { final Vertex v1 = graph.addVertex(); try { graph.vertices(graphProvider.convertId("1", Vertex.class), v1); fail("Should have thrown an exception because id arguments were mixed."); } catch (Exception ex) { final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement(); assertEquals(expected.getClass(), ex.getClass()); assertEquals(expected.getMessage(), ex.getMessage()); } }
resultgraph = graph.newTransaction(); for (Map.Entry<Long, Map<String, Object>> vertexProperty : mutatedProperties.entrySet()) { Vertex v = resultgraph.vertices(vertexProperty.getKey()).next(); for (Map.Entry<String, Object> prop : vertexProperty.getValue().entrySet()) { if (prop.getValue() instanceof List) {
/** * Generate a graph with lots of vertices, then iterate the vertices and remove them from the graph */ @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_REMOVE_VERTICES) public void shouldRemoveVerticesWithoutConcurrentModificationException() { for (int i = 0; i < 100; i++) { graph.addVertex(); } final Iterator<Vertex> vertexIterator = graph.vertices(); assertTrue(vertexIterator.hasNext()); while (vertexIterator.hasNext()) { vertexIterator.next().remove(); } assertFalse(vertexIterator.hasNext()); tryCommit(graph, graph -> assertFalse(graph.vertices().hasNext())); }
public static Consumer<Graph> getAssertVertexEdgeCounts(final int expectedVertexCount, final int expectedEdgeCount) { return (g) -> { assertEquals(expectedVertexCount, IteratorUtils.count(g.vertices())); assertEquals(expectedEdgeCount, IteratorUtils.count(g.edges())); }; }
@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_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ANY_IDS) public void shouldAddVertexWithUserSuppliedAnyIdUsingString() { final UUID uuid = UUID.randomUUID(); graph.addVertex(T.id, uuid.toString()); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(uuid.toString()).next(); assertEquals(uuid.toString(), v.id()); }); }
@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_ANY_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_STRING_IDS) public void shouldNotMixTypesForGettingSpecificVerticesWithVertexFirst() { final Vertex v1 = graph.addVertex(); try { graph.vertices(v1, graphProvider.convertId("1", Vertex.class)); fail("Should have thrown an exception because id arguments were mixed."); } catch (Exception ex) { final Exception expected = Graph.Exceptions.idArgsMustBeEitherIdOrElement(); assertEquals(expected.getClass(), ex.getClass()); assertEquals(expected.getMessage(), ex.getMessage()); } }
private Iterable<Vertex> getVerticesAndNormalizeIfRequired(final Graph graph) { final Iterable<Vertex> vertices; if (normalize) { vertices = new ArrayList<>(); final Iterator<Vertex> vertexIterator = graph.vertices(); while (vertexIterator.hasNext()) { ((Collection<Vertex>) vertices).add(vertexIterator.next()); } Collections.sort((List<Vertex>) vertices, Comparators.ELEMENT_COMPARATOR); } else vertices = IteratorUtils.list(graph.vertices()); return vertices; }
@Test @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY) public void shouldAllowRemovalFromVertexWhenAlreadyRemoved() { final Vertex v = graph.addVertex("name", "marko"); tryCommit(graph); final Vertex v1 = graph.vertices(v.id()).next(); try { final Property p = v1.property("name"); p.remove(); p.remove(); v1.property("name").remove(); v1.property("name").remove(); } catch (Exception ex) { fail("Removing a vertex property that was already removed should not throw an exception"); } }
@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 shouldIterateVerticesWithCustomIdSupportUsingReferenceVertex() { final Vertex v1 = graph.addVertex(); graph.addVertex(); tryCommit(graph, graph -> { final Vertex v = graph.vertices(ReferenceFactory.detach(v1)).next(); assertEquals(v1.id(), v.id()); assertThat(v, is(not(instanceOf(ReferenceVertex.class)))); }); }
@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()))); }); }
public static void createRandomGraph(final Graph graph, final int numberOfVertices, final int maxNumberOfEdgesPerVertex) { final Random random = new Random(); for (int i = 0; i < numberOfVertices; i++) { graph.addVertex(T.id, i); } graph.vertices().forEachRemaining(vertex -> { for (int i = 0; i < random.nextInt(maxNumberOfEdgesPerVertex); i++) { final Vertex other = graph.vertices(random.nextInt(numberOfVertices)).next(); vertex.addEdge("link", other); } }); } }
@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.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS) public void shouldCountVerticesEdgesOnPreTransactionCommit() { // see a more complex version of this test at GraphTest.shouldProperlyCountVerticesAndEdgesOnAddRemove() Vertex v1 = graph.addVertex(); graph.tx().commit(); assertVertexEdgeCounts(graph, 1, 0); final Vertex v2 = graph.addVertex(); v1 = graph.vertices(v1.id()).next(); v1.addEdge("friend", v2); assertVertexEdgeCounts(graph, 2, 1); graph.tx().commit(); assertVertexEdgeCounts(graph, 2, 1); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertex() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Vertex v = graph.vertices(convertToVertexId("marko")).next(); final String json = mapper.writeValueAsString(v); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(GraphSONTokens.VERTEX, m.get(GraphSONTokens.TYPE)); assertEquals(v.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); final Map<String,List<Map<String,Object>>> properties = (Map<String,List<Map<String,Object>>>) m.get(GraphSONTokens.PROPERTIES); assertEquals(v.value("name").toString(), properties.get("name").get(0).get(GraphSONTokens.VALUE).toString()); assertEquals((Integer) v.value("age"), properties.get("age").get(0).get(GraphSONTokens.VALUE)); assertEquals(1, properties.get("name").size()); assertEquals(1, properties.get("age").size()); assertEquals(2, properties.size()); }
@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) public void shouldReadGraphMLWithoutEdgeIds() throws IOException { final GraphReader reader = GraphMLReader.build().strict(false).create(); try (final InputStream stream = IoTest.class.getResourceAsStream(TestHelper.convertPackageToResourcePath(GraphMLResourceAccess.class) + "graph-no-edge-ids.xml")) { reader.readGraph(stream, graph); } assertEquals(1, IteratorUtils.count(graph.edges())); assertEquals(2, IteratorUtils.count(graph.vertices())); }