Search in sources :

Example 61 with Subscriber

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();
        }
    };
}
Also used : Subscriber(org.reactivestreams.Subscriber) Intent(android.content.Intent) Subscription(org.reactivestreams.Subscription) File(java.io.File)

Example 62 with Subscriber

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);
}
Also used : Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 63 with Subscriber

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);
}
Also used : Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 64 with Subscriber

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();
}
Also used : Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 65 with Subscriber

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();
}
Also used : Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Aggregations

Subscriber (org.reactivestreams.Subscriber)92 Subscription (org.reactivestreams.Subscription)56 Test (org.junit.Test)49 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 ProtonClient (io.vertx.proton.ProtonClient)22 ProtonConnection (io.vertx.proton.ProtonConnection)22 Message (org.apache.qpid.proton.message.Message)20 List (java.util.List)18 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)17 Handler (io.vertx.core.Handler)16 Logger (io.vertx.core.impl.logging.Logger)16 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)16 ProtonStreams (io.vertx.proton.streams.ProtonStreams)16 ExecutionException (java.util.concurrent.ExecutionException)16 Symbol (org.apache.qpid.proton.amqp.Symbol)16 Section (org.apache.qpid.proton.amqp.messaging.Section)16 ArrayList (java.util.ArrayList)14 Collections (java.util.Collections)13