本文整理汇总了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();
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
示例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);
}
示例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);
}
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}