summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/src/main/java/com/yahoo/application/container/DocumentAccesses.java44
-rw-r--r--documentapi/src/main/java/com/yahoo/documentapi/local/LocalDocumentAccess.java5
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/DocumentOperationExecutorTest.java5
3 files changed, 50 insertions, 4 deletions
diff --git a/application/src/main/java/com/yahoo/application/container/DocumentAccesses.java b/application/src/main/java/com/yahoo/application/container/DocumentAccesses.java
new file mode 100644
index 00000000000..c0edad2baa6
--- /dev/null
+++ b/application/src/main/java/com/yahoo/application/container/DocumentAccesses.java
@@ -0,0 +1,44 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.application.container;
+
+import com.yahoo.document.config.DocumentmanagerConfig;
+import com.yahoo.documentapi.DocumentAccess;
+import com.yahoo.documentapi.DocumentAccessParams;
+import com.yahoo.documentapi.local.LocalDocumentAccess;
+import com.yahoo.searchdefinition.derived.Deriver;
+
+import java.io.File;
+import java.util.stream.Stream;
+
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Utility for working with a {@link LocalDocumentAccess} for unit testing components which require a {@link DocumentAccess}.
+ *
+ * @author jonmv
+ */
+public class DocumentAccesses {
+
+ private DocumentAccesses() { }
+
+ /**
+ * Reads the {@code .sd} files in the given directory, and returns a {@link LocalDocumentAccess} with these document types.
+ * <br>
+ * Example usage:
+ * <pre>
+ * LocalDocumentAccess access = DocumentAccesses.ofSchemas("src/main/application/schemas");
+ * </pre>
+ */
+ public static LocalDocumentAccess createFromSchemas(String schemaDirectory) {
+ File[] schemasFiles = new File(schemaDirectory).listFiles(name -> name.toString().endsWith(".sd"));
+ if (schemasFiles == null)
+ throw new IllegalArgumentException(schemaDirectory + " is not a directory");
+ if (schemasFiles.length == 0)
+ throw new IllegalArgumentException("No schema files found under " + schemaDirectory);
+ DocumentmanagerConfig config = Deriver.getDocumentManagerConfig(Stream.of(schemasFiles)
+ .map(File::toString)
+ .collect(toList())).build();
+ return new LocalDocumentAccess(new DocumentAccessParams().setDocumentmanagerConfig(config));
+ }
+
+}
diff --git a/documentapi/src/main/java/com/yahoo/documentapi/local/LocalDocumentAccess.java b/documentapi/src/main/java/com/yahoo/documentapi/local/LocalDocumentAccess.java
index dd21a55d029..90bf0bccfdd 100644
--- a/documentapi/src/main/java/com/yahoo/documentapi/local/LocalDocumentAccess.java
+++ b/documentapi/src/main/java/com/yahoo/documentapi/local/LocalDocumentAccess.java
@@ -22,9 +22,12 @@ import java.util.concurrent.Phaser;
import java.util.concurrent.atomic.AtomicReference;
/**
- * The main class of the local implementation of the document api
+ * The main class of the local implementation of the document api.
+ * To easily obtain an instance of this, with the documents using the schemas (.sd-files) in a given directoy,
+ * use the {@code com.yahoo.vespa.application} test module and {@code DocumentAccesses.ofSchemas(schemaDirectory)}
*
* @author bratseth
+ * @author jonmv
*/
public class LocalDocumentAccess extends DocumentAccess {
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/DocumentOperationExecutorTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/DocumentOperationExecutorTest.java
index 68975d846e5..7d7cda826b1 100644
--- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/DocumentOperationExecutorTest.java
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/DocumentOperationExecutorTest.java
@@ -1,6 +1,7 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.restapi;
+import com.yahoo.application.container.DocumentAccesses;
import com.yahoo.cloud.config.ClusterListConfig;
import com.yahoo.document.Document;
import com.yahoo.document.DocumentPut;
@@ -13,12 +14,10 @@ import com.yahoo.document.restapi.DocumentOperationExecutor.VisitOperationsConte
import com.yahoo.document.restapi.DocumentOperationExecutor.VisitorOptions;
import com.yahoo.document.restapi.DocumentOperationExecutorImpl.StorageCluster;
import com.yahoo.document.restapi.DocumentOperationExecutorImpl.DelayQueue;
-import com.yahoo.documentapi.DocumentAccessParams;
import com.yahoo.documentapi.Result;
import com.yahoo.documentapi.VisitorControlHandler;
import com.yahoo.documentapi.local.LocalAsyncSession;
import com.yahoo.documentapi.local.LocalDocumentAccess;
-import com.yahoo.searchdefinition.derived.Deriver;
import com.yahoo.test.ManualClock;
import com.yahoo.vespa.config.content.AllClustersBucketSpacesConfig;
import org.junit.After;
@@ -106,7 +105,7 @@ public class DocumentOperationExecutorTest {
@Before
public void setUp() {
clock = new ManualClock();
- access = new LocalDocumentAccess(new DocumentAccessParams().setDocumentmanagerConfig(Deriver.getDocumentManagerConfig("src/test/cfg/music.sd").build()));
+ access = DocumentAccesses.createFromSchemas("src/test/cfg");
executor = new DocumentOperationExecutorImpl(clusterConfig, bucketConfig, executorConfig, access, clock);
received.clear();
errors.clear();