Search in sources :

Example 1 with EmitResult

use of reactor.core.publisher.Sinks.EmitResult in project reactor-core by reactor.

the class NextProcessor method emitEmpty.

void emitEmpty(Sinks.EmitFailureHandler failureHandler) {
    for (; ; ) {
        Sinks.EmitResult emitResult = tryEmitValue(null);
        if (emitResult.isSuccess()) {
            return;
        }
        boolean shouldRetry = failureHandler.onEmitFailure(SignalType.ON_COMPLETE, emitResult);
        if (shouldRetry) {
            continue;
        }
        switch(emitResult) {
            case FAIL_ZERO_SUBSCRIBER:
            case FAIL_OVERFLOW:
            case FAIL_CANCELLED:
            case FAIL_TERMINATED:
                return;
            case FAIL_NON_SERIALIZED:
                throw new EmissionException(emitResult, "Spec. Rule 1.3 - onSubscribe, onNext, onError and onComplete signaled to a Subscriber MUST be signaled serially.");
            default:
                throw new EmissionException(emitResult, "Unknown emitResult value");
        }
    }
}
Also used : EmitResult(reactor.core.publisher.Sinks.EmitResult) EmissionException(reactor.core.publisher.Sinks.EmissionException)

Example 2 with EmitResult

use of reactor.core.publisher.Sinks.EmitResult in project reactor-core by reactor.

the class SinkOneMulticastTest method successDoOnTerminate.

@Test
void successDoOnTerminate() {
    SinkOneMulticast<String> sink = new SinkOneMulticast<>();
    AtomicInteger invoked = new AtomicInteger();
    sink.doOnTerminate(invoked::incrementAndGet).subscribe();
    EmitResult emitResult = sink.tryEmitValue("test");
    assertThat(emitResult).isEqualTo(EmitResult.OK);
    assertThat(invoked).hasValue(1);
    assertThat(sink.scan(Scannable.Attr.ERROR)).isNull();
    assertThat(sink.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmitResult(reactor.core.publisher.Sinks.EmitResult) Test(org.junit.jupiter.api.Test)

Example 3 with EmitResult

use of reactor.core.publisher.Sinks.EmitResult in project reactor-core by reactor.

the class SinkOneMulticastTest method successDoOnSuccess.

@Test
void successDoOnSuccess() {
    SinkOneMulticast<String> sink = new SinkOneMulticast<>();
    AtomicReference<String> ref = new AtomicReference<>();
    sink.doOnSuccess(ref::set).subscribe();
    EmitResult emitResult = sink.tryEmitValue("test");
    assertThat(emitResult).isEqualTo(EmitResult.OK);
    assertThat(ref.get()).isEqualToIgnoringCase("test");
    assertThat(sink.scan(Scannable.Attr.ERROR)).isNull();
    assertThat(sink.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) EmitResult(reactor.core.publisher.Sinks.EmitResult) Test(org.junit.jupiter.api.Test)

Example 4 with EmitResult

use of reactor.core.publisher.Sinks.EmitResult in project reactor-core by reactor.

the class SinkOneMulticastTest method rejectedDoOnError.

@Test
void rejectedDoOnError() {
    SinkOneMulticast<String> sink = new SinkOneMulticast<>();
    AtomicReference<Throwable> ref = new AtomicReference<>();
    sink.doOnError(ref::set).subscribe(v -> {
    }, e -> {
    });
    EmitResult emitResult = sink.tryEmitError(new Exception("test"));
    assertThat(emitResult).isEqualTo(EmitResult.OK);
    assertThat(ref.get()).hasMessage("test");
    assertThat(sink.scan(Scannable.Attr.ERROR)).hasMessage("test");
    assertThat(sink.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) EmitResult(reactor.core.publisher.Sinks.EmitResult) Test(org.junit.jupiter.api.Test)

Example 5 with EmitResult

use of reactor.core.publisher.Sinks.EmitResult in project reactor-core by reactor.

the class SinkOneMulticastTest method rejectedDoOnTerminate.

@Test
void rejectedDoOnTerminate() {
    SinkOneMulticast<String> sink = new SinkOneMulticast<>();
    AtomicInteger invoked = new AtomicInteger();
    sink.doOnTerminate(invoked::incrementAndGet).subscribe(v -> {
    }, e -> {
    });
    EmitResult emitResult = sink.tryEmitError(new Exception("test"));
    assertThat(emitResult).isEqualTo(EmitResult.OK);
    assertThat(invoked).hasValue(1);
    assertThat(sink.scan(Scannable.Attr.ERROR)).hasMessage("test");
    assertThat(sink.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmitResult(reactor.core.publisher.Sinks.EmitResult) Test(org.junit.jupiter.api.Test)

Aggregations

EmitResult (reactor.core.publisher.Sinks.EmitResult)12 Test (org.junit.jupiter.api.Test)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 EmissionException (reactor.core.publisher.Sinks.EmissionException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)2 Assumptions.assumeThat (org.assertj.core.api.Assumptions.assumeThat)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 Exceptions (reactor.core.Exceptions)2 EmitFailureHandler (reactor.core.publisher.Sinks.EmitFailureHandler)2 ParameterizedTestWithName (reactor.test.ParameterizedTestWithName)2 Context (reactor.util.context.Context)2