Search in sources :

Example 41 with AssertSubscriber

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

the class FluxUsingTest method normalEager.

@Test
public void normalEager() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Flux.using(() -> 1, r -> Flux.range(r, 10), cleanup::set).subscribe(ts);
    ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).assertComplete().assertNoError();
    Assert.assertEquals(1, cleanup.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Mockito(org.mockito.Mockito) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) MockUtils(reactor.test.MockUtils) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 42 with AssertSubscriber

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

the class FluxUsingTest method subscriberCancels.

@Test
public void subscriberCancels() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    DirectProcessor<Integer> tp = DirectProcessor.create();
    Flux.using(() -> 1, r -> tp, cleanup::set, true).subscribe(ts);
    Assert.assertTrue("No subscriber?", tp.hasDownstreams());
    tp.onNext(1);
    ts.assertValues(1).assertNotComplete().assertNoError();
    ts.cancel();
    tp.onNext(2);
    ts.assertValues(1).assertNotComplete().assertNoError();
    Assert.assertFalse("Has subscriber?", tp.hasDownstreams());
    Assert.assertEquals(1, cleanup.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Mockito(org.mockito.Mockito) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) MockUtils(reactor.test.MockUtils) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 43 with AssertSubscriber

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

the class FluxDoOnEachTest method completeCallbackError.

@Test
public void completeCallbackError() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    LongAdder state = new LongAdder();
    Throwable err = new Exception("test");
    Flux.just(1).doOnEach(s -> {
        if (s.isOnComplete()) {
            state.increment();
            throw Exceptions.propagate(err);
        }
    }).subscribe(ts);
    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 44 with AssertSubscriber

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

the class FluxDoOnEachTest method empty.

@Test
public void empty() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicReference<Integer> onNext = new AtomicReference<>();
    AtomicReference<Throwable> onError = new AtomicReference<>();
    AtomicBoolean onComplete = new AtomicBoolean();
    LongAdder state = new LongAdder();
    Flux.empty().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.assertTrue(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 45 with AssertSubscriber

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

the class FluxDoOnEachTest method error.

@Test
public void error() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicReference<Integer> onNext = new AtomicReference<>();
    AtomicReference<Throwable> onError = new AtomicReference<>();
    AtomicBoolean onComplete = new AtomicBoolean();
    LongAdder state = new LongAdder();
    Flux.error(new RuntimeException("forced " + "failure")).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.assertTrue(onError.get() instanceof RuntimeException);
    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)

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