Skip to content

Commit 9414863

Browse files
author
mpv1989
committed
Fix tests for cluster
1 parent 9b25bca commit 9414863

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

src/main/java/com/arangodb/ArangoDBAsync.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.arangodb.entity.ArangoDBVersion;
3535
import com.arangodb.entity.LogEntity;
3636
import com.arangodb.entity.LogLevelEntity;
37+
import com.arangodb.entity.ServerRole;
3738
import com.arangodb.entity.UserEntity;
3839
import com.arangodb.internal.ArangoDBConstants;
3940
import com.arangodb.internal.ArangoExecutorAsync;
@@ -461,6 +462,16 @@ public CompletableFuture<ArangoDBVersion> getVersion() {
461462
return db().getVersion();
462463
}
463464

465+
/**
466+
* Returns the server role.
467+
*
468+
* @return the server role
469+
* @throws ArangoDBException
470+
*/
471+
public CompletableFuture<ServerRole> getRole() {
472+
return executor.execute(getRoleRequest(), getRoleResponseDeserializer());
473+
}
474+
464475
/**
465476
* Create a new user. This user will not have access to any database. You need permission to the _system database in
466477
* order to execute this call.

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.arangodb.entity.IndexEntity;
5858
import com.arangodb.entity.IndexType;
5959
import com.arangodb.entity.MultiDocumentEntity;
60+
import com.arangodb.entity.ServerRole;
6061
import com.arangodb.model.CollectionCreateOptions;
6162
import com.arangodb.model.CollectionPropertiesOptions;
6263
import com.arangodb.model.DocumentCreateOptions;
@@ -815,7 +816,12 @@ public void createHashIndex() throws InterruptedException, ExecutionException {
815816
assertThat(indexResult.getId(), startsWith(COLLECTION_NAME));
816817
assertThat(indexResult.getIsNewlyCreated(), is(true));
817818
assertThat(indexResult.getMinLength(), is(nullValue()));
818-
assertThat(indexResult.getSelectivityEstimate(), is(1));
819+
try {
820+
if (arangoDB.getRole().get() == ServerRole.SINGLE) {
821+
assertThat(indexResult.getSelectivityEstimate(), is(1));
822+
}
823+
} catch (InterruptedException | ExecutionException e) {
824+
}
819825
assertThat(indexResult.getSparse(), is(false));
820826
assertThat(indexResult.getType(), is(IndexType.hash));
821827
assertThat(indexResult.getUnique(), is(false));

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode;
6363
import com.arangodb.entity.QueryEntity;
6464
import com.arangodb.entity.QueryTrackingPropertiesEntity;
65+
import com.arangodb.entity.ServerRole;
6566
import com.arangodb.entity.TraversalEntity;
6667
import com.arangodb.model.AqlFunctionDeleteOptions;
6768
import com.arangodb.model.AqlQueryOptions;
@@ -135,6 +136,9 @@ public void deleteCollection() throws InterruptedException, ExecutionException {
135136

136137
@Test
137138
public void deleteSystemCollection() throws InterruptedException, ExecutionException {
139+
if (arangoDB.getRole().get() != ServerRole.SINGLE) {
140+
return;
141+
}
138142
final String name = "_system_test";
139143
db.createCollection(name, new CollectionCreateOptions().isSystem(true)).get();
140144
db.collection(name).drop(true).get();
@@ -147,6 +151,9 @@ public void deleteSystemCollection() throws InterruptedException, ExecutionExcep
147151

148152
@Test
149153
public void deleteSystemCollectionFail() throws InterruptedException, ExecutionException {
154+
if (arangoDB.getRole().get() != ServerRole.SINGLE) {
155+
return;
156+
}
150157
final String name = "_system_test";
151158
db.createCollection(name, new CollectionCreateOptions().isSystem(true)).get();
152159
try {
@@ -488,6 +495,9 @@ public void changeQueryCache() throws InterruptedException, ExecutionException {
488495

489496
@Test
490497
public void queryWithCache() throws InterruptedException, ArangoDBException, ExecutionException {
498+
if (arangoDB.getRole().get() != ServerRole.SINGLE) {
499+
return;
500+
}
491501
try {
492502
db.createCollection(COLLECTION_NAME, null).get();
493503
for (int i = 0; i < 10; i++) {

src/test/java/com/arangodb/example/graph/AQLActorsAndMoviesExample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public static void tearDown() throws InterruptedException, ExecutionException {
7979
@Test
8080
public void allActorsActsInMovie1or2() {
8181
final CompletableFuture<ArangoCursorAsync<String>> f = db.query(
82-
"FOR x IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN x._id", null,
83-
null, String.class);
82+
"WITH actors FOR x IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN x._id",
83+
null, null, String.class);
8484
f.whenComplete((cursor, ex) -> {
8585
assertThat(cursor.asListRemaining(),
8686
hasItems("actors/Keanu", "actors/Hugo", "actors/Emil", "actors/Carrie", "actors/Laurence"));
@@ -95,7 +95,7 @@ public void allActorsActsInMovie1or2() {
9595
@Test
9696
public void allActorsActsInMovie1or2UnionDistinct() {
9797
final CompletableFuture<ArangoCursorAsync<String>> f = db.query(
98-
"FOR x IN UNION_DISTINCT ((FOR y IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'movies/TheDevilsAdvocate' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x",
98+
"WITH actors FOR x IN UNION_DISTINCT ((FOR y IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'movies/TheDevilsAdvocate' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x",
9999
null, null, String.class);
100100
f.whenComplete((cursor, ex) -> {
101101
assertThat(cursor.asListRemaining(), hasItems("actors/Emil", "actors/Hugo", "actors/Carrie",
@@ -111,7 +111,7 @@ public void allActorsActsInMovie1or2UnionDistinct() {
111111
@Test
112112
public void allActorsActsInMovie1and2() {
113113
final CompletableFuture<ArangoCursorAsync<String>> f = db.query(
114-
"FOR x IN INTERSECTION ((FOR y IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'movies/TheDevilsAdvocate' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x",
114+
"WITH actors FOR x IN INTERSECTION ((FOR y IN ANY 'movies/TheMatrix' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'movies/TheDevilsAdvocate' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x",
115115
null, null, String.class);
116116
f.whenComplete((cursor, ex) -> {
117117
assertThat(cursor.asListRemaining(), hasItems("actors/Keanu"));
@@ -126,7 +126,7 @@ public void allActorsActsInMovie1and2() {
126126
@Test
127127
public void allMoviesBetweenActor1andActor2() {
128128
final CompletableFuture<ArangoCursorAsync<String>> f = db.query(
129-
"FOR x IN INTERSECTION ((FOR y IN ANY 'actors/Hugo' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'actors/Keanu' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x",
129+
"WITH movies FOR x IN INTERSECTION ((FOR y IN ANY 'actors/Hugo' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id), (FOR y IN ANY 'actors/Keanu' actsIn OPTIONS {bfs: true, uniqueVertices: 'global'} RETURN y._id)) RETURN x",
130130
null, null, String.class);
131131
f.whenComplete((cursor, ex) -> {
132132
assertThat(cursor.asListRemaining(),

src/test/java/com/arangodb/example/graph/GraphTraversalsInAQLExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void queryAllVertices() throws ArangoDBException, InterruptedException, E
4949
Collection<String> result = cursor.asListRemaining();
5050
assertThat(result.size(), is(10));
5151

52-
queryString = "FOR v IN 1..3 OUTBOUND 'circles/A' edges RETURN v._key";
52+
queryString = "WITH circles FOR v IN 1..3 OUTBOUND 'circles/A' edges RETURN v._key";
5353
cursor = db.query(queryString, null, null, String.class).get();
5454
result = cursor.asListRemaining();
5555
assertThat(result.size(), is(10));

src/test/java/com/arangodb/example/graph/ShortestPathInAQLExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void queryShortestPathFromAToD() throws ArangoDBException, InterruptedExc
7575
assertThat(collection.size(), is(4));
7676
assertThat(collection, hasItems("A", "B", "C", "D"));
7777

78-
queryString = "FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' edges RETURN {'vertex': v._key, 'edge': e._key}";
78+
queryString = "WITH circles FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' edges RETURN {'vertex': v._key, 'edge': e._key}";
7979
cursor = db.query(queryString, null, null, Pair.class).get();
8080
assertThat(collection.size(), is(4));
8181
assertThat(collection, hasItems("A", "B", "C", "D"));

0 commit comments

Comments
 (0)