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


Java Subject.subscribe方法代码示例

本文整理汇总了Java中rx.subjects.Subject.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.subscribe方法的具体用法?Java Subject.subscribe怎么用?Java Subject.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.subjects.Subject的用法示例。


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

示例1: testIndirectUsage

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void testIndirectUsage() {
	// 1. Define action (a biz facade points from where 'real' action)
	Subject<Float,Float> actionf0 = PublishSubject.create();

	// 2. map InputEvents --to--> actions (setup InputMapper's mappings)
	sut.mappings.clear();
	sut.map(tmplKeyInputEvent(KeyInput.KEY_0), InputMapperHelpers.isPressedAsOne, actionf0);

	// 3. map actions --to--> subscribe listener/observer
	@SuppressWarnings("unchecked")
	Observer<Float> observer = mock(Observer.class);
	actionf0.subscribe(observer);

	sut.onEvent(new KeyInputEvent(KeyInput.KEY_0, '0', true, false));
	sut.onEvent(new KeyInputEvent(KeyInput.KEY_0, '0', false, false));

	InOrder inOrder1 = inOrder(observer);
	inOrder1.verify(observer, times(1)).onNext(1.0f);
	inOrder1.verify(observer, times(1)).onNext(0.0f);
	verify(observer, Mockito.never()).onCompleted();
}
 
开发者ID:davidB,项目名称:jme3_skel,代码行数:23,代码来源:InputMapperTest.java

示例2: shouldFailWhenUsedAgainstMemcacheBucket

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void shouldFailWhenUsedAgainstMemcacheBucket() {
    Locator locator = new ViewLocator(0);

    ClusterConfig config = mock(ClusterConfig.class);
    when(config.bucketConfig("default")).thenReturn(mock(MemcachedBucketConfig.class));

    CouchbaseRequest request = mock(ViewQueryRequest.class);
    Subject<CouchbaseResponse, CouchbaseResponse> response = AsyncSubject.create();
    when(request.bucket()).thenReturn("default");
    when(request.observable()).thenReturn(response);

    TestSubscriber<CouchbaseResponse> subscriber = new TestSubscriber<CouchbaseResponse>();
    response.subscribe(subscriber);

    locator.locateAndDispatch(request, Collections.<Node>emptyList(), config, null, null);

    subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    List<Throwable> errors = subscriber.getOnErrorEvents();
    assertEquals(1, errors.size());
    assertTrue(errors.get(0) instanceof ServiceNotAvailableException);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:23,代码来源:ViewLocatorTest.java

示例3:

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void should_only_emits_the_last_item_and_call_onComplete_without_throwing_exception_when_AsyncSubject_without_error() {
  Subject<String, String> asyncSubjectSubject = AsyncSubject.<String>create();

  asyncSubjectSubject.subscribe(mTestSubscriber);
  asyncSubjectSubject.onNext("One");
  asyncSubjectSubject.onNext("Two");
  asyncSubjectSubject.onCompleted();

  mTestSubscriber.assertValues("Two");
  mTestSubscriber.assertNoErrors();
  mTestSubscriber.assertCompleted();
}
 
开发者ID:ChunyuanCai,项目名称:PocketBeer,代码行数:14,代码来源:RxAsyncSubjectTester.java

示例4: should_only_throw_exception_when_AsyncSubject_whit_error

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test public void should_only_throw_exception_when_AsyncSubject_whit_error() {
  Subject<String, String> asyncSubjectSubject = AsyncSubject.<String>create();

  asyncSubjectSubject.subscribe(mTestSubscriber);
  asyncSubjectSubject.onNext("One");
  asyncSubjectSubject.onError(new RuntimeException("Error occurs"));
  asyncSubjectSubject.onNext("Two");

  mTestSubscriber.assertNoValues();
  mTestSubscriber.assertError(RuntimeException.class);
  mTestSubscriber.assertNotCompleted();
}
 
开发者ID:ChunyuanCai,项目名称:PocketBeer,代码行数:13,代码来源:RxAsyncSubjectTester.java

示例5:

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void should_emits_all_items_and_call_onComplete_without_throwing_exception_when_ReplaySubject_without_error() {
  Subject<String, String> replaySubject = ReplaySubject.<String>create();

  replaySubject.subscribe(mTestSubscriber);
  replaySubject.onNext("One");
  replaySubject.onNext("Two");
  replaySubject.onCompleted();

  mTestSubscriber.assertValues("One", "Two");
  mTestSubscriber.assertNoErrors();
  mTestSubscriber.assertCompleted();
}
 
开发者ID:ChunyuanCai,项目名称:PocketBeer,代码行数:14,代码来源:RxReplaySubjectTester.java

示例6: should_still_emits_all_items_and_throw_exception_but_not_onComplete_when_ReplaySubject_with_error

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void should_still_emits_all_items_and_throw_exception_but_not_onComplete_when_ReplaySubject_with_error() {
  Subject<String, String> replaySubject = ReplaySubject.<String>create();

  replaySubject.subscribe(mTestSubscriber);
  replaySubject.onNext("One");
  replaySubject.onNext("Two");
  replaySubject.onError(new RuntimeException("Error occurs"));
  replaySubject.onCompleted();

  mTestSubscriber.assertValues("One", "Two");
  mTestSubscriber.assertError(RuntimeException.class);
  mTestSubscriber.assertNotCompleted();
}
 
开发者ID:ChunyuanCai,项目名称:PocketBeer,代码行数:15,代码来源:RxReplaySubjectTester.java

示例7: should_also_emit_item_from_subscriber_when_subscriber_executes_onNext_from_the_same_thread

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void should_also_emit_item_from_subscriber_when_subscriber_executes_onNext_from_the_same_thread() {
  Subject<String, String> replaySubject = ReplaySubject.<String>create();

  replaySubject.subscribe(mTestSubscriber);
  replaySubject.onNext("One");
  replaySubject.onNext("Two");
  mTestSubscriber.onNext("Three");
  replaySubject.onCompleted();

  mTestSubscriber.assertValues("One", "Two", "Three");
  mTestSubscriber.assertNoErrors();
  mTestSubscriber.assertCompleted();
}
 
开发者ID:ChunyuanCai,项目名称:PocketBeer,代码行数:15,代码来源:RxReplaySubjectTester.java

示例8: testErrorThrownIssue1685

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void testErrorThrownIssue1685() {
    Subject<Object, Object> subject = ReplaySubject.create();

    Observable.error(new RuntimeException("oops"))
        .materialize()
        .delay(1, TimeUnit.SECONDS)
        .dematerialize()
        .subscribe(subject);

    subject.subscribe();
    subject.materialize().toBlocking().first();

    System.out.println("Done");
}
 
开发者ID:akarnokd,项目名称:RxJavaFlow,代码行数:16,代码来源:ObservableTests.java

示例9: testSubscribing

import rx.subjects.Subject; //导入方法依赖的package包/类
public void testSubscribing() {
    Subject<Integer, Integer> s = ReplaySubject.create();
    Subscription sub = s.subscribe(new Observer<Integer>() {
        @Override
        public void onCompleted() {
            System.out.println("Completed");
        }

        @Override
        public void onError(Throwable e) {
            System.out.println(e);
        }

        @Override
        public void onNext(Integer integer) {
            System.out.println(integer);
        }
    });

    s.onNext(0);
    s.onNext(1);
    //s.onError(new Exception("Oops"));

    //unsubscribe
    sub.unsubscribe();
    s.onNext(2);
}
 
开发者ID:yeungeek,项目名称:Android-Gradle-Samples,代码行数:28,代码来源:LifetimeTest.java

示例10: main

import rx.subjects.Subject; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        DefaultWampChannelFactory factory =
                new DefaultWampChannelFactory();

        WampChannel channel =
                factory.createJsonChannel(new URI("ws://127.0.0.1:8080/ws"), "realm1");

        CompletionStage open = channel.open();

        open.toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);

        WampRealmServiceProvider services = channel.getRealmProxy().getServices();

        Subject<Integer, Integer> subject =
                services.getSubject(Integer.class, "com.myapp.topic1");

        Subscription disposable = subject.subscribe(new Action1<Integer>() {
            @Override
            public void call(Integer counter) {
                System.out.println("Got " + counter);
            }
        });

        System.in.read();

        disposable.unsubscribe();

        System.in.read();

    } catch (Exception ex) {
        // Catch everything! :(
        System.out.println(ex);
    }
}
 
开发者ID:Code-Sharp,项目名称:JWampSharp,代码行数:36,代码来源:Program.java

示例11: testFailSafe

import rx.subjects.Subject; //导入方法依赖的package包/类
/**
 * Heper method to test fail-safe functionality.
 *
 * @param scheduler the scheduler to test against. if null, it will be failed on the current thread.
 * @param threadName the part of a thread name to match against for additional verification.
 */
private static void testFailSafe(final Scheduler scheduler, final String threadName) {
    Subject<CouchbaseResponse, CouchbaseResponse> subject = AsyncSubject.create();
    TestSubscriber<CouchbaseResponse> subscriber = TestSubscriber.create();
    subject.subscribe(subscriber);
    Exception failure = new CouchbaseException("Some Error");

    Observables.failSafe(scheduler, scheduler != null, subject, failure);

    subscriber.awaitTerminalEvent();
    subscriber.assertError(failure);
    assertTrue(subscriber.getLastSeenThread().getName().contains(threadName));
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:19,代码来源:ObservablesTest.java

示例12: shouldHavePipeliningDisabled

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void shouldHavePipeliningDisabled() {
    Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create();
    ViewQueryRequest requestMock1 = mock(ViewQueryRequest.class);
    when(requestMock1.query()).thenReturn("{...}");
    when(requestMock1.bucket()).thenReturn("foo");
    when(requestMock1.username()).thenReturn("foo");
    when(requestMock1.password()).thenReturn("");
    when(requestMock1.observable()).thenReturn(obs1);
    when(requestMock1.isActive()).thenReturn(true);

    Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create();
    ViewQueryRequest requestMock2 = mock(ViewQueryRequest.class);
    when(requestMock2.query()).thenReturn("{...}");
    when(requestMock2.bucket()).thenReturn("foo");
    when(requestMock2.username()).thenReturn("foo");
    when(requestMock2.password()).thenReturn("");
    when(requestMock2.observable()).thenReturn(obs2);
    when(requestMock2.isActive()).thenReturn(true);


    TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create();
    TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create();

    obs1.subscribe(t1);
    obs2.subscribe(t2);

    channel.writeOutbound(requestMock1, requestMock2);

    t1.assertNotCompleted();
    t2.assertError(RequestCancelledException.class);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:33,代码来源:ViewHandlerTest.java

示例13: shouldHavePipeliningDisabled

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void shouldHavePipeliningDisabled() {
    Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create();
    RawQueryRequest requestMock1 = mock(RawQueryRequest.class);
    when(requestMock1.query()).thenReturn("SELECT * FROM `foo`");
    when(requestMock1.bucket()).thenReturn("foo");
    when(requestMock1.username()).thenReturn("foo");
    when(requestMock1.password()).thenReturn("");
    when(requestMock1.observable()).thenReturn(obs1);
    when(requestMock1.isActive()).thenReturn(true);

    Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create();
    RawQueryRequest requestMock2 = mock(RawQueryRequest.class);
    when(requestMock2.query()).thenReturn("SELECT * FROM `foo`");
    when(requestMock2.bucket()).thenReturn("foo");
    when(requestMock2.username()).thenReturn("foo");
    when(requestMock2.password()).thenReturn("");
    when(requestMock2.observable()).thenReturn(obs2);
    when(requestMock2.isActive()).thenReturn(true);

    TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create();
    TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create();

    obs1.subscribe(t1);
    obs2.subscribe(t2);

    channel.writeOutbound(requestMock1, requestMock2);

    t1.assertNotCompleted();
    t2.assertError(RequestCancelledException.class);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:32,代码来源:QueryHandlerTest.java

示例14: shouldHavePipeliningDisabled

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void shouldHavePipeliningDisabled() {
    Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create();
    SearchQueryRequest requestMock1 = mock(SearchQueryRequest.class);
    when(requestMock1.path()).thenReturn("");
    when(requestMock1.payload()).thenReturn("");
    when(requestMock1.bucket()).thenReturn("foo");
    when(requestMock1.username()).thenReturn("foo");
    when(requestMock1.password()).thenReturn("");
    when(requestMock1.observable()).thenReturn(obs1);
    when(requestMock1.isActive()).thenReturn(true);

    Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create();
    SearchQueryRequest requestMock2 = mock(SearchQueryRequest.class);
    when(requestMock2.path()).thenReturn("");
    when(requestMock2.payload()).thenReturn("");
    when(requestMock2.bucket()).thenReturn("foo");
    when(requestMock2.username()).thenReturn("foo");
    when(requestMock2.password()).thenReturn("");
    when(requestMock2.observable()).thenReturn(obs2);
    when(requestMock2.isActive()).thenReturn(true);


    TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create();
    TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create();

    obs1.subscribe(t1);
    obs2.subscribe(t2);

    channel.writeOutbound(requestMock1, requestMock2);

    t1.assertNotCompleted();
    t2.assertError(RequestCancelledException.class);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:35,代码来源:SearchHandlerTest.java

示例15: shouldHavePipeliningDisabled

import rx.subjects.Subject; //导入方法依赖的package包/类
@Test
public void shouldHavePipeliningDisabled() {
    Subject<CouchbaseResponse,CouchbaseResponse> obs1 = AsyncSubject.create();
    GetDesignDocumentsRequest requestMock1 = mock(GetDesignDocumentsRequest.class);
    when(requestMock1.path()).thenReturn("");
    when(requestMock1.bucket()).thenReturn("foo");
    when(requestMock1.username()).thenReturn("foo");
    when(requestMock1.password()).thenReturn("");
    when(requestMock1.observable()).thenReturn(obs1);
    when(requestMock1.isActive()).thenReturn(true);

    Subject<CouchbaseResponse,CouchbaseResponse> obs2 = AsyncSubject.create();
    GetDesignDocumentsRequest requestMock2 = mock(GetDesignDocumentsRequest.class);
    when(requestMock1.path()).thenReturn("");
    when(requestMock2.bucket()).thenReturn("foo");
    when(requestMock2.username()).thenReturn("foo");
    when(requestMock2.password()).thenReturn("");
    when(requestMock2.observable()).thenReturn(obs2);
    when(requestMock2.isActive()).thenReturn(true);


    TestSubscriber<CouchbaseResponse> t1 = TestSubscriber.create();
    TestSubscriber<CouchbaseResponse> t2 = TestSubscriber.create();

    obs1.subscribe(t1);
    obs2.subscribe(t2);

    channel.writeOutbound(requestMock1, requestMock2);

    t1.assertNotCompleted();
    t2.assertError(RequestCancelledException.class);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:33,代码来源:ConfigHandlerTest.java


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