From 4b07572ee136e28c56a0c0f7c85b4b79f0653560 Mon Sep 17 00:00:00 2001 From: rashtao Date: Tue, 27 Aug 2019 15:34:11 +0200 Subject: [PATCH] Bugfix/synchronous exceptions (#23) * cleanup ArangoDBException from tests * cleanup ArangoDBException from async interfaces * bugfix async drop() invocations in tests * cleanup creation of new CompletableFutures --- .../com/arangodb/ArangoCollectionAsync.java | 6 +- src/main/java/com/arangodb/ArangoDBAsync.java | 11 +- .../com/arangodb/ArangoDatabaseAsync.java | 32 +- .../arangodb/ArangoVertexCollectionAsync.java | 6 +- .../java/com/arangodb/ArangoViewAsync.java | 4 - .../internal/ArangoCollectionAsyncImpl.java | 771 +++++++++--------- .../arangodb/internal/ArangoDBAsyncImpl.java | 6 +- .../internal/ArangoDatabaseAsyncImpl.java | 34 +- .../internal/ArangoExecutorAsync.java | 27 +- .../internal/ArangoSearchAsyncImpl.java | 12 +- .../ArangoVertexCollectionAsyncImpl.java | 6 +- .../velocystream/VstCommunicationAsync.java | 28 +- .../com/arangodb/ArangoCollectionTest.java | 44 +- src/test/java/com/arangodb/ArangoDBTest.java | 9 +- .../java/com/arangodb/ArangoDatabaseTest.java | 38 +- .../arangodb/ArangoEdgeCollectionTest.java | 2 +- .../java/com/arangodb/ArangoGraphTest.java | 2 +- .../java/com/arangodb/ArangoRouteTest.java | 5 +- .../arangodb/example/graph/BaseGraphTest.java | 7 +- .../graph/GraphTraversalsInAQLExample.java | 9 +- .../graph/ShortestPathInAQLExample.java | 5 +- 21 files changed, 471 insertions(+), 593 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoCollectionAsync.java b/src/main/java/com/arangodb/ArangoCollectionAsync.java index 0152de3..136ee92 100644 --- a/src/main/java/com/arangodb/ArangoCollectionAsync.java +++ b/src/main/java/com/arangodb/ArangoCollectionAsync.java @@ -131,7 +131,6 @@ CompletableFuture>> insertDocume * @param values * a list of Objects that will be stored as documents * @return information about the import - * @throws ArangoDBException */ CompletableFuture importDocuments(final Collection values); @@ -143,7 +142,6 @@ CompletableFuture>> insertDocume * @param options * Additional options, can be null * @return information about the import - * @throws ArangoDBException */ CompletableFuture importDocuments( final Collection values, @@ -155,7 +153,6 @@ CompletableFuture importDocuments( * @param values * JSON-encoded array of objects that will be stored as documents * @return information about the import - * @throws ArangoDBException */ CompletableFuture importDocuments(final String values); @@ -167,7 +164,6 @@ CompletableFuture importDocuments( * @param options * Additional options, can be null * @return information about the import - * @throws ArangoDBException */ CompletableFuture importDocuments(final String values, final DocumentImportOptions options); @@ -740,5 +736,5 @@ CompletableFuture ensureFulltextIndex( * @return permissions of the user * @since ArangoDB 3.2.0 */ - CompletableFuture getPermissions(final String user) throws ArangoDBException; + CompletableFuture getPermissions(final String user); } diff --git a/src/main/java/com/arangodb/ArangoDBAsync.java b/src/main/java/com/arangodb/ArangoDBAsync.java index 7fc07fe..8d7aa44 100644 --- a/src/main/java/com/arangodb/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/ArangoDBAsync.java @@ -655,7 +655,6 @@ private VstCommunicationSync.Builder syncBuilder(final HostHandler hostHandler) * @param user * The name of the user for which you want to query the databases * @return - * @throws ArangoDBException */ CompletableFuture> getAccessibleDatabasesFor(final String user); @@ -672,7 +671,6 @@ private VstCommunicationSync.Builder syncBuilder(final HostHandler hostHandler) * Returns the server role. * * @return the server role - * @throws ArangoDBException */ CompletableFuture getRole(); @@ -772,8 +770,7 @@ private VstCommunicationSync.Builder syncBuilder(final HostHandler hostHandler) * @since ArangoDB 3.2.0 * @return void */ - CompletableFuture grantDefaultDatabaseAccess(final String user, final Permissions permissions) - throws ArangoDBException; + CompletableFuture grantDefaultDatabaseAccess(final String user, final Permissions permissions); /** * Sets the default access level for collections for the user user. You need permission to the _system @@ -786,8 +783,7 @@ CompletableFuture grantDefaultDatabaseAccess(final String user, final Perm * @since ArangoDB 3.2.0 * @return void */ - CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions) - throws ArangoDBException; + CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions); /** * Generic Execute. Use this method to execute custom FOXX services. @@ -795,7 +791,6 @@ CompletableFuture grantDefaultCollectionAccess(final String user, final Pe * @param request * VelocyStream request * @return VelocyStream response - * @throws ArangoDBException */ CompletableFuture execute(final Request request); @@ -815,7 +810,6 @@ CompletableFuture grantDefaultCollectionAccess(final String user, final Pe * Returns the server's current loglevel settings. * * @return the server's current loglevel settings - * @throws ArangoDBException */ CompletableFuture getLogLevel(); @@ -825,7 +819,6 @@ CompletableFuture grantDefaultCollectionAccess(final String user, final Pe * @param entity * loglevel settings * @return the server's current loglevel settings - * @throws ArangoDBException */ CompletableFuture setLogLevel(final LogLevelEntity entity); } diff --git a/src/main/java/com/arangodb/ArangoDatabaseAsync.java b/src/main/java/com/arangodb/ArangoDatabaseAsync.java index 882f977..01a06b3 100644 --- a/src/main/java/com/arangodb/ArangoDatabaseAsync.java +++ b/src/main/java/com/arangodb/ArangoDatabaseAsync.java @@ -254,10 +254,8 @@ public interface ArangoDatabaseAsync extends ArangoSerializationAccessor { * @param permissions * The permissions the user grant * @since ArangoDB 3.2.0 - * @throws ArangoDBException */ - CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions) - throws ArangoDBException; + CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions); /** * Get specific database access level @@ -269,7 +267,7 @@ CompletableFuture grantDefaultCollectionAccess(final String user, final Pe * @return permissions of the user * @since ArangoDB 3.2.0 */ - CompletableFuture getPermissions(final String user) throws ArangoDBException; + CompletableFuture getPermissions(final String user); /** * Performs a database query using the given {@code query} and {@code bindVars}, then returns a new @@ -286,13 +284,12 @@ CompletableFuture grantDefaultCollectionAccess(final String user, final Pe * @param type * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return cursor of the results - * @throws ArangoDBException */ CompletableFuture> query( final String query, final Map bindVars, final AqlQueryOptions options, - final Class type) throws ArangoDBException; + final Class type); /** * Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor} instance for the @@ -307,12 +304,11 @@ CompletableFuture> query( * @param type * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return cursor of the results - * @throws ArangoDBException */ CompletableFuture> query( final String query, final AqlQueryOptions options, - final Class type) throws ArangoDBException; + final Class type); /** * Performs a database query using the given {@code query} and {@code bindVars}, then returns a new @@ -327,12 +323,11 @@ CompletableFuture> query( * @param type * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return cursor of the results - * @throws ArangoDBException */ CompletableFuture> query( final String query, final Map bindVars, - final Class type) throws ArangoDBException; + final Class type); /** * Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor} instance for the @@ -345,9 +340,8 @@ CompletableFuture> query( * @param type * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return cursor of the results - * @throws ArangoDBException */ - CompletableFuture> query(final String query, final Class type) throws ArangoDBException; + CompletableFuture> query(final String query, final Class type); /** * Return an cursor from the given cursor-ID if still existing @@ -360,10 +354,8 @@ CompletableFuture> query( * @param type * The type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return cursor of the results - * @throws ArangoDBException */ - CompletableFuture> cursor(final String cursorId, final Class type) - throws ArangoDBException; + CompletableFuture> cursor(final String cursorId, final Class type); /** * Explain an AQL query and return information about it @@ -684,10 +676,9 @@ CompletableFuture getDocument(final String id, final Class type, final * * @see API Documentation * @return list of information about all views - * @throws ArangoDBException * @since ArangoDB 3.4.0 */ - CompletableFuture> getViews() throws ArangoDBException; + CompletableFuture> getViews(); /** * Returns a {@code ArangoViewAsync} instance for the given view name. @@ -718,9 +709,8 @@ CompletableFuture getDocument(final String id, final Class type, final * The type of the view * @return information about the view * @since ArangoDB 3.4.0 - * @throws ArangoDBException */ - CompletableFuture createView(String name, ViewType type) throws ArangoDBException; + CompletableFuture createView(String name, ViewType type); /** * Creates a ArangoSearch view with the given {@code options}, then returns view information from the server. @@ -733,9 +723,7 @@ CompletableFuture getDocument(final String id, final Class type, final * Additional options, can be null * @return information about the view * @since ArangoDB 3.4.0 - * @throws ArangoDBException */ - CompletableFuture createArangoSearch(String name, ArangoSearchCreateOptions options) - throws ArangoDBException; + CompletableFuture createArangoSearch(String name, ArangoSearchCreateOptions options); } diff --git a/src/main/java/com/arangodb/ArangoVertexCollectionAsync.java b/src/main/java/com/arangodb/ArangoVertexCollectionAsync.java index d8c35fc..56a26ef 100644 --- a/src/main/java/com/arangodb/ArangoVertexCollectionAsync.java +++ b/src/main/java/com/arangodb/ArangoVertexCollectionAsync.java @@ -154,9 +154,8 @@ CompletableFuture replaceVertex( * @param type * The type of the vertex-document (POJO class, VPackSlice or String for Json) * @return information about the vertex - * @throws ArangoDBException */ - CompletableFuture updateVertex(final String key, final T value) throws ArangoDBException; + CompletableFuture updateVertex(final String key, final T value); /** * Partially updates the vertex identified by document-key. The value must contain a document with the attributes to @@ -171,12 +170,11 @@ CompletableFuture replaceVertex( * @param options * Additional options, can be null * @return information about the vertex - * @throws ArangoDBException */ CompletableFuture updateVertex( final String key, final T value, - final VertexUpdateOptions options) throws ArangoDBException; + final VertexUpdateOptions options); /** * Removes a vertex diff --git a/src/main/java/com/arangodb/ArangoViewAsync.java b/src/main/java/com/arangodb/ArangoViewAsync.java index d74cf66..a80689e 100644 --- a/src/main/java/com/arangodb/ArangoViewAsync.java +++ b/src/main/java/com/arangodb/ArangoViewAsync.java @@ -51,7 +51,6 @@ public interface ArangoViewAsync extends ArangoSerializationAccessor { * Checks whether the view exists. * * @return true if the view exists, otherwise false - * @throws ArangoDBException */ CompletableFuture exists(); @@ -59,7 +58,6 @@ public interface ArangoViewAsync extends ArangoSerializationAccessor { * Deletes the view from the database. * * @see API Documentation - * @throws ArangoDBException */ CompletableFuture drop(); @@ -70,7 +68,6 @@ public interface ArangoViewAsync extends ArangoSerializationAccessor { * @param newName * The new name * @return information about the view - * @throws ArangoDBException */ CompletableFuture rename(String newName); @@ -80,7 +77,6 @@ public interface ArangoViewAsync extends ArangoSerializationAccessor { * @see API * Documentation * @return information about the view - * @throws ArangoDBException */ CompletableFuture getInfo(); diff --git a/src/main/java/com/arangodb/internal/ArangoCollectionAsyncImpl.java b/src/main/java/com/arangodb/internal/ArangoCollectionAsyncImpl.java index 446d18c..003dc79 100644 --- a/src/main/java/com/arangodb/internal/ArangoCollectionAsyncImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoCollectionAsyncImpl.java @@ -20,413 +20,382 @@ package com.arangodb.internal; -import java.util.Collection; -import java.util.concurrent.CompletableFuture; -import java.util.function.BiConsumer; - import com.arangodb.ArangoCollectionAsync; import com.arangodb.ArangoDBException; -import com.arangodb.entity.CollectionEntity; -import com.arangodb.entity.CollectionPropertiesEntity; -import com.arangodb.entity.CollectionRevisionEntity; -import com.arangodb.entity.DocumentCreateEntity; -import com.arangodb.entity.DocumentDeleteEntity; -import com.arangodb.entity.DocumentImportEntity; -import com.arangodb.entity.DocumentUpdateEntity; -import com.arangodb.entity.IndexEntity; -import com.arangodb.entity.MultiDocumentEntity; -import com.arangodb.entity.Permissions; -import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; +import com.arangodb.entity.*; import com.arangodb.internal.util.DocumentUtil; -import com.arangodb.model.CollectionCreateOptions; -import com.arangodb.model.CollectionPropertiesOptions; -import com.arangodb.model.DocumentCreateOptions; -import com.arangodb.model.DocumentDeleteOptions; -import com.arangodb.model.DocumentExistsOptions; -import com.arangodb.model.DocumentImportOptions; -import com.arangodb.model.DocumentReadOptions; -import com.arangodb.model.DocumentReplaceOptions; -import com.arangodb.model.DocumentUpdateOptions; -import com.arangodb.model.FulltextIndexOptions; -import com.arangodb.model.GeoIndexOptions; -import com.arangodb.model.HashIndexOptions; -import com.arangodb.model.PersistentIndexOptions; -import com.arangodb.model.SkiplistIndexOptions; -import com.arangodb.velocypack.exception.VPackException; -import com.arangodb.velocystream.Response; +import com.arangodb.model.*; + +import java.util.Collection; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.function.Function; /** * @author Mark Vollmary - * */ public class ArangoCollectionAsyncImpl - extends InternalArangoCollection - implements ArangoCollectionAsync { - - protected ArangoCollectionAsyncImpl(final ArangoDatabaseAsyncImpl db, final String name) { - super(db, name); - } - - @Override - public CompletableFuture> insertDocument(final T value) { - final DocumentCreateOptions options = new DocumentCreateOptions(); - return executor.execute(insertDocumentRequest(value, options), - insertDocumentResponseDeserializer(value, options)); - } - - @Override - public CompletableFuture> insertDocument( - final T value, - final DocumentCreateOptions options) { - return executor.execute(insertDocumentRequest(value, options), - insertDocumentResponseDeserializer(value, options)); - } - - @Override - public CompletableFuture>> insertDocuments( - final Collection values) { - final DocumentCreateOptions params = new DocumentCreateOptions(); - return executor.execute(insertDocumentsRequest(values, params), - insertDocumentsResponseDeserializer(values, params)); - } - - @Override - public CompletableFuture>> insertDocuments( - final Collection values, - final DocumentCreateOptions options) { - final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); - return executor.execute(insertDocumentsRequest(values, params), - insertDocumentsResponseDeserializer(values, params)); - } - - @Override - public CompletableFuture importDocuments(final Collection values) { - return importDocuments(values, new DocumentImportOptions()); - } - - @Override - public CompletableFuture importDocuments( - final Collection values, - final DocumentImportOptions options) { - return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class); - } - - @Override - public CompletableFuture importDocuments(final String values) { - return executor.execute(importDocumentsRequest(values, new DocumentImportOptions()), - DocumentImportEntity.class); - } - - @Override - public CompletableFuture importDocuments( - final String values, - final DocumentImportOptions options) { - return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class); - } - - @Override - public CompletableFuture getDocument(final String key, final Class type) throws ArangoDBException { - DocumentUtil.validateDocumentKey(key); - final CompletableFuture result = new CompletableFuture<>(); - final CompletableFuture execute = executor.execute(getDocumentRequest(key, new DocumentReadOptions()), type); - execute.whenComplete((response, ex) -> result.complete(response)); - return result; - } - - @Override - public CompletableFuture getDocument( - final String key, - final Class type, - final DocumentReadOptions options) throws ArangoDBException { - DocumentUtil.validateDocumentKey(key); - final CompletableFuture result = new CompletableFuture<>(); - final CompletableFuture execute = executor.execute(getDocumentRequest(key, options), type); - execute.whenComplete((response, ex) -> result.complete(response)); - return result; - } - - @Override - public CompletableFuture> getDocuments( - final Collection keys, - final Class type) { - return getDocuments(keys, type, new DocumentReadOptions()); - } - - @Override - public CompletableFuture> getDocuments( - final Collection keys, - final Class type, - final DocumentReadOptions options) { - return executor.execute(getDocumentsRequest(keys, options), getDocumentsResponseDeserializer(type, options)); - } - - @Override - public CompletableFuture> replaceDocument(final String key, final T value) { - final DocumentReplaceOptions options = new DocumentReplaceOptions(); - return executor.execute(replaceDocumentRequest(key, value, options), - replaceDocumentResponseDeserializer(value, options)); - } - - @Override - public CompletableFuture> replaceDocument( - final String key, - final T value, - final DocumentReplaceOptions options) { - return executor.execute(replaceDocumentRequest(key, value, options), - replaceDocumentResponseDeserializer(value, options)); - } - - @Override - public CompletableFuture>> replaceDocuments( - final Collection values) { - final DocumentReplaceOptions params = new DocumentReplaceOptions(); - return executor.execute(replaceDocumentsRequest(values, params), - replaceDocumentsResponseDeserializer(values, params)); - } - - @Override - public CompletableFuture>> replaceDocuments( - final Collection values, - final DocumentReplaceOptions options) { - final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions()); - return executor.execute(replaceDocumentsRequest(values, params), - replaceDocumentsResponseDeserializer(values, params)); - } - - @Override - public CompletableFuture> updateDocument(final String key, final T value) { - final DocumentUpdateOptions options = new DocumentUpdateOptions(); - return executor.execute(updateDocumentRequest(key, value, options), - updateDocumentResponseDeserializer(value, options)); - } - - @Override - public CompletableFuture> updateDocument( - final String key, - final T value, - final DocumentUpdateOptions options) { - return executor.execute(updateDocumentRequest(key, value, options), - updateDocumentResponseDeserializer(value, options)); - } - - @Override - public CompletableFuture>> updateDocuments( - final Collection values) { - final DocumentUpdateOptions params = new DocumentUpdateOptions(); - return executor.execute(updateDocumentsRequest(values, params), - updateDocumentsResponseDeserializer(values, params)); - } - - @Override - public CompletableFuture>> updateDocuments( - final Collection values, - final DocumentUpdateOptions options) { - final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions()); - return executor.execute(updateDocumentsRequest(values, params), - updateDocumentsResponseDeserializer(values, params)); - } - - @Override - public CompletableFuture> deleteDocument(final String key) { - return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()), - deleteDocumentResponseDeserializer(Void.class)); - } - - @Override - public CompletableFuture> deleteDocument( - final String key, - final Class type, - final DocumentDeleteOptions options) { - return executor.execute(deleteDocumentRequest(key, options), deleteDocumentResponseDeserializer(type)); - } - - @Override - public CompletableFuture>> deleteDocuments( - final Collection values) { - return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()), - deleteDocumentsResponseDeserializer(Void.class)); - } - - @Override - public CompletableFuture>> deleteDocuments( - final Collection values, - final Class type, - final DocumentDeleteOptions options) { - return executor.execute(deleteDocumentsRequest(values, options), deleteDocumentsResponseDeserializer(type)); - } - - @Override - public CompletableFuture documentExists(final String key) { - final CompletableFuture result = new CompletableFuture<>(); - executor.execute(documentExistsRequest(key, new DocumentExistsOptions()), new ResponseDeserializer() { - @Override - public Response deserialize(final Response response) throws VPackException { - return response; - } - }).whenComplete(documentExistsResponseConsumer(result)); - return result; - } - - @Override - public CompletableFuture documentExists(final String key, final DocumentExistsOptions options) { - final CompletableFuture result = new CompletableFuture<>(); - executor.execute(documentExistsRequest(key, options), new ResponseDeserializer() { - @Override - public Response deserialize(final Response response) throws VPackException { - return response; - } - }).whenComplete(documentExistsResponseConsumer(result)); - return result; - } - - private BiConsumer documentExistsResponseConsumer( - final CompletableFuture result) { - return (response, ex) -> { - if (response != null) { - result.complete(true); - } else if (ex != null) { - result.complete(false); - } else { - result.cancel(true); - } - }; - } - - @Override - public CompletableFuture getIndex(final String id) { - return executor.execute(getIndexRequest(id), IndexEntity.class); - } - - @Override - public CompletableFuture deleteIndex(final String id) { - return executor.execute(deleteIndexRequest(id), deleteIndexResponseDeserializer()); - } - - @Override - public CompletableFuture ensureHashIndex( - final Iterable fields, - final HashIndexOptions options) { - return executor.execute(createHashIndexRequest(fields, options), IndexEntity.class); - } - - @Override - public CompletableFuture ensureSkiplistIndex( - final Iterable fields, - final SkiplistIndexOptions options) { - return executor.execute(createSkiplistIndexRequest(fields, options), IndexEntity.class); - } - - @Override - public CompletableFuture ensurePersistentIndex( - final Iterable fields, - final PersistentIndexOptions options) { - return executor.execute(createPersistentIndexRequest(fields, options), IndexEntity.class); - } - - @Override - public CompletableFuture ensureGeoIndex(final Iterable fields, final GeoIndexOptions options) { - return executor.execute(createGeoIndexRequest(fields, options), IndexEntity.class); - } - - @Override - public CompletableFuture ensureFulltextIndex( - final Iterable fields, - final FulltextIndexOptions options) { - return executor.execute(createFulltextIndexRequest(fields, options), IndexEntity.class); - } - - @Override - public CompletableFuture> getIndexes() { - return executor.execute(getIndexesRequest(), getIndexesResponseDeserializer()); - } - - @Override - public CompletableFuture exists() { - return getInfo().thenApply(info -> info != null).exceptionally(e -> e == null); - } - - @Override - public CompletableFuture truncate() { - return executor.execute(truncateRequest(), CollectionEntity.class); - } - - @Override - public CompletableFuture count() { - return executor.execute(countRequest(), CollectionPropertiesEntity.class); - } - - @Override - public CompletableFuture create() { - return db().createCollection(name()); - } - - @Override - public CompletableFuture create(final CollectionCreateOptions options) { - return db().createCollection(name(), options); - } - - @Override - public CompletableFuture drop() { - return executor.execute(dropRequest(null), Void.class); - } - - @Override - public CompletableFuture drop(final boolean isSystem) { - return executor.execute(dropRequest(isSystem), Void.class); - } - - @Override - public CompletableFuture load() { - return executor.execute(loadRequest(), CollectionEntity.class); - } - - @Override - public CompletableFuture unload() { - return executor.execute(unloadRequest(), CollectionEntity.class); - } - - @Override - public CompletableFuture getInfo() { - return executor.execute(getInfoRequest(), CollectionEntity.class); - } - - @Override - public CompletableFuture getProperties() { - return executor.execute(getPropertiesRequest(), CollectionPropertiesEntity.class); - } - - @Override - public CompletableFuture changeProperties(final CollectionPropertiesOptions options) { - return executor.execute(changePropertiesRequest(options), CollectionPropertiesEntity.class); - } - - @Override - public CompletableFuture rename(final String newName) { - return executor.execute(renameRequest(newName), CollectionEntity.class); - } - - @Override - public CompletableFuture getRevision() { - return executor.execute(getRevisionRequest(), CollectionRevisionEntity.class); - } - - @Override - public CompletableFuture grantAccess(final String user, final Permissions permissions) { - return executor.execute(grantAccessRequest(user, permissions), Void.class); - } - - @Override - public CompletableFuture revokeAccess(final String user) { - return executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class); - } - - @Override - public CompletableFuture resetAccess(final String user) { - return executor.execute(resetAccessRequest(user), Void.class); - } - - @Override - public CompletableFuture getPermissions(final String user) throws ArangoDBException { - return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer()); - } + extends InternalArangoCollection + implements ArangoCollectionAsync { + + protected ArangoCollectionAsyncImpl(final ArangoDatabaseAsyncImpl db, final String name) { + super(db, name); + } + + @Override + public CompletableFuture> insertDocument(final T value) { + final DocumentCreateOptions options = new DocumentCreateOptions(); + return executor.execute(insertDocumentRequest(value, options), + insertDocumentResponseDeserializer(value, options)); + } + + @Override + public CompletableFuture> insertDocument( + final T value, + final DocumentCreateOptions options) { + return executor.execute(insertDocumentRequest(value, options), + insertDocumentResponseDeserializer(value, options)); + } + + @Override + public CompletableFuture>> insertDocuments( + final Collection values) { + final DocumentCreateOptions params = new DocumentCreateOptions(); + return executor.execute(insertDocumentsRequest(values, params), + insertDocumentsResponseDeserializer(values, params)); + } + + @Override + public CompletableFuture>> insertDocuments( + final Collection values, + final DocumentCreateOptions options) { + final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions()); + return executor.execute(insertDocumentsRequest(values, params), + insertDocumentsResponseDeserializer(values, params)); + } + + @Override + public CompletableFuture importDocuments(final Collection values) { + return importDocuments(values, new DocumentImportOptions()); + } + + @Override + public CompletableFuture importDocuments( + final Collection values, + final DocumentImportOptions options) { + return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class); + } + + @Override + public CompletableFuture importDocuments(final String values) { + return executor.execute(importDocumentsRequest(values, new DocumentImportOptions()), + DocumentImportEntity.class); + } + + @Override + public CompletableFuture importDocuments( + final String values, + final DocumentImportOptions options) { + return executor.execute(importDocumentsRequest(values, options), DocumentImportEntity.class); + } + + @Override + public CompletableFuture getDocument(final String key, final Class type) throws ArangoDBException { + return getDocument(key, type, new DocumentReadOptions()); + } + + @Override + @SuppressWarnings("unchecked") + public CompletableFuture getDocument( + final String key, + final Class type, + final DocumentReadOptions options) throws ArangoDBException { + DocumentUtil.validateDocumentKey(key); + return (CompletableFuture) executor.execute(getDocumentRequest(key, options), type) + .exceptionally(handleGetDocumentExceptions(options != null ? options.isCatchException() : new DocumentReadOptions().isCatchException())); + } + + private Function handleGetDocumentExceptions(Boolean isCatchException) { + return throwable -> { + ArangoDBException arangoDBException = null; + + if (throwable instanceof ArangoDBException) { + arangoDBException = (ArangoDBException) throwable; + } else if (throwable instanceof CompletionException) { + CompletionException completionException = (CompletionException) throwable; + if (completionException.getCause() instanceof ArangoDBException) { + arangoDBException = (ArangoDBException) completionException.getCause(); + } + } + + if (arangoDBException != null) { + if ((arangoDBException.getResponseCode() != null && (arangoDBException.getResponseCode() == 404 || arangoDBException.getResponseCode() == 304 + || arangoDBException.getResponseCode() == 412)) && isCatchException) { + return null; + } + } + throw new CompletionException(throwable); + }; + } + + @Override + public CompletableFuture> getDocuments( + final Collection keys, + final Class type) { + return getDocuments(keys, type, new DocumentReadOptions()); + } + + @Override + public CompletableFuture> getDocuments( + final Collection keys, + final Class type, + final DocumentReadOptions options) { + return executor.execute(getDocumentsRequest(keys, options), getDocumentsResponseDeserializer(type, options)); + } + + @Override + public CompletableFuture> replaceDocument(final String key, final T value) { + final DocumentReplaceOptions options = new DocumentReplaceOptions(); + return executor.execute(replaceDocumentRequest(key, value, options), + replaceDocumentResponseDeserializer(value, options)); + } + + @Override + public CompletableFuture> replaceDocument( + final String key, + final T value, + final DocumentReplaceOptions options) { + return executor.execute(replaceDocumentRequest(key, value, options), + replaceDocumentResponseDeserializer(value, options)); + } + + @Override + public CompletableFuture>> replaceDocuments( + final Collection values) { + final DocumentReplaceOptions params = new DocumentReplaceOptions(); + return executor.execute(replaceDocumentsRequest(values, params), + replaceDocumentsResponseDeserializer(values, params)); + } + + @Override + public CompletableFuture>> replaceDocuments( + final Collection values, + final DocumentReplaceOptions options) { + final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions()); + return executor.execute(replaceDocumentsRequest(values, params), + replaceDocumentsResponseDeserializer(values, params)); + } + + @Override + public CompletableFuture> updateDocument(final String key, final T value) { + final DocumentUpdateOptions options = new DocumentUpdateOptions(); + return executor.execute(updateDocumentRequest(key, value, options), + updateDocumentResponseDeserializer(value, options)); + } + + @Override + public CompletableFuture> updateDocument( + final String key, + final T value, + final DocumentUpdateOptions options) { + return executor.execute(updateDocumentRequest(key, value, options), + updateDocumentResponseDeserializer(value, options)); + } + + @Override + public CompletableFuture>> updateDocuments( + final Collection values) { + final DocumentUpdateOptions params = new DocumentUpdateOptions(); + return executor.execute(updateDocumentsRequest(values, params), + updateDocumentsResponseDeserializer(values, params)); + } + + @Override + public CompletableFuture>> updateDocuments( + final Collection values, + final DocumentUpdateOptions options) { + final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions()); + return executor.execute(updateDocumentsRequest(values, params), + updateDocumentsResponseDeserializer(values, params)); + } + + @Override + public CompletableFuture> deleteDocument(final String key) { + return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()), + deleteDocumentResponseDeserializer(Void.class)); + } + + @Override + public CompletableFuture> deleteDocument( + final String key, + final Class type, + final DocumentDeleteOptions options) { + return executor.execute(deleteDocumentRequest(key, options), deleteDocumentResponseDeserializer(type)); + } + + @Override + public CompletableFuture>> deleteDocuments( + final Collection values) { + return executor.execute(deleteDocumentsRequest(values, new DocumentDeleteOptions()), + deleteDocumentsResponseDeserializer(Void.class)); + } + + @Override + public CompletableFuture>> deleteDocuments( + final Collection values, + final Class type, + final DocumentDeleteOptions options) { + return executor.execute(deleteDocumentsRequest(values, options), deleteDocumentsResponseDeserializer(type)); + } + + @Override + public CompletableFuture documentExists(final String key) { + return documentExists(key, new DocumentExistsOptions()); + } + + @Override + public CompletableFuture documentExists(final String key, final DocumentExistsOptions options) { + return executor.execute(documentExistsRequest(key, options), response -> response) + .exceptionally(handleGetDocumentExceptions(options != null ? options.isCatchException() : new DocumentExistsOptions().isCatchException())) + .thenApply(Objects::nonNull); + } + + @Override + public CompletableFuture getIndex(final String id) { + return executor.execute(getIndexRequest(id), IndexEntity.class); + } + + @Override + public CompletableFuture deleteIndex(final String id) { + return executor.execute(deleteIndexRequest(id), deleteIndexResponseDeserializer()); + } + + @Override + public CompletableFuture ensureHashIndex( + final Iterable fields, + final HashIndexOptions options) { + return executor.execute(createHashIndexRequest(fields, options), IndexEntity.class); + } + + @Override + public CompletableFuture ensureSkiplistIndex( + final Iterable fields, + final SkiplistIndexOptions options) { + return executor.execute(createSkiplistIndexRequest(fields, options), IndexEntity.class); + } + + @Override + public CompletableFuture ensurePersistentIndex( + final Iterable fields, + final PersistentIndexOptions options) { + return executor.execute(createPersistentIndexRequest(fields, options), IndexEntity.class); + } + + @Override + public CompletableFuture ensureGeoIndex(final Iterable fields, final GeoIndexOptions options) { + return executor.execute(createGeoIndexRequest(fields, options), IndexEntity.class); + } + + @Override + public CompletableFuture ensureFulltextIndex( + final Iterable fields, + final FulltextIndexOptions options) { + return executor.execute(createFulltextIndexRequest(fields, options), IndexEntity.class); + } + + @Override + public CompletableFuture> getIndexes() { + return executor.execute(getIndexesRequest(), getIndexesResponseDeserializer()); + } + + @Override + public CompletableFuture exists() { + return getInfo().thenApply(info -> info != null).exceptionally(e -> e == null); + } + + @Override + public CompletableFuture truncate() { + return executor.execute(truncateRequest(), CollectionEntity.class); + } + + @Override + public CompletableFuture count() { + return executor.execute(countRequest(), CollectionPropertiesEntity.class); + } + + @Override + public CompletableFuture create() { + return db().createCollection(name()); + } + + @Override + public CompletableFuture create(final CollectionCreateOptions options) { + return db().createCollection(name(), options); + } + + @Override + public CompletableFuture drop() { + return executor.execute(dropRequest(null), Void.class); + } + + @Override + public CompletableFuture drop(final boolean isSystem) { + return executor.execute(dropRequest(isSystem), Void.class); + } + + @Override + public CompletableFuture load() { + return executor.execute(loadRequest(), CollectionEntity.class); + } + + @Override + public CompletableFuture unload() { + return executor.execute(unloadRequest(), CollectionEntity.class); + } + + @Override + public CompletableFuture getInfo() { + return executor.execute(getInfoRequest(), CollectionEntity.class); + } + + @Override + public CompletableFuture getProperties() { + return executor.execute(getPropertiesRequest(), CollectionPropertiesEntity.class); + } + + @Override + public CompletableFuture changeProperties(final CollectionPropertiesOptions options) { + return executor.execute(changePropertiesRequest(options), CollectionPropertiesEntity.class); + } + + @Override + public CompletableFuture rename(final String newName) { + return executor.execute(renameRequest(newName), CollectionEntity.class); + } + + @Override + public CompletableFuture getRevision() { + return executor.execute(getRevisionRequest(), CollectionRevisionEntity.class); + } + + @Override + public CompletableFuture grantAccess(final String user, final Permissions permissions) { + return executor.execute(grantAccessRequest(user, permissions), Void.class); + } + + @Override + public CompletableFuture revokeAccess(final String user) { + return executor.execute(grantAccessRequest(user, Permissions.NONE), Void.class); + } + + @Override + public CompletableFuture resetAccess(final String user) { + return executor.execute(resetAccessRequest(user), Void.class); + } + + @Override + public CompletableFuture getPermissions(final String user) { + return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer()); + } } diff --git a/src/main/java/com/arangodb/internal/ArangoDBAsyncImpl.java b/src/main/java/com/arangodb/internal/ArangoDBAsyncImpl.java index e7cce13..47848ee 100644 --- a/src/main/java/com/arangodb/internal/ArangoDBAsyncImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDBAsyncImpl.java @@ -166,14 +166,12 @@ public CompletableFuture replaceUser(final String user, final UserUp } @Override - public CompletableFuture grantDefaultDatabaseAccess(final String user, final Permissions permissions) - throws ArangoDBException { + public CompletableFuture grantDefaultDatabaseAccess(final String user, final Permissions permissions) { return executor.execute(updateUserDefaultDatabaseAccessRequest(user, permissions), Void.class); } @Override - public CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions) - throws ArangoDBException { + public CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions) { return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class); } diff --git a/src/main/java/com/arangodb/internal/ArangoDatabaseAsyncImpl.java b/src/main/java/com/arangodb/internal/ArangoDatabaseAsyncImpl.java index 6a408b3..05a61af 100644 --- a/src/main/java/com/arangodb/internal/ArangoDatabaseAsyncImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDatabaseAsyncImpl.java @@ -167,13 +167,12 @@ public CompletableFuture resetAccess(final String user) { } @Override - public CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions) - throws ArangoDBException { + public CompletableFuture grantDefaultCollectionAccess(final String user, final Permissions permissions) { return executor.execute(updateUserDefaultCollectionAccessRequest(user, permissions), Void.class); } @Override - public CompletableFuture getPermissions(final String user) throws ArangoDBException { + public CompletableFuture getPermissions(final String user) { return executor.execute(getPermissionsRequest(user), getPermissionsResponseDeserialzer()); } @@ -182,20 +181,18 @@ public CompletableFuture> query( final String query, final Map bindVars, final AqlQueryOptions options, - final Class type) throws ArangoDBException { + final Class type) { final Request request = queryRequest(query, bindVars, options); final HostHandle hostHandle = new HostHandle(); final CompletableFuture execution = executor.execute(request, CursorEntity.class, hostHandle); - return execution.thenApply(result -> { - return createCursor(result, type, options, hostHandle); - }); + return execution.thenApply(result -> createCursor(result, type, options, hostHandle)); } @Override public CompletableFuture> query( final String query, final AqlQueryOptions options, - final Class type) throws ArangoDBException { + final Class type) { return query(query, null, options, type); } @@ -203,26 +200,20 @@ public CompletableFuture> query( public CompletableFuture> query( final String query, final Map bindVars, - final Class type) throws ArangoDBException { + final Class type) { return query(query, bindVars, null, type); } @Override - public CompletableFuture> query(final String query, final Class type) - throws ArangoDBException { + public CompletableFuture> query(final String query, final Class type) { return query(query, null, null, type); } @Override - public CompletableFuture> cursor(final String cursorId, final Class type) throws ArangoDBException { - + public CompletableFuture> cursor(final String cursorId, final Class type) { final HostHandle hostHandle = new HostHandle(); - final CompletableFuture execution = executor.execute(queryNextRequest(cursorId, null, null), CursorEntity.class, hostHandle); - - return execution.thenApply(result -> { - return createCursor(result, type, null, hostHandle); - }); + return execution.thenApply(result -> createCursor(result, type, null, hostHandle)); } private ArangoCursorAsync createCursor( @@ -408,7 +399,7 @@ public ArangoRouteAsync route(final String... path) { } @Override - public CompletableFuture> getViews() throws ArangoDBException { + public CompletableFuture> getViews() { return executor.execute(getViewsRequest(), getViewsResponseDeserializer()); } @@ -423,13 +414,12 @@ public ArangoSearchAsync arangoSearch(final String name) { } @Override - public CompletableFuture createView(final String name, final ViewType type) throws ArangoDBException { + public CompletableFuture createView(final String name, final ViewType type){ return executor.execute(createViewRequest(name, type), ViewEntity.class); } @Override - public CompletableFuture createArangoSearch(final String name, final ArangoSearchCreateOptions options) - throws ArangoDBException { + public CompletableFuture createArangoSearch(final String name, final ArangoSearchCreateOptions options) { return executor.execute(createArangoSearchRequest(name, options), ViewEntity.class); } diff --git a/src/main/java/com/arangodb/internal/ArangoExecutorAsync.java b/src/main/java/com/arangodb/internal/ArangoExecutorAsync.java index 5012dc8..655a9f9 100644 --- a/src/main/java/com/arangodb/internal/ArangoExecutorAsync.java +++ b/src/main/java/com/arangodb/internal/ArangoExecutorAsync.java @@ -20,11 +20,9 @@ package com.arangodb.internal; -import com.arangodb.ArangoDBException; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.ArangoSerializationFactory; import com.arangodb.internal.velocystream.VstCommunicationAsync; -import com.arangodb.velocypack.exception.VPackException; import com.arangodb.velocystream.Request; import java.io.IOException; @@ -32,6 +30,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.function.Function; /** * @author Mark Vollmary @@ -65,27 +64,9 @@ public CompletableFuture execute( final ResponseDeserializer responseDeserializer, final HostHandle hostHandle) { - CompletableFuture result = new CompletableFuture<>(); - outgoingExecutor.execute(() -> { - try { - communication.execute(request, hostHandle) - .whenCompleteAsync((response, ex) -> { - if (ex != null) { - result.completeExceptionally(ex); - } else if (response != null) { - try { - result.complete(responseDeserializer.deserialize(response)); - } catch (final VPackException | ArangoDBException e) { - result.completeExceptionally(e); - } - } - }); - } catch (ArangoDBException e) { - result.completeExceptionally(e); - } - } - ); - return result; + return CompletableFuture.supplyAsync(() -> communication.execute(request, hostHandle), outgoingExecutor) + .thenCompose(Function.identity()) + .thenApplyAsync(responseDeserializer::deserialize); } public void disconnect() throws IOException { diff --git a/src/main/java/com/arangodb/internal/ArangoSearchAsyncImpl.java b/src/main/java/com/arangodb/internal/ArangoSearchAsyncImpl.java index 6bed1c0..bdc7716 100644 --- a/src/main/java/com/arangodb/internal/ArangoSearchAsyncImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoSearchAsyncImpl.java @@ -22,7 +22,6 @@ import java.util.concurrent.CompletableFuture; -import com.arangodb.ArangoDBException; import com.arangodb.ArangoSearchAsync; import com.arangodb.entity.ViewEntity; import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; @@ -62,29 +61,28 @@ public CompletableFuture getInfo() { } @Override - public CompletableFuture create() throws ArangoDBException { + public CompletableFuture create() { return create(new ArangoSearchCreateOptions()); } @Override - public CompletableFuture create(final ArangoSearchCreateOptions options) throws ArangoDBException { + public CompletableFuture create(final ArangoSearchCreateOptions options) { return db().createArangoSearch(name(), options); } @Override - public CompletableFuture getProperties() throws ArangoDBException { + public CompletableFuture getProperties() { return executor.execute(getPropertiesRequest(), ArangoSearchPropertiesEntity.class); } @Override - public CompletableFuture updateProperties(final ArangoSearchPropertiesOptions options) - throws ArangoDBException { + public CompletableFuture updateProperties(final ArangoSearchPropertiesOptions options) { return executor.execute(updatePropertiesRequest(options), ArangoSearchPropertiesEntity.class); } @Override public CompletableFuture replaceProperties( - final ArangoSearchPropertiesOptions options) throws ArangoDBException { + final ArangoSearchPropertiesOptions options) { return executor.execute(replacePropertiesRequest(options), ArangoSearchPropertiesEntity.class); } diff --git a/src/main/java/com/arangodb/internal/ArangoVertexCollectionAsyncImpl.java b/src/main/java/com/arangodb/internal/ArangoVertexCollectionAsyncImpl.java index 5e31529..5f1801b 100644 --- a/src/main/java/com/arangodb/internal/ArangoVertexCollectionAsyncImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoVertexCollectionAsyncImpl.java @@ -22,7 +22,6 @@ import java.util.concurrent.CompletableFuture; -import com.arangodb.ArangoDBException; import com.arangodb.ArangoVertexCollectionAsync; import com.arangodb.entity.VertexEntity; import com.arangodb.entity.VertexUpdateEntity; @@ -88,8 +87,7 @@ public CompletableFuture replaceVertex( } @Override - public CompletableFuture updateVertex(final String key, final T value) - throws ArangoDBException { + public CompletableFuture updateVertex(final String key, final T value) { return executor.execute(updateVertexRequest(key, value, new VertexUpdateOptions()), updateVertexResponseDeserializer(value)); } @@ -98,7 +96,7 @@ public CompletableFuture updateVertex(final String key, public CompletableFuture updateVertex( final String key, final T value, - final VertexUpdateOptions options) throws ArangoDBException { + final VertexUpdateOptions options) { return executor.execute(updateVertexRequest(key, value, options), updateVertexResponseDeserializer(value)); } diff --git a/src/main/java/com/arangodb/internal/velocystream/VstCommunicationAsync.java b/src/main/java/com/arangodb/internal/velocystream/VstCommunicationAsync.java index 0ae955e..1fe7f82 100644 --- a/src/main/java/com/arangodb/internal/velocystream/VstCommunicationAsync.java +++ b/src/main/java/com/arangodb/internal/velocystream/VstCommunicationAsync.java @@ -20,15 +20,6 @@ package com.arangodb.internal.velocystream; -import java.io.IOException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import javax.net.ssl.SSLContext; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.arangodb.ArangoDBException; import com.arangodb.entity.ErrorEntity; import com.arangodb.internal.net.HostHandler; @@ -39,6 +30,12 @@ import com.arangodb.velocypack.exception.VPackParserException; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.SSLContext; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; /** * @author Mark Vollmary @@ -132,7 +129,7 @@ protected CompletableFuture execute(final Request request, final VstCo rfuture.completeExceptionally(new ArangoDBException(errorEntity)); } else { rfuture.completeExceptionally(new ArangoDBException( - String.format("Response Code: %s", response.getResponseCode()))); + String.format("Response Code: %s", response.getResponseCode()), response.getResponseCode())); } } else { rfuture.complete(response); @@ -148,15 +145,14 @@ protected CompletableFuture execute(final Request request, final VstCo rfuture.cancel(true); } }); - } catch (final IOException | VPackException e) { + } catch (final VPackException e) { LOGGER.error(e.getMessage(), e); rfuture.completeExceptionally(e); } return rfuture; } - private CompletableFuture send(final Message message, final VstConnectionAsync connection) - throws IOException { + private CompletableFuture send(final Message message, final VstConnectionAsync connection) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Send Message (id=%s, head=%s, body=%s)", message.getId(), message.getHead(), message.getBody() != null ? message.getBody() : "{}")); @@ -166,13 +162,11 @@ private CompletableFuture send(final Message message, final VstConnecti @Override protected void authenticate(final VstConnectionAsync connection) { - Response response = null; + Response response; try { response = execute(new AuthenticationRequest(user, password != null ? password : "", ENCRYPTION_PLAIN), connection).get(); - } catch (final InterruptedException e) { - throw new ArangoDBException(e); - } catch (final ExecutionException e) { + } catch (final InterruptedException | ExecutionException e) { throw new ArangoDBException(e); } checkError(response); diff --git a/src/test/java/com/arangodb/ArangoCollectionTest.java b/src/test/java/com/arangodb/ArangoCollectionTest.java index 74a51e2..ce0bd57 100644 --- a/src/test/java/com/arangodb/ArangoCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoCollectionTest.java @@ -61,7 +61,7 @@ public void create() throws InterruptedException, ExecutionException { assertThat(result, is(notNullValue())); assertThat(result.getId(), is(notNullValue())); } finally { - db.collection(COLLECTION_NAME + "_1").drop(); + db.collection(COLLECTION_NAME + "_1").drop().get(); } } @@ -211,8 +211,8 @@ public void getDocumentNotFound() throws InterruptedException, ExecutionExceptio } @Test(expected = ArangoDBException.class) - public void getDocumentWrongKey() throws InterruptedException, ExecutionException { - db.collection(COLLECTION_NAME).getDocument("no/no", BaseDocument.class).get(); + public void getDocumentWrongKey() { + db.collection(COLLECTION_NAME).getDocument("no/no", BaseDocument.class); } @Test @@ -251,7 +251,7 @@ public void getDocumentsWrongKey() throws InterruptedException, ExecutionExcepti } @Test - public void updateDocument() throws ArangoDBException, InterruptedException, ExecutionException { + public void updateDocument() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); doc.addAttribute("c", "test"); @@ -408,7 +408,7 @@ public void updateDocumentKeepNullTrue() throws InterruptedException, ExecutionE } @Test - public void updateDocumentKeepNullFalse() throws ArangoDBException, InterruptedException, ExecutionException { + public void updateDocumentKeepNullFalse() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) @@ -434,7 +434,7 @@ public void updateDocumentKeepNullFalse() throws ArangoDBException, InterruptedE @SuppressWarnings("unchecked") @Test - public void updateDocumentMergeObjectsTrue() throws ArangoDBException, InterruptedException, ExecutionException { + public void updateDocumentMergeObjectsTrue() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); final Map a = new HashMap<>(); a.put("a", "test"); @@ -466,7 +466,7 @@ public void updateDocumentMergeObjectsTrue() throws ArangoDBException, Interrupt @SuppressWarnings("unchecked") @Test - public void updateDocumentMergeObjectsFalse() throws ArangoDBException, InterruptedException, ExecutionException { + public void updateDocumentMergeObjectsFalse() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); final Map a = new HashMap<>(); a.put("a", "test"); @@ -513,7 +513,7 @@ public void updateDocumentIgnoreRevsFalse() throws InterruptedException, Executi } @Test - public void replaceDocument() throws ArangoDBException, InterruptedException, ExecutionException { + public void replaceDocument() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); final DocumentCreateEntity createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) @@ -1327,14 +1327,10 @@ public void importDocumentsFromToPrefix() throws InterruptedException, Execution assertThat(importResult.getCreated(), is(values.size())); for (int i = 0; i < keys.length; i++) { BaseEdgeDocument doc; - try { - doc = collection.getDocument(keys[i], BaseEdgeDocument.class).get(); - assertThat(doc, is(notNullValue())); - assertThat(doc.getFrom(), is("foo/from")); - assertThat(doc.getTo(), is("bar/to")); - } catch (ArangoDBException | InterruptedException | ExecutionException e) { - fail(); - } + doc = collection.getDocument(keys[i], BaseEdgeDocument.class).get(); + assertThat(doc, is(notNullValue())); + assertThat(doc.getFrom(), is("foo/from")); + assertThat(doc.getTo(), is("bar/to")); } } finally { collection.drop().get(); @@ -1501,14 +1497,10 @@ public void importDocumentsJsonFromToPrefix() throws InterruptedException, Execu assertThat(importResult.getCreated(), is(2)); for (int i = 0; i < keys.length; i++) { BaseEdgeDocument doc; - try { - doc = collection.getDocument(keys[i], BaseEdgeDocument.class).get(); - assertThat(doc, is(notNullValue())); - assertThat(doc.getFrom(), is("foo/from")); - assertThat(doc.getTo(), is("bar/to")); - } catch (ArangoDBException | InterruptedException | ExecutionException e) { - fail(); - } + doc = collection.getDocument(keys[i], BaseEdgeDocument.class).get(); + assertThat(doc, is(notNullValue())); + assertThat(doc.getFrom(), is("foo/from")); + assertThat(doc.getTo(), is("bar/to")); } } finally { collection.drop().get(); @@ -1874,7 +1866,7 @@ public void changeProperties() throws InterruptedException, ExecutionException { }) .get(); } finally { - db.collection(collection).drop(); + db.collection(collection).drop().get(); } } @@ -1979,7 +1971,7 @@ public void resetAccessUserNotFound() throws InterruptedException, ExecutionExce } @Test - public void getPermissions() throws ArangoDBException, InterruptedException, ExecutionException { + public void getPermissions() throws InterruptedException, ExecutionException { assertThat(Permissions.RW, is(db.collection(COLLECTION_NAME).getPermissions("root").get())); } } diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 692caea..ec7e66d 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -112,10 +112,7 @@ public void createDatabase() throws InterruptedException, ExecutionException { assertThat(result, is(true)); }) .get(); - try { - arangoDB.db(BaseTest.TEST_DB).drop().get(); - } catch (final ArangoDBException e) { - } + arangoDB.db(BaseTest.TEST_DB).drop().get(); } @Test @@ -351,7 +348,7 @@ public void updateUserDefaultCollectionAccess() throws InterruptedException, Exe } @Test - public void authenticationFailPassword() throws InterruptedException, ExecutionException { + public void authenticationFailPassword() throws InterruptedException { final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().password("no").build(); try { arangoDB.getVersion().get(); @@ -362,7 +359,7 @@ public void authenticationFailPassword() throws InterruptedException, ExecutionE } @Test - public void authenticationFailUser() throws InterruptedException, ExecutionException { + public void authenticationFailUser() throws InterruptedException { final ArangoDBAsync arangoDB = new ArangoDBAsync.Builder().user("no").build(); try { arangoDB.getVersion().get(); diff --git a/src/test/java/com/arangodb/ArangoDatabaseTest.java b/src/test/java/com/arangodb/ArangoDatabaseTest.java index a1c4273..9c4682b 100644 --- a/src/test/java/com/arangodb/ArangoDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDatabaseTest.java @@ -59,10 +59,7 @@ public void create() throws InterruptedException, ExecutionException { final Boolean result = arangoDB.db(BaseTest.TEST_DB + "_1").create().get(); assertThat(result, is(true)); } finally { - try { - arangoDB.db(BaseTest.TEST_DB + "_1").drop(); - } catch (final ArangoDBException e) { - } + arangoDB.db(BaseTest.TEST_DB + "_1").drop().get(); } } @@ -390,7 +387,7 @@ public void grantDefaultCollectionAccess() throws InterruptedException, Executio } @Test - public void getPermissions() throws ArangoDBException, InterruptedException, ExecutionException { + public void getPermissions() throws InterruptedException, ExecutionException { assertThat(Permissions.RW, is(db.getPermissions("root").get())); } @@ -597,7 +594,7 @@ public void changeQueryCache() throws InterruptedException, ExecutionException { } @Test - public void queryWithCache() throws InterruptedException, ArangoDBException, ExecutionException { + public void queryWithCache() throws InterruptedException, ExecutionException { if (arangoDB.getRole().get() != ServerRole.SINGLE) { return; } @@ -636,7 +633,7 @@ public void queryWithCache() throws InterruptedException, ArangoDBException, Exe } @Test - public void queryCursor() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryCursor() throws InterruptedException, ExecutionException { try { db.createCollection(COLLECTION_NAME, null).get(); final int numbDocs = 10; @@ -723,7 +720,7 @@ public void queryWithWarning() throws InterruptedException, ExecutionException { } @Test - public void queryClose() throws IOException, ArangoDBException, InterruptedException, ExecutionException { + public void queryClose() throws IOException, InterruptedException, ExecutionException { final ArangoCursorAsync cursor = arangoDB.db() .query("for i in 1..2 return i", null, new AqlQueryOptions().batchSize(1), String.class).get(); cursor.close(); @@ -1049,21 +1046,16 @@ public void getDocument() throws InterruptedException, ExecutionException { } @Test - public void shouldIncludeExceptionMessage() throws InterruptedException, ExecutionException { - if (!requireVersion(3, 2)) { - final String exceptionMessage = "My error context"; - final String action = "function (params) {" + "throw '" + exceptionMessage + "';" + "}"; - try { - db.transaction(action, VPackSlice.class, null).join(); - fail(); - } catch (final CompletionException e) { - final Throwable cause = e.getCause(); - if (cause instanceof ArangoDBException) { - assertTrue(((ArangoDBException) cause).getException().equals(exceptionMessage)); - } else { - fail("Root cause expected to be an ArangoDBException"); - } - } + public void shouldIncludeExceptionMessage() { + final String exceptionMessage = "My error context"; + final String action = "function (params) {" + "throw '" + exceptionMessage + "';" + "}"; + try { + db.transaction(action, VPackSlice.class, null).join(); + fail(); + } catch (final CompletionException e) { + assertThat(e.getCause(), instanceOf(ArangoDBException.class)); + ArangoDBException cause = ((ArangoDBException) e.getCause()); + assertThat(cause.getErrorMessage(), is(exceptionMessage)); } } diff --git a/src/test/java/com/arangodb/ArangoEdgeCollectionTest.java b/src/test/java/com/arangodb/ArangoEdgeCollectionTest.java index ae9869f..3e9c31c 100644 --- a/src/test/java/com/arangodb/ArangoEdgeCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoEdgeCollectionTest.java @@ -94,7 +94,7 @@ private BaseEdgeDocument createEdgeValue() throws InterruptedException, Executio } @Test - public void insertEdge() throws ArangoDBException, InterruptedException, ExecutionException { + public void insertEdge() throws InterruptedException, ExecutionException { final BaseEdgeDocument value = createEdgeValue(); final EdgeEntity edge = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(value, null).get(); assertThat(edge, is(notNullValue())); diff --git a/src/test/java/com/arangodb/ArangoGraphTest.java b/src/test/java/com/arangodb/ArangoGraphTest.java index cba7b99..b1745a6 100644 --- a/src/test/java/com/arangodb/ArangoGraphTest.java +++ b/src/test/java/com/arangodb/ArangoGraphTest.java @@ -96,7 +96,7 @@ public void create() throws InterruptedException, ExecutionException { assertThat(result, is(notNullValue())); assertThat(result.getName(), is(GRAPH_NAME + "_1")); } finally { - db.graph(GRAPH_NAME + "_1").drop(); + db.graph(GRAPH_NAME + "_1").drop().get(); } } diff --git a/src/test/java/com/arangodb/ArangoRouteTest.java b/src/test/java/com/arangodb/ArangoRouteTest.java index 0df4f12..4aef03f 100644 --- a/src/test/java/com/arangodb/ArangoRouteTest.java +++ b/src/test/java/com/arangodb/ArangoRouteTest.java @@ -20,6 +20,7 @@ package com.arangodb; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -75,9 +76,9 @@ public void withParentHeader() throws InterruptedException, ExecutionException { .route(doc.getId()).get().get(); fail(); } catch (final ExecutionException e) { - assertThat(e.getCause() instanceof ArangoDBException, is(true)); + assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } finally { - collection.drop(); + collection.drop().get(); } } diff --git a/src/test/java/com/arangodb/example/graph/BaseGraphTest.java b/src/test/java/com/arangodb/example/graph/BaseGraphTest.java index 71e1e0f..988a9d7 100644 --- a/src/test/java/com/arangodb/example/graph/BaseGraphTest.java +++ b/src/test/java/com/arangodb/example/graph/BaseGraphTest.java @@ -28,7 +28,6 @@ import org.junit.BeforeClass; import com.arangodb.ArangoDBAsync; -import com.arangodb.ArangoDBException; import com.arangodb.ArangoDatabaseAsync; import com.arangodb.entity.EdgeDefinition; import com.arangodb.entity.EdgeEntity; @@ -78,7 +77,7 @@ public static void shutdown() throws InterruptedException, ExecutionException { arangoDB = null; } - private static void addExampleElements() throws ArangoDBException, InterruptedException, ExecutionException { + private static void addExampleElements() throws InterruptedException, ExecutionException { // Add circle circles final VertexEntity vA = createVertex(new Circle("A", "1")); @@ -109,12 +108,12 @@ private static void addExampleElements() throws ArangoDBException, InterruptedEx } private static EdgeEntity saveEdge(final CircleEdge edge) - throws ArangoDBException, InterruptedException, ExecutionException { + throws InterruptedException, ExecutionException { return db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(edge).get(); } private static VertexEntity createVertex(final Circle vertex) - throws ArangoDBException, InterruptedException, ExecutionException { + throws InterruptedException, ExecutionException { return db.graph(GRAPH_NAME).vertexCollection(VERTEXT_COLLECTION_NAME).insertVertex(vertex).get(); } diff --git a/src/test/java/com/arangodb/example/graph/GraphTraversalsInAQLExample.java b/src/test/java/com/arangodb/example/graph/GraphTraversalsInAQLExample.java index 9d42a21..55fa9b7 100644 --- a/src/test/java/com/arangodb/example/graph/GraphTraversalsInAQLExample.java +++ b/src/test/java/com/arangodb/example/graph/GraphTraversalsInAQLExample.java @@ -30,7 +30,6 @@ import org.junit.Test; import com.arangodb.ArangoCursorAsync; -import com.arangodb.ArangoDBException; /** * Graph traversals in AQL @@ -43,7 +42,7 @@ public class GraphTraversalsInAQLExample extends BaseGraphTest { @Test - public void queryAllVertices() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryAllVertices() throws InterruptedException, ExecutionException { String queryString = "FOR v IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' RETURN v._key"; ArangoCursorAsync cursor = db.query(queryString, null, null, String.class).get(); Collection result = cursor.asListRemaining(); @@ -56,7 +55,7 @@ public void queryAllVertices() throws ArangoDBException, InterruptedException, E } @Test - public void queryDepthTwo() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryDepthTwo() throws InterruptedException, ExecutionException { String queryString = "FOR v IN 2..2 OUTBOUND 'circles/A' GRAPH 'traversalGraph' return v._key"; ArangoCursorAsync cursor = db.query(queryString, null, null, String.class).get(); Collection result = cursor.asListRemaining(); @@ -71,7 +70,7 @@ public void queryDepthTwo() throws ArangoDBException, InterruptedException, Exec } @Test - public void queryWithFilter() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryWithFilter() throws InterruptedException, ExecutionException { String queryString = "FOR v, e, p IN 1..3 OUTBOUND 'circles/A' GRAPH 'traversalGraph' FILTER p.vertices[1]._key != 'G' RETURN v._key"; ArangoCursorAsync cursor = db.query(queryString, null, null, String.class).get(); Collection result = cursor.asListRemaining(); @@ -99,7 +98,7 @@ public void queryWithFilter() throws ArangoDBException, InterruptedException, Ex } @Test - public void queryOutboundInbound() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryOutboundInbound() throws InterruptedException, ExecutionException { String queryString = "FOR v IN 1..3 OUTBOUND 'circles/E' GRAPH 'traversalGraph' return v._key"; ArangoCursorAsync cursor = db.query(queryString, null, null, String.class).get(); Collection result = cursor.asListRemaining(); diff --git a/src/test/java/com/arangodb/example/graph/ShortestPathInAQLExample.java b/src/test/java/com/arangodb/example/graph/ShortestPathInAQLExample.java index cb1a379..1882358 100644 --- a/src/test/java/com/arangodb/example/graph/ShortestPathInAQLExample.java +++ b/src/test/java/com/arangodb/example/graph/ShortestPathInAQLExample.java @@ -32,7 +32,6 @@ import org.junit.Test; import com.arangodb.ArangoCursorAsync; -import com.arangodb.ArangoDBException; /** * Shortest Path in AQL @@ -68,7 +67,7 @@ public void setEdge(final String edge) { } @Test - public void queryShortestPathFromAToD() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryShortestPathFromAToD() throws InterruptedException, ExecutionException { String queryString = "FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' GRAPH 'traversalGraph' RETURN {'vertex': v._key, 'edge': e._key}"; ArangoCursorAsync cursor = db.query(queryString, null, null, Pair.class).get(); final Collection collection = toVertexCollection(cursor); @@ -82,7 +81,7 @@ public void queryShortestPathFromAToD() throws ArangoDBException, InterruptedExc } @Test - public void queryShortestPathByFilter() throws ArangoDBException, InterruptedException, ExecutionException { + public void queryShortestPathByFilter() throws InterruptedException, ExecutionException { String queryString = "FOR a IN circles FILTER a._key == 'A' FOR d IN circles FILTER d._key == 'D' FOR v, e IN OUTBOUND SHORTEST_PATH a TO d GRAPH 'traversalGraph' RETURN {'vertex':v._key, 'edge':e._key}"; ArangoCursorAsync cursor = db.query(queryString, null, null, Pair.class).get(); final Collection collection = toVertexCollection(cursor);