本文整理匯總了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);
}