本文整理汇总了Java中rx.observables.BlockingObservable类的典型用法代码示例。如果您正苦于以下问题:Java BlockingObservable类的具体用法?Java BlockingObservable怎么用?Java BlockingObservable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockingObservable类属于rx.observables包,在下文中一共展示了BlockingObservable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldExecuteFallbackOnServerError
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test
public void shouldExecuteFallbackOnServerError() {
// given
final Response response = someResponse(500, "Very Bad");
final ServiceClient mockClient = someResilientHttpClient(response, "/test");
// when
final ContentProvider contentProvider = contentFrom(mockClient, "/test", TEXT_PLAIN,
fallbackTo(staticTextContent("test", X, "Some Alternative Facts"))
);
final BlockingObservable<Content> content = contentProvider
.getContent(X, noOpTracer(), emptyParameters())
.toBlocking();
// then
verify(mockClient).get("/test", TEXT_PLAIN_TYPE);
assertThat(content.first().getBody(), is("Some Alternative Facts"));
}
示例2: shouldExecuteFallbackOnClientError
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test
public void shouldExecuteFallbackOnClientError() {
// given
final Response response = someResponse(404, "Not Found");
final ServiceClient mockClient = someResilientHttpClient(response, "/test");
// when
final ContentProvider contentProvider = contentFrom(mockClient, "/test", TEXT_PLAIN,
fallbackTo(staticTextContent("test", X, "Some Fallback"))
);
final BlockingObservable<Content> content = contentProvider
.getContent(X, noOpTracer(), emptyParameters())
.toBlocking();
// then
verify(mockClient).get("/test", TEXT_PLAIN_TYPE);
assertThat(content.first().getBody(), is("Some Fallback"));
}
示例3: testSimple
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(timeout = 1000)
public void testSimple() {
TestScheduler scheduler = new TestScheduler();
BlockingObservable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking();
Iterable<Long> iter = source.latest();
Iterator<Long> it = iter.iterator();
// only 9 because take(10) will immediately call onComplete() when receiving the 10th item
// which onComplete() will overwrite the previous value
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
示例4: testSameSourceMultipleIterators
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(timeout = 1000)
public void testSameSourceMultipleIterators() {
TestScheduler scheduler = new TestScheduler();
BlockingObservable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking();
Iterable<Long> iter = source.latest();
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
// only 9 because take(10) will immediately call onComplete() when receiving the 10th item
// which onComplete() will overwrite the previous value
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
}
示例5: testSimpleJustNext
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(timeout = 1000, expected = NoSuchElementException.class)
public void testSimpleJustNext() {
TestScheduler scheduler = new TestScheduler();
BlockingObservable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking();
Iterable<Long> iter = source.latest();
Iterator<Long> it = iter.iterator();
// only 9 because take(10) will immediately call onComplete() when receiving the 10th item
// which onComplete() will overwrite the previous value
for (int i = 0; i < 10; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(Long.valueOf(i), it.next());
}
}
示例6: testSingleSourceManyIterators
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test /* (timeout = 8000) */
public void testSingleSourceManyIterators() throws InterruptedException {
Observable<Long> o = Observable.interval(100, TimeUnit.MILLISECONDS);
PublishSubject<Void> terminal = PublishSubject.create();
BlockingObservable<Long> source = o.takeUntil(terminal).toBlocking();
Iterable<Long> iter = source.next();
for (int j = 0; j < 3; j++) {
BlockingOperatorNext.NextIterator<Long> it = (BlockingOperatorNext.NextIterator<Long>)iter.iterator();
for (long i = 0; i < 10; i++) {
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(j + "th iteration next", Long.valueOf(i), it.next());
}
terminal.onNext(null);
}
}
示例7: testSingleSourceManyIterators
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(timeout = 1000)
public void testSingleSourceManyIterators() {
TestScheduler scheduler = new TestScheduler();
BlockingObservable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking();
Iterable<Long> iter = source.mostRecent(-1L);
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
Assert.assertEquals(Long.valueOf(-1), it.next());
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(true, it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertEquals(false, it.hasNext());
}
}
示例8: testToIterableNextOnlyTwice
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(expected = NoSuchElementException.class)
public void testToIterableNextOnlyTwice() {
BlockingObservable<Integer> obs = BlockingObservable.from(Observable.just(1, 2, 3));
Iterator<Integer> it = obs.toIterable().iterator();
Assert.assertEquals((Integer) 1, it.next());
Assert.assertEquals((Integer) 2, it.next());
Assert.assertEquals((Integer) 3, it.next());
boolean exc = false;
try {
it.next();
} catch (NoSuchElementException ex) {
exc = true;
}
Assert.assertEquals(true, exc);
it.next();
}
示例9: testToIterableManyTimes
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test
public void testToIterableManyTimes() {
BlockingObservable<Integer> obs = BlockingObservable.from(Observable.just(1, 2, 3));
Iterable<Integer> iter = obs.toIterable();
for (int j = 0; j < 3; j++) {
Iterator<Integer> it = iter.iterator();
Assert.assertTrue(it.hasNext());
Assert.assertEquals((Integer) 1, it.next());
Assert.assertTrue(it.hasNext());
Assert.assertEquals((Integer) 2, it.next());
Assert.assertTrue(it.hasNext());
Assert.assertEquals((Integer) 3, it.next());
Assert.assertFalse(it.hasNext());
}
}
示例10: testToIterableWithException
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(expected = TestException.class)
public void testToIterableWithException() {
BlockingObservable<String> obs = BlockingObservable.from(Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> observer) {
observer.onNext("one");
observer.onError(new TestException());
}
}));
Iterator<String> it = obs.toIterable().iterator();
assertEquals(true, it.hasNext());
assertEquals("one", it.next());
assertEquals(true, it.hasNext());
it.next();
}
示例11: startBlockingAndInterrupt
import rx.observables.BlockingObservable; //导入依赖的package包/类
private void startBlockingAndInterrupt(final Action1<BlockingObservable<Void>> blockingAction) {
Thread subscriptionThread = new Thread() {
@Override
public void run() {
try {
blockingAction.call(createObservable().toBlocking());
} catch (RuntimeException e) {
if (!(e.getCause() instanceof InterruptedException)) {
error = e;
}
}
latch.countDown();
}
};
subscriptionThread.start();
subscriptionThread.interrupt();
}
示例12: testStream
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test
@Ignore
public void testStream() throws Exception {
final String singleResponse = "Hello World";
final int repeats = 3;
final String streamBody = Strings.repeat(singleResponse, repeats);
dispatcher.enqueue(new MockResponse().setChunkedBody(streamBody, streamBody.length() / repeats));
final HttpClient httpClient = HttpClient.createDefault();
final String url = server.url("/helloWorldStream").toString();
final BlockingObservable<Response> responseStream = httpClient.get(url).asStream().toBlocking();
final AtomicInteger counter = new AtomicInteger(0);
final AtomicReference<Response> lastResponse = new AtomicReference<>();
responseStream.forEach(response -> {
counter.incrementAndGet();
lastResponse.set(response);
});
assertEquals("response elements size equals to repeats", repeats, counter.get());
assertEquals("chunks contain singleResponse", singleResponse, lastResponse.get().getResponseBody());
}
示例13: shouldThrowExceptionOnHttpServerError
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test(expected = ServerErrorException.class)
public void shouldThrowExceptionOnHttpServerError() {
// given
final Response response = someResponse(500, "Some Server Error");
final ServiceClient mockClient = someHttpClient(response, "/test");
// when
final ContentProvider contentProvider = contentFrom(mockClient, "/test", TEXT_PLAIN);
final BlockingObservable<Content> content = contentProvider.getContent(X, noOpTracer(), emptyParameters()).toBlocking();
// then
verify(mockClient).get("/test", TEXT_PLAIN_TYPE);
content.single();
}
示例14: shouldReturnEmptyContentOnHttpClientError
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test
public void shouldReturnEmptyContentOnHttpClientError() {
// given
final Response response = someResponse(404, "Not Found");
final ServiceClient mockClient = someHttpClient(response, "/test");
// when
final ContentProvider contentProvider = contentFrom(mockClient, "/test", TEXT_PLAIN);
final BlockingObservable<Content> content = contentProvider.getContent(X, noOpTracer(), emptyParameters()).toBlocking();
// then
verify(mockClient).get("/test", TEXT_PLAIN_TYPE);
assertThat(content.getIterator().hasNext(), is(false));
}
示例15: testingWithBlockingObservable
import rx.observables.BlockingObservable; //导入依赖的package包/类
@Test
public void testingWithBlockingObservable() {
Observable<Integer> intObservable = Observable.just(1, 2, 3);
BlockingObservable<Integer> blocking = intObservable.toBlocking();
assertThat(blocking.first()).isEqualTo(1);
assertThat(blocking.last()).isEqualTo(3);
blocking.getIterator();
blocking.toIterable();
}