Java Code Examples for rx.observers.TestSubscriber#getCompletions()
The following examples show how to use
rx.observers.TestSubscriber#getCompletions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackPressureTest.java From azure-cosmosdb-java with MIT License | 5 votes |
@Test(groups = { "long" }, timeOut = TIMEOUT) public void readFeed() throws Exception { FeedOptions options = new FeedOptions(); options.setMaxItemCount(1); Observable<FeedResponse<Document>> queryObservable = client .readDocuments(getCollectionLink(), options); client.httpRequests.clear(); TestSubscriber subscriber = new TestSubscriber(1); queryObservable.observeOn(Schedulers.io(), 1).subscribe(subscriber); int sleepTimeInMillis = 10000; // 10 seconds int i = 0; // use a test subscriber and request for more result and sleep in between while (subscriber.getCompletions() == 0 && subscriber.getOnErrorEvents().isEmpty()) { TimeUnit.MILLISECONDS.sleep(sleepTimeInMillis); sleepTimeInMillis /= 2; if (sleepTimeInMillis > 1000) { // validate that only one item is returned to subscriber in each iteration assertThat(subscriber.getValueCount() - i).isEqualTo(1); } // validate that only one item is returned to subscriber in each iteration // validate that the difference between the number of requests to backend // and the number of returned results is always less than a fixed threshold assertThat(client.httpRequests.size() - subscriber.getOnNextEvents().size()) .isLessThanOrEqualTo(RxRingBuffer.SIZE + THRESHOLD); subscriber.requestMore(1); i++; } subscriber.assertNoErrors(); subscriber.assertCompleted(); assertThat(subscriber.getOnNextEvents()).hasSize(createdDocuments.size()); }
Example 2
Source File: BackPressureTest.java From azure-cosmosdb-java with MIT License | 5 votes |
@Test(groups = { "long" }, timeOut = TIMEOUT) public void query() throws Exception { FeedOptions options = new FeedOptions(); options.setMaxItemCount(1); Observable<FeedResponse<Document>> queryObservable = client .queryDocuments(getCollectionLink(), "SELECT * from r", options); client.httpRequests.clear(); TestSubscriber subscriber = new TestSubscriber(1); queryObservable.observeOn(Schedulers.io(), 1).subscribe(subscriber); int sleepTimeInMillis = 10000; int i = 0; // use a test subscriber and request for more result and sleep in between while(subscriber.getCompletions() == 0 && subscriber.getOnErrorEvents().isEmpty()) { TimeUnit.MILLISECONDS.sleep(sleepTimeInMillis); sleepTimeInMillis /= 2; if (sleepTimeInMillis > 1000) { // validate that only one item is returned to subscriber in each iteration assertThat(subscriber.getValueCount() - i).isEqualTo(1); } // validate that the difference between the number of requests to backend // and the number of returned results is always less than a fixed threshold assertThat(client.httpRequests.size() - subscriber.getValueCount()) .isLessThanOrEqualTo(RxRingBuffer.SIZE + THRESHOLD); subscriber.requestMore(1); i++; } subscriber.assertNoErrors(); subscriber.assertCompleted(); assertThat(subscriber.getOnNextEvents()).hasSize(createdDocuments.size()); }