use of reactor.util.annotation.NonNull in project incubator-shenyu by apache.
the class CryptorResponseDecorator method writeWith.
@Override
@NonNull
@SuppressWarnings("unchecked")
public Mono<Void> writeWith(@NonNull final Publisher<? extends DataBuffer> body) {
ClientResponse clientResponse = ResponseUtils.buildClientResponse(this.getDelegate(), body);
Mono<String> mono = clientResponse.bodyToMono(String.class).flatMap(originalBody -> strategyMatch(originalBody, this.ruleHandle, this.exchange));
return ResponseUtils.writeWith(clientResponse, this.exchange, mono, String.class);
}
use of reactor.util.annotation.NonNull in project incubator-shenyu by apache.
the class LoggingServerHttpResponse method appendResponse.
/**
* append response.
*
* @param body publisher
* @return wrap Flux
*/
@NonNull
private Flux<? extends DataBuffer> appendResponse(final Publisher<? extends DataBuffer> body) {
ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
assert shenyuContext != null;
if (getStatusCode() != null) {
logInfo.setStatus(getStatusCode().value());
}
logInfo.setResponseHeader(LogCollectUtils.getResponseHeaders(getHeaders()));
BodyWriter writer = new BodyWriter();
String traceId = (String) exchange.getAttributes().get(SHENYU_AGENT_TRACE_ID);
logInfo.setTraceId(traceId);
boolean collectResponseBody = LogCollectConfigUtils.getLogFieldSwitchConfig().isResponseBody();
return Flux.from(body).doOnNext(buffer -> {
if (LogCollectUtils.isNotBinaryType(getHeaders()) && collectResponseBody) {
writer.write(buffer.asByteBuffer().asReadOnlyBuffer());
}
}).doFinally(signal -> logResponse(shenyuContext, writer));
}
use of reactor.util.annotation.NonNull in project reactor-core by reactor.
the class ExecutorSchedulerTest method failingAndShutDownExecutorServiceIsTerminated.
@Test
public void failingAndShutDownExecutorServiceIsTerminated() {
final IllegalStateException boom = new IllegalStateException("boom");
ExecutorService service = new AbstractExecutorService() {
boolean shutdown;
@Override
public void shutdown() {
shutdown = true;
}
@NonNull
@Override
public List<Runnable> shutdownNow() {
return Collections.emptyList();
}
@Override
public boolean isShutdown() {
return shutdown;
}
@Override
public boolean isTerminated() {
return shutdown;
}
@Override
public boolean awaitTermination(long timeout, @NonNull TimeUnit unit) throws InterruptedException {
return false;
}
@Override
public void execute(@NonNull Runnable command) {
if (shutdown)
throw boom;
shutdown = true;
}
};
ExecutorScheduler scheduler = new ExecutorScheduler(service, false);
assertThatCode(() -> scheduler.schedule(() -> {
})).as("initial-no rejection").doesNotThrowAnyException();
assertThatExceptionOfType(RejectedExecutionException.class).as("second-transient rejection").isThrownBy(() -> scheduler.schedule(() -> {
})).withCause(boom);
assertThatExceptionOfType(RejectedExecutionException.class).as("third scheduler terminated rejection").isThrownBy(() -> scheduler.schedule(() -> {
})).isSameAs(Exceptions.failWithRejected()).withNoCause();
}
use of reactor.util.annotation.NonNull in project reactor-core by reactor.
the class FluxIterableTest method infiniteGeneratorDoesntHangFusedDiscard.
@Test
void infiniteGeneratorDoesntHangFusedDiscard() {
class Generator implements Iterable<Integer> {
final int seed;
Generator(int seed) {
this.seed = seed;
}
@NonNull
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
int value = seed;
@Override
public boolean hasNext() {
return true;
}
@Override
public Integer next() {
return value++;
}
};
}
}
Generator one = new Generator(1);
// smoke test: this Iterable is indeed NOT SIZED
assertThat(one.spliterator().hasCharacteristics(Spliterator.SIZED)).as("spliterator not sized").isFalse();
AtomicInteger discardCount = new AtomicInteger();
Flux.fromIterable(one).publishOn(Schedulers.single()).take(10, false).doOnDiscard(Integer.class, i -> discardCount.incrementAndGet()).blockLast(Duration.ofSeconds(1));
assertThat(discardCount).as("discardCount").hasValue(0);
}
use of reactor.util.annotation.NonNull in project reactor-core by reactor.
the class ExecutorSchedulerTest method failingExecutorServiceIsNotTerminated.
@Test
public void failingExecutorServiceIsNotTerminated() {
AtomicInteger count = new AtomicInteger();
final IllegalStateException boom = new IllegalStateException("boom");
ExecutorService service = new AbstractExecutorService() {
boolean shutdown;
@Override
public void shutdown() {
shutdown = true;
}
@NonNull
@Override
public List<Runnable> shutdownNow() {
return Collections.emptyList();
}
@Override
public boolean isShutdown() {
return shutdown;
}
@Override
public boolean isTerminated() {
return shutdown;
}
@Override
public boolean awaitTermination(long timeout, @NonNull TimeUnit unit) throws InterruptedException {
return false;
}
@Override
public void execute(@NonNull Runnable command) {
if (count.incrementAndGet() % 2 == 0)
throw boom;
}
};
ExecutorScheduler scheduler = new ExecutorScheduler(service, false);
assertThatCode(() -> scheduler.schedule(() -> {
})).as("initial-no rejection").doesNotThrowAnyException();
assertThatExceptionOfType(RejectedExecutionException.class).as("second-transient rejection").isThrownBy(() -> scheduler.schedule(() -> {
})).withCause(boom);
assertThatCode(() -> scheduler.schedule(() -> {
})).as("third-no rejection").doesNotThrowAnyException();
assertThat(count).hasValue(3);
}
Aggregations