use of org.reactivestreams.Subscriber in project NewPipe by TeamNewPipe.
the class SubscriptionsExportService method getSubscriber.
private Subscriber<File> getSubscriber() {
return new Subscriber<File>() {
@Override
public void onSubscribe(Subscription s) {
subscription = s;
s.request(1);
}
@Override
public void onNext(File file) {
if (DEBUG)
Log.d(TAG, "startExport() success: file = " + file);
}
@Override
public void onError(Throwable error) {
Log.e(TAG, "onError() called with: error = [" + error + "]", error);
handleError(error);
}
@Override
public void onComplete() {
LocalBroadcastManager.getInstance(SubscriptionsExportService.this).sendBroadcast(new Intent(EXPORT_COMPLETE_ACTION));
showToast(R.string.export_complete_toast);
stopService();
}
};
}
use of org.reactivestreams.Subscriber in project resilience4j by resilience4j.
the class BulkheadSubscriberTest method shouldHonorCancelledWhenCallingOnError.
@Test
public void shouldHonorCancelledWhenCallingOnError() throws Exception {
// Given
Subscription subscription = mock(Subscription.class);
Subscriber childSubscriber = mock(Subscriber.class);
Subscriber decoratedSubscriber = BulkheadOperator.of(bulkhead).apply(childSubscriber);
decoratedSubscriber.onSubscribe(subscription);
// When
((Subscription) decoratedSubscriber).cancel();
decoratedSubscriber.onError(new IllegalStateException());
// Then
verify(childSubscriber, never()).onError(any());
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
use of org.reactivestreams.Subscriber in project resilience4j by resilience4j.
the class BulkheadSubscriberTest method shouldNotReleaseBulkheadWhenWasCancelledAfterNotPermittedSubscribe.
@Test
public void shouldNotReleaseBulkheadWhenWasCancelledAfterNotPermittedSubscribe() throws Exception {
// Given
Subscription subscription = mock(Subscription.class);
Subscriber childObserver = mock(Subscriber.class);
Subscriber decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
bulkhead.isCallPermitted();
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
decoratedObserver.onSubscribe(subscription);
// When
((Subscription) decoratedObserver).cancel();
// Then
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}
use of org.reactivestreams.Subscriber in project resilience4j by resilience4j.
the class CircuitBreakerSubscriberTest method shouldHonorDisposedWhenCallingOnError.
@Test
public void shouldHonorDisposedWhenCallingOnError() throws Exception {
// Given
Subscription subscription = mock(Subscription.class);
Subscriber childSubscriber = mock(Subscriber.class);
Subscriber decoratedSubscriber = CircuitBreakerOperator.of(circuitBreaker).apply(childSubscriber);
decoratedSubscriber.onSubscribe(subscription);
// When
((Subscription) decoratedSubscriber).cancel();
decoratedSubscriber.onError(new IllegalStateException());
// Then
verify(childSubscriber, never()).onError(any());
assertSingleFailedCall();
}
use of org.reactivestreams.Subscriber in project resilience4j by resilience4j.
the class RateLimiterSubscriberTest method shouldHonorCancelledWhenCallingOnComplete.
@Test
public void shouldHonorCancelledWhenCallingOnComplete() throws Exception {
// Given
Subscription subscription = mock(Subscription.class);
Subscriber childSubscriber = mock(Subscriber.class);
Subscriber decoratedSubscriber = RateLimiterOperator.of(rateLimiter).apply(childSubscriber);
decoratedSubscriber.onSubscribe(subscription);
// When
((Subscription) decoratedSubscriber).cancel();
decoratedSubscriber.onComplete();
// Then
verify(childSubscriber, never()).onComplete();
assertSinglePermitUsed();
}
Aggregations