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

The following examples show how to use org.reactivestreams.Processor#onComplete() . 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 = 20)
public void verifyOnNextOnCompleteThreadSafety() {
    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::onComplete;

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

    subscriber.await();
    subscriber
            .assertSubscribed()
            .assertCompletedSuccessfully();

    if (subscriber.items().size() != 0) {
        assertThat(subscriber.items()).containsExactly(1);
    }
}
 
Example 2
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 6 votes vote down vote up
@Test(invocationCount = 20)
public void verifyOnSubscribeOnCompleteThreadSafety() {
    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.onSubscribe(new Subscriptions.EmptySubscription());

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

    subscriber.await();
    subscriber
            .assertSubscribed()
            .assertCompletedSuccessfully();

    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 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 4
Source File: MultiWindowOp.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Override
public void onCompletion() {
    Subscription subscription = upstream.getAndSet(CANCELLED);
    if (subscription != CANCELLED) {
        Processor<T, T> proc = processor;
        if (proc != null) {
            processor = null;
            proc.onComplete();
        }

        downstream.onCompletion();
    }
}
 
Example 5
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithMultipleItems() {
    Processor<Integer, Integer> processor = UnicastProcessor.<Integer> create().serialized();
    MultiAssertSubscriber<Integer> subscriber = MultiAssertSubscriber.create(10);
    processor.subscribe(subscriber);

    Multi.createFrom().range(1, 11).subscribe(processor);

    subscriber
            .assertReceived(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            .assertCompletedSuccessfully();

    processor.onNext(11);
    processor.onComplete();
}
 
Example 6
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 7
Source File: SerializedProcessorTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscriptionAfterTerminalEvent() {
    final Processor<Integer, Integer> processor = UnicastProcessor.<Integer> create().serialized();
    processor.onComplete();
    Subscription subscription = mock(Subscription.class);
    processor.onSubscribe(subscription);
    verify(subscription).cancel();
}
 
Example 8
Source File: StatsdMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private Consumer<String> toSink(Processor<String, String> lines, int numLines) {
    AtomicInteger latch = new AtomicInteger(numLines);
    return l -> {
        lines.onNext(l);
        if (latch.decrementAndGet() == 0) {
            lines.onComplete();
        }
    };
}
 
Example 9
Source File: SubjectPerf.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
final void run(Processor<Integer, Integer> subject, Blackhole bh) {
    subject.subscribe(new PerfConsumer(bh));
    int e = count;
    for (int i = 0; i < e; i++) {
        subject.onNext(1);
    }
    subject.onComplete();
    bh.consume(subject);
}
 
Example 10
Source File: SubjectPerf.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
final void run(Processor<Integer, Integer> subject, Blackhole bh) {
    subject.subscribe(new PerfConsumer(bh));
    int e = count;
    for (int i = 0; i < e; i++) {
        subject.onNext(1);
    }
    subject.onComplete();
    bh.consume(subject);
}
 
Example 11
Source File: FluxWindow.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete() {
	if (done) {
		return;
	}
	done = true;
	Processor<T, T> w = window;
	if (w != null) {
		window = null;
		w.onComplete();
	}

	actual.onComplete();
}
 
Example 12
Source File: FluxWindow.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete() {
	if (done) {
		return;
	}
	done = true;

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

	actual.onComplete();
}
 
Example 13
Source File: FluxWindow.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete() {
	if (done) {
		return;
	}
	done = true;

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

	drain();
}
 
Example 14
Source File: PublisherWindow.java    From reactive-streams-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void onComplete() {
    if (done) {
        return;
    }

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

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

    for (Processor<T, T> w : windows) {
        w.onComplete();
    }
    windows.clear();
    
    done = true;
    drain();
}