當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。