本文整理汇总了Java中io.reactivex.subjects.SingleSubject.create方法的典型用法代码示例。如果您正苦于以下问题:Java SingleSubject.create方法的具体用法?Java SingleSubject.create怎么用?Java SingleSubject.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.subjects.SingleSubject
的用法示例。
在下文中一共展示了SingleSubject.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRequest
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Override
public <T> Single<T> sendRequest(SqsAction<T> action) {
Request asyncRequest = action.toHttpRequest(credentialsProvider.getCredentials());
SingleSubject<T> responseSubject = SingleSubject.create();
httpClient.executeRequest(asyncRequest, new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response httpResponse) {
Single.fromCallable(() -> action.parseHttpResponse(httpResponse))
.subscribeWith(responseSubject);
return httpResponse;
}
@Override
public void onThrowable(Throwable throwable) {
responseSubject.onError(throwable);
}
});
return responseSubject;
}
示例2: testShutdownWithPendingPermits
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test
public void testShutdownWithPendingPermits() {
SingleSubject<List<SqsMessage<String>>> singleSubject = SingleSubject.create();
when(sqsQueueMock.deleteMessage(any(String.class))).thenReturn(Completable.complete());
when(sqsQueueMock.receiveMessages(anyInt(), any(Optional.class))).thenReturn(singleSubject);
consumer.setMessageBuffer(messageBufferSmall);
consumer.processNextMessage(consumer.getNextMessage());
//handler does not ack here, so permits will be pending forever
Completable shutdownCompletable = consumer.shutdownAsync();
singleSubject.onSuccess(Collections.emptyList());
shutdownCompletable.test().assertNotComplete();
}
示例3: testHandlerDeleteAndShutdown
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test
public void testHandlerDeleteAndShutdown() {
SingleSubject<List<SqsMessage<String>>> singleSubject = SingleSubject.create();
when(sqsQueueMock.deleteMessage(any(String.class))).thenReturn(Completable.complete());
when(sqsQueueMock.receiveMessages(anyInt(), any(Optional.class))).thenReturn(singleSubject);
doAnswer((invocation -> {
((MessageAcknowledger) invocation.getArgument(1)).delete();
return null;
})).when(consumerHandlerMock).handleMessage(any(), any());
consumer.setMessageBuffer(messageBufferSmall);
consumer.processNextMessage(consumer.getNextMessage());
Completable shutdownCompletable = consumer.shutdownAsync();
singleSubject.onSuccess(Collections.emptyList());
shutdownCompletable.test().assertComplete();
verify(sqsQueueMock).deleteMessage(any(String.class));
}
示例4: testHandlerIgnoreAndShutdown
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test
public void testHandlerIgnoreAndShutdown() {
SingleSubject<List<SqsMessage<String>>> singleSubject = SingleSubject.create();
when(sqsQueueMock.deleteMessage(any(String.class))).thenReturn(Completable.complete());
when(sqsQueueMock.receiveMessages(anyInt(), any(Optional.class))).thenReturn(singleSubject);
doAnswer((invocation -> {
((MessageAcknowledger) invocation.getArgument(1)).ignore();
return null;
})).when(consumerHandlerMock).handleMessage(any(), any());
consumer.setMessageBuffer(messageBufferSmall);
consumer.processNextMessage(consumer.getNextMessage());
Completable shutdownCompletable = consumer.shutdownAsync();
singleSubject.onSuccess(Collections.emptyList());
shutdownCompletable.test().assertComplete();
verify(sqsQueueMock, never()).deleteMessage(any(String.class));
}
示例5: test
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void test() {
SingleSubject<String> subject = SingleSubject.create();
Single<String> singleSource = subject.hide();
TestObserver testObserver = new TestObserver();
CompositeDisposable composite = new CompositeDisposable();
Disposable disposable = singleSource
.compose(DisposableAttach.<String>to(composite))
.subscribeWith(testObserver);
subject.onSuccess("Foo");
testObserver.assertValue("Foo");
assertTrue(composite.size() == 1);
composite.dispose();
assertTrue(composite.size() == 0);
assertTrue(composite.isDisposed());
assertTrue(disposable.isDisposed());
assertTrue(testObserver.isDisposed());
}
示例6: fromFuture
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
/**
* Returns a Single that emits the value of the CompletionStage, its error or
* NoSuchElementException if it signals null.
* @param <T> the value type
* @param future the source CompletionStage instance
* @return the new Completable instance
*/
public static <T> Single<T> fromFuture(CompletionStage<T> future) {
SingleSubject<T> cs = SingleSubject.create();
future.whenComplete((v, e) -> {
if (e != null) {
cs.onError(e);
} else
if (v != null) {
cs.onSuccess(v);
} else {
cs.onError(new NoSuchElementException());
}
});
return cs;
}
示例7: autoDispose_withMaybe_normal
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withMaybe_normal() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
SingleSubject<Integer> source = SingleSubject.create();
MaybeSubject<Integer> lifecycle = MaybeSubject.create();
source.as(AutoDispose.<Integer>autoDisposable(lifecycle))
.subscribe(o);
o.takeSubscribe();
assertThat(source.hasObservers()).isTrue();
assertThat(lifecycle.hasObservers()).isTrue();
// Got the event
source.onSuccess(1);
assertThat(o.takeSuccess()).isEqualTo(1);
// Nothing more, lifecycle disposed too
o.assertNoMoreEvents();
assertThat(source.hasObservers()).isFalse();
assertThat(lifecycle.hasObservers()).isFalse();
}
示例8: autoDispose_withMaybe_interrupted
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withMaybe_interrupted() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
SingleSubject<Integer> source = SingleSubject.create();
MaybeSubject<Integer> lifecycle = MaybeSubject.create();
source.as(AutoDispose.<Integer>autoDisposable(lifecycle))
.subscribe(o);
o.takeSubscribe();
assertThat(source.hasObservers()).isTrue();
assertThat(lifecycle.hasObservers()).isTrue();
// Lifecycle ends
lifecycle.onSuccess(2);
assertThat(source.hasObservers()).isFalse();
assertThat(lifecycle.hasObservers()).isFalse();
// Event if upstream emits, no one is listening
source.onSuccess(2);
o.assertNoMoreEvents();
}
示例9: autoDispose_withProvider
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withProvider() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
SingleSubject<Integer> source = SingleSubject.create();
MaybeSubject<Integer> scope = MaybeSubject.create();
ScopeProvider provider = makeProvider(scope);
source.as(AutoDispose.<Integer>autoDisposable(provider))
.subscribe(o);
o.takeSubscribe();
assertThat(source.hasObservers()).isTrue();
assertThat(scope.hasObservers()).isTrue();
source.onSuccess(3);
o.takeSuccess();
// All cleaned up
o.assertNoMoreEvents();
assertThat(source.hasObservers()).isFalse();
assertThat(scope.hasObservers()).isFalse();
}
示例10: autoDispose_withProvider_interrupted
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withProvider_interrupted() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
SingleSubject<Integer> source = SingleSubject.create();
MaybeSubject<Integer> scope = MaybeSubject.create();
ScopeProvider provider = makeProvider(scope);
source.as(AutoDispose.<Integer>autoDisposable(provider))
.subscribe(o);
o.takeSubscribe();
assertThat(source.hasObservers()).isTrue();
assertThat(scope.hasObservers()).isTrue();
// Lifecycle ends
scope.onSuccess(3);
assertThat(source.hasObservers()).isFalse();
assertThat(scope.hasObservers()).isFalse();
// No one is listening even if upstream finally does emit
source.onSuccess(3);
o.assertNoMoreEvents();
}
示例11: autoDispose_withLifecycleProvider
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withLifecycleProvider() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
SingleSubject<Integer> source = SingleSubject.create();
BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
source.as(AutoDispose.<Integer>autoDisposable(provider))
.subscribe(o);
o.takeSubscribe();
assertThat(source.hasObservers()).isTrue();
assertThat(lifecycle.hasObservers()).isTrue();
lifecycle.onNext(1);
assertThat(source.hasObservers()).isTrue();
assertThat(lifecycle.hasObservers()).isTrue();
source.onSuccess(3);
o.takeSuccess();
// All cleaned up
o.assertNoMoreEvents();
assertThat(source.hasObservers()).isFalse();
assertThat(lifecycle.hasObservers()).isFalse();
}
示例12: autoDispose_withLifecycleProvider_interrupted
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withLifecycleProvider_interrupted() {
RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
SingleSubject<Integer> source = SingleSubject.create();
BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
source.as(AutoDispose.<Integer>autoDisposable(provider))
.subscribe(o);
o.takeSubscribe();
assertThat(source.hasObservers()).isTrue();
assertThat(lifecycle.hasObservers()).isTrue();
lifecycle.onNext(1);
assertThat(source.hasObservers()).isTrue();
assertThat(lifecycle.hasObservers()).isTrue();
// Lifecycle ends
lifecycle.onNext(3);
assertThat(source.hasObservers()).isFalse();
assertThat(lifecycle.hasObservers()).isFalse();
// No one is listening even if upstream finally does emit
source.onSuccess(3);
o.assertNoMoreEvents();
}
示例13: autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() {
AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
@Override public void accept(OutsideLifecycleException e) { }
});
BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
SingleSubject<Integer> source = SingleSubject.create();
TestObserver<Integer> o = source
.as(AutoDispose.<Integer>autoDisposable(provider))
.test();
assertThat(source.hasObservers()).isFalse();
assertThat(lifecycle.hasObservers()).isFalse();
o.assertNoValues();
o.assertNoErrors();
}
示例14: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
@Override public void accept(OutsideLifecycleException e) {
// Noop
}
});
BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
lifecycle.onNext(1);
lifecycle.onNext(2);
lifecycle.onNext(3);
LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
SingleSubject<Integer> source = SingleSubject.create();
TestObserver<Integer> o = source
.as(AutoDispose.<Integer>autoDisposable(provider))
.test();
assertThat(source.hasObservers()).isFalse();
assertThat(lifecycle.hasObservers()).isFalse();
o.assertNoValues();
o.assertNoErrors();
}
示例15: autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithExp
import io.reactivex.subjects.SingleSubject; //导入方法依赖的package包/类
@Test public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithExp() {
AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
@Override public void accept(OutsideLifecycleException e) {
// Wrap in an IllegalStateException so we can verify this is the exception we see on the
// other side
throw new IllegalStateException(e);
}
});
BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
SingleSubject<Integer> source = SingleSubject.create();
TestObserver<Integer> o = source
.as(AutoDispose.<Integer>autoDisposable(provider))
.test();
o.assertNoValues();
o.assertError(new Predicate<Throwable>() {
@Override public boolean test(Throwable throwable) {
return throwable instanceof IllegalStateException
&& throwable.getCause() instanceof OutsideLifecycleException;
}
});
}