use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onNextFailureWithStrategyMatchingDoesntCancel.
@Test
public void onNextFailureWithStrategyMatchingDoesntCancel() {
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, new OnNextFailureStrategy() {
@Override
public boolean test(Throwable error, @Nullable Object value) {
return true;
}
@Nullable
@Override
public Throwable process(Throwable error, @Nullable Object value, Context context) {
return null;
}
});
Operators.DeferredSubscription s = new Operators.DeferredSubscription();
Throwable t = Operators.onNextError("foo", new NullPointerException("bar"), context, s);
assertThat(t).as("exception processed").isNull();
assertThat(s.isCancelled()).as("subscription cancelled").isFalse();
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onRejectedExecutionLocalTakesPrecedenceOverOnOperatorError.
@Test
public void onRejectedExecutionLocalTakesPrecedenceOverOnOperatorError() {
BiFunction<Throwable, Object, Throwable> localOperatorErrorHook = (e, v) -> new IllegalStateException("boom_" + v, e);
BiFunction<Throwable, Object, Throwable> localReeHook = (e, v) -> new IllegalStateException("rejected_" + v, e);
Context c = Context.of(Hooks.KEY_ON_OPERATOR_ERROR, localOperatorErrorHook, Hooks.KEY_ON_REJECTED_EXECUTION, localReeHook);
IllegalArgumentException failure = new IllegalArgumentException("foo");
final Throwable throwable = Operators.onRejectedExecution(failure, null, null, "bar", c);
assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("rejected_bar").hasNoSuppressedExceptions();
assertThat(throwable.getCause()).isInstanceOf(RejectedExecutionException.class).hasMessage("Scheduler unavailable").hasCause(failure);
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class OperatorsTest method onNextDroppedLocal.
@Test
public void onNextDroppedLocal() {
AtomicReference<Object> hookState = new AtomicReference<>();
Consumer<Object> localHook = hookState::set;
Context c = Context.of(Hooks.KEY_ON_NEXT_DROPPED, localHook);
Operators.onNextDropped("foo", c);
assertThat(hookState.get()).isEqualTo("foo");
}
use of reactor.util.context.Context in project reactor-core by reactor.
the class FluxContextStart method subscribe.
@Override
public void subscribe(CoreSubscriber<? super T> actual) {
Context c;
try {
c = doOnContext.apply(actual.currentContext());
} catch (Throwable t) {
Operators.error(actual, Operators.onOperatorError(t, actual.currentContext()));
return;
}
source.subscribe(new ContextStartSubscriber<>(actual, c));
}
use of reactor.util.context.Context in project reactor-netty by reactor.
the class HttpServerTests method sendFileSecure.
@Test
public void sendFileSecure() throws CertificateException, SSLException, URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SslContext sslClient = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
NettyContext context = HttpServer.create(opt -> opt.sslContext(sslServer)).newHandler((req, resp) -> resp.sendFile(largeFile)).block();
HttpClientResponse response = HttpClient.create(opt -> opt.port(context.address().getPort()).sslContext(sslClient)).get("/foo").block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String body = response.receive().aggregate().asString(StandardCharsets.UTF_8).block();
assertThat(body).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
Aggregations