Skip to content

Commit 4bda644

Browse files
committed
added dropCollection flag for dropGraph, added tests
1 parent 19d5265 commit 4bda644

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
88

99
## [5.0.1] - 2018-09-25
1010

11+
### Added
12+
13+
- added `ArangoGraphAsync#drop(boolean dropCollections)`
14+
1115
### Fixed
1216

1317
- fixed `ArangoCursor#next` when performing a dirty read

src/main/java/com/arangodb/ArangoGraphAsync.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ CompletableFuture<GraphEntity> createGraph(
9292
*/
9393
CompletableFuture<Void> drop();
9494

95+
/**
96+
* Delete an existing graph including
97+
*
98+
* @see <a href="https://docs.arangodb.com/current/HTTP/Gharial/Management.html#drop-a-graph">API Documentation</a>
99+
* @param dropCollections
100+
* Drop collections of this graph as well. Collections will only be dropped if they are not used in other
101+
* graphs.
102+
* @return void
103+
*/
104+
CompletableFuture<Void> drop(boolean dropCollection);
105+
95106
/**
96107
* Get a graph from the graph module
97108
*

src/main/java/com/arangodb/internal/ArangoGraphAsyncImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public CompletableFuture<Void> drop() {
6464
return executor.execute(dropRequest(), Void.class);
6565
}
6666

67+
@Override
68+
public CompletableFuture<Void> drop(boolean dropCollection) {
69+
return executor.execute(dropRequest(dropCollection), Void.class);
70+
}
71+
6772
@Override
6873
public CompletableFuture<GraphEntity> getInfo() {
6974
return executor.execute(getInfoRequest(), getInfoResponseDeserializer());
@@ -109,5 +114,4 @@ public CompletableFuture<GraphEntity> removeEdgeDefinition(final String definiti
109114
return executor.execute(removeEdgeDefinitionRequest(definitionName),
110115
removeEdgeDefinitionResponseDeserializer());
111116
}
112-
113117
}

src/test/java/com/arangodb/ArangoGraphTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.util.ArrayList;
3131
import java.util.Collection;
32+
import java.util.Collections;
3233
import java.util.Iterator;
3334
import java.util.concurrent.ExecutionException;
3435

@@ -239,9 +240,37 @@ public void smartGraph() throws InterruptedException, ExecutionException {
239240
assertThat(graph.getSmartGraphAttribute(), is("test"));
240241
assertThat(graph.getNumberOfShards(), is(2));
241242
try {
242-
db.graph(GRAPH_NAME + "_smart").drop().get();
243+
db.graph(GRAPH_NAME + "_smart").drop(true).get();
243244
} catch (final Exception e) {
244245
}
245246
}
246247
}
248+
249+
@Test
250+
public void drop() throws InterruptedException, ExecutionException {
251+
final String edgeCollection = "edge_drop";
252+
final String vertexCollection = "vertex_drop";
253+
final String graph = GRAPH_NAME + "_drop";
254+
final GraphEntity result = db.graph(graph).create(Collections
255+
.singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)))
256+
.get();
257+
assertThat(result, is(notNullValue()));
258+
db.graph(graph).drop().get();
259+
assertThat(db.collection(edgeCollection).exists().get(), is(true));
260+
assertThat(db.collection(vertexCollection).exists().get(), is(true));
261+
}
262+
263+
@Test
264+
public void dropPlusDropCollections() throws InterruptedException, ExecutionException {
265+
final String edgeCollection = "edge_dropC";
266+
final String vertexCollection = "vertex_dropC";
267+
final String graph = GRAPH_NAME + "_dropC";
268+
final GraphEntity result = db.graph(graph).create(Collections
269+
.singleton(new EdgeDefinition().collection(edgeCollection).from(vertexCollection).to(vertexCollection)))
270+
.get();
271+
assertThat(result, is(notNullValue()));
272+
db.graph(graph).drop(true).get();
273+
assertThat(db.collection(edgeCollection).exists().get(), is(false));
274+
assertThat(db.collection(vertexCollection).exists().get(), is(false));
275+
}
247276
}

0 commit comments

Comments
 (0)