{"action":"created","comment":{"url":"https://api.github.com/repos/Netflix/eureka/pulls/comments/23094447","id":23094447,"diff_hunk":"@@ -0,0 +1,139 @@\n+package com.netflix.eureka2.integration;\n+\n+import com.netflix.eureka2.client.EurekaClient;\n+import com.netflix.eureka2.interests.ChangeNotification;\n+import com.netflix.eureka2.registry.instance.InstanceInfo;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+import rx.Subscriber;\n+import rx.Subscription;\n+import rx.observers.SerializedSubscriber;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.Random;\n+import java.util.UUID;\n+import java.util.concurrent.CountDownLatch;\n+import java.util.concurrent.TimeUnit;\n+\n+/**\n+ * A test client that generates a random sequence of register/update/unregister events,\n+ * and subscribes to itself.\n+ *\n+ * @author David Liu\n+ */\n+public class IntegrationTestClient {\n+\n+    private static final Logger logger = LoggerFactory.getLogger(IntegrationTestClient.class);\n+\n+    private static final String APPNAME_PREFIX = \"IntegTestClient_\";\n+\n+    private final String appName;\n+    private final List<ChangeNotification<InstanceInfo>> lifecycle;\n+    private final EurekaClient readClient;\n+    private final EurekaClient writeClient;\n+    private final int unregisterPercentage;\n+    private final int gapWaitMs;\n+    private final int endWaitMs;\n+\n+    private final List<ChangeNotification<InstanceInfo>> actualLifecycle;\n+\n+    public IntegrationTestClient(EurekaClient readClient, EurekaClient writeClient) {\n+        this(readClient, writeClient, 15, 300, 10000);\n+    }\n+\n+    public IntegrationTestClient(EurekaClient readClient, EurekaClient writeClient, int unregisterPerecentage, int gapWaitMs, int endWaitMs) {\n+        this.readClient = readClient;\n+        this.writeClient = writeClient;\n+\n+        this.unregisterPercentage = unregisterPerecentage;\n+        this.gapWaitMs = gapWaitMs;\n+        this.endWaitMs = endWaitMs;\n+\n+        this.appName = APPNAME_PREFIX + UUID.randomUUID().toString();\n+        this.lifecycle = generateLifecycle(appName);\n+        this.actualLifecycle = new ArrayList<>();\n+    }\n+\n+    public List<ChangeNotification<InstanceInfo>> getExpectedLifecycle() {\n+        return lifecycle;\n+    }\n+\n+    public List<ChangeNotification<InstanceInfo>> playLifecycle() {\n+        final ChangeNotification<InstanceInfo> expectedEnd = lifecycle.get(lifecycle.size() - 1);\n+\n+        final CountDownLatch expectedEndLatch = new CountDownLatch(1);\n+        Subscription subscription = readClient.forApplication(appName).subscribe(\n+                new SerializedSubscriber<>(\n+                        new Subscriber<ChangeNotification<InstanceInfo>>() {\n+                            @Override\n+                            public void onCompleted() {\n+                            }\n+\n+                            @Override\n+                            public void onError(Throwable e) {\n+                            }\n+\n+                            @Override\n+                            public void onNext(ChangeNotification<InstanceInfo> notification) {","path":"eureka2-integration/src/main/java/com/netflix/eureka2/integration/IntegrationTestClient.java","position":79,"original_position":79,"commit_id":"7460ed3b74e70042971dc9defcf7623a9f823ba7","original_commit_id":"7460ed3b74e70042971dc9defcf7623a9f823ba7","user":{"login":"tbak","id":728768,"avatar_url":"https://avatars.githubusercontent.com/u/728768?v=3","gravatar_id":"","url":"https://api.github.com/users/tbak","html_url":"https://github.com/tbak","followers_url":"https://api.github.com/users/tbak/followers","following_url":"https://api.github.com/users/tbak/following{/other_user}","gists_url":"https://api.github.com/users/tbak/gists{/gist_id}","starred_url":"https://api.github.com/users/tbak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbak/subscriptions","organizations_url":"https://api.github.com/users/tbak/orgs","repos_url":"https://api.github.com/users/tbak/repos","events_url":"https://api.github.com/users/tbak/events{/privacy}","received_events_url":"https://api.github.com/users/tbak/received_events","type":"User","site_admin":false},"body":"We can use takeWhile + TestSubscriber or ExtTestSubscriber. The code is more compact this way.","created_at":"2015-01-16T17:21:27Z","updated_at":"2015-01-16T17:21:27Z","html_url":"https://github.com/Netflix/eureka/pull/345#discussion_r23094447","pull_request_url":"https://api.github.com/repos/Netflix/eureka/pulls/345","_links":{"self":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/comments/23094447"},"html":{"href":"https://github.com/Netflix/eureka/pull/345#discussion_r23094447"},"pull_request":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/345"}}},"pull_request":{"url":"https://api.github.com/repos/Netflix/eureka/pulls/345","id":27490937,"html_url":"https://github.com/Netflix/eureka/pull/345","diff_url":"https://github.com/Netflix/eureka/pull/345.diff","patch_url":"https://github.com/Netflix/eureka/pull/345.patch","issue_url":"https://api.github.com/repos/Netflix/eureka/issues/345","number":345,"state":"closed","locked":false,"title":"Adding random lifecycle test suite","user":{"login":"qiangdavidliu","id":6243760,"avatar_url":"https://avatars.githubusercontent.com/u/6243760?v=3","gravatar_id":"","url":"https://api.github.com/users/qiangdavidliu","html_url":"https://github.com/qiangdavidliu","followers_url":"https://api.github.com/users/qiangdavidliu/followers","following_url":"https://api.github.com/users/qiangdavidliu/following{/other_user}","gists_url":"https://api.github.com/users/qiangdavidliu/gists{/gist_id}","starred_url":"https://api.github.com/users/qiangdavidliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiangdavidliu/subscriptions","organizations_url":"https://api.github.com/users/qiangdavidliu/orgs","repos_url":"https://api.github.com/users/qiangdavidliu/repos","events_url":"https://api.github.com/users/qiangdavidliu/events{/privacy}","received_events_url":"https://api.github.com/users/qiangdavidliu/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-16T08:40:24Z","updated_at":"2015-01-16T17:21:27Z","closed_at":"2015-01-16T08:49:43Z","merged_at":"2015-01-16T08:49:43Z","merge_commit_sha":"9ec61ad2d5ceb2c4976d2f6c8270c047e7707ed7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Netflix/eureka/pulls/345/commits","review_comments_url":"https://api.github.com/repos/Netflix/eureka/pulls/345/comments","review_comment_url":"https://api.github.com/repos/Netflix/eureka/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Netflix/eureka/issues/345/comments","statuses_url":"https://api.github.com/repos/Netflix/eureka/statuses/7460ed3b74e70042971dc9defcf7623a9f823ba7","head":{"label":"qiangdavidliu:2.x","ref":"2.x","sha":"7460ed3b74e70042971dc9defcf7623a9f823ba7","user":{"login":"qiangdavidliu","id":6243760,"avatar_url":"https://avatars.githubusercontent.com/u/6243760?v=3","gravatar_id":"","url":"https://api.github.com/users/qiangdavidliu","html_url":"https://github.com/qiangdavidliu","followers_url":"https://api.github.com/users/qiangdavidliu/followers","following_url":"https://api.github.com/users/qiangdavidliu/following{/other_user}","gists_url":"https://api.github.com/users/qiangdavidliu/gists{/gist_id}","starred_url":"https://api.github.com/users/qiangdavidliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiangdavidliu/subscriptions","organizations_url":"https://api.github.com/users/qiangdavidliu/orgs","repos_url":"https://api.github.com/users/qiangdavidliu/repos","events_url":"https://api.github.com/users/qiangdavidliu/events{/privacy}","received_events_url":"https://api.github.com/users/qiangdavidliu/received_events","type":"User","site_admin":false},"repo":{"id":23604941,"name":"eureka","full_name":"qiangdavidliu/eureka","owner":{"login":"qiangdavidliu","id":6243760,"avatar_url":"https://avatars.githubusercontent.com/u/6243760?v=3","gravatar_id":"","url":"https://api.github.com/users/qiangdavidliu","html_url":"https://github.com/qiangdavidliu","followers_url":"https://api.github.com/users/qiangdavidliu/followers","following_url":"https://api.github.com/users/qiangdavidliu/following{/other_user}","gists_url":"https://api.github.com/users/qiangdavidliu/gists{/gist_id}","starred_url":"https://api.github.com/users/qiangdavidliu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiangdavidliu/subscriptions","organizations_url":"https://api.github.com/users/qiangdavidliu/orgs","repos_url":"https://api.github.com/users/qiangdavidliu/repos","events_url":"https://api.github.com/users/qiangdavidliu/events{/privacy}","received_events_url":"https://api.github.com/users/qiangdavidliu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/qiangdavidliu/eureka","description":"AWS Service registry for resilient mid-tier load balancing and failover.","fork":true,"url":"https://api.github.com/repos/qiangdavidliu/eureka","forks_url":"https://api.github.com/repos/qiangdavidliu/eureka/forks","keys_url":"https://api.github.com/repos/qiangdavidliu/eureka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qiangdavidliu/eureka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qiangdavidliu/eureka/teams","hooks_url":"https://api.github.com/repos/qiangdavidliu/eureka/hooks","issue_events_url":"https://api.github.com/repos/qiangdavidliu/eureka/issues/events{/number}","events_url":"https://api.github.com/repos/qiangdavidliu/eureka/events","assignees_url":"https://api.github.com/repos/qiangdavidliu/eureka/assignees{/user}","branches_url":"https://api.github.com/repos/qiangdavidliu/eureka/branches{/branch}","tags_url":"https://api.github.com/repos/qiangdavidliu/eureka/tags","blobs_url":"https://api.github.com/repos/qiangdavidliu/eureka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qiangdavidliu/eureka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qiangdavidliu/eureka/git/refs{/sha}","trees_url":"https://api.github.com/repos/qiangdavidliu/eureka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qiangdavidliu/eureka/statuses/{sha}","languages_url":"https://api.github.com/repos/qiangdavidliu/eureka/languages","stargazers_url":"https://api.github.com/repos/qiangdavidliu/eureka/stargazers","contributors_url":"https://api.github.com/repos/qiangdavidliu/eureka/contributors","subscribers_url":"https://api.github.com/repos/qiangdavidliu/eureka/subscribers","subscription_url":"https://api.github.com/repos/qiangdavidliu/eureka/subscription","commits_url":"https://api.github.com/repos/qiangdavidliu/eureka/commits{/sha}","git_commits_url":"https://api.github.com/repos/qiangdavidliu/eureka/git/commits{/sha}","comments_url":"https://api.github.com/repos/qiangdavidliu/eureka/comments{/number}","issue_comment_url":"https://api.github.com/repos/qiangdavidliu/eureka/issues/comments/{number}","contents_url":"https://api.github.com/repos/qiangdavidliu/eureka/contents/{+path}","compare_url":"https://api.github.com/repos/qiangdavidliu/eureka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qiangdavidliu/eureka/merges","archive_url":"https://api.github.com/repos/qiangdavidliu/eureka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qiangdavidliu/eureka/downloads","issues_url":"https://api.github.com/repos/qiangdavidliu/eureka/issues{/number}","pulls_url":"https://api.github.com/repos/qiangdavidliu/eureka/pulls{/number}","milestones_url":"https://api.github.com/repos/qiangdavidliu/eureka/milestones{/number}","notifications_url":"https://api.github.com/repos/qiangdavidliu/eureka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qiangdavidliu/eureka/labels{/name}","releases_url":"https://api.github.com/repos/qiangdavidliu/eureka/releases{/id}","created_at":"2014-09-03T03:18:30Z","updated_at":"2015-01-16T17:12:25Z","pushed_at":"2015-01-16T17:12:25Z","git_url":"git://github.com/qiangdavidliu/eureka.git","ssh_url":"git@github.com:qiangdavidliu/eureka.git","clone_url":"https://github.com/qiangdavidliu/eureka.git","svn_url":"https://github.com/qiangdavidliu/eureka","homepage":"","size":6649,"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":"Netflix:2.x","ref":"2.x","sha":"f7c825c99e89ac2970c5fd69ec5213276963c2e2","user":{"login":"Netflix","id":913567,"avatar_url":"https://avatars.githubusercontent.com/u/913567?v=3","gravatar_id":"","url":"https://api.github.com/users/Netflix","html_url":"https://github.com/Netflix","followers_url":"https://api.github.com/users/Netflix/followers","following_url":"https://api.github.com/users/Netflix/following{/other_user}","gists_url":"https://api.github.com/users/Netflix/gists{/gist_id}","starred_url":"https://api.github.com/users/Netflix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Netflix/subscriptions","organizations_url":"https://api.github.com/users/Netflix/orgs","repos_url":"https://api.github.com/users/Netflix/repos","events_url":"https://api.github.com/users/Netflix/events{/privacy}","received_events_url":"https://api.github.com/users/Netflix/received_events","type":"Organization","site_admin":false},"repo":{"id":5198041,"name":"eureka","full_name":"Netflix/eureka","owner":{"login":"Netflix","id":913567,"avatar_url":"https://avatars.githubusercontent.com/u/913567?v=3","gravatar_id":"","url":"https://api.github.com/users/Netflix","html_url":"https://github.com/Netflix","followers_url":"https://api.github.com/users/Netflix/followers","following_url":"https://api.github.com/users/Netflix/following{/other_user}","gists_url":"https://api.github.com/users/Netflix/gists{/gist_id}","starred_url":"https://api.github.com/users/Netflix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Netflix/subscriptions","organizations_url":"https://api.github.com/users/Netflix/orgs","repos_url":"https://api.github.com/users/Netflix/repos","events_url":"https://api.github.com/users/Netflix/events{/privacy}","received_events_url":"https://api.github.com/users/Netflix/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Netflix/eureka","description":"AWS Service registry for resilient mid-tier load balancing and failover.","fork":false,"url":"https://api.github.com/repos/Netflix/eureka","forks_url":"https://api.github.com/repos/Netflix/eureka/forks","keys_url":"https://api.github.com/repos/Netflix/eureka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Netflix/eureka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Netflix/eureka/teams","hooks_url":"https://api.github.com/repos/Netflix/eureka/hooks","issue_events_url":"https://api.github.com/repos/Netflix/eureka/issues/events{/number}","events_url":"https://api.github.com/repos/Netflix/eureka/events","assignees_url":"https://api.github.com/repos/Netflix/eureka/assignees{/user}","branches_url":"https://api.github.com/repos/Netflix/eureka/branches{/branch}","tags_url":"https://api.github.com/repos/Netflix/eureka/tags","blobs_url":"https://api.github.com/repos/Netflix/eureka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Netflix/eureka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Netflix/eureka/git/refs{/sha}","trees_url":"https://api.github.com/repos/Netflix/eureka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Netflix/eureka/statuses/{sha}","languages_url":"https://api.github.com/repos/Netflix/eureka/languages","stargazers_url":"https://api.github.com/repos/Netflix/eureka/stargazers","contributors_url":"https://api.github.com/repos/Netflix/eureka/contributors","subscribers_url":"https://api.github.com/repos/Netflix/eureka/subscribers","subscription_url":"https://api.github.com/repos/Netflix/eureka/subscription","commits_url":"https://api.github.com/repos/Netflix/eureka/commits{/sha}","git_commits_url":"https://api.github.com/repos/Netflix/eureka/git/commits{/sha}","comments_url":"https://api.github.com/repos/Netflix/eureka/comments{/number}","issue_comment_url":"https://api.github.com/repos/Netflix/eureka/issues/comments/{number}","contents_url":"https://api.github.com/repos/Netflix/eureka/contents/{+path}","compare_url":"https://api.github.com/repos/Netflix/eureka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Netflix/eureka/merges","archive_url":"https://api.github.com/repos/Netflix/eureka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Netflix/eureka/downloads","issues_url":"https://api.github.com/repos/Netflix/eureka/issues{/number}","pulls_url":"https://api.github.com/repos/Netflix/eureka/pulls{/number}","milestones_url":"https://api.github.com/repos/Netflix/eureka/milestones{/number}","notifications_url":"https://api.github.com/repos/Netflix/eureka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Netflix/eureka/labels{/name}","releases_url":"https://api.github.com/repos/Netflix/eureka/releases{/id}","created_at":"2012-07-26T22:23:07Z","updated_at":"2015-01-16T13:46:10Z","pushed_at":"2015-01-16T08:49:44Z","git_url":"git://github.com/Netflix/eureka.git","ssh_url":"git@github.com:Netflix/eureka.git","clone_url":"https://github.com/Netflix/eureka.git","svn_url":"https://github.com/Netflix/eureka","homepage":"","size":10760,"stargazers_count":715,"watchers_count":715,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":153,"mirror_url":null,"open_issues_count":21,"forks":153,"open_issues":21,"watchers":715,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/345"},"html":{"href":"https://github.com/Netflix/eureka/pull/345"},"issue":{"href":"https://api.github.com/repos/Netflix/eureka/issues/345"},"comments":{"href":"https://api.github.com/repos/Netflix/eureka/issues/345/comments"},"review_comments":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/345/comments"},"review_comment":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Netflix/eureka/pulls/345/commits"},"statuses":{"href":"https://api.github.com/repos/Netflix/eureka/statuses/7460ed3b74e70042971dc9defcf7623a9f823ba7"}}}}