Search in sources :

Example 6 with AssertSubscriber

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

the class MonoUsingTest method checkCleanupExecutionTime.

void checkCleanupExecutionTime(boolean eager, boolean fail) {
    AtomicInteger cleanup = new AtomicInteger();
    AtomicBoolean before = new AtomicBoolean();
    AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {

        @Override
        public void onError(Throwable t) {
            super.onError(t);
            before.set(cleanup.get() != 0);
        }

        @Override
        public void onComplete() {
            super.onComplete();
            before.set(cleanup.get() != 0);
        }
    };
    Mono.using(() -> 1, r -> {
        if (fail) {
            return Mono.error(new RuntimeException("forced failure"));
        }
        return Mono.just(1);
    }, cleanup::set, eager).subscribe(ts);
    if (fail) {
        ts.assertNoValues().assertError(RuntimeException.class).assertNotComplete().assertErrorMessage("forced failure");
    } else {
        ts.assertValues(1).assertComplete().assertNoError();
    }
    Assert.assertEquals(1, cleanup.get());
    Assert.assertEquals(eager, before.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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertSubscriber(reactor.test.subscriber.AssertSubscriber)

Example 7 with AssertSubscriber

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

the class MonoUsingTest method resourceThrowsEager.

@Test
public void resourceThrowsEager() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Mono.using(() -> {
        throw new RuntimeException("forced failure");
    }, r -> Mono.just(1), cleanup::set, false).subscribe(ts);
    ts.assertNoValues().assertNotComplete().assertError(RuntimeException.class).assertErrorMessage("forced failure");
    Assert.assertEquals(0, cleanup.get());
}
Also used : 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)

Example 8 with AssertSubscriber

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

the class MonoUsingTest method factoryReturnsNull.

@Test
public void factoryReturnsNull() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Mono.<Integer, Integer>using(() -> 1, r -> null, cleanup::set, false).subscribe(ts);
    ts.assertNoValues().assertNotComplete().assertError(NullPointerException.class);
    Assert.assertEquals(1, cleanup.get());
}
Also used : 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)

Example 9 with AssertSubscriber

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

the class MonoUsingTest method factoryThrowsEager.

@Test
public void factoryThrowsEager() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Mono.using(() -> 1, r -> {
        throw new RuntimeException("forced failure");
    }, cleanup::set, false).subscribe(ts);
    ts.assertNoValues().assertNotComplete().assertError(RuntimeException.class).assertErrorMessage("forced failure");
    Assert.assertEquals(1, cleanup.get());
}
Also used : 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)

Example 10 with AssertSubscriber

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

the class ParallelReduceSeedTest method collectAsync3Take.

@Test
public void collectAsync3Take() {
    Scheduler s = Schedulers.newParallel("test", 4);
    Supplier<List<Integer>> as = () -> new ArrayList<>();
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    Flux.range(1, 100000).publishOn(s).parallel(3).runOn(s).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).groups().flatMap(v -> v).reduce(0, (a, b) -> b.size() + a).subscribe(ts);
    ts.await(Duration.ofSeconds(5));
    ts.assertValues(100_000).assertNoError().assertComplete();
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Scheduler(reactor.core.scheduler.Scheduler) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest) Duration(java.time.Duration) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Schedulers(reactor.core.scheduler.Schedulers) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) ParallelOperatorTest(reactor.test.publisher.ParallelOperatorTest)

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