{"action":"created","comment":{"url":"https://api.github.com/repos/yegor256/takes/pulls/comments/48678944","id":48678944,"diff_hunk":"@@ -0,0 +1,122 @@\n+/**\n+ * The MIT License (MIT)\n+ *\n+ * Copyright (c) 2015 Yegor Bugayenko\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included\n+ * in all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+ * SOFTWARE.\n+ */\n+\n+package org.takes.tk;\n+\n+import java.io.IOException;\n+import org.hamcrest.MatcherAssert;\n+import org.hamcrest.Matchers;\n+import org.junit.Test;\n+import org.mockito.Mockito;\n+import org.takes.Request;\n+import org.takes.Take;\n+import org.takes.rq.RqFake;\n+import org.takes.rq.RqMethod;\n+import org.takes.rs.RsPrint;\n+import org.takes.rs.RsText;\n+\n+/**\n+ * TkRetry can retry till success or retry count is reached.\n+ *\n+ * @author Hamdi Douss (douss.hamdi@gmail.com)\n+ * @version $Id$\n+ * @since 0.28.3\n+ */\n+public final class TkRetryTest {\n+\n+    /**\n+     * TkRetry can work when no IOException.\n+     *\n+     * @throws Exception if something is wrong\n+     */\n+    @Test\n+    public void worksWithNoException() throws Exception {\n+        final String test = \"test\";\n+        MatcherAssert.assertThat(\n+                new RsPrint(\n+                        new TkRetry(2, 2, new TkText(test))\n+                                .act(new RqFake())\n+                ).print(),\n+                Matchers.containsString(test)\n+        );\n+    }\n+\n+    /**\n+     * TkRetry can retry when initial take fails with IOException,\n+     * till retry count is reached.\n+     *\n+     * @throws Exception if something is wrong\n+     */\n+    @Test(expected = IOException.class)\n+    public void retriesOnExceptionTillCount() throws Exception {\n+        final int count = 3;\n+        final int delay = 1000;\n+        final Take take = Mockito.mock(Take.class);\n+        final Request req = new RqFake(RqMethod.GET);\n+        Mockito.when(take.act(Mockito.any(Request.class))).thenThrow(\n+                new IOException()\n+        );\n+        final long startTime = System.currentTimeMillis();\n+        try {\n+            new TkRetry(count, delay, take).act(req);\n+        } catch (final IOException exception) {\n+            MatcherAssert.assertThat(\n+                new Long(count * delay),\n+                Matchers.lessThanOrEqualTo(\n+                        System.currentTimeMillis() - startTime\n+                )\n+            );\n+            throw exception;\n+        }\n+    }\n+\n+    /**\n+     * TkRetry can retry when initial take fails with IOException,","path":"src/test/java/org/takes/tk/TkRetryTest.java","position":95,"original_position":95,"commit_id":"445714ba39d99a5684c20ef3a3108368576cf6c0","original_commit_id":"445714ba39d99a5684c20ef3a3108368576cf6c0","user":{"login":"pinaf","id":1054771,"avatar_url":"https://avatars.githubusercontent.com/u/1054771?v=3","gravatar_id":"","url":"https://api.github.com/users/pinaf","html_url":"https://github.com/pinaf","followers_url":"https://api.github.com/users/pinaf/followers","following_url":"https://api.github.com/users/pinaf/following{/other_user}","gists_url":"https://api.github.com/users/pinaf/gists{/gist_id}","starred_url":"https://api.github.com/users/pinaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pinaf/subscriptions","organizations_url":"https://api.github.com/users/pinaf/orgs","repos_url":"https://api.github.com/users/pinaf/repos","events_url":"https://api.github.com/users/pinaf/events{/privacy}","received_events_url":"https://api.github.com/users/pinaf/received_events","type":"User","site_admin":false},"body":"@HDouss fails `once` with IOException","created_at":"2016-01-01T17:21:42Z","updated_at":"2016-01-01T17:21:42Z","html_url":"https://github.com/yegor256/takes/pull/493#discussion_r48678944","pull_request_url":"https://api.github.com/repos/yegor256/takes/pulls/493","_links":{"self":{"href":"https://api.github.com/repos/yegor256/takes/pulls/comments/48678944"},"html":{"href":"https://github.com/yegor256/takes/pull/493#discussion_r48678944"},"pull_request":{"href":"https://api.github.com/repos/yegor256/takes/pulls/493"}}},"pull_request":{"url":"https://api.github.com/repos/yegor256/takes/pulls/493","id":54871713,"html_url":"https://github.com/yegor256/takes/pull/493","diff_url":"https://github.com/yegor256/takes/pull/493.diff","patch_url":"https://github.com/yegor256/takes/pull/493.patch","issue_url":"https://api.github.com/repos/yegor256/takes/issues/493","number":493,"state":"open","locked":false,"title":"TkRetry #430","user":{"login":"HDouss","id":2956255,"avatar_url":"https://avatars.githubusercontent.com/u/2956255?v=3","gravatar_id":"","url":"https://api.github.com/users/HDouss","html_url":"https://github.com/HDouss","followers_url":"https://api.github.com/users/HDouss/followers","following_url":"https://api.github.com/users/HDouss/following{/other_user}","gists_url":"https://api.github.com/users/HDouss/gists{/gist_id}","starred_url":"https://api.github.com/users/HDouss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HDouss/subscriptions","organizations_url":"https://api.github.com/users/HDouss/orgs","repos_url":"https://api.github.com/users/HDouss/repos","events_url":"https://api.github.com/users/HDouss/events{/privacy}","received_events_url":"https://api.github.com/users/HDouss/received_events","type":"User","site_admin":false},"body":"Resolving #430. Nearly the same as the last suggested PR.\r\nAdded an assertion on the last test to ensure expected response is returned after the first fail.","created_at":"2015-12-31T17:03:16Z","updated_at":"2016-01-01T17:21:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"38268af30edb629236b26923f60df8ba50b5a615","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yegor256/takes/pulls/493/commits","review_comments_url":"https://api.github.com/repos/yegor256/takes/pulls/493/comments","review_comment_url":"https://api.github.com/repos/yegor256/takes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yegor256/takes/issues/493/comments","statuses_url":"https://api.github.com/repos/yegor256/takes/statuses/445714ba39d99a5684c20ef3a3108368576cf6c0","head":{"label":"HDouss:#430","ref":"#430","sha":"445714ba39d99a5684c20ef3a3108368576cf6c0","user":{"login":"HDouss","id":2956255,"avatar_url":"https://avatars.githubusercontent.com/u/2956255?v=3","gravatar_id":"","url":"https://api.github.com/users/HDouss","html_url":"https://github.com/HDouss","followers_url":"https://api.github.com/users/HDouss/followers","following_url":"https://api.github.com/users/HDouss/following{/other_user}","gists_url":"https://api.github.com/users/HDouss/gists{/gist_id}","starred_url":"https://api.github.com/users/HDouss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HDouss/subscriptions","organizations_url":"https://api.github.com/users/HDouss/orgs","repos_url":"https://api.github.com/users/HDouss/repos","events_url":"https://api.github.com/users/HDouss/events{/privacy}","received_events_url":"https://api.github.com/users/HDouss/received_events","type":"User","site_admin":false},"repo":{"id":46545594,"name":"takes","full_name":"HDouss/takes","owner":{"login":"HDouss","id":2956255,"avatar_url":"https://avatars.githubusercontent.com/u/2956255?v=3","gravatar_id":"","url":"https://api.github.com/users/HDouss","html_url":"https://github.com/HDouss","followers_url":"https://api.github.com/users/HDouss/followers","following_url":"https://api.github.com/users/HDouss/following{/other_user}","gists_url":"https://api.github.com/users/HDouss/gists{/gist_id}","starred_url":"https://api.github.com/users/HDouss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HDouss/subscriptions","organizations_url":"https://api.github.com/users/HDouss/orgs","repos_url":"https://api.github.com/users/HDouss/repos","events_url":"https://api.github.com/users/HDouss/events{/privacy}","received_events_url":"https://api.github.com/users/HDouss/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HDouss/takes","description":"True Object-Oriented and Immutable Java Web Framework","fork":true,"url":"https://api.github.com/repos/HDouss/takes","forks_url":"https://api.github.com/repos/HDouss/takes/forks","keys_url":"https://api.github.com/repos/HDouss/takes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HDouss/takes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HDouss/takes/teams","hooks_url":"https://api.github.com/repos/HDouss/takes/hooks","issue_events_url":"https://api.github.com/repos/HDouss/takes/issues/events{/number}","events_url":"https://api.github.com/repos/HDouss/takes/events","assignees_url":"https://api.github.com/repos/HDouss/takes/assignees{/user}","branches_url":"https://api.github.com/repos/HDouss/takes/branches{/branch}","tags_url":"https://api.github.com/repos/HDouss/takes/tags","blobs_url":"https://api.github.com/repos/HDouss/takes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HDouss/takes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HDouss/takes/git/refs{/sha}","trees_url":"https://api.github.com/repos/HDouss/takes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HDouss/takes/statuses/{sha}","languages_url":"https://api.github.com/repos/HDouss/takes/languages","stargazers_url":"https://api.github.com/repos/HDouss/takes/stargazers","contributors_url":"https://api.github.com/repos/HDouss/takes/contributors","subscribers_url":"https://api.github.com/repos/HDouss/takes/subscribers","subscription_url":"https://api.github.com/repos/HDouss/takes/subscription","commits_url":"https://api.github.com/repos/HDouss/takes/commits{/sha}","git_commits_url":"https://api.github.com/repos/HDouss/takes/git/commits{/sha}","comments_url":"https://api.github.com/repos/HDouss/takes/comments{/number}","issue_comment_url":"https://api.github.com/repos/HDouss/takes/issues/comments{/number}","contents_url":"https://api.github.com/repos/HDouss/takes/contents/{+path}","compare_url":"https://api.github.com/repos/HDouss/takes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HDouss/takes/merges","archive_url":"https://api.github.com/repos/HDouss/takes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HDouss/takes/downloads","issues_url":"https://api.github.com/repos/HDouss/takes/issues{/number}","pulls_url":"https://api.github.com/repos/HDouss/takes/pulls{/number}","milestones_url":"https://api.github.com/repos/HDouss/takes/milestones{/number}","notifications_url":"https://api.github.com/repos/HDouss/takes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HDouss/takes/labels{/name}","releases_url":"https://api.github.com/repos/HDouss/takes/releases{/id}","created_at":"2015-11-20T07:07:34Z","updated_at":"2015-11-20T07:07:40Z","pushed_at":"2016-01-01T17:15:39Z","git_url":"git://github.com/HDouss/takes.git","ssh_url":"git@github.com:HDouss/takes.git","clone_url":"https://github.com/HDouss/takes.git","svn_url":"https://github.com/HDouss/takes","homepage":"http://www.takes.org","size":28327,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"yegor256:master","ref":"master","sha":"2ce69dd60359a1a726762d884948926de72e0e16","user":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"repo":{"id":28924109,"name":"takes","full_name":"yegor256/takes","owner":{"login":"yegor256","id":526301,"avatar_url":"https://avatars.githubusercontent.com/u/526301?v=3","gravatar_id":"","url":"https://api.github.com/users/yegor256","html_url":"https://github.com/yegor256","followers_url":"https://api.github.com/users/yegor256/followers","following_url":"https://api.github.com/users/yegor256/following{/other_user}","gists_url":"https://api.github.com/users/yegor256/gists{/gist_id}","starred_url":"https://api.github.com/users/yegor256/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yegor256/subscriptions","organizations_url":"https://api.github.com/users/yegor256/orgs","repos_url":"https://api.github.com/users/yegor256/repos","events_url":"https://api.github.com/users/yegor256/events{/privacy}","received_events_url":"https://api.github.com/users/yegor256/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yegor256/takes","description":"True Object-Oriented and Immutable Java Web Framework","fork":false,"url":"https://api.github.com/repos/yegor256/takes","forks_url":"https://api.github.com/repos/yegor256/takes/forks","keys_url":"https://api.github.com/repos/yegor256/takes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yegor256/takes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yegor256/takes/teams","hooks_url":"https://api.github.com/repos/yegor256/takes/hooks","issue_events_url":"https://api.github.com/repos/yegor256/takes/issues/events{/number}","events_url":"https://api.github.com/repos/yegor256/takes/events","assignees_url":"https://api.github.com/repos/yegor256/takes/assignees{/user}","branches_url":"https://api.github.com/repos/yegor256/takes/branches{/branch}","tags_url":"https://api.github.com/repos/yegor256/takes/tags","blobs_url":"https://api.github.com/repos/yegor256/takes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yegor256/takes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yegor256/takes/git/refs{/sha}","trees_url":"https://api.github.com/repos/yegor256/takes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yegor256/takes/statuses/{sha}","languages_url":"https://api.github.com/repos/yegor256/takes/languages","stargazers_url":"https://api.github.com/repos/yegor256/takes/stargazers","contributors_url":"https://api.github.com/repos/yegor256/takes/contributors","subscribers_url":"https://api.github.com/repos/yegor256/takes/subscribers","subscription_url":"https://api.github.com/repos/yegor256/takes/subscription","commits_url":"https://api.github.com/repos/yegor256/takes/commits{/sha}","git_commits_url":"https://api.github.com/repos/yegor256/takes/git/commits{/sha}","comments_url":"https://api.github.com/repos/yegor256/takes/comments{/number}","issue_comment_url":"https://api.github.com/repos/yegor256/takes/issues/comments{/number}","contents_url":"https://api.github.com/repos/yegor256/takes/contents/{+path}","compare_url":"https://api.github.com/repos/yegor256/takes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yegor256/takes/merges","archive_url":"https://api.github.com/repos/yegor256/takes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yegor256/takes/downloads","issues_url":"https://api.github.com/repos/yegor256/takes/issues{/number}","pulls_url":"https://api.github.com/repos/yegor256/takes/pulls{/number}","milestones_url":"https://api.github.com/repos/yegor256/takes/milestones{/number}","notifications_url":"https://api.github.com/repos/yegor256/takes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yegor256/takes/labels{/name}","releases_url":"https://api.github.com/repos/yegor256/takes/releases{/id}","created_at":"2015-01-07T16:57:47Z","updated_at":"2015-12-30T09:09:40Z","pushed_at":"2016-01-01T17:15:40Z","git_url":"git://github.com/yegor256/takes.git","ssh_url":"git@github.com:yegor256/takes.git","clone_url":"https://github.com/yegor256/takes.git","svn_url":"https://github.com/yegor256/takes","homepage":"http://www.takes.org","size":29399,"stargazers_count":125,"watchers_count":125,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":52,"forks":63,"open_issues":52,"watchers":125,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yegor256/takes/pulls/493"},"html":{"href":"https://github.com/yegor256/takes/pull/493"},"issue":{"href":"https://api.github.com/repos/yegor256/takes/issues/493"},"comments":{"href":"https://api.github.com/repos/yegor256/takes/issues/493/comments"},"review_comments":{"href":"https://api.github.com/repos/yegor256/takes/pulls/493/comments"},"review_comment":{"href":"https://api.github.com/repos/yegor256/takes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yegor256/takes/pulls/493/commits"},"statuses":{"href":"https://api.github.com/repos/yegor256/takes/statuses/445714ba39d99a5684c20ef3a3108368576cf6c0"}}}}