@Test public void testAddEdgeWithProperties() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Edge addedEdge = graph.prepareEdge("e1", v1, v2, "label1", VISIBILITY_A) .setProperty("propA", "valueA", VISIBILITY_A) .setProperty("propB", "valueB", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Edge e = graph.getEdge("e1", AUTHORIZATIONS_A); assertEquals(1, count(e.getProperties())); assertEquals("valueA", e.getPropertyValues("propA").iterator().next()); assertEquals(0, count(e.getPropertyValues("propB"))); e = graph.getEdge("e1", AUTHORIZATIONS_A_AND_B); assertEquals(2, count(e.getProperties())); assertEquals("valueA", e.getPropertyValues("propA").iterator().next()); assertEquals("valueB", e.getPropertyValues("propB").iterator().next()); assertEquals("valueA", e.getPropertyValue("propA")); assertEquals("valueB", e.getPropertyValue("propB")); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge), new AddPropertyEvent(graph, addedEdge, addedEdge.getProperty("propA")), new AddPropertyEvent(graph, addedEdge, addedEdge.getProperty("propB")) ); }
@Test public void testAddVertexWithoutId() { Vertex vertexAdded = graph.addVertex(VISIBILITY_A, AUTHORIZATIONS_A); assertNotNull(vertexAdded); String vertexId = vertexAdded.getId(); assertNotNull(vertexId); graph.flush(); Vertex v = graph.getVertex(vertexId, AUTHORIZATIONS_A); assertNotNull(v); assertNotNull(vertexId); assertEvents( new AddVertexEvent(graph, vertexAdded) ); }
@Test public void testAddEdgeWithProperties() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Edge addedEdge = graph.prepareEdge("e1", v1, v2, "label1", VISIBILITY_A) .setProperty("propA", "valueA", VISIBILITY_A) .setProperty("propB", "valueB", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Edge e = graph.getEdge("e1", AUTHORIZATIONS_A); assertEquals(1, count(e.getProperties())); assertEquals("valueA", e.getPropertyValues("propA").iterator().next()); assertEquals(0, count(e.getPropertyValues("propB"))); e = graph.getEdge("e1", AUTHORIZATIONS_A_AND_B); assertEquals(2, count(e.getProperties())); assertEquals("valueA", e.getPropertyValues("propA").iterator().next()); assertEquals("valueB", e.getPropertyValues("propB").iterator().next()); assertEquals("valueA", e.getPropertyValue("propA")); assertEquals("valueB", e.getPropertyValue("propB")); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge), new AddPropertyEvent(graph, addedEdge, addedEdge.getProperty("propA")), new AddPropertyEvent(graph, addedEdge, addedEdge.getProperty("propB")) ); }
@Test public void testAddVertexWithoutId() { Vertex vertexAdded = graph.addVertex(VISIBILITY_A, AUTHORIZATIONS_A); assertNotNull(vertexAdded); String vertexId = vertexAdded.getId(); assertNotNull(vertexId); graph.flush(); Vertex v = graph.getVertex(vertexId, AUTHORIZATIONS_A); assertNotNull(v); assertNotNull(vertexId); assertEvents( new AddVertexEvent(graph, vertexAdded) ); }
new AddVertexEvent(graph, vertexAdded), new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop1")), new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop2"))
@Override public Vertex save(Authorizations authorizations) { AccumuloVertex vertex = new AccumuloVertex( AccumuloGraph.this, getVertexId(), getVisibility(), getProperties(), getPropertyRemoves(), null, authorizations, System.currentTimeMillis() ); elementMutationBuilder.saveVertex(vertex); if (getIndexHint() != IndexHint.DO_NOT_INDEX) { getSearchIndex().addElement(AccumuloGraph.this, vertex, authorizations); } if (hasEventListeners()) { queueEvent(new AddVertexEvent(AccumuloGraph.this, vertex)); for (Property property : getProperties()) { queueEvent(new AddPropertyEvent(AccumuloGraph.this, vertex, property)); } for (PropertyRemoveMutation propertyRemoveMutation : getPropertyRemoves()) { queueEvent(new RemovePropertyEvent(AccumuloGraph.this, vertex, propertyRemoveMutation)); } } return vertex; } };
new AddVertexEvent(graph, vertexAdded), new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop1")), new AddPropertyEvent(graph, vertexAdded, vertexAdded.getProperty("prop2"))
@Override public Vertex save(Authorizations authorizations) { InMemoryVertex newVertex = new InMemoryVertex(InMemoryGraph.this, getVertexId(), getVisibility(), getProperties(), getPropertyRemoves(), null, authorizations); // to more closely simulate how accumulo works. add a potentially sparse (in case of an update) vertex to the search index. if (getIndexHint() != IndexHint.DO_NOT_INDEX) { getSearchIndex().addElement(InMemoryGraph.this, newVertex, authorizations); } InMemoryVertex existingVertex = (InMemoryVertex) getVertex(getVertexId(), authorizations); InMemoryVertex vertex = InMemoryVertex.updateOrCreate(InMemoryGraph.this, existingVertex, newVertex, authorizations); vertices.put(getVertexId(), vertex); if (hasEventListeners()) { fireGraphEvent(new AddVertexEvent(InMemoryGraph.this, vertex)); for (Property property : getProperties()) { fireGraphEvent(new AddPropertyEvent(InMemoryGraph.this, vertex, property)); } for (PropertyRemoveMutation propertyRemoveMutation : getPropertyRemoves()) { fireGraphEvent(new RemovePropertyEvent(InMemoryGraph.this, vertex, propertyRemoveMutation)); } } return vertex; } };
@Test public void testRemoveVertexWithProperties() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Property prop1 = v1.getProperty("prop1"); assertEquals(1, count(graph.getVertices(AUTHORIZATIONS_A))); graph.removeVertex(v1, AUTHORIZATIONS_A); assertEquals(0, count(graph.getVertices(AUTHORIZATIONS_A_AND_B))); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddPropertyEvent(graph, v1, prop1), new RemoveVertexEvent(graph, v1) ); }
@Test public void testRemoveEdge() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Edge addedEdge = graph.addEdge("e1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A); assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); try { graph.removeEdge("e1", AUTHORIZATIONS_B); } catch (IllegalArgumentException e) { // expected } assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); graph.removeEdge("e1", AUTHORIZATIONS_A); assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A))); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); v2 = graph.getVertex("v2", AUTHORIZATIONS_A); assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge), new RemoveEdgeEvent(graph, addedEdge) ); }
@Test public void testRemoveEdge() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); Vertex v2 = graph.addVertex("v2", VISIBILITY_A, AUTHORIZATIONS_A); Edge addedEdge = graph.addEdge("e1", v1, v2, "label1", VISIBILITY_A, AUTHORIZATIONS_A); assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); try { graph.removeEdge("e1", AUTHORIZATIONS_B); } catch (IllegalArgumentException e) { // expected } assertEquals(1, count(graph.getEdges(AUTHORIZATIONS_A))); graph.removeEdge("e1", AUTHORIZATIONS_A); assertEquals(0, count(graph.getEdges(AUTHORIZATIONS_A))); v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals(0, count(v1.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); v2 = graph.getVertex("v2", AUTHORIZATIONS_A); assertEquals(0, count(v2.getVertices(Direction.BOTH, AUTHORIZATIONS_A))); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge), new RemoveEdgeEvent(graph, addedEdge) ); }
@Test public void testRemoveVertexWithProperties() { Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Property prop1 = v1.getProperty("prop1"); assertEquals(1, count(graph.getVertices(AUTHORIZATIONS_A))); graph.removeVertex(v1, AUTHORIZATIONS_A); assertEquals(0, count(graph.getVertices(AUTHORIZATIONS_A_AND_B))); graph.flush(); assertEvents( new AddVertexEvent(graph, v1), new AddPropertyEvent(graph, v1, prop1), new RemoveVertexEvent(graph, v1) ); }
@Test public void testAddVertexWithId() { Vertex vertexAdded = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); assertNotNull(vertexAdded); assertEquals("v1", vertexAdded.getId()); graph.flush(); Vertex v = graph.getVertex("v1", AUTHORIZATIONS_A); assertNotNull(v); assertEquals("v1", v.getId()); assertEquals(VISIBILITY_A, v.getVisibility()); v = graph.getVertex("", AUTHORIZATIONS_A); assertNull(v); v = graph.getVertex(null, AUTHORIZATIONS_A); assertNull(v); assertEvents( new AddVertexEvent(graph, vertexAdded) ); }
@Test public void testAddVertexWithId() { Vertex vertexAdded = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_A); assertNotNull(vertexAdded); assertEquals("v1", vertexAdded.getId()); graph.flush(); Vertex v = graph.getVertex("v1", AUTHORIZATIONS_A); assertNotNull(v); assertEquals("v1", v.getId()); assertEquals(VISIBILITY_A, v.getVisibility()); v = graph.getVertex("", AUTHORIZATIONS_A); assertNull(v); v = graph.getVertex(null, AUTHORIZATIONS_A); assertNull(v); assertEvents( new AddVertexEvent(graph, vertexAdded) ); }
new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge) );
new AddVertexEvent(graph, v1), new AddVertexEvent(graph, v2), new AddEdgeEvent(graph, addedEdge) );