当前位置: 首页>>代码示例>>Java>>正文


Java BlockingObservable类代码示例

本文整理汇总了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"));
}
 
开发者ID:otto-de,项目名称:rx-composer,代码行数:17,代码来源:HttpContentProviderTest.java

示例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"));
}
 
开发者ID:otto-de,项目名称:rx-composer,代码行数:17,代码来源:HttpContentProviderTest.java

示例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());
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:24,代码来源:BlockingOperatorLatestTest.java

示例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());
    }
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:26,代码来源:BlockingOperatorLatestTest.java

示例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());
    }
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:19,代码来源:BlockingOperatorLatestTest.java

示例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);
    }
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:19,代码来源:BlockingOperatorNextTest.java

示例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());
    }

}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:25,代码来源:BlockingOperatorMostRecentTest.java

示例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();
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:21,代码来源:BlockingObservableTest.java

示例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());
    }
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:19,代码来源:BlockingObservableTest.java

示例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();

}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:21,代码来源:BlockingObservableTest.java

示例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();
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:18,代码来源:BlockingObservableTest.java

示例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());
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:26,代码来源:ClientBasicFlowsTest.java

示例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();
}
 
开发者ID:otto-de,项目名称:rx-composer,代码行数:13,代码来源:HttpContentProviderTest.java

示例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));
}
 
开发者ID:otto-de,项目名称:rx-composer,代码行数:13,代码来源:HttpContentProviderTest.java

示例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();
}
 
开发者ID:Egorand,项目名称:intro-to-rxjava-rxandroid,代码行数:12,代码来源:ObservableTests.java


注:本文中的rx.observables.BlockingObservable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。