{"action":"created","comment":{"url":"https://api.github.com/repos/linkedin/gobblin/pulls/comments/47569100","id":47569100,"diff_hunk":"@@ -0,0 +1,121 @@\n+package gobblin.testing;\n+\n+import java.util.concurrent.Callable;\n+import java.util.concurrent.TimeoutException;\n+\n+import org.slf4j.Logger;\n+\n+import com.google.common.base.Optional;\n+\n+/** Common utilities to help with testing */\n+public class TestingUtils {\n+  public static final Double DEFAULT_ASSERT_BACKOFF_FACTOR = 1.5;\n+  public static final Long DEFAULT_MAX_ASSERT_BACKOFF_SLEEP_MS = 10 * 1000L;\n+\n+  /**\n+   * Performs a check for a condition with a back-off. Primary use of this is when a tests\n+   * needs for something asynchronous to happen, say a service to start.\n+   *\n+   * @param condition           the condition to wait for\n+   * @param assertTimeoutMs     the max time in milliseconds to wait for the condition to become true\n+   * @param message             a message to print while waiting for the condition\n+   * @param log                 a logger to use for logging waiting, results\n+   * @throws TimeoutException   if the condition did not become true in the specified time budget\n+   */\n+  public static void assertWithBackoff(\n+      Callable<Boolean> condition, long assertTimeoutMs, String message,\n+      Logger log) throws TimeoutException, InterruptedException {\n+    assertWithBackoff(condition, assertTimeoutMs, Optional.of(message), Optional.of(log),\n+        Optional.<Double>absent(),\n+        Optional.<Long>absent());\n+  }\n+\n+  /**\n+   * Performs a check for a condition with a back-off. Primary use of this is when a tests\n+   * needs for something asynchronous to happen, say a service to start.\n+   *\n+   * @param condition           the condition to wait for\n+   * @param assertTimeoutMs     the max time in milliseconds to wait for the condition to become true\n+   * @param message             a message to print while waiting for the condition\n+   * @throws TimeoutException   if the condition did not become true in the specified time budget\n+   */\n+  public static void assertWithBackoff(\n+      Callable<Boolean> condition, long assertTimeoutMs, String message)\n+      throws TimeoutException, InterruptedException {\n+    assertWithBackoff(condition, assertTimeoutMs, Optional.of(message), Optional.<Logger>absent(),\n+        Optional.<Double>absent(),\n+        Optional.<Long>absent());\n+  }\n+\n+  /**\n+   * Performs a check for a condition with a back-off. Primary use of this is when a tests\n+   * needs for something asynchronous to happen, say a service to start.\n+   *\n+   * @param condition           the condition to wait for\n+   * @param assertTimeoutMs     the max time in milliseconds to wait for the condition to become true\n+   * @param message             an optional message to print while waiting for the condition\n+   * @param log                 an optional logger to use for logging waiting, results\n+   * @param backoffFactor       optional number to multiple the sleep after condition failure;\n+   *                            default is {@link #DEFAULT_ASSERT_BACKOFF_FACTOR}\n+   * @param maxSleepMs          the max time to sleep between condition failures; default is\n+   * @throws TimeoutException   if the condition did not become true in the specified time budget\n+   */\n+  public static void assertWithBackoff(\n+      Callable<Boolean> condition, long assertTimeoutMs, Optional<String> message,\n+      Optional<Logger> log, Optional<Double> backoffFactor, Optional<Long> maxSleepMs)\n+          throws TimeoutException, InterruptedException {\n+    long startTimeMs = System.currentTimeMillis();\n+    long endTimeMs = startTimeMs + assertTimeoutMs;\n+    double realBackoffFactor = backoffFactor.or(DEFAULT_ASSERT_BACKOFF_FACTOR);\n+    long realMaxSleepMs = maxSleepMs.or(DEFAULT_MAX_ASSERT_BACKOFF_SLEEP_MS);\n+    long currentSleepMs = 0;\n+    String realMessage = \"'\" + message.or(\"\") + \"'\";\n+    boolean done = false;\n+    try {\n+      while (!done && System.currentTimeMillis() < endTimeMs) {\n+          done = condition.call().booleanValue();\n+          if (!done) {\n+            currentSleepMs = computeRetrySleep(currentSleepMs, realBackoffFactor, realMaxSleepMs,\n+                endTimeMs);\n+            if (log.isPresent()) {\n+              log.get().debug(\"Condition check for \" + realMessage + \" failed; sleeping for \" +\n+                              currentSleepMs + \"ms\");\n+            }\n+            Thread.sleep(currentSleepMs);\n+          }\n+      }\n+      //one last try","path":"gobblin-api/src/main/java/gobblin/testing/TestingUtils.java","position":87,"original_position":87,"commit_id":"2d26e86114a040410de6d333242edd30d3a85b36","original_commit_id":"2d26e86114a040410de6d333242edd30d3a85b36","user":{"login":"liyinan926","id":3709137,"avatar_url":"https://avatars.githubusercontent.com/u/3709137?v=3","gravatar_id":"","url":"https://api.github.com/users/liyinan926","html_url":"https://github.com/liyinan926","followers_url":"https://api.github.com/users/liyinan926/followers","following_url":"https://api.github.com/users/liyinan926/following{/other_user}","gists_url":"https://api.github.com/users/liyinan926/gists{/gist_id}","starred_url":"https://api.github.com/users/liyinan926/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liyinan926/subscriptions","organizations_url":"https://api.github.com/users/liyinan926/orgs","repos_url":"https://api.github.com/users/liyinan926/repos","events_url":"https://api.github.com/users/liyinan926/events{/privacy}","received_events_url":"https://api.github.com/users/liyinan926/received_events","type":"User","site_admin":false},"body":"First letter capital and one empty space after `//`.","created_at":"2015-12-14T22:31:14Z","updated_at":"2015-12-14T22:31:14Z","html_url":"https://github.com/linkedin/gobblin/pull/523#discussion_r47569100","pull_request_url":"https://api.github.com/repos/linkedin/gobblin/pulls/523","_links":{"self":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/comments/47569100"},"html":{"href":"https://github.com/linkedin/gobblin/pull/523#discussion_r47569100"},"pull_request":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/523"}}},"pull_request":{"url":"https://api.github.com/repos/linkedin/gobblin/pulls/523","id":53598895,"html_url":"https://github.com/linkedin/gobblin/pull/523","diff_url":"https://github.com/linkedin/gobblin/pull/523.diff","patch_url":"https://github.com/linkedin/gobblin/pull/523.patch","issue_url":"https://api.github.com/repos/linkedin/gobblin/issues/523","number":523,"state":"open","locked":false,"title":"Wait to connect to ZK in gobblin.yarn.GobblinYarnAppLauncherTest.setUp()","user":{"login":"chavdar","id":928795,"avatar_url":"https://avatars.githubusercontent.com/u/928795?v=3","gravatar_id":"","url":"https://api.github.com/users/chavdar","html_url":"https://github.com/chavdar","followers_url":"https://api.github.com/users/chavdar/followers","following_url":"https://api.github.com/users/chavdar/following{/other_user}","gists_url":"https://api.github.com/users/chavdar/gists{/gist_id}","starred_url":"https://api.github.com/users/chavdar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chavdar/subscriptions","organizations_url":"https://api.github.com/users/chavdar/orgs","repos_url":"https://api.github.com/users/chavdar/repos","events_url":"https://api.github.com/users/chavdar/events{/privacy}","received_events_url":"https://api.github.com/users/chavdar/received_events","type":"User","site_admin":false},"body":"I see frequent test failures on Travis which cannot be reproduced locally. I suspect it might be a race condition when starting/connecting to ZK. I've added an explicit wait to connect to gobblin.yarn.GobblinYarnAppLauncherTest to see if that will help.\r\n\r\n@liyinan926 can you review?\r\n\r\nUPDATE: \r\n* Added TestingUtils.assertWithBackoff() to check a condition multiple times\r\n* Added Unit tests for TestingUtils.assertWithBackoff()\r\n* Refactored JobConfigFileMonitorTest to use the TestingUtils.assertWithBackoff() because of intermittent failures\r\n\r\n@liyinan926 @zliu41 Can you review?","created_at":"2015-12-14T17:56:37Z","updated_at":"2015-12-14T22:31:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7be16a4578d66425529104a921a095b7a7ba6705","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/linkedin/gobblin/pulls/523/commits","review_comments_url":"https://api.github.com/repos/linkedin/gobblin/pulls/523/comments","review_comment_url":"https://api.github.com/repos/linkedin/gobblin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/linkedin/gobblin/issues/523/comments","statuses_url":"https://api.github.com/repos/linkedin/gobblin/statuses/2d26e86114a040410de6d333242edd30d3a85b36","head":{"label":"chavdar:test_zk_wait","ref":"test_zk_wait","sha":"2d26e86114a040410de6d333242edd30d3a85b36","user":{"login":"chavdar","id":928795,"avatar_url":"https://avatars.githubusercontent.com/u/928795?v=3","gravatar_id":"","url":"https://api.github.com/users/chavdar","html_url":"https://github.com/chavdar","followers_url":"https://api.github.com/users/chavdar/followers","following_url":"https://api.github.com/users/chavdar/following{/other_user}","gists_url":"https://api.github.com/users/chavdar/gists{/gist_id}","starred_url":"https://api.github.com/users/chavdar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chavdar/subscriptions","organizations_url":"https://api.github.com/users/chavdar/orgs","repos_url":"https://api.github.com/users/chavdar/repos","events_url":"https://api.github.com/users/chavdar/events{/privacy}","received_events_url":"https://api.github.com/users/chavdar/received_events","type":"User","site_admin":false},"repo":{"id":31112986,"name":"gobblin-1","full_name":"chavdar/gobblin-1","owner":{"login":"chavdar","id":928795,"avatar_url":"https://avatars.githubusercontent.com/u/928795?v=3","gravatar_id":"","url":"https://api.github.com/users/chavdar","html_url":"https://github.com/chavdar","followers_url":"https://api.github.com/users/chavdar/followers","following_url":"https://api.github.com/users/chavdar/following{/other_user}","gists_url":"https://api.github.com/users/chavdar/gists{/gist_id}","starred_url":"https://api.github.com/users/chavdar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chavdar/subscriptions","organizations_url":"https://api.github.com/users/chavdar/orgs","repos_url":"https://api.github.com/users/chavdar/repos","events_url":"https://api.github.com/users/chavdar/events{/privacy}","received_events_url":"https://api.github.com/users/chavdar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chavdar/gobblin-1","description":"","fork":true,"url":"https://api.github.com/repos/chavdar/gobblin-1","forks_url":"https://api.github.com/repos/chavdar/gobblin-1/forks","keys_url":"https://api.github.com/repos/chavdar/gobblin-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chavdar/gobblin-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chavdar/gobblin-1/teams","hooks_url":"https://api.github.com/repos/chavdar/gobblin-1/hooks","issue_events_url":"https://api.github.com/repos/chavdar/gobblin-1/issues/events{/number}","events_url":"https://api.github.com/repos/chavdar/gobblin-1/events","assignees_url":"https://api.github.com/repos/chavdar/gobblin-1/assignees{/user}","branches_url":"https://api.github.com/repos/chavdar/gobblin-1/branches{/branch}","tags_url":"https://api.github.com/repos/chavdar/gobblin-1/tags","blobs_url":"https://api.github.com/repos/chavdar/gobblin-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chavdar/gobblin-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chavdar/gobblin-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/chavdar/gobblin-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chavdar/gobblin-1/statuses/{sha}","languages_url":"https://api.github.com/repos/chavdar/gobblin-1/languages","stargazers_url":"https://api.github.com/repos/chavdar/gobblin-1/stargazers","contributors_url":"https://api.github.com/repos/chavdar/gobblin-1/contributors","subscribers_url":"https://api.github.com/repos/chavdar/gobblin-1/subscribers","subscription_url":"https://api.github.com/repos/chavdar/gobblin-1/subscription","commits_url":"https://api.github.com/repos/chavdar/gobblin-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/chavdar/gobblin-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/chavdar/gobblin-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/chavdar/gobblin-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/chavdar/gobblin-1/contents/{+path}","compare_url":"https://api.github.com/repos/chavdar/gobblin-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chavdar/gobblin-1/merges","archive_url":"https://api.github.com/repos/chavdar/gobblin-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chavdar/gobblin-1/downloads","issues_url":"https://api.github.com/repos/chavdar/gobblin-1/issues{/number}","pulls_url":"https://api.github.com/repos/chavdar/gobblin-1/pulls{/number}","milestones_url":"https://api.github.com/repos/chavdar/gobblin-1/milestones{/number}","notifications_url":"https://api.github.com/repos/chavdar/gobblin-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chavdar/gobblin-1/labels{/name}","releases_url":"https://api.github.com/repos/chavdar/gobblin-1/releases{/id}","created_at":"2015-02-21T02:34:18Z","updated_at":"2015-03-24T04:36:09Z","pushed_at":"2015-12-14T20:54:40Z","git_url":"git://github.com/chavdar/gobblin-1.git","ssh_url":"git@github.com:chavdar/gobblin-1.git","clone_url":"https://github.com/chavdar/gobblin-1.git","svn_url":"https://github.com/chavdar/gobblin-1","homepage":null,"size":81457,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"linkedin:master","ref":"master","sha":"48f70d5ae6363cb6a7d8286b19b4c5b8f2a29829","user":{"login":"linkedin","id":357098,"avatar_url":"https://avatars.githubusercontent.com/u/357098?v=3","gravatar_id":"","url":"https://api.github.com/users/linkedin","html_url":"https://github.com/linkedin","followers_url":"https://api.github.com/users/linkedin/followers","following_url":"https://api.github.com/users/linkedin/following{/other_user}","gists_url":"https://api.github.com/users/linkedin/gists{/gist_id}","starred_url":"https://api.github.com/users/linkedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linkedin/subscriptions","organizations_url":"https://api.github.com/users/linkedin/orgs","repos_url":"https://api.github.com/users/linkedin/repos","events_url":"https://api.github.com/users/linkedin/events{/privacy}","received_events_url":"https://api.github.com/users/linkedin/received_events","type":"Organization","site_admin":false},"repo":{"id":27392543,"name":"gobblin","full_name":"linkedin/gobblin","owner":{"login":"linkedin","id":357098,"avatar_url":"https://avatars.githubusercontent.com/u/357098?v=3","gravatar_id":"","url":"https://api.github.com/users/linkedin","html_url":"https://github.com/linkedin","followers_url":"https://api.github.com/users/linkedin/followers","following_url":"https://api.github.com/users/linkedin/following{/other_user}","gists_url":"https://api.github.com/users/linkedin/gists{/gist_id}","starred_url":"https://api.github.com/users/linkedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linkedin/subscriptions","organizations_url":"https://api.github.com/users/linkedin/orgs","repos_url":"https://api.github.com/users/linkedin/repos","events_url":"https://api.github.com/users/linkedin/events{/privacy}","received_events_url":"https://api.github.com/users/linkedin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/linkedin/gobblin","description":"Universal data ingestion framework for Hadoop.","fork":false,"url":"https://api.github.com/repos/linkedin/gobblin","forks_url":"https://api.github.com/repos/linkedin/gobblin/forks","keys_url":"https://api.github.com/repos/linkedin/gobblin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/linkedin/gobblin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/linkedin/gobblin/teams","hooks_url":"https://api.github.com/repos/linkedin/gobblin/hooks","issue_events_url":"https://api.github.com/repos/linkedin/gobblin/issues/events{/number}","events_url":"https://api.github.com/repos/linkedin/gobblin/events","assignees_url":"https://api.github.com/repos/linkedin/gobblin/assignees{/user}","branches_url":"https://api.github.com/repos/linkedin/gobblin/branches{/branch}","tags_url":"https://api.github.com/repos/linkedin/gobblin/tags","blobs_url":"https://api.github.com/repos/linkedin/gobblin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/linkedin/gobblin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/linkedin/gobblin/git/refs{/sha}","trees_url":"https://api.github.com/repos/linkedin/gobblin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/linkedin/gobblin/statuses/{sha}","languages_url":"https://api.github.com/repos/linkedin/gobblin/languages","stargazers_url":"https://api.github.com/repos/linkedin/gobblin/stargazers","contributors_url":"https://api.github.com/repos/linkedin/gobblin/contributors","subscribers_url":"https://api.github.com/repos/linkedin/gobblin/subscribers","subscription_url":"https://api.github.com/repos/linkedin/gobblin/subscription","commits_url":"https://api.github.com/repos/linkedin/gobblin/commits{/sha}","git_commits_url":"https://api.github.com/repos/linkedin/gobblin/git/commits{/sha}","comments_url":"https://api.github.com/repos/linkedin/gobblin/comments{/number}","issue_comment_url":"https://api.github.com/repos/linkedin/gobblin/issues/comments{/number}","contents_url":"https://api.github.com/repos/linkedin/gobblin/contents/{+path}","compare_url":"https://api.github.com/repos/linkedin/gobblin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/linkedin/gobblin/merges","archive_url":"https://api.github.com/repos/linkedin/gobblin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/linkedin/gobblin/downloads","issues_url":"https://api.github.com/repos/linkedin/gobblin/issues{/number}","pulls_url":"https://api.github.com/repos/linkedin/gobblin/pulls{/number}","milestones_url":"https://api.github.com/repos/linkedin/gobblin/milestones{/number}","notifications_url":"https://api.github.com/repos/linkedin/gobblin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/linkedin/gobblin/labels{/name}","releases_url":"https://api.github.com/repos/linkedin/gobblin/releases{/id}","created_at":"2014-12-01T18:10:50Z","updated_at":"2015-12-14T09:10:48Z","pushed_at":"2015-12-14T21:32:40Z","git_url":"git://github.com/linkedin/gobblin.git","ssh_url":"git@github.com:linkedin/gobblin.git","clone_url":"https://github.com/linkedin/gobblin.git","svn_url":"https://github.com/linkedin/gobblin","homepage":"https://github.com/linkedin/gobblin/wiki","size":158203,"stargazers_count":330,"watchers_count":330,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":128,"mirror_url":null,"open_issues_count":22,"forks":128,"open_issues":22,"watchers":330,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/523"},"html":{"href":"https://github.com/linkedin/gobblin/pull/523"},"issue":{"href":"https://api.github.com/repos/linkedin/gobblin/issues/523"},"comments":{"href":"https://api.github.com/repos/linkedin/gobblin/issues/523/comments"},"review_comments":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/523/comments"},"review_comment":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/linkedin/gobblin/pulls/523/commits"},"statuses":{"href":"https://api.github.com/repos/linkedin/gobblin/statuses/2d26e86114a040410de6d333242edd30d3a85b36"}}}}