Repository: eclipse/microprofile-lra
Pull request #219 (2019-08-08 09:40:26)

issue218 Define long and short consistency delay config properties
#218 
This PR implements the recommendation on issue https://github.com/eclipse/microprofile-lra/pull/215#issuecomment-519186466


Patch:
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/LraTckConfigBean.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/LraTckConfigBean.java
index 9705a0b..5380f4c 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/LraTckConfigBean.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/LraTckConfigBean.java
@@ -65,6 +65,9 @@ public class LraTckConfigBean {
      *     milliseconds that a test will wait for before it checks if a complete
      *     or compensate method has been called.
      *
+     *     There are two properties for configuring delays. The long version should be
+     *     used when multiple calls to these participant methods needs to be performed.
+     *
      *     The default is set to zero which implies that the implementation will
      *     notify participants as soon as the LRA enters the
      *     {@link LRAStatus#Closing} or {@link LRAStatus#Cancelling}
@@ -74,8 +77,20 @@ public class LraTckConfigBean {
      *     states first if a participant cannot clean up or compensate immediately.
      * </p>
      */
-    @Inject @ConfigProperty(name = "lra.tck.consistency.delay", defaultValue = "0")
-    long consistencyDelay;
+    @Inject @ConfigProperty(name = "lra.tck.consistency.longDelay", defaultValue = "0")
+    long longConsistencyDelay;
+
+    /**
+     * <p>
+     *     An alternative to @see LraTckConfigBean#longConsistencyDelay
+     *     This can be useful if the consistency delay needs to be changed for some tests
+     *
+     *     There are two properties for configuring delays. The short version should be
+     *     used when we just need to wait for the implementation to call the participant methods
+     * </p>
+     */
+    @Inject @ConfigProperty(name = "lra.tck.consistency.shortDelay", defaultValue = "0")
+    long shortConsistencyDelay;
 
     /**
      * <p>
@@ -116,8 +131,12 @@ public class LraTckConfigBean {
         return timeoutFactor;
     }
 
-    long getConsistencyDelay() {
-        return consistencyDelay;
+    long getLongConsistencyDelay() {
+        return longConsistencyDelay;
+    }
+
+    long getShortConsistencyDelay() {
+        return shortConsistencyDelay;
     }
 
     public Long recoveryTimeout() {


Test patch:
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckCancelOnTests.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckCancelOnTests.java
index a65e25e..c165211 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckCancelOnTests.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckCancelOnTests.java
@@ -64,7 +64,7 @@ public class TckCancelOnTests extends TckTestBase {
         Response response = resourcePath.request().get();
 
         URI lraId = URI.create(checkStatusReadAndCloseResponse(Status.BAD_REQUEST, response, resourcePath));
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         assertEquals("After 400 compensate should be invoked", 
             1, lraMetricService.getMetric(LRAMetricType.Compensated, lraId));
         assertEquals("After 400 complete can't be invoked", 
@@ -82,7 +82,7 @@ public class TckCancelOnTests extends TckTestBase {
         Response response = resourcePath.request().get();
 
         URI lraId = URI.create(checkStatusReadAndCloseResponse(Status.INTERNAL_SERVER_ERROR, response, resourcePath));
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         assertEquals("After 500 compensate should be invoked", 
             1, lraMetricService.getMetric(LRAMetricType.Compensated, lraId));
         assertEquals("After 500 complete can't be invoked", 
@@ -100,7 +100,7 @@ public class TckCancelOnTests extends TckTestBase {
         Response response = resourcePath.request().get();
 
         URI lraId = URI.create(checkStatusReadAndCloseResponse(Status.SEE_OTHER, response, resourcePath));
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         assertEquals("After status code 303 is received, compensate should be invoked as set by attribute cancelOnFamily",
                 1, lraMetricService.getMetric(LRAMetricType.Compensated, lraId));
         assertEquals("After status code 303 is received, complete can't be invoked as not defined in annotation @LRA",
@@ -118,7 +118,7 @@ public class TckCancelOnTests extends TckTestBase {
         Response response = resourcePath.request().get();
 
         URI lraId = URI.create(checkStatusReadAndCloseResponse(Status.MOVED_PERMANENTLY, response, resourcePath));
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         assertEquals("After status code 301 is received, compensate should be invoked as set by attribute cancelOn",
                 1, lraMetricService.getMetric(LRAMetricType.Compensated, lraId));
         assertEquals("After status code 301 is received, complete can't be invoked as not defined in annotation @LRA",
@@ -136,7 +136,7 @@ public class TckCancelOnTests extends TckTestBase {
         Response response = resourcePath.request().get();
 
         URI lraId = URI.create(checkStatusReadAndCloseResponse(Status.INTERNAL_SERVER_ERROR, response, resourcePath));
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         assertEquals("After status code 500 is received, compensate can't be invoked as default behaviour was changed",
                 0, lraMetricService.getMetric(LRAMetricType.Compensated, lraId));
         assertEquals("After status code 500 is received, complete has to be called as default behaviour was changed",
@@ -154,7 +154,7 @@ public class TckCancelOnTests extends TckTestBase {
         Response response = resourcePath.request().get();
 
         URI lraId = URI.create(checkStatusReadAndCloseResponse(Status.OK, response, resourcePath));
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         // LraCancelOnResource enlists twice the same participant, compensate is expected to be called only once
         assertEquals("Status was 200 but compensate should be called as LRA should be cancelled for remotely called participant as well",
                 1, lraMetricService.getMetric(LRAMetricType.Compensated, lraId));
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckContextTests.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckContextTests.java
index 0a87fab..e2faaec 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckContextTests.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckContextTests.java
@@ -271,7 +271,7 @@ public class TckContextTests extends TckTestBase {
         }
 
         if (delay) {
-            applyConsistencyDelay();
+            applyShortConsistencyDelay();
         }
 
         switch (method) {
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTestBase.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTestBase.java
index f879027..a34be13 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTestBase.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTestBase.java
@@ -134,12 +134,25 @@ public class TckTestBase {
     }
 
     /**
-     * @see LraTckConfigBean#consistencyDelay
+     * @see LraTckConfigBean#shortConsistencyDelay
      */
-    void applyConsistencyDelay() {
-        if (config.getConsistencyDelay() > 0) {
+    void applyShortConsistencyDelay() {
+        if (config.getShortConsistencyDelay() > 0) {
             try {
-                Thread.sleep(config.getConsistencyDelay());
+                Thread.sleep(config.getShortConsistencyDelay());
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    /**
+     * @see LraTckConfigBean#longConsistencyDelay
+     */
+    void applyLongConsistencyDelay() {
+        if (config.getLongConsistencyDelay() > 0) {
+            try {
+                Thread.sleep(config.getLongConsistencyDelay());
             } catch (InterruptedException e) {
                 throw new RuntimeException(e);
             }
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTests.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTests.java
index d9528a7..5a02726 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTests.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckTests.java
@@ -191,7 +191,7 @@ public class TckTests extends TckTestBase {
 
         // close the LRA
         lraClient.closeLRA(lra);
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         
         // check that participant was told to complete
         assertEquals("Wrong completion count for call " + resourcePath.getUri() + ". Expecting the method LRA was completed "
@@ -278,7 +278,7 @@ public class TckTests extends TckTestBase {
         checkStatusAndCloseResponse(Response.Status.OK, response, resourcePath);
 
         lraClient.closeLRA(lra);
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
 
         // check that participant was not told to complete
         assertEquals("Wrong completion count when participant left the LRA. "
@@ -321,7 +321,7 @@ public class TckTests extends TckTestBase {
         // (depends upon how long the coordinator keeps a record of finished LRAs
 
         // check that participant was invoked
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         
         /*
          * The call to activities/timeLimit should have started an LRA which should have timed out
@@ -365,7 +365,7 @@ public class TckTests extends TckTestBase {
         }
 
         replayEndPhase(null);
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
 
         int completionCount = lraMetricService.getMetric(LRAMetricType.Completed, lra, LraResource.class.getName());
         int compensationCount = lraMetricService.getMetric(LRAMetricType.Compensated, lra, LraResource.class.getName());
@@ -401,7 +401,7 @@ public class TckTests extends TckTestBase {
                 lraId, lra.toString());
 
         lraClient.cancelLRA(lra);
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
 
         // check that second service (the LRA aware one), namely
         // {@link org.eclipse.microprofile.lra.tck.participant.api.LraResource#activityWithMandatoryLRA(String, String)}
@@ -496,14 +496,14 @@ public class TckTests extends TckTestBase {
 
         if (close) {
             lraClient.closeLRA(lra);
-            applyConsistencyDelay();
+            applyShortConsistencyDelay();
             
             assertTrue(methodName + ": resource should have completed once with no compensations",
                     1 == lraMetricService.getMetric(LRAMetricType.Completed, lra, ParticipatingTckResource.class.getName()) &&
                     0 == lraMetricService.getMetric(LRAMetricType.Compensated, lra, ParticipatingTckResource.class.getName()));
         } else {
             lraClient.cancelLRA(lra);
-            applyConsistencyDelay();
+            applyShortConsistencyDelay();
 
             assertTrue(methodName + ":: resource should have compensated once with no completions",
                     0 == lraMetricService.getMetric(LRAMetricType.Completed, lra, ParticipatingTckResource.class.getName()) &&
@@ -526,14 +526,14 @@ public class TckTests extends TckTestBase {
 
         if (close) {
             lraClient.closeLRA(lra);
-            applyConsistencyDelay();
+            applyShortConsistencyDelay();
 
             assertTrue("joinWithTwoResourcesWithClose: both resources should have completed",
                     lraMetricService.getMetric(LRAMetricType.Completed, lra, LraResource.class.getName()) == 1 &&
                     lraMetricService.getMetric(LRAMetricType.Completed, lra, ParticipatingTckResource.class.getName()) == 1);
         } else {
             lraClient.cancelLRA(lra);
-            applyConsistencyDelay();
+            applyShortConsistencyDelay();
 
             assertTrue("joinWithTwoResourcesWithCancel: both resources should have compensated",
                     lraMetricService.getMetric(LRAMetricType.Compensated, lra, LraResource.class.getName()) == 1 &&
@@ -581,7 +581,7 @@ public class TckTests extends TckTestBase {
         assertFalse("multiLevelNestedActivity: top level LRA should be active (path called " + resourcePath.getUri() + ")",
                 lraClient.isLRAFinished(URI.create( lraArray[0])));
 
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         int inMiddleCompletedCount = lraMetricService.getMetric(LRAMetricType.Completed);
         int inMiddleCompensatedCount = lraMetricService.getMetric(LRAMetricType.Compensated);
 
@@ -622,7 +622,7 @@ public class TckTests extends TckTestBase {
                         (i == 0 ? "top level" : "nested"), resourcePath.getUri()),
                 lraClient.isLRAFinished(URI.create(lraArray[i]))));
 
-        applyConsistencyDelay();
+        applyShortConsistencyDelay();
         int afterCompletedCount = lraMetricService.getMetric(LRAMetricType.Completed);
         int afterCompensatedCount = lraMetricService.getMetric(LRAMetricType.Compensated);
 
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownStatusTests.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownStatusTests.java
index 3a57d31..d76fe6a 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownStatusTests.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownStatusTests.java
@@ -64,7 +64,7 @@ public class TckUnknownStatusTests extends TckTestBase {
         String lraIdString = invoke(Scenario.COMPENSATE_RETRY);
         URI lraId = URI.create(lraIdString);
 
-        applyConsistencyDelay();
+        applyLongConsistencyDelay();
         int compensated = lraMetricService.getMetric(LRAMetricType.Compensated, lraId);
         int status = lraMetricService.getMetric(LRAMetricType.Status, lraId);
         int afterLRA = lraMetricService.getMetric(LRAMetricType.AfterLRA, lraId);
@@ -81,7 +81,7 @@ public class TckUnknownStatusTests extends TckTestBase {
         String lraIdString = invoke(Scenario.COMPLETE_RETRY);
         URI lraId = URI.create(lraIdString);
 
-        applyConsistencyDelay();
+        applyLongConsistencyDelay();
         int completed = lraMetricService.getMetric(LRAMetricType.Completed, lraId);
         int status = lraMetricService.getMetric(LRAMetricType.Status, lraId);
         int afterLRA = lraMetricService.getMetric(LRAMetricType.AfterLRA, lraId);
diff --git a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownTests.java b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownTests.java
index 23b9660..cb0183b 100644
--- a/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownTests.java
+++ b/tck/src/main/java/org/eclipse/microprofile/lra/tck/TckUnknownTests.java
@@ -64,7 +64,7 @@ public class TckUnknownTests extends TckTestBase {
         String lraIdString = invoke(Scenario.COMPENSATE_IMMEDIATE);
         URI lraId = URI.create(lraIdString);
 
-        applyConsistencyDelay();
+        applyLongConsistencyDelay();
         int compensated = lraMetricService.getMetric(LRAMetricType.Compensated, lraId);
         int afterLRA = lraMetricService.getMetric(LRAMetricType.AfterLRA, lraId);
         int cancelled = lraMetricService.getMetric(LRAMetricType.Cancelled, lraId);
@@ -79,7 +79,7 @@ public class TckUnknownTests extends TckTestBase {
         String lraIdString = invoke(Scenario.COMPENSATE_RETRY);
         URI lraId = URI.create(lraIdString);
 
-        applyConsistencyDelay();
+        applyLongConsistencyDelay();
         int compensated = lraMetricService.getMetric(LRAMetricType.Compensated, lraId);
         int afterLRA = lraMetricService.getMetric(LRAMetricType.AfterLRA, lraId);
         int cancelled = lraMetricService.getMetric(LRAMetricType.Cancelled, lraId);
@@ -94,7 +94,7 @@ public class TckUnknownTests extends TckTestBase {
         String lraIdString = invoke(Scenario.COMPLETE_IMMEDIATE);
         URI lraId = URI.create(lraIdString);
 
-        applyConsistencyDelay();
+        applyLongConsistencyDelay();
         int completed = lraMetricService.getMetric(LRAMetricType.Completed, lraId);
         int afterLRA = lraMetricService.getMetric(LRAMetricType.AfterLRA, lraId);
         int closed = lraMetricService.getMetric(LRAMetricType.Closed, lraId);
@@ -109,7 +109,7 @@ public class TckUnknownTests extends TckTestBase {
         String lraIdString = invoke(Scenario.COMPLETE_RETRY);
         URI lraId = URI.create(lraIdString);
 
-        applyConsistencyDelay();
+        applyLongConsistencyDelay();
         int completed = lraMetricService.getMetric(LRAMetricType.Completed, lraId);
         int afterLRA = lraMetricService.getMetric(LRAMetricType.AfterLRA, lraId);
         int closed = lraMetricService.getMetric(LRAMetricType.Closed, lraId);