[ 
https://issues.apache.org/jira/browse/BEAM-3949?focusedWorklogId=108585&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-108585
 ]

ASF GitHub Bot logged work on BEAM-3949:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 04/Jun/18 13:52
            Start Date: 04/Jun/18 13:52
    Worklog Time Spent: 10m 
      Work Description: kkucharc commented on a change in pull request #5434: 
[BEAM-3949] IOIT's setup() and teardown() db connection attempt sometimes fail 
resulting in test flakiness
URL: https://github.com/apache/beam/pull/5434#discussion_r192748002
 
 

 ##########
 File path: 
sdks/java/io/common/src/test/java/org/apache/beam/sdk/io/common/IOITHelper.java
 ##########
 @@ -36,4 +40,54 @@ public static String getHashForRecordCount(int recordCount, 
Map<Integer, String>
     }
     return hash;
   }
+
+  /**
+   * Interface for passing method to executeWithRetry method.
+   */
+  public interface RetryFunction {
+    void run() throws Exception;
+  }
+
+  public static void executeWithRetry(RetryFunction function)
+      throws Exception {
+    int maxAttempts = 3;
+    long minDelay = 10_000;
+    executeWithRetry(maxAttempts, minDelay, function);
+  }
+
+  public static void executeWithRetry(int maxAttempts, long minDelay, 
RetryFunction function)
+      throws Exception {
+    ArrayList<Exception> errorList = new ArrayList<Exception>();
+    int attempts = 0;
+    long delay = minDelay;
+
+    while (attempts < maxAttempts) {
+      try {
+        function.run();
+        return;
+      } catch (Exception e) {
+        LOG.error(
+            "Attempt #{} of {} threw an exception: {} after {} ms",
+            attempts + 1,
+            maxAttempts,
+            e.getMessage(),
+            delay);
+        errorList.add(e);
+
+        if (attempts == maxAttempts - 1) {
+          for (int i = 0; i < errorList.size(); i++) {
 
 Review comment:
   I had inner struggle how it should look like. 😄 
   Right now if there are retry problems but finally it will succeed there are 
only logs without stackstrace:
   ```
   May 30, 2018 5:03:00 PM org.apache.beam.sdk.io.common.IOITHelper 
executeWithRetry
   SEVERE: Attempt #2 of 3 threw an exception: The connection attempt failed. 
after 20000 ms
   ```
   
   But when all attempts fail, there are full logs of all attempts with 
stacktraces.
   Do you think it would look better if there will be stacktraces even it 
method finishes with success?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 108585)
    Time Spent: 6h 50m  (was: 6h 40m)

> IOIT's setup() and teardown() db connection attempt sometimes fail resulting 
> in test flakiness
> ----------------------------------------------------------------------------------------------
>
>                 Key: BEAM-3949
>                 URL: https://issues.apache.org/jira/browse/BEAM-3949
>             Project: Beam
>          Issue Type: Sub-task
>          Components: testing
>            Reporter: Łukasz Gajowy
>            Assignee: Kasia Kucharczyk
>            Priority: Major
>          Time Spent: 6h 50m
>  Remaining Estimate: 0h
>
> setup() and teardown() methods sometimes have trouble connecting database in 
> Performance tests. It results in test flakiness. 
> Example logs: 
> [https://builds.apache.org/view/A-D/view/Beam/job/beam_PerformanceTests_HadoopInputFormat/65/console]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to