@Test public void testRemove() { ThunderGraph graph = new ThunderGraph(this.dbPath); try { graph.createKeyIndex("name", Vertex.class); graph.commit(); Vertex v1 = graph.addVertex(null); v1.setProperty("name", 1); for (int i = 0; i < 10; i++) { Vertex v2 = graph.addVertex(null); v2.setProperty("name", 2); Edge e = graph.addEdge(null, v1, v2, "label1"); e.setProperty("name", "cccc"); } graph.commit(); Assert.assertEquals(11, count(graph.getVertices())); Assert.assertEquals(1, count(graph.getVertices("name", 1))); Assert.assertEquals(10, count(graph.getVertices("name", 2))); Assert.assertEquals(10, count(graph.getEdges("name", "cccc"))); Iterator<Vertex> iter = graph.getVertices("name", 2).iterator(); Vertex v = iter.next(); Assert.assertEquals(1L, v.getId()); Assert.assertEquals(2, v.getProperty("name")); iter.remove(); Assert.assertNull(graph.getVertex(1L)); Assert.assertEquals(9, count(iter)); } finally { graph.shutdown(); } }
@Test public void testCursorRefreshOnFirst() { ThunderGraph graph = new ThunderGraph(this.dbPath); try { graph.createKeyIndex("name", Vertex.class); graph.commit(); Vertex v1 = graph.addVertex(null); v1.setProperty("name", 1); for (int i = 0; i < 10; i++) { Vertex v2 = graph.addVertex(null); v2.setProperty("name", 2); Edge e = graph.addEdge(null, v1, v2, "label1"); e.setProperty("name", "cccc"); } graph.commit(); Assert.assertEquals(11, count(graph.getVertices())); Assert.assertEquals(1, count(graph.getVertices("name", 1))); Assert.assertEquals(10, count(graph.getVertices("name", 2))); Assert.assertEquals(10, count(graph.getEdges("name", "cccc"))); Iterator<Vertex> iter = graph.getVertices("name", 1).iterator(); // This will cause the transaction to be upgraded to a writable transaction. // I.e. iter's cursor gets closed graph.getEdges("name", "cccc").iterator().next().setProperty("name", "cccd"); Vertex v = iter.next(); Assert.assertEquals(1, v.getProperty("name")); } finally { graph.shutdown(); } }