Search in sources :

Example 1 with DirectProcessor

use of reactor.core.publisher.DirectProcessor in project reactor-core by reactor.

the class StepVerifierTests method assertNextWithSubscribeOnDirectProcessor.

// see https://github.com/reactor/reactor-core/issues/959
@Test
public void assertNextWithSubscribeOnDirectProcessor() {
    Scheduler scheduler = Schedulers.newElastic("test");
    DirectProcessor<Integer> processor = DirectProcessor.create();
    Mono<Integer> doAction = Mono.fromSupplier(() -> 22).doOnNext(processor::onNext).subscribeOn(scheduler);
    assertThatExceptionOfType(AssertionError.class).isThrownBy(StepVerifier.create(processor).then(doAction::subscribe).assertNext(v -> assertThat(v).isEqualTo(23)).thenCancel()::verify);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) UnicastProcessor(reactor.core.publisher.UnicastProcessor) TestPublisher(reactor.test.publisher.TestPublisher) Arrays(java.util.Arrays) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Scheduler(reactor.core.scheduler.Scheduler) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Duration(java.time.Duration) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) ExecutorService(java.util.concurrent.ExecutorService) DirectProcessor(reactor.core.publisher.DirectProcessor) VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) Collections.emptyList(java.util.Collections.emptyList) Context(reactor.util.context.Context) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) LockSupport(java.util.concurrent.locks.LockSupport) Flux(reactor.core.publisher.Flux) List(java.util.List) Fuseable(reactor.core.Fuseable) REQUEST_OVERFLOW(reactor.test.publisher.TestPublisher.Violation.REQUEST_OVERFLOW) Assert(org.junit.Assert) Collections(java.util.Collections) Scheduler(reactor.core.scheduler.Scheduler) VirtualTimeScheduler(reactor.test.scheduler.VirtualTimeScheduler) Test(org.junit.Test)

Example 2 with DirectProcessor

use of reactor.core.publisher.DirectProcessor in project reactor-netty by reactor.

the class HttpClientTest method prematureCancel.

@Test
public void prematureCancel() throws Exception {
    DirectProcessor<Void> signal = DirectProcessor.create();
    NettyContext x = TcpServer.create("localhost", 0).newHandler((in, out) -> {
        signal.onComplete();
        return out.context(c -> c.addHandlerFirst(new HttpResponseEncoder())).sendObject(Mono.delay(Duration.ofSeconds(2)).map(t -> new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.PROCESSING))).neverComplete();
    }).block(Duration.ofSeconds(30));
    StepVerifier.create(createHttpClientForContext(x).get("/").timeout(signal)).verifyError(TimeoutException.class);
// Thread.sleep(1000000);
}
Also used : HttpResources(reactor.ipc.netty.http.HttpResources) HttpVersion(io.netty.handler.codec.http.HttpVersion) StepVerifier(reactor.test.StepVerifier) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Unpooled(io.netty.buffer.Unpooled) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) Duration(java.time.Duration) CharsetUtil(io.netty.util.CharsetUtil) Path(java.nio.file.Path) HttpServer(reactor.ipc.netty.http.server.HttpServer) DirectProcessor(reactor.core.publisher.DirectProcessor) SslContext(io.netty.handler.ssl.SslContext) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) FutureMono(reactor.ipc.netty.FutureMono) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) SSLException(javax.net.ssl.SSLException) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) TcpServer(reactor.ipc.netty.tcp.TcpServer) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NettyContext(reactor.ipc.netty.NettyContext) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) AbortedException(reactor.ipc.netty.channel.AbortedException) Assert(org.junit.Assert) InputStream(java.io.InputStream) Proxy(reactor.ipc.netty.options.ClientProxyOptions.Proxy) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NettyContext(reactor.ipc.netty.NettyContext) Test(org.junit.Test)

Example 3 with DirectProcessor

use of reactor.core.publisher.DirectProcessor in project reactor-core by reactor.

the class SchedulersTest method assertRejectingScheduler.

public void assertRejectingScheduler(Scheduler scheduler) {
    try {
        DirectProcessor<String> p = DirectProcessor.create();
        AtomicReference<String> r = new AtomicReference<>();
        CountDownLatch l = new CountDownLatch(1);
        p.publishOn(scheduler).log().subscribe(r::set, null, l::countDown);
        scheduler.dispose();
        p.onNext("reject me");
        l.await(3, TimeUnit.SECONDS);
    } catch (Exception ree) {
        ree.printStackTrace();
        Throwable throwable = Exceptions.unwrap(ree);
        if (throwable instanceof RejectedExecutionException) {
            return;
        }
        fail(throwable + " is not a RejectedExecutionException");
    } finally {
        scheduler.dispose();
    }
}
Also used : StepVerifier(reactor.test.StepVerifier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) DirectProcessor(reactor.core.publisher.DirectProcessor) Executor(java.util.concurrent.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Consumer(java.util.function.Consumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Assert.fail(org.junit.Assert.fail) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

DirectProcessor (reactor.core.publisher.DirectProcessor)3 Duration (java.time.Duration)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 Flux (reactor.core.publisher.Flux)2 StepVerifier (reactor.test.StepVerifier)2 Unpooled (io.netty.buffer.Unpooled)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)1 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 HttpVersion (io.netty.handler.codec.http.HttpVersion)1 SslContext (io.netty.handler.ssl.SslContext)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1