From 51d41dfe7a681420479a61ebd523d3cbf40edaaa Mon Sep 17 00:00:00 2001
From: "Stefan E. Funk" <funk@sub.uni-goettingen.de>
Date: Thu, 23 May 2019 11:13:31 +0200
Subject: [PATCH] Add test for concurrent GetRecord use

---
 .../middleware/DublinCoreBuilder.java         |  31 ++--
 .../middleware/OaiPmhTextgridOnlineTests.java | 132 ++++++++++++++++++
 2 files changed, 148 insertions(+), 15 deletions(-)

diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java
index 291c9c31..b07a6750 100644
--- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java
+++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java
@@ -40,7 +40,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the contributors and build the specific dublinCore element for
+   * Takes a string list containing the contributors and build the specific dublinCore element for
    * each
    * </p>
    * 
@@ -59,7 +59,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the creators and build the specific dublinCore element for each
+   * Takes a string list containing the creators and build the specific dublinCore element for each
    * </p>
    * 
    * @param creators
@@ -76,7 +76,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <P>
-   * Takes a Stringlist containing the coverages and build the specific dublinCore element for each
+   * Takes a string list containing the coverages and build the specific dublinCore element for each
    * </p>
    * 
    * @param coverages
@@ -93,7 +93,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the dates and build the specific dublinCore element for each
+   * Takes a string list containing the dates and build the specific dublinCore element for each
    * </p>
    * 
    * @param dates
@@ -110,7 +110,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the descriptions and build the specific dublinCore element for
+   * Takes a string list containing the descriptions and build the specific dublinCore element for
    * each
    * </p>
    * 
@@ -129,7 +129,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the formats and build the specific dublinCore element for each
+   * Takes a string list containing the formats and build the specific dublinCore element for each
    * </p>
    * 
    * @param formats
@@ -146,7 +146,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the identifiers and build the specific dublinCore element for
+   * Takes a string list containing the identifiers and build the specific dublinCore element for
    * each
    * </p>
    * 
@@ -164,7 +164,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the languages and build the specific dublinCore element for each
+   * Takes a string list containing the languages and build the specific dublinCore element for each
    * </p>
    * 
    * @param languages
@@ -181,7 +181,8 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the publishers and build the specific dublinCore element for each
+   * Takes a string list containing the publishers and build the specific dublinCore element for
+   * each
    * </p>
    * 
    * @param publishers
@@ -198,7 +199,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the relations and build the specific dublinCore element for each
+   * Takes a string list containing the relations and build the specific dublinCore element for each
    * </p>
    * 
    * @param relations
@@ -215,7 +216,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the rights and build the specific dublinCore element for each
+   * Takes a string list containing the rights and build the specific dublinCore element for each
    * </p>
    * 
    * @param rights
@@ -232,7 +233,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the sources and build the specific dublinCore element for each
+   * Takes a string list containing the sources and build the specific dublinCore element for each
    * </p>
    * 
    * @param sources
@@ -249,7 +250,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the subjects and build the specific dublinCore element for each
+   * Takes a string list containing the subjects and build the specific dublinCore element for each
    * </p>
    * 
    * @param subjects
@@ -266,7 +267,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the titles and build the specific dublinCore element for each
+   * Takes a string list containing the titles and build the specific dublinCore element for each
    * </p>
    * 
    * @param titles
@@ -283,7 +284,7 @@ public final class DublinCoreBuilder {
 
   /**
    * <p>
-   * Takes a Stringlist containing the types and build the specific dublinCore element for each
+   * Takes a string list containing the types and build the specific dublinCore element for each
    * </p>
    * 
    * @param types
diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java
index 70a0c887..6d142e1e 100644
--- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java
+++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java
@@ -493,6 +493,90 @@ public class OaiPmhTextgridOnlineTests {
     System.out.println(OK + ": [B1]=" + f1.get() + ", [B2]=" + f2.get() + ", [B3]=" + f3.get());
   }
 
+  /**
+   * @throws IOException
+   * @throws InterruptedException
+   * @throws ExecutionException
+   */
+  @Test
+  public void testConcurrentlyOAIDCGetRecord() throws InterruptedException, ExecutionException {
+
+    System.out.println(TESTING + "testConcurrentlyOAIDCGetRecord()");
+
+    for (int i = 0; i < 9; i++) {
+
+      System.out.println("\tThis is loop " + (i + 1));
+
+      String id1 = "textgrid:mq05.0";
+      String id2 = "textgrid:jgv6.0";
+      String id3 = "textgrid:w7rz.0";
+      String id4 = "textgrid:w36b.0";
+      String id5 = "textgrid:mcdv.0";
+      String id6 = "textgrid:v0qx.0";
+      String id7 = "textgrid:xkck.0";
+      String id8 = "textgrid:t3m1.0";
+      String id9 = "textgrid:10rsq.0";
+      String idA = "textgrid:mq06.0";
+      String idB = "textgrid:jgv7.0";
+      String idC = "textgrid:w7rd.0";
+      String idD = "textgrid:w361.0";
+      String idE = "textgrid:mcd7.0";
+      String idF = "textgrid:v0qa.0";
+      String idG = "textgrid:xkc8.0";
+      String idH = "textgrid:t3m2.0";
+      String idI = "textgrid:10rjq.0";
+
+      ExecutorService executor = Executors.newFixedThreadPool(2);
+
+      if (!host.contains("dev.textgridlab.org")) {
+        Future<Boolean> f1 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id1, OAI_DC_PREFIX, "[GR1]"));
+        Future<Boolean> f2 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id2, OAI_DC_PREFIX, "[GR2]"));
+        Future<Boolean> f3 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id3, OAI_DC_PREFIX, "[GR3]"));
+        Future<Boolean> f4 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id4, OAI_DC_PREFIX, "[GR4]"));
+        Future<Boolean> f5 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id5, OAI_DC_PREFIX, "[GR5]"));
+        Future<Boolean> f6 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id6, OAI_DC_PREFIX, "[GR6]"));
+        Future<Boolean> f7 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id7, OAI_DC_PREFIX, "[GR7]"));
+        Future<Boolean> f8 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id8, OAI_DC_PREFIX, "[GR8]"));
+        Future<Boolean> f9 = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            id9, OAI_DC_PREFIX, "[GR9]"));
+        Future<Boolean> fA = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idA, OAI_DC_PREFIX, "[GRA]"));
+        Future<Boolean> fB = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idB, OAI_DC_PREFIX, "[GRB]"));
+        Future<Boolean> fC = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idC, OAI_DC_PREFIX, "[GRC]"));
+        Future<Boolean> fD = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idD, OAI_DC_PREFIX, "[GRD]"));
+        Future<Boolean> fE = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idE, OAI_DC_PREFIX, "[GRE]"));
+        Future<Boolean> fF = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idF, OAI_DC_PREFIX, "[GRF]"));
+        Future<Boolean> fG = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idG, OAI_DC_PREFIX, "[GRG]"));
+        Future<Boolean> fH = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idH, OAI_DC_PREFIX, "[GRH]"));
+        Future<Boolean> fI = executor.submit(new OaiPmhGetRecordTestThread(VERB_GET_RECORD,
+            idI, OAI_DC_PREFIX, "[GRI]"));
+
+        executor.shutdown();
+
+        System.out.println(OK + ": [GR1]=" + f1.get() + ", [GR2]=" + f2.get() + ", [GR3]="
+            + f3.get() + ", [GR4]=" + f4.get() + ", [GR5]=" + f5.get() + ", [GR6]=" + f6.get()
+            + ", [GR7]=" + f7.get() + ", [GR8]=" + f8.get() + ", [GR9]=" + f9.get());
+      } else {
+        System.out.println(NOT_TESTED);
+      }
+    }
+  }
+
   // **
   // PRIVATE METHODS
   // **
@@ -758,4 +842,52 @@ public class OaiPmhTextgridOnlineTests {
 
   }
 
+  /**
+   * <p>
+   * Starts a new OAI-PMH thread.
+   * </p>
+   */
+
+  private class OaiPmhGetRecordTestThread implements Callable<Boolean> {
+
+    protected String verb;
+    protected String identifier;
+    protected String metadataPrefix;
+    protected String threadName;
+
+    /**
+     * @param theVerb
+     * @param theIdentifier
+     * @param theMetadataPrefix
+     * @param theThreadName
+     */
+    public OaiPmhGetRecordTestThread(String theVerb, String theIdentifier, String theMetadataPrefix,
+        String theThreadName) {
+      this.verb = theVerb;
+      this.identifier = theIdentifier;
+      this.metadataPrefix = theMetadataPrefix;
+      this.threadName = theThreadName;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.concurrent.Callable#call()
+     */
+    public Boolean call() throws IOException {
+
+      String url = host + "oai?verb=" + VERB_GET_RECORD + "&identifier=" + this.identifier
+          + "&metadataPrefix=" + this.metadataPrefix;
+
+      TGHttpResponse httpResponse = getHttpResponse(url, this.threadName);
+      int status = httpResponse.getStatusCode();
+      String response = IOUtils.readStringFromStream(httpResponse.getInputstream());
+
+      System.out.println("\t" + this.threadName + " response: " + response);
+
+      return true;
+    }
+
+  }
+
 }
-- 
GitLab