Java Code Examples for org.reactivestreams.Processor#onError()

The following examples show how to use org.reactivestreams.Processor#onError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test(invocationCount = 50)
public void verifyOnErrorThreadSafety() {
    Exception failure = new Exception("boom");
    final Processor<Integer, Integer> processor = UnicastProcessor.<Integer> create().serialized();
    MultiAssertSubscriber<Integer> subscriber = MultiAssertSubscriber.create(100);
    processor.subscribe(subscriber);

    Runnable r1 = () -> processor.onError(failure);
    Runnable r2 = () -> processor.onError(failure);

    new Thread(r1).start();
    new Thread(r2).start();

    subscriber
            .await()
            .assertSubscribed()
            .assertHasFailedWith(Exception.class, "boom");
}
 
Example 2
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test(invocationCount = 50)
public void verifyOnFailureOnCompleteThreadSafety() {
    final Processor<Integer, Integer> processor = UnicastProcessor.<Integer> create().serialized();
    MultiAssertSubscriber<Integer> subscriber = MultiAssertSubscriber.create(100);
    processor.subscribe(subscriber);

    Runnable r1 = () -> {
        processor.onNext(1);
        processor.onComplete();
    };
    Runnable r2 = () -> processor.onError(new Exception("boom"));

    new Thread(r1).start();
    new Thread(r2).start();

    subscriber.await();
    subscriber
            .assertSubscribed()
            .assertTerminated();

    if (subscriber.items().size() != 0) {
        assertThat(subscriber.items()).containsExactly(1);
    }
}
 
Example 3
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test(invocationCount = 50)
public void verifyOnFailureOnFailureThreadSafety() {
    final Processor<Integer, Integer> processor = UnicastProcessor.<Integer> create().serialized();
    MultiAssertSubscriber<Integer> subscriber = MultiAssertSubscriber.create(100);
    processor.subscribe(subscriber);

    Runnable r1 = () -> processor.onError(new Exception("boom"));
    Runnable r2 = () -> processor.onError(new Exception("boom"));

    new Thread(r1).start();
    new Thread(r2).start();

    subscriber.await();
    subscriber
            .assertSubscribed()
            .assertTerminated()
            .assertHasFailedWith(Exception.class, "boom");
}
 
Example 4
Source File: FluxWindow.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void onError(Throwable t) {
	if (done) {
		Operators.onErrorDropped(t, ctx);
		return;
	}
	done = true;

	Processor<T, T> w = window;
	if (w != null) {
		window = null;
		w.onError(t);
	}

	actual.onError(t);
}
 
Example 5
Source File: FluxWindow.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Override
public void onError(Throwable t) {
	if (done) {
		Operators.onErrorDropped(t, actual.currentContext());
		return;
	}
	done = true;

	for (Processor<T, T> w : this) {
		w.onError(t);
	}
	clear();

	error = t;
	drain();
}
 
Example 6
Source File: RSocketResponder.java    From rsocket-java with Apache License 2.0 6 votes vote down vote up
private void handleCancelFrame(int streamId) {
  Subscription subscription = sendingSubscriptions.remove(streamId);
  Processor<Payload, Payload> processor = channelProcessors.remove(streamId);

  if (processor != null) {
    try {
      processor.onError(new CancellationException("Disposed"));
    } catch (Exception e) {
      // ignore
    }
  }

  if (subscription != null) {
    subscription.cancel();
  }
}
 
Example 7
Source File: PublisherWindow.java    From reactive-streams-commons with Apache License 2.0 6 votes vote down vote up
@Override
public void onError(Throwable t) {
    if (done) {
        UnsignalledExceptions.onErrorDropped(t);
        return;
    }

    for (Processor<T, T> w : windows) {
        w.onError(t);
    }
    windows.clear();
    
    error = t;
    done = true;
    drain();
}
 
Example 8
Source File: MultiWindowOp.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(Throwable failure) {
    Subscription subscription = upstream.getAndSet(CANCELLED);
    if (subscription != CANCELLED) {
        Processor<T, T> proc = processor;
        if (proc != null) {
            processor = null;
            proc.onError(failure);
        }
        downstream.onFailure(failure);
    }
}
 
Example 9
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test(invocationCount = 20)
public void verifyOnNextOnErrorThreadSafety() {
    Exception failure = new Exception("boom");
    final Processor<Integer, Integer> processor = UnicastProcessor.<Integer> create().serialized();
    MultiAssertSubscriber<Integer> subscriber = MultiAssertSubscriber.create(100);
    processor.subscribe(subscriber);

    Runnable r1 = () -> {
        processor.onNext(1);
        processor.onComplete();
    };
    Runnable r2 = () -> processor.onError(failure);

    new Thread(r1).start();
    new Thread(r2).start();

    await().until(() -> !subscriber.items().isEmpty() || !subscriber.failures().isEmpty());

    subscriber
            .assertSubscribed()
            .assertTerminated();

    if (subscriber.items().size() != 0) {
        assertThat(subscriber.items()).containsExactly(1);
    } else {
        assertThat(subscriber.failures()).containsExactly(failure);
    }
}
 
Example 10
Source File: FluxWindow.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onError(Throwable t) {
	if (done) {
		Operators.onErrorDropped(t, actual.currentContext());
		return;
	}
	done = true;
	Processor<T, T> w = window;
	if (w != null) {
		window = null;
		w.onError(t);
	}

	actual.onError(t);
}
 
Example 11
Source File: PublisherWindow.java    From reactive-streams-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onError(Throwable t) {
    if (done) {
        UnsignalledExceptions.onErrorDropped(t);
        return;
    }
    Processor<T, T> w = window;
    if (w != null) {
        window = null;
        w.onError(t);
    }
    
    actual.onError(t);
}
 
Example 12
Source File: PublisherWindow.java    From reactive-streams-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onError(Throwable t) {
    if (done) {
        UnsignalledExceptions.onErrorDropped(t);
        return;
    }
    Processor<T, T> w = window;
    if (w != null) {
        window = null;
        w.onError(t);
    }
    
    actual.onError(t);
}