{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/comments/149566018","pull_request_review_id":74980287,"id":149566018,"diff_hunk":"@@ -0,0 +1,129 @@\n+package org.jvnet.hudson.test;\n+\n+import groovy.lang.Closure;\n+import org.junit.rules.MethodRule;\n+import org.junit.rules.TemporaryFolder;\n+import org.junit.runner.Description;\n+import org.junit.runners.model.FrameworkMethod;\n+import org.junit.runners.model.Statement;\n+\n+import java.io.File;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.concurrent.Callable;\n+\n+/**\n+ * Provides a pattern for executing a sequence of steps.\n+ * In between steps, Jenkins gets restarted.\n+ *\n+ * <p>\n+ * To use this, add this rule instead of {@link JenkinsRule} to the test,\n+ * then from your test method, call {@link #step(Closure)} or {@link #addStep(Statement)} repeatedly.\n+ *\n+ * <p>\n+ * The rule will evaluate your test method to collect all steps, then execute them in turn and restart\n+ * Jenkins in between.\n+ *\n+ * @author Kohsuke Kawaguchi\n+ * @see JenkinsRule\n+ * @since 1.567\n+ */\n+public class RestartableJenkinsNonLocalhostRule implements MethodRule {\n+    public JenkinsRule j;\n+    private Description description;\n+    private final List<Statement> steps = new ArrayList<Statement>();\n+\n+    private TemporaryFolder tmp = new TemporaryFolder();\n+\n+    /**\n+     * Object that defines a test.\n+     */\n+    private Object target;\n+\n+    /**\n+     * JENKINS_HOME\n+     */\n+    public File home;\n+\n+\n+    @Override\n+    public Statement apply(final Statement base, FrameworkMethod method, Object target) {\n+        this.description = Description.createTestDescription(\n+                method.getMethod().getDeclaringClass(), method.getName(), method.getAnnotations());\n+\n+        this.target = target;\n+\n+        return tmp.apply(new Statement() {\n+            @Override\n+            public void evaluate() throws Throwable {\n+                // JENKINS_HOME needs to survive restarts, so we'll allocate our own\n+                home = tmp.newFolder();\n+\n+                // test method will accumulate steps\n+                base.evaluate();\n+                // and we'll run them\n+                run();\n+            }\n+        }, description);\n+    }\n+\n+    public void step(final Closure c) {\n+        addStep(new Statement() {\n+            @Override\n+            public void evaluate() throws Throwable {\n+                c.call(j);\n+            }\n+        });\n+    }\n+\n+    /**\n+     * One step to run, intended to be a SAM for lambdas with {@link #then}.\n+     * {@link Closure} does not work because it is an abstract class, not an interface.\n+     * {@link Callable} of {@link Void} does not work because you have to return null.\n+     * {@link Runnable} does not work because it throws no checked exceptions.\n+     * {@code Consumer} is the same, and is not present in Java 7.\n+     * Other candidates had similar issues.\n+     */\n+    // TODO Java 8: @FunctionalInterface\n+    public interface Step {\n+        void run(JenkinsRule r) throws Throwable;\n+    }\n+    /**\n+     * Run one Jenkins session and shut down.\n+     * @since 2.24\n+     */\n+    public void then(final Step s) {\n+        addStep(new Statement() {\n+            @Override\n+            public void evaluate() throws Throwable {\n+                s.run(j);\n+            }\n+        });\n+    }\n+\n+    public void addStep(final Statement step) {\n+        steps.add(new Statement() {\n+            @Override\n+            public void evaluate() throws Throwable {\n+                j.jenkins.getInjector().injectMembers(step);\n+                j.jenkins.getInjector().injectMembers(target);\n+                step.evaluate();\n+            }\n+        });\n+    }\n+\n+    private void run() throws Throwable {\n+        HudsonHomeLoader loader = new HudsonHomeLoader() {\n+            @Override\n+            public File allocate() throws Exception {\n+                return home;\n+            }\n+        };\n+\n+        // run each step inside its own JenkinsRule\n+        for (Statement step : steps) {\n+            j = new JenkinsRuleNonLocalhost().with(loader);","path":"src/test/java/org/jvnet/hudson/test/RestartableJenkinsNonLocalhostRule.java","position":125,"original_position":125,"commit_id":"e60e8d75ab4e6706a15038ee79a1694f2b98afcc","original_commit_id":"e60e8d75ab4e6706a15038ee79a1694f2b98afcc","user":{"login":"jglick","id":154109,"avatar_url":"https://avatars1.githubusercontent.com/u/154109?v=4","gravatar_id":"","url":"https://api.github.com/users/jglick","html_url":"https://github.com/jglick","followers_url":"https://api.github.com/users/jglick/followers","following_url":"https://api.github.com/users/jglick/following{/other_user}","gists_url":"https://api.github.com/users/jglick/gists{/gist_id}","starred_url":"https://api.github.com/users/jglick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jglick/subscriptions","organizations_url":"https://api.github.com/users/jglick/orgs","repos_url":"https://api.github.com/users/jglick/repos","events_url":"https://api.github.com/users/jglick/events{/privacy}","received_events_url":"https://api.github.com/users/jglick/received_events","type":"User","site_admin":false},"body":"You could probably use https://github.com/jenkinsci/jenkins-test-harness/pull/75 and avoid a lot of code duplication, no?","created_at":"2017-11-08T03:15:51Z","updated_at":"2017-11-08T03:15:51Z","html_url":"https://github.com/jenkinsci/kubernetes-plugin/pull/244#discussion_r149566018","pull_request_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/comments/149566018"},"html":{"href":"https://github.com/jenkinsci/kubernetes-plugin/pull/244#discussion_r149566018"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244","id":150544443,"html_url":"https://github.com/jenkinsci/kubernetes-plugin/pull/244","diff_url":"https://github.com/jenkinsci/kubernetes-plugin/pull/244.diff","patch_url":"https://github.com/jenkinsci/kubernetes-plugin/pull/244.patch","issue_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues/244","number":244,"state":"open","locked":false,"title":"allow re-use of existing pods for restarts","user":{"login":"scoheb","id":3596711,"avatar_url":"https://avatars1.githubusercontent.com/u/3596711?v=4","gravatar_id":"","url":"https://api.github.com/users/scoheb","html_url":"https://github.com/scoheb","followers_url":"https://api.github.com/users/scoheb/followers","following_url":"https://api.github.com/users/scoheb/following{/other_user}","gists_url":"https://api.github.com/users/scoheb/gists{/gist_id}","starred_url":"https://api.github.com/users/scoheb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scoheb/subscriptions","organizations_url":"https://api.github.com/users/scoheb/orgs","repos_url":"https://api.github.com/users/scoheb/repos","events_url":"https://api.github.com/users/scoheb/events{/privacy}","received_events_url":"https://api.github.com/users/scoheb/received_events","type":"User","site_admin":false},"body":"[FIXES JENKINS-47476]","created_at":"2017-11-03T14:40:09Z","updated_at":"2017-11-08T03:15:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07fe1d8ecfd2754506a387715fb7d633a43e8f11","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues/244/comments","statuses_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/statuses/e60e8d75ab4e6706a15038ee79a1694f2b98afcc","head":{"label":"scoheb:restart-2","ref":"restart-2","sha":"e60e8d75ab4e6706a15038ee79a1694f2b98afcc","user":{"login":"scoheb","id":3596711,"avatar_url":"https://avatars1.githubusercontent.com/u/3596711?v=4","gravatar_id":"","url":"https://api.github.com/users/scoheb","html_url":"https://github.com/scoheb","followers_url":"https://api.github.com/users/scoheb/followers","following_url":"https://api.github.com/users/scoheb/following{/other_user}","gists_url":"https://api.github.com/users/scoheb/gists{/gist_id}","starred_url":"https://api.github.com/users/scoheb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scoheb/subscriptions","organizations_url":"https://api.github.com/users/scoheb/orgs","repos_url":"https://api.github.com/users/scoheb/repos","events_url":"https://api.github.com/users/scoheb/events{/privacy}","received_events_url":"https://api.github.com/users/scoheb/received_events","type":"User","site_admin":false},"repo":{"id":98945909,"name":"kubernetes-plugin","full_name":"scoheb/kubernetes-plugin","owner":{"login":"scoheb","id":3596711,"avatar_url":"https://avatars1.githubusercontent.com/u/3596711?v=4","gravatar_id":"","url":"https://api.github.com/users/scoheb","html_url":"https://github.com/scoheb","followers_url":"https://api.github.com/users/scoheb/followers","following_url":"https://api.github.com/users/scoheb/following{/other_user}","gists_url":"https://api.github.com/users/scoheb/gists{/gist_id}","starred_url":"https://api.github.com/users/scoheb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scoheb/subscriptions","organizations_url":"https://api.github.com/users/scoheb/orgs","repos_url":"https://api.github.com/users/scoheb/repos","events_url":"https://api.github.com/users/scoheb/events{/privacy}","received_events_url":"https://api.github.com/users/scoheb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/scoheb/kubernetes-plugin","description":"Jenkins plugin to run dynamic slaves in a Kubernetes/Docker environment","fork":true,"url":"https://api.github.com/repos/scoheb/kubernetes-plugin","forks_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/forks","keys_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/teams","hooks_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/hooks","issue_events_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/events","assignees_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/tags","blobs_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/languages","stargazers_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/stargazers","contributors_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/contributors","subscribers_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/subscribers","subscription_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/subscription","commits_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/merges","archive_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/downloads","issues_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/labels{/name}","releases_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/scoheb/kubernetes-plugin/deployments","created_at":"2017-08-01T01:33:00Z","updated_at":"2017-08-01T01:33:01Z","pushed_at":"2017-11-07T18:44:49Z","git_url":"git://github.com/scoheb/kubernetes-plugin.git","ssh_url":"git@github.com:scoheb/kubernetes-plugin.git","clone_url":"https://github.com/scoheb/kubernetes-plugin.git","svn_url":"https://github.com/scoheb/kubernetes-plugin","homepage":null,"size":1338,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jenkinsci:master","ref":"master","sha":"4303ec3c913c80c020eb7a6880853dc1c4838325","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars0.githubusercontent.com/u/107424?v=4","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":30860673,"name":"kubernetes-plugin","full_name":"jenkinsci/kubernetes-plugin","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars0.githubusercontent.com/u/107424?v=4","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/kubernetes-plugin","description":"Jenkins plugin to run dynamic slaves in a Kubernetes/Docker environment","fork":true,"url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin","forks_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/forks","keys_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/teams","hooks_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/events","assignees_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/tags","blobs_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/subscription","commits_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/merges","archive_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/downloads","issues_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/deployments","created_at":"2015-02-16T09:02:22Z","updated_at":"2017-11-06T17:03:10Z","pushed_at":"2017-11-07T18:44:50Z","git_url":"git://github.com/jenkinsci/kubernetes-plugin.git","ssh_url":"git@github.com:jenkinsci/kubernetes-plugin.git","clone_url":"https://github.com/jenkinsci/kubernetes-plugin.git","svn_url":"https://github.com/jenkinsci/kubernetes-plugin","homepage":null,"size":1365,"stargazers_count":340,"watchers_count":340,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":214,"mirror_url":null,"archived":false,"open_issues_count":19,"forks":214,"open_issues":19,"watchers":340,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244"},"html":{"href":"https://github.com/jenkinsci/kubernetes-plugin/pull/244"},"issue":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues/244"},"comments":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/issues/244/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/pulls/244/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/kubernetes-plugin/statuses/e60e8d75ab4e6706a15038ee79a1694f2b98afcc"}},"author_association":"NONE"}}
{"actor":{"display_login":"jglick"}}