本文整理汇总了Java中io.reactivex.subjects.SingleSubject类的典型用法代码示例。如果您正苦于以下问题:Java SingleSubject类的具体用法?Java SingleSubject怎么用?Java SingleSubject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SingleSubject类属于io.reactivex.subjects包,在下文中一共展示了SingleSubject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:20,代码来源:BaseSqsRequestSender.java
示例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();
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:18,代码来源:SqsConsumerTest.java
示例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));
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:21,代码来源:SqsConsumerTest.java
示例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));
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:21,代码来源:SqsConsumerTest.java
示例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());
}
开发者ID:cp949,项目名称:DisposableAttach,代码行数:21,代码来源:DisposableAttachSingleTest.java
示例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;
}
开发者ID:akarnokd,项目名称:RxJava2Jdk8Interop,代码行数:24,代码来源:SingleInterop.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:21,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:21,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:21,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:22,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:26,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:27,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:17,代码来源:AutoDisposeSingleObserverTest.java
示例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();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:22,代码来源:AutoDisposeSingleObserverTest.java
示例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;
}
});
}
开发者ID:uber,项目名称:AutoDispose,代码行数:24,代码来源:AutoDisposeSingleObserverTest.java
示例16: MessageAcknowledger
import io.reactivex.subjects.SingleSubject; //导入依赖的package包/类
public MessageAcknowledger(SqsQueue<T> sqsQueue, String receiptId, Instant expirationTime) {
this.expirationTime = expirationTime;
this.sqsQueue = sqsQueue;
this.receiptId = receiptId;
this.ackModeSingle = SingleSubject.create();
this.ackingComplete = CompletableSubject.create();
Duration duration = Duration.between(Instant.now(), expirationTime);
Completable.timer(duration.toMillis(), TimeUnit.MILLISECONDS).subscribe(this::ignore);
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:11,代码来源:MessageAcknowledger.java
示例17: publishMessage
import io.reactivex.subjects.SingleSubject; //导入依赖的package包/类
@Override
public Single<String> publishMessage(U body, Optional<Duration> maybeDelay) {
return Single.defer(() -> {
T serializedBody = inverseMap.apply(body);
return delegate.publishMessage(serializedBody, maybeDelay);
}).subscribeWith(SingleSubject.create());
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:8,代码来源:MappingSqsQueue.java
示例18: sendRequest
import io.reactivex.subjects.SingleSubject; //导入依赖的package包/类
@Override
public <T> Single<T> sendRequest(SqsAction<T> request) {
return Single.defer(() -> delegate.sendRequest(request))
.retry((errCount, error) -> {
if (errCount > retryCount || request.isBatchAction()) {
return false;
}
if (error instanceof AmazonSQSException) {
return ((AmazonSQSException) error).getErrorType() == AmazonServiceException.ErrorType.Service;
}
return true;
}).subscribeWith(SingleSubject.create());//convert to Hot single
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:14,代码来源:RetryingSqsRequestSender.java
示例19: autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions
import io.reactivex.subjects.SingleSubject; //导入依赖的package包/类
@Test public void autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions() {
TestObserver<Object> o = SingleSubject.create()
.as(AutoDispose.autoDisposable(ScopeProvider.UNBOUND))
.test();
o.assertNoValues();
o.assertNoErrors();
rule.assertNoErrors();
}
开发者ID:uber,项目名称:AutoDispose,代码行数:10,代码来源:AutoDisposeSingleObserverTest.java
示例20: unbound_shouldStillPassValues
import io.reactivex.subjects.SingleSubject; //导入依赖的package包/类
@Test public void unbound_shouldStillPassValues() {
SingleSubject<Integer> s = SingleSubject.create();
TestObserver<Integer> o = s
.as(AutoDispose.<Integer>autoDisposable(ScopeProvider.UNBOUND))
.test();
s.onSuccess(1);
o.assertValue(1);
}
开发者ID:uber,项目名称:AutoDispose,代码行数:10,代码来源:AutoDisposeSingleObserverTest.java
注:本文中的io.reactivex.subjects.SingleSubject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论