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


Java Subscriber类代码示例

本文整理汇总了Java中org.reactivestreams.Subscriber的典型用法代码示例。如果您正苦于以下问题:Java Subscriber类的具体用法?Java Subscriber怎么用?Java Subscriber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Subscriber类属于org.reactivestreams包,在下文中一共展示了Subscriber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWithConsumerRecord

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Ignore
@Test
public void testWithConsumerRecord() throws Exception {
    KafkaComponent kafka = createComponent();
    
    Mono<List<Object>> receive = Flux.from(kafka.from(TOPIC1, ConsumerRecord.class))
        .map(record -> record.value())
        .take(2)
        .collectList();

    Subscriber<ProducerRecord> toTopic = kafka.to(TOPIC1, ProducerRecord.class);
    Flux.just(new ProducerRecord<String, String>(TOPIC1, "1", "test"),
              new ProducerRecord<String, String>(TOPIC1, "1", "test2"))
        .subscribe(toTopic);

    List<Object> received = receive.block(Duration.ofSeconds(10));
    Assert.assertEquals(2, received.size());
    Assert.assertEquals("test", received.get(0));
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:20,代码来源:TestKafka.java

示例2: sourceOverflow

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void sourceOverflow() {
    new Flowable<Integer>() {
        @Override
        protected void subscribeActual(Subscriber<? super Integer> s) {
            s.onSubscribe(new BooleanSubscription());
            for (int i = 0; i < 10; i++) {
                s.onNext(i);
            }
        }
    }
    .parallel(1, 1)
    .sequential(1)
    .test(0)
    .assertFailure(MissingBackpressureException.class);
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:17,代码来源:ParallelFromPublisherTest.java

示例3: subscribeActual

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Override
protected void subscribeActual(Subscriber<? super T> s) {

    Subscriber<? super T> subscriber;
    try {
        subscriber = ObjectHelper.requireNonNull(s, "Null Observer");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // can't call onError because no way to know if a Disposable has been set or not
        // can't call onSubscribe because the call might have set a Disposable already
        RxJavaPlugins.onError(e);

        NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS");
        npe.initCause(e);
        throw npe;
    }

    source.subscribe(new AttachSingleObserver<>(subscriber, this.compositeDisposable));
}
 
开发者ID:cp949,项目名称:DisposableAttach,代码行数:20,代码来源:AttachDisposableFlowable.java

示例4: badSource

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void badSource() {
    List<Throwable> errors = TestCommonHelper.trackPluginErrors();
    try {
        flatMapMaybe(new Flowable<Integer>() {
            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onError(new TestException("First"));
                observer.onError(new TestException("Second"));
            }
        }, Functions.justFunction(Maybe.just(2)))
        .test()
        .assertFailureAndMessage(TestException.class, "First");

        TestCommonHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaCommonPlugins.reset();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:21,代码来源:FlowableFlatMapMaybeTest.java

示例5: testZipIterableFirstShorter

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void testZipIterableFirstShorter() {
    PublishProcessor<String> r1 = PublishProcessor.create();
    /* define a Subscriber to receive aggregated events */
    Subscriber<String> o = TestHelper.mockSubscriber();
    InOrder io = inOrder(o);

    Iterable<String> r2 = Arrays.asList("1", "2", "3");

    r1.zipWith(r2, zipr2).subscribe(o);

    r1.onNext("one-");
    r1.onNext("two-");
    r1.onComplete();

    io.verify(o).onNext("one-1");
    io.verify(o).onNext("two-2");
    io.verify(o).onComplete();

    verify(o, never()).onError(any(Throwable.class));

}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:23,代码来源:FlowableZipIterableTest.java

示例6: fetchArticleLists

import org.reactivestreams.Subscriber; //导入依赖的package包/类
public void fetchArticleLists(){
//         mActicleListInterface.showLoading();
        mIacticleModel.requestData(new Subscriber<ArticleListBean>() {
            @Override
            public void onSubscribe(Subscription s) {
                s.request(Long.MAX_VALUE);
            }

            @Override
            public void onNext(ArticleListBean  articleListBean) {
                  mActicleListInterface.showData(articleListBean);
            }

            @Override
            public void onError(Throwable t) {
                Log.e("ArticleListPresenter",t.getMessage());
            }

            @Override
            public void onComplete() {
                mActicleListInterface.hideLoading();
            }
        });

    }
 
开发者ID:AnnyBaby,项目名称:Mvp-Retrofit-Rxjava-Rxbus,代码行数:26,代码来源:ArticleListPresenter.java

示例7: badSource2

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void badSource2() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        elementAt(new Flowable<Integer>() {
            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());

                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }, 0, 1)
        .test()
        .assertResult(1);

        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaCommonPlugins.reset();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:24,代码来源:FlowableElementAtTest.java

示例8: testByRequest

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void testByRequest(){
	Subscriber<Employee> subscriber = new Subscriber<Employee>(){
		
		

		@Override
		public void onComplete() {	}

		@Override
		public void onError(Throwable arg0) {	}

		@Override
		public void onNext(Employee emp) {
			System.out.println(emp);
			
		}

		@Override
		public void onSubscribe(Subscription subs) {
			subs.request(1);
		}
	};
	employeeBatchStreamServiceImpl.selectSomeEmpRecords().subscribe(subscriber);
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:26,代码来源:TestEmployeeBatchStream.java

示例9: testCompletedAfterErrorIsNotSent

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void testCompletedAfterErrorIsNotSent() {
    BehaviorProcessor<String> subject = BehaviorProcessor.createDefault("default");

    Subscriber<String> observer = TestHelper.mockSubscriber();
    subject.subscribe(observer);

    subject.onNext("one");
    subject.onError(testException);
    subject.onNext("two");
    subject.onComplete();

    verify(observer, times(1)).onNext("default");
    verify(observer, times(1)).onNext("one");
    verify(observer, times(1)).onError(testException);
    verify(observer, never()).onNext("two");
    verify(observer, never()).onComplete();
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:19,代码来源:BehaviorProcessorTest.java

示例10: badSource

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void badSource() {
    List<Throwable> errors = TestCommonHelper.trackPluginErrors();
    try {
        flatMapSingle(new Flowable<Integer>() {
            @Override
            protected void subscribeActual(Subscriber<? super Integer> observer) {
                observer.onSubscribe(new BooleanSubscription());
                observer.onError(new TestException("First"));
                observer.onError(new TestException("Second"));
            }
        }, Functions.justFunction(Single.just(2)))
        .test()
        .assertFailureAndMessage(TestException.class, "First");

        TestCommonHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaCommonPlugins.reset();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:21,代码来源:FlowableFlatMapSingleTest.java

示例11: onNextDelegates

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void onNextDelegates() {
    ClientCallStreamObserver<Object> obs = mock(ClientCallStreamObserver.class);
    RxConsumerStreamObserver rxObs = new RxConsumerStreamObserver();
    Subscriber<Object> sub = mock(Subscriber.class);

    rxObs.beforeStart(obs);
    rxObs.getRxConsumer().subscribe(sub);

    TestSubscriber<Object> testSubscriber = ((Flowable<Object>)rxObs.getRxConsumer()).test();

    Object obj = new Object();
    rxObs.onNext(obj);
    rxObs.onCompleted();

    testSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
    testSubscriber.assertValues(obj);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:19,代码来源:RxConsumerStreamObserverTest.java

示例12: onErrorDelegates

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void onErrorDelegates() {
    ClientCallStreamObserver<Object> obs = mock(ClientCallStreamObserver.class);
    RxConsumerStreamObserver rxObs = new RxConsumerStreamObserver();
    Subscriber<Object> sub = mock(Subscriber.class);

    rxObs.beforeStart(obs);
    rxObs.getRxConsumer().subscribe(sub);

    TestSubscriber<Object> testSubscriber = ((Flowable<Object>)rxObs.getRxConsumer()).test();

    Throwable obj = new Exception();
    rxObs.onError(obj);

    testSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
    testSubscriber.assertError(obj);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:18,代码来源:RxConsumerStreamObserverTest.java

示例13: testSuccessOperatesOnSuppliedScheduler

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void testSuccessOperatesOnSuppliedScheduler() throws Exception {
    @SuppressWarnings("unchecked")
    Future<Object> future = mock(Future.class);
    Object value = new Object();
    when(future.get()).thenReturn(value);

    Subscriber<Object> o = TestHelper.mockSubscriber();

    TestScheduler scheduler = new TestScheduler();
    TestSubscriber<Object> ts = new TestSubscriber<Object>(o);

    Flowable.fromFuture(future, scheduler).subscribe(ts);

    verify(o, never()).onNext(value);

    scheduler.triggerActions();

    verify(o, times(1)).onNext(value);
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:21,代码来源:FlowableToFutureTest.java

示例14: testCompletedAfterErrorIsNotSent2

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Test
public void testCompletedAfterErrorIsNotSent2() {
    BehaviorProcessor<String> subject = BehaviorProcessor.createDefault("default");

    Subscriber<String> observer = TestHelper.mockSubscriber();
    subject.subscribe(observer);

    subject.onNext("one");
    subject.onError(testException);
    subject.onNext("two");
    subject.onComplete();

    verify(observer, times(1)).onNext("default");
    verify(observer, times(1)).onNext("one");
    verify(observer, times(1)).onError(testException);
    verify(observer, never()).onNext("two");
    verify(observer, never()).onComplete();

    Subscriber<Object> o2 = TestHelper.mockSubscriber();
    subject.subscribe(o2);
    verify(o2, times(1)).onError(testException);
    verify(o2, never()).onNext(any());
    verify(o2, never()).onComplete();
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:25,代码来源:BehaviorProcessorTest.java

示例15: subscribe

import org.reactivestreams.Subscriber; //导入依赖的package包/类
@Override
public void subscribe(
    final Subscriber<? super MappingSupplier<JamepadController, PlayerIdentity>> subscriber
) {
  Flux.<Controller.MappingSupplier<JamepadController, PlayerIdentity>>create(fluxSink -> {
    while (true) {
      IntStream.range(0, this.getControllers().getNumControllers())
          .boxed()
          .filter(controllerIndex -> this.getControllers().getControllerIndex(controllerIndex)
              .isConnected())
          .forEach(index ->
              fluxSink.next(() ->
                  Collections.singletonMap(new JamepadController(
                          new JamepadControllerIdentity(index),
                          this.getControllers().getState(index)),
                      this.getControllerMapping().get(new JamepadControllerIdentity(index)))));
    }
  }).subscribe(subscriber);
}
 
开发者ID:delta-leonis,项目名称:subra,代码行数:20,代码来源:JamepadPublisher.java


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