{"action":"created","comment":{"url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/comments/51575402","id":51575402,"diff_hunk":"@@ -0,0 +1,285 @@\n+/**\n+ * Copyright 2014 Netflix, Inc.\n+ * <p/>\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ * <p/>\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ * <p/>\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package rx.internal.util;\n+\n+import org.junit.Test;\n+\n+import rx.Single;\n+import rx.SingleSubscriber;\n+import rx.Subscription;\n+import rx.exceptions.TestException;\n+import rx.functions.Action0;\n+import rx.functions.Func1;\n+import rx.observers.TestSubscriber;\n+import rx.schedulers.Schedulers;\n+import rx.subscriptions.Subscriptions;\n+\n+import static org.junit.Assert.assertEquals;\n+import static org.mockito.Mockito.mock;\n+import static org.mockito.Mockito.verify;\n+\n+public class ScalarSynchronousSingleTest {\n+    @Test\n+    public void testBackpressure() {\n+        TestSubscriber<Integer> ts = TestSubscriber.create(0);\n+\n+        Single.just(1).subscribe(ts);\n+\n+        ts.assertNoValues();\n+        ts.assertNoErrors();\n+        ts.assertNotCompleted();\n+\n+        ts.requestMore(1);\n+\n+        ts.assertValue(1);\n+        ts.assertCompleted();\n+        ts.assertNoErrors();\n+\n+        ts.requestMore(1);\n+\n+        ts.assertValue(1);\n+        ts.assertCompleted();\n+        ts.assertNoErrors();\n+    }\n+\n+    @Test(timeout = 1000)\n+    public void testBackpressureSubscribeOn() throws Exception {\n+        TestSubscriber<Integer> ts = TestSubscriber.create(0);\n+\n+        Single.just(1).subscribeOn(Schedulers.computation()).subscribe(ts);\n+\n+        Thread.sleep(200);\n+\n+        ts.assertNoValues();\n+        ts.assertNoErrors();\n+        ts.assertNotCompleted();\n+\n+        ts.requestMore(1);\n+\n+        ts.awaitTerminalEvent();\n+\n+        ts.assertValue(1);\n+        ts.assertCompleted();\n+        ts.assertNoErrors();\n+    }\n+\n+    @Test(timeout = 1000)\n+    public void testBackpressureObserveOn() throws Exception {\n+        TestSubscriber<Integer> ts = TestSubscriber.create(0);\n+\n+        Single.just(1).observeOn(Schedulers.computation()).subscribe(ts);\n+\n+        Thread.sleep(200);\n+\n+        ts.assertNoValues();\n+        ts.assertNoErrors();\n+        ts.assertNotCompleted();\n+\n+        ts.requestMore(1);\n+\n+        ts.awaitTerminalEvent();\n+\n+        ts.assertValue(1);\n+        ts.assertCompleted();\n+        ts.assertNoErrors();\n+    }\n+\n+    @Test(timeout = 1000)\n+    public void testBackpressureSubscribeOn2() throws Exception {\n+        TestSubscriber<Integer> ts = TestSubscriber.create(0);\n+\n+        Single.just(1).subscribeOn(Schedulers.newThread()).subscribe(ts);\n+\n+        Thread.sleep(200);\n+\n+        ts.assertNoValues();\n+        ts.assertNoErrors();\n+        ts.assertNotCompleted();\n+\n+        ts.requestMore(1);\n+\n+        ts.awaitTerminalEvent();\n+\n+        ts.assertValue(1);\n+        ts.assertCompleted();\n+        ts.assertNoErrors();\n+    }\n+\n+    @Test(timeout = 1000)\n+    public void testBackpressureObserveOn2() throws Exception {\n+        TestSubscriber<Integer> ts = TestSubscriber.create(0);\n+\n+        Single.just(1).observeOn(Schedulers.newThread()).subscribe(ts);\n+\n+        Thread.sleep(200);\n+\n+        ts.assertNoValues();\n+        ts.assertNoErrors();\n+        ts.assertNotCompleted();\n+\n+        ts.requestMore(1);\n+\n+        ts.awaitTerminalEvent();\n+\n+        ts.assertValue(1);\n+        ts.assertCompleted();\n+        ts.assertNoErrors();\n+    }\n+\n+    @Test\n+    public void testBackpressureFlatMapJust() {\n+        TestSubscriber<Integer> ts = TestSubscriber.create(0);\n+\n+        Single.just(1).flatMap(new Func1<Integer, Single<Integer>>() {\n+            @Override\n+            public Single<Integer> call(Integer v) {\n+                return Single.just(v);","path":"src/test/java/rx/internal/util/ScalarSynchronousSingleTest.java","position":150,"original_position":150,"commit_id":"8b8971fa7686912d467df284ae55aa99eb92f085","original_commit_id":"8b8971fa7686912d467df284ae55aa99eb92f085","user":{"login":"artem-zinnatullin","id":967132,"avatar_url":"https://avatars.githubusercontent.com/u/967132?v=3","gravatar_id":"","url":"https://api.github.com/users/artem-zinnatullin","html_url":"https://github.com/artem-zinnatullin","followers_url":"https://api.github.com/users/artem-zinnatullin/followers","following_url":"https://api.github.com/users/artem-zinnatullin/following{/other_user}","gists_url":"https://api.github.com/users/artem-zinnatullin/gists{/gist_id}","starred_url":"https://api.github.com/users/artem-zinnatullin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artem-zinnatullin/subscriptions","organizations_url":"https://api.github.com/users/artem-zinnatullin/orgs","repos_url":"https://api.github.com/users/artem-zinnatullin/repos","events_url":"https://api.github.com/users/artem-zinnatullin/events{/privacy}","received_events_url":"https://api.github.com/users/artem-zinnatullin/received_events","type":"User","site_admin":false},"body":"Please return another result, at the moment test can pass even if `flatMap` returns same `Single`, you can also change type from `Integer` to let's say `String` during `flatMap` :)","created_at":"2016-02-02T14:36:51Z","updated_at":"2016-02-02T14:36:51Z","html_url":"https://github.com/ReactiveX/RxJava/pull/3642#discussion_r51575402","pull_request_url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642","_links":{"self":{"href":"https://api.github.com/repos/ReactiveX/RxJava/pulls/comments/51575402"},"html":{"href":"https://github.com/ReactiveX/RxJava/pull/3642#discussion_r51575402"},"pull_request":{"href":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642"}}},"pull_request":{"url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642","id":57023521,"html_url":"https://github.com/ReactiveX/RxJava/pull/3642","diff_url":"https://github.com/ReactiveX/RxJava/pull/3642.diff","patch_url":"https://github.com/ReactiveX/RxJava/pull/3642.patch","issue_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3642","number":3642,"state":"open","locked":false,"title":"1.x: Optimizate single just","user":{"login":"Chaoba","id":8577318,"avatar_url":"https://avatars.githubusercontent.com/u/8577318?v=3","gravatar_id":"","url":"https://api.github.com/users/Chaoba","html_url":"https://github.com/Chaoba","followers_url":"https://api.github.com/users/Chaoba/followers","following_url":"https://api.github.com/users/Chaoba/following{/other_user}","gists_url":"https://api.github.com/users/Chaoba/gists{/gist_id}","starred_url":"https://api.github.com/users/Chaoba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chaoba/subscriptions","organizations_url":"https://api.github.com/users/Chaoba/orgs","repos_url":"https://api.github.com/users/Chaoba/repos","events_url":"https://api.github.com/users/Chaoba/events{/privacy}","received_events_url":"https://api.github.com/users/Chaoba/received_events","type":"User","site_admin":false},"body":"This PR add similar optimization as ScalarSynchronousObservable to Single.just method.","created_at":"2016-01-25T02:43:12Z","updated_at":"2016-02-02T14:36:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9775ea3f286f6c5f98b503a8ec686746e49cd7a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642/commits","review_comments_url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642/comments","review_comment_url":"https://api.github.com/repos/ReactiveX/RxJava/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/3642/comments","statuses_url":"https://api.github.com/repos/ReactiveX/RxJava/statuses/8b8971fa7686912d467df284ae55aa99eb92f085","head":{"label":"Chaoba:optimizate_single_just","ref":"optimizate_single_just","sha":"8b8971fa7686912d467df284ae55aa99eb92f085","user":{"login":"Chaoba","id":8577318,"avatar_url":"https://avatars.githubusercontent.com/u/8577318?v=3","gravatar_id":"","url":"https://api.github.com/users/Chaoba","html_url":"https://github.com/Chaoba","followers_url":"https://api.github.com/users/Chaoba/followers","following_url":"https://api.github.com/users/Chaoba/following{/other_user}","gists_url":"https://api.github.com/users/Chaoba/gists{/gist_id}","starred_url":"https://api.github.com/users/Chaoba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chaoba/subscriptions","organizations_url":"https://api.github.com/users/Chaoba/orgs","repos_url":"https://api.github.com/users/Chaoba/repos","events_url":"https://api.github.com/users/Chaoba/events{/privacy}","received_events_url":"https://api.github.com/users/Chaoba/received_events","type":"User","site_admin":false},"repo":{"id":48739123,"name":"RxJava","full_name":"Chaoba/RxJava","owner":{"login":"Chaoba","id":8577318,"avatar_url":"https://avatars.githubusercontent.com/u/8577318?v=3","gravatar_id":"","url":"https://api.github.com/users/Chaoba","html_url":"https://github.com/Chaoba","followers_url":"https://api.github.com/users/Chaoba/followers","following_url":"https://api.github.com/users/Chaoba/following{/other_user}","gists_url":"https://api.github.com/users/Chaoba/gists{/gist_id}","starred_url":"https://api.github.com/users/Chaoba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chaoba/subscriptions","organizations_url":"https://api.github.com/users/Chaoba/orgs","repos_url":"https://api.github.com/users/Chaoba/repos","events_url":"https://api.github.com/users/Chaoba/events{/privacy}","received_events_url":"https://api.github.com/users/Chaoba/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Chaoba/RxJava","description":"RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.","fork":true,"url":"https://api.github.com/repos/Chaoba/RxJava","forks_url":"https://api.github.com/repos/Chaoba/RxJava/forks","keys_url":"https://api.github.com/repos/Chaoba/RxJava/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Chaoba/RxJava/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Chaoba/RxJava/teams","hooks_url":"https://api.github.com/repos/Chaoba/RxJava/hooks","issue_events_url":"https://api.github.com/repos/Chaoba/RxJava/issues/events{/number}","events_url":"https://api.github.com/repos/Chaoba/RxJava/events","assignees_url":"https://api.github.com/repos/Chaoba/RxJava/assignees{/user}","branches_url":"https://api.github.com/repos/Chaoba/RxJava/branches{/branch}","tags_url":"https://api.github.com/repos/Chaoba/RxJava/tags","blobs_url":"https://api.github.com/repos/Chaoba/RxJava/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Chaoba/RxJava/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Chaoba/RxJava/git/refs{/sha}","trees_url":"https://api.github.com/repos/Chaoba/RxJava/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Chaoba/RxJava/statuses/{sha}","languages_url":"https://api.github.com/repos/Chaoba/RxJava/languages","stargazers_url":"https://api.github.com/repos/Chaoba/RxJava/stargazers","contributors_url":"https://api.github.com/repos/Chaoba/RxJava/contributors","subscribers_url":"https://api.github.com/repos/Chaoba/RxJava/subscribers","subscription_url":"https://api.github.com/repos/Chaoba/RxJava/subscription","commits_url":"https://api.github.com/repos/Chaoba/RxJava/commits{/sha}","git_commits_url":"https://api.github.com/repos/Chaoba/RxJava/git/commits{/sha}","comments_url":"https://api.github.com/repos/Chaoba/RxJava/comments{/number}","issue_comment_url":"https://api.github.com/repos/Chaoba/RxJava/issues/comments{/number}","contents_url":"https://api.github.com/repos/Chaoba/RxJava/contents/{+path}","compare_url":"https://api.github.com/repos/Chaoba/RxJava/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Chaoba/RxJava/merges","archive_url":"https://api.github.com/repos/Chaoba/RxJava/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Chaoba/RxJava/downloads","issues_url":"https://api.github.com/repos/Chaoba/RxJava/issues{/number}","pulls_url":"https://api.github.com/repos/Chaoba/RxJava/pulls{/number}","milestones_url":"https://api.github.com/repos/Chaoba/RxJava/milestones{/number}","notifications_url":"https://api.github.com/repos/Chaoba/RxJava/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Chaoba/RxJava/labels{/name}","releases_url":"https://api.github.com/repos/Chaoba/RxJava/releases{/id}","deployments_url":"https://api.github.com/repos/Chaoba/RxJava/deployments","created_at":"2015-12-29T09:17:32Z","updated_at":"2016-01-12T01:58:13Z","pushed_at":"2016-02-02T03:20:43Z","git_url":"git://github.com/Chaoba/RxJava.git","ssh_url":"git@github.com:Chaoba/RxJava.git","clone_url":"https://github.com/Chaoba/RxJava.git","svn_url":"https://github.com/Chaoba/RxJava","homepage":"","size":20680,"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":"1.x"}},"base":{"label":"ReactiveX:1.x","ref":"1.x","sha":"c5a4902be865616a7c04759e7f92d1e66d574655","user":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"repo":{"id":7508411,"name":"RxJava","full_name":"ReactiveX/RxJava","owner":{"login":"ReactiveX","id":6407041,"avatar_url":"https://avatars.githubusercontent.com/u/6407041?v=3","gravatar_id":"","url":"https://api.github.com/users/ReactiveX","html_url":"https://github.com/ReactiveX","followers_url":"https://api.github.com/users/ReactiveX/followers","following_url":"https://api.github.com/users/ReactiveX/following{/other_user}","gists_url":"https://api.github.com/users/ReactiveX/gists{/gist_id}","starred_url":"https://api.github.com/users/ReactiveX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReactiveX/subscriptions","organizations_url":"https://api.github.com/users/ReactiveX/orgs","repos_url":"https://api.github.com/users/ReactiveX/repos","events_url":"https://api.github.com/users/ReactiveX/events{/privacy}","received_events_url":"https://api.github.com/users/ReactiveX/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ReactiveX/RxJava","description":"RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.","fork":false,"url":"https://api.github.com/repos/ReactiveX/RxJava","forks_url":"https://api.github.com/repos/ReactiveX/RxJava/forks","keys_url":"https://api.github.com/repos/ReactiveX/RxJava/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ReactiveX/RxJava/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ReactiveX/RxJava/teams","hooks_url":"https://api.github.com/repos/ReactiveX/RxJava/hooks","issue_events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/events{/number}","events_url":"https://api.github.com/repos/ReactiveX/RxJava/events","assignees_url":"https://api.github.com/repos/ReactiveX/RxJava/assignees{/user}","branches_url":"https://api.github.com/repos/ReactiveX/RxJava/branches{/branch}","tags_url":"https://api.github.com/repos/ReactiveX/RxJava/tags","blobs_url":"https://api.github.com/repos/ReactiveX/RxJava/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ReactiveX/RxJava/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ReactiveX/RxJava/git/refs{/sha}","trees_url":"https://api.github.com/repos/ReactiveX/RxJava/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ReactiveX/RxJava/statuses/{sha}","languages_url":"https://api.github.com/repos/ReactiveX/RxJava/languages","stargazers_url":"https://api.github.com/repos/ReactiveX/RxJava/stargazers","contributors_url":"https://api.github.com/repos/ReactiveX/RxJava/contributors","subscribers_url":"https://api.github.com/repos/ReactiveX/RxJava/subscribers","subscription_url":"https://api.github.com/repos/ReactiveX/RxJava/subscription","commits_url":"https://api.github.com/repos/ReactiveX/RxJava/commits{/sha}","git_commits_url":"https://api.github.com/repos/ReactiveX/RxJava/git/commits{/sha}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/comments{/number}","issue_comment_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/comments{/number}","contents_url":"https://api.github.com/repos/ReactiveX/RxJava/contents/{+path}","compare_url":"https://api.github.com/repos/ReactiveX/RxJava/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ReactiveX/RxJava/merges","archive_url":"https://api.github.com/repos/ReactiveX/RxJava/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ReactiveX/RxJava/downloads","issues_url":"https://api.github.com/repos/ReactiveX/RxJava/issues{/number}","pulls_url":"https://api.github.com/repos/ReactiveX/RxJava/pulls{/number}","milestones_url":"https://api.github.com/repos/ReactiveX/RxJava/milestones{/number}","notifications_url":"https://api.github.com/repos/ReactiveX/RxJava/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/labels{/name}","releases_url":"https://api.github.com/repos/ReactiveX/RxJava/releases{/id}","deployments_url":"https://api.github.com/repos/ReactiveX/RxJava/deployments","created_at":"2013-01-08T20:11:48Z","updated_at":"2016-02-02T14:22:46Z","pushed_at":"2016-02-02T08:53:56Z","git_url":"git://github.com/ReactiveX/RxJava.git","ssh_url":"git@github.com:ReactiveX/RxJava.git","clone_url":"https://github.com/ReactiveX/RxJava.git","svn_url":"https://github.com/ReactiveX/RxJava","homepage":"","size":25069,"stargazers_count":10758,"watchers_count":10758,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1617,"mirror_url":null,"open_issues_count":198,"forks":1617,"open_issues":198,"watchers":10758,"default_branch":"1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642"},"html":{"href":"https://github.com/ReactiveX/RxJava/pull/3642"},"issue":{"href":"https://api.github.com/repos/ReactiveX/RxJava/issues/3642"},"comments":{"href":"https://api.github.com/repos/ReactiveX/RxJava/issues/3642/comments"},"review_comments":{"href":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642/comments"},"review_comment":{"href":"https://api.github.com/repos/ReactiveX/RxJava/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ReactiveX/RxJava/pulls/3642/commits"},"statuses":{"href":"https://api.github.com/repos/ReactiveX/RxJava/statuses/8b8971fa7686912d467df284ae55aa99eb92f085"}}}}