Search in sources :

Example 56 with AssertSubscriber

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

the class FluxUsingTest method normal.

@Test
public void normal() {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Flux.using(() -> 1, r -> Flux.range(r, 10), cleanup::set, false).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 57 with AssertSubscriber

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

the class FluxUsingTest method factoryThrowsEager.

@Test
public void factoryThrowsEager() {
    AssertSubscriber<Object> ts = AssertSubscriber.create();
    AtomicInteger cleanup = new AtomicInteger();
    Flux.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 : 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 58 with AssertSubscriber

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

the class FluxUsingTest method factoryReturnsNull.

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

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

the class MonoPublishOnTest method rejectedExecutionExceptionOnErrorSignalExecutor.

@Test
public void rejectedExecutionExceptionOnErrorSignalExecutor() throws InterruptedException {
    int data = 1;
    Exception exception = new IllegalStateException();
    final AtomicReference<Throwable> throwableInOnOperatorError = new AtomicReference<>();
    final AtomicReference<Object> dataInOnOperatorError = new AtomicReference<>();
    try {
        CountDownLatch hookLatch = new CountDownLatch(2);
        Hooks.onOperatorError((t, d) -> {
            throwableInOnOperatorError.set(t);
            dataInOnOperatorError.set(d);
            hookLatch.countDown();
            return t;
        });
        ExecutorService executor = newCachedThreadPool();
        CountDownLatch latch = new CountDownLatch(1);
        AssertSubscriber<Integer> assertSubscriber = new AssertSubscriber<>();
        Mono.just(data).publishOn(fromExecutorService(executor)).doOnNext(s -> {
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw Exceptions.propagate(exception);
            }
        }).publishOn(fromExecutor(executor)).subscribe(assertSubscriber);
        executor.shutdownNow();
        assertSubscriber.assertNoValues().assertNoError().assertNotComplete();
        hookLatch.await();
        assertThat(throwableInOnOperatorError.get(), instanceOf(RejectedExecutionException.class));
        Assert.assertSame(throwableInOnOperatorError.get().getSuppressed()[0], exception);
    } finally {
        Hooks.resetOnOperatorError();
    }
}
Also used : AssertSubscriber(reactor.test.subscriber.AssertSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 60 with AssertSubscriber

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

the class MonoPublishOnTest method rejectedExecutionExceptionOnErrorSignalExecutorService.

@Test
public void rejectedExecutionExceptionOnErrorSignalExecutorService() throws InterruptedException {
    int data = 1;
    Exception exception = new IllegalStateException();
    final AtomicReference<Throwable> throwableInOnOperatorError = new AtomicReference<>();
    final AtomicReference<Object> dataInOnOperatorError = new AtomicReference<>();
    try {
        CountDownLatch hookLatch = new CountDownLatch(2);
        Hooks.onOperatorError((t, d) -> {
            throwableInOnOperatorError.set(t);
            dataInOnOperatorError.set(d);
            hookLatch.countDown();
            return t;
        });
        ExecutorService executor = newCachedThreadPool();
        CountDownLatch latch = new CountDownLatch(1);
        AssertSubscriber<Integer> assertSubscriber = new AssertSubscriber<>();
        Mono.just(data).publishOn(fromExecutorService(executor)).doOnNext(s -> {
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw Exceptions.propagate(exception);
            }
        }).publishOn(fromExecutorService(executor)).subscribe(assertSubscriber);
        executor.shutdownNow();
        assertSubscriber.assertNoValues().assertNoError().assertNotComplete();
        hookLatch.await();
        assertThat(throwableInOnOperatorError.get(), instanceOf(RejectedExecutionException.class));
        Assert.assertSame(throwableInOnOperatorError.get().getSuppressed()[0], exception);
    } finally {
        Hooks.resetOnOperatorError();
    }
}
Also used : AssertSubscriber(reactor.test.subscriber.AssertSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) ExecutorService(java.util.concurrent.ExecutorService) 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