Search in sources :

Example 1 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxDoOnEachTest method nextCallbackError.

@Test
public void nextCallbackError() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    LongAdder state = new LongAdder();
    Throwable err = new Exception("test");
    Flux.just(1).doOnEach(s -> {
        if (s.isOnNext()) {
            state.increment();
            throw Exceptions.propagate(err);
        }
    }).subscribe(ts);
    // nominal error path (DownstreamException)
    ts.assertErrorMessage("test");
    Assert.assertEquals(1, state.intValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert.fail(org.junit.Assert.fail) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) StepVerifierOptions(reactor.test.StepVerifierOptions) LongAdder(java.util.concurrent.atomic.LongAdder) Test(org.junit.Test)

Example 2 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxDoOnEachTest method never.

@Test
public void never() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicReference<Integer> onNext = new AtomicReference<>();
    AtomicReference<Throwable> onError = new AtomicReference<>();
    AtomicBoolean onComplete = new AtomicBoolean();
    LongAdder state = new LongAdder();
    Flux.never().cast(Integer.class).doOnEach(s -> {
        if (s.isOnNext()) {
            onNext.set(s.get());
            state.increment();
        } else if (s.isOnError()) {
            onError.set(s.getThrowable());
        } else if (s.isOnComplete()) {
            onComplete.set(true);
        }
    }).subscribe(ts);
    Assert.assertNull(onNext.get());
    Assert.assertNull(onError.get());
    Assert.assertFalse(onComplete.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert.fail(org.junit.Assert.fail) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) StepVerifierOptions(reactor.test.StepVerifierOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 3 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxDoOnEachTest method errorCallbackError.

@Test
public void errorCallbackError() {
    AssertSubscriber<String> ts = AssertSubscriber.create();
    LongAdder state = new LongAdder();
    IllegalStateException err = new IllegalStateException("test");
    Flux.error(new IllegalStateException("bar")).cast(String.class).doOnEach(s -> {
        if (s.isOnError()) {
            state.increment();
            throw Exceptions.propagate(err);
        }
    }).subscribe(ts);
    ts.assertNoValues();
    ts.assertError(IllegalStateException.class);
    ts.assertErrorWith(e -> e.getSuppressed()[0].getMessage().equals("bar"));
    Assert.assertEquals(1, state.intValue());
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert.fail(org.junit.Assert.fail) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) StepVerifierOptions(reactor.test.StepVerifierOptions) LongAdder(java.util.concurrent.atomic.LongAdder) Test(org.junit.Test)

Example 4 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class FluxDoOnEachTest method normal.

@Test
public void normal() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicReference<Integer> onNext = new AtomicReference<>();
    AtomicReference<Throwable> onError = new AtomicReference<>();
    AtomicBoolean onComplete = new AtomicBoolean();
    LongAdder state = new LongAdder();
    Flux.just(1, 2).hide().doOnEach(s -> {
        if (s.isOnNext()) {
            onNext.set(s.get());
            state.increment();
        } else if (s.isOnError()) {
            onError.set(s.getThrowable());
        } else if (s.isOnComplete()) {
            onComplete.set(true);
        }
    }).subscribe(ts);
    Assert.assertEquals((Integer) 2, onNext.get());
    Assert.assertNull(onError.get());
    Assert.assertTrue(onComplete.get());
    Assert.assertEquals(2, state.intValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Assert.fail(org.junit.Assert.fail) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) StepVerifierOptions(reactor.test.StepVerifierOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 5 with AssertSubscriber

use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.

the class MonoUsingTest method subscriberCancels.

@Test
public void subscriberCancels() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    MonoProcessor<Integer> tp = MonoProcessor.create();
    Mono.using(() -> 1, r -> tp, cleanup::set, true).subscribe(ts);
    Assert.assertTrue("No subscriber?", tp.hasDownstreams());
    tp.onNext(1);
    ts.assertValues(1).assertComplete().assertNoError();
    Assert.assertEquals(1, cleanup.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Condition(org.assertj.core.api.Condition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)65 AssertSubscriber (reactor.test.subscriber.AssertSubscriber)65 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)52 StepVerifier (reactor.test.StepVerifier)51 List (java.util.List)49 CoreSubscriber (reactor.core.CoreSubscriber)46 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)44 Assert (org.junit.Assert)43 Scannable (reactor.core.Scannable)41 Arrays (java.util.Arrays)40 Subscription (org.reactivestreams.Subscription)37 ArrayList (java.util.ArrayList)33 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)33 Schedulers (reactor.core.scheduler.Schedulers)32 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 Duration (java.time.Duration)21 Fuseable (reactor.core.Fuseable)21 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)20 Exceptions (reactor.core.Exceptions)19 Queues (reactor.util.concurrent.Queues)19