Skip to content

Commit

Permalink
Remove deprecated API usages (#5249)
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox authored Oct 19, 2023
1 parent eb28cc6 commit 3ce0a5f
Show file tree
Hide file tree
Showing 34 changed files with 193 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import io.netty.resolver.dns.DnsServerAddressStreamProvider;
import io.netty.resolver.dns.DnsServerAddressStreamProviders;
import io.netty.resolver.dns.DnsServerAddresses;
import io.netty.resolver.dns.LoggingDnsQueryLifeCycleObserverFactory;
import io.netty.resolver.dns.NoopAuthoritativeDnsServerCache;
import io.netty.resolver.dns.NoopDnsCache;
import io.netty.resolver.dns.NoopDnsCnameCache;
Expand Down Expand Up @@ -94,7 +95,11 @@ protected AbstractDnsResolverBuilder() {}
/**
* Sets if this resolver should generate detailed trace information in exception messages so that
* it is easier to understand the cause of resolution failure. This flag is enabled by default.
*
* @deprecated Use {@link #dnsQueryLifecycleObserverFactory(DnsQueryLifecycleObserverFactory)} with
* {@link LoggingDnsQueryLifeCycleObserverFactory}.
*/
@Deprecated
public AbstractDnsResolverBuilder traceEnabled(boolean traceEnabled) {
this.traceEnabled = traceEnabled;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface ContextAwareBiConsumer<T, U> extends BiConsumer<T, U>, ContextH
* Returns a new {@link ContextAwareBiConsumer} that sets the specified {@link RequestContext}
* before executing an underlying {@link BiConsumer}.
*/
static <T, U> ContextAwareBiConsumer of(RequestContext context, BiConsumer<T, U> action) {
return new DefaultContextAwareBiConsumer(context, action);
static <T, U> ContextAwareBiConsumer<T, U> of(RequestContext context, BiConsumer<T, U> action) {
return new DefaultContextAwareBiConsumer<>(context, action);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface ContextAwareBiFunction<T, U, R> extends BiFunction<T, U, R>, Co
* Returns a new {@link ContextAwareBiFunction} that sets the specified {@link RequestContext}
* before executing an underlying {@link BiFunction}.
*/
static <T, U, R> ContextAwareBiFunction of(RequestContext context, BiFunction<T, U, R> function) {
return new DefaultContextAwareBiFunction(context, function);
static <T, U, R> ContextAwareBiFunction<T, U, R> of(RequestContext context, BiFunction<T, U, R> function) {
return new DefaultContextAwareBiFunction<>(context, function);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface ContextAwareConsumer<T> extends Consumer<T>, ContextHolder {
* Returns a new {@link ContextAwareConsumer} that sets the specified {@link RequestContext}
* before executing an underlying {@link Consumer}.
*/
static <T, R> ContextAwareConsumer of(RequestContext context, Consumer<T> action) {
return new DefaultContextAwareConsumer(context, action);
static <T> ContextAwareConsumer<T> of(RequestContext context, Consumer<T> action) {
return new DefaultContextAwareConsumer<>(context, action);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public interface ContextAwareFunction<T, R> extends Function<T, R>, ContextHolde
* Returns a new {@link ContextAwareFuture} that sets the specified {@link RequestContext}
* before executing an underlying {@link Function}.
*/
static <T, R> ContextAwareFunction of(RequestContext context, Function<T, R> function) {
return new DefaultContextAwareFunction(context, function);
static <T, R> ContextAwareFunction<T, R> of(RequestContext context, Function<T, R> function) {
return new DefaultContextAwareFunction<>(context, function);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void timeout() {
final WebClient client = WebClient.of(SessionProtocol.H2C, group);
final Stopwatch stopwatch = Stopwatch.createStarted();
assertThatThrownBy(() -> client.get("/").aggregate().join())
.getCause().isInstanceOf(UnprocessedRequestException.class)
.getCause().isInstanceOf(EndpointSelectionTimeoutException.class);
.cause().isInstanceOf(UnprocessedRequestException.class)
.cause().isInstanceOf(EndpointSelectionTimeoutException.class);
assertThat(stopwatch.elapsed(TimeUnit.MILLISECONDS))
.isGreaterThanOrEqualTo(Flags.defaultConnectTimeoutMillis());
}
Expand Down Expand Up @@ -97,8 +97,8 @@ public Endpoint selectNow(ClientRequestContext ctx) {
final CompletableFuture<AggregatedHttpResponse> future = client.get("/").aggregate();
group.add(server.httpEndpoint());
assertThatThrownBy(future::join)
.getCause().isInstanceOf(UnprocessedRequestException.class)
.getCause().isSameAs(cause);
.cause().isInstanceOf(UnprocessedRequestException.class)
.cause().isSameAs(cause);
}

private static final class Group extends DynamicEndpointGroup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.net.ssl.SSLSession;

import org.junit.jupiter.api.Test;
import org.mockito.quality.Strictness;

import com.linecorp.armeria.client.RedirectingClient.RedirectContext;
import com.linecorp.armeria.common.HttpHeaderNames;
Expand Down Expand Up @@ -88,7 +89,7 @@ private static HttpRequest request(HttpHeaders headers) {
}

private static SSLSession newSslSession() {
final SSLSession sslSession = mock(SSLSession.class, withSettings().lenient());
final SSLSession sslSession = mock(SSLSession.class, withSettings().strictness(Strictness.LENIENT));
when(sslSession.getId()).thenReturn(new byte[] { 1, 1, 2, 3, 5, 8, 13, 21 });
when(sslSession.getProtocol()).thenReturn("TLSv1.2");
when(sslSession.getCipherSuite()).thenReturn("some-cipher");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ void testInterrupt() throws Exception {
assertThatThrownBy(consumer::get)
.isInstanceOf(ExecutionException.class)
.hasCauseExactlyInstanceOf(InterruptedIOException.class)
.getCause().hasCauseExactlyInstanceOf(IllegalStateException.class)
.getCause().hasMessageContaining("my fault");
.cause().hasCauseExactlyInstanceOf(IllegalStateException.class)
.cause().hasMessageContaining("my fault");
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void thrownTypeMismatchRecoverStreamMessageShortcut() {
assertThatThrownBy(() -> recoverable.collect().join())
.isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(CompositeException.class)
.getCause()
.cause()
.extracting("exceptions", ITERABLE)
.element(0)
.isInstanceOf(ClosedStreamException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void configure(ServerBuilder sb) throws Exception {
sb.route()
.get("/httpResponseException")
.build((ctx, req) -> {
throw HttpResponseException.of(201);
throw HttpResponseException.of(HttpResponse.of(201));
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class EurekaClientUtil {

private static final ClientOptions retryingClientOptions =
ClientOptions.of(ClientOptions.DECORATION.newValue(ClientDecoration.of(
RetryingClient.newDecorator(RetryRule.failsafe(), 3))));
RetryingClient.builder(RetryRule.failsafe()).maxTotalAttempts(3).newDecorator())));

/**
* Returns the {@link ClientOptions} that has {@link RetryingClient} decorator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

import com.google.common.collect.ImmutableList;

import graphql.execution.instrumentation.SimpleInstrumentation;
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLTypeVisitor;
import graphql.schema.GraphQLTypeVisitorStub;
Expand Down Expand Up @@ -134,7 +134,7 @@ void successful() throws Exception {
new File(getClass().getResource("/testing/graphql/test.graphqls").toURI());
final GraphqlServiceBuilder builder = new GraphqlServiceBuilder();
final GraphqlService service = builder.schemaFile(graphqlSchemaFile)
.instrumentation(SimpleInstrumentation.INSTANCE)
.instrumentation(SimplePerformantInstrumentation.INSTANCE)
.runtimeWiring(it -> {
// noop
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class CustomJacksonObjectMapperProvider implements JacksonObjectMap
@Override
public ObjectMapper newObjectMapper() {
return JsonMapper.builder()
.addModules(new KotlinModule())
.addModules(new KotlinModule.Builder().build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.Resource;
Expand Down Expand Up @@ -88,11 +84,6 @@ static WebAppContext newWebAppContext() throws MalformedURLException {
"hello.jar")).getURI().toURL()
},
JettyService.class.getClassLoader()));

handler.addBean(new ServletContainerInitializersStarter(handler), true);
handler.setAttribute(
"org.eclipse.jetty.containerInitializers",
Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null)));
return handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.Resource;
Expand Down Expand Up @@ -198,11 +194,6 @@ static WebAppContext newWebAppContext() throws MalformedURLException {
"hello.jar")).getURI().toURL()
},
JettyService.class.getClassLoader()));

handler.addBean(new ServletContainerInitializersStarter(handler), true);
handler.setAttribute(
"org.eclipse.jetty.containerInitializers",
Collections.singletonList(new ContainerInitializer(new JettyJasperInitializer(), null)));
return handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.linecorp.armeria.server.kotlin

import com.linecorp.armeria.common.logging.LogFormatter
import com.linecorp.armeria.server.logging.LoggingService
import org.junit.jupiter.api.Test

class Jsr305StrictTest {
Expand All @@ -26,17 +25,6 @@ class Jsr305StrictTest {
fun shouldAllowReturningNulls() {
// Make sure the code compiles with `-Xjsr305=strict`
// See: https://github.com/line/armeria/issues/2793#issuecomment-892325587
LoggingService.builder()
.requestHeadersSanitizer { _, _ -> null }
.responseHeadersSanitizer { _, _ -> null }
.requestTrailersSanitizer { _, _ -> null }
.responseTrailersSanitizer { _, _ -> null }
.headersSanitizer { _, _ -> null }
.requestContentSanitizer { _, _ -> null }
.responseContentSanitizer { _, _ -> null }
.contentSanitizer { _, _ -> null }
.responseCauseSanitizer { _, _ -> null }

LogFormatter.builderForText()
.requestHeadersSanitizer { _, _ -> null }
.responseHeadersSanitizer { _, _ -> null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.mockito.ArgumentCaptor;
import org.mockito.quality.Strictness;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

Expand Down Expand Up @@ -699,7 +700,7 @@ private static ClientRequestContext newClientContext(
}

private static SSLSession newSslSession() {
final SSLSession sslSession = mock(SSLSession.class, withSettings().lenient());
final SSLSession sslSession = mock(SSLSession.class, withSettings().strictness(Strictness.LENIENT));
when(sslSession.getId()).thenReturn(new byte[] { 1, 1, 2, 3, 5, 8, 13, 21 });
when(sslSession.getProtocol()).thenReturn("TLSv1.2");
when(sslSession.getCipherSuite()).thenReturn("some-cipher");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void testUnauthorized() {

assertThatThrownBy(() -> client.get("/resource-read-write/").aggregate().join())
.isInstanceOf(CompletionException.class)
.getCause().isInstanceOf(InvalidClientException.class);
.cause().isInstanceOf(InvalidClientException.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testUnauthorized() {

assertThatThrownBy(() -> client.get("/resource-read-write/").aggregate().join())
.isInstanceOf(CompletionException.class)
.getCause().isInstanceOf(InvalidClientException.class);
.cause().isInstanceOf(InvalidClientException.class);
}
}

Expand All @@ -183,7 +183,7 @@ public void testUnauthorized2() {

assertThatThrownBy(() -> client.get("/resource-read-write/").aggregate().join())
.isInstanceOf(CompletionException.class)
.getCause().isInstanceOf(InvalidClientException.class);
.cause().isInstanceOf(InvalidClientException.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.test.StepVerifier;
import reactor.util.context.Context;
import reactor.util.function.Tuple2;

@GenerateNativeImageTrace
Expand Down Expand Up @@ -102,7 +101,7 @@ void monoCreate_currentContext() {
final Mono<Object> mono;
try (SafeCloseable ignored = ctx.push()) {
mono = addCallbacks(Mono.create(sink -> {
final Context context = sink.currentContext();
assertThat(ctxExists(ctx)).isTrue();
sink.success("foo");
}).publishOn(Schedulers.single()), ctx);
}
Expand Down Expand Up @@ -166,11 +165,11 @@ void monoFirst() {
final ClientRequestContext ctx = newContext();
final Mono<String> mono;
try (SafeCloseable ignored = ctx.push()) {
mono = addCallbacks(Mono.first(Mono.delay(Duration.ofMillis(1000)).then(Mono.just("bar")),
Mono.fromCallable(() -> {
assertThat(ctxExists(ctx)).isTrue();
return "foo";
})).publishOn(Schedulers.single()), ctx);
mono = addCallbacks(Mono.firstWithSignal(Mono.delay(Duration.ofMillis(1000)).then(Mono.just("bar")),
Mono.fromCallable(() -> {
assertThat(ctxExists(ctx)).isTrue();
return "foo";
})).publishOn(Schedulers.single()), ctx);
}
StepVerifier.create(mono)
.expectSubscriptionMatches(s -> ctxExists(ctx))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ trait CommonConversions {
final class HttpResponseCompletionStageOps(private val stage: CompletionStage[HttpResponse]) extends AnyVal {

/**
* Converts this `CompletionStage` into an `HttpResponse` using `HttpResponse.from(CompletionStage)`.
* Converts this `CompletionStage` into an `HttpResponse` using `HttpResponse.of(CompletionStage)`.
*/
def toHttpResponse: HttpResponse = HttpResponse.from(stage)
def toHttpResponse: HttpResponse = HttpResponse.of(stage)
}

@UnstableApi
Expand All @@ -91,9 +91,9 @@ final class VoidCompletionStageOps(private val future: CompletionStage[Void]) ex
final class HttpResponseFutureOps(private val future: Future[HttpResponse]) extends AnyVal {

/**
* Converts this `Future` into an `HttpResponse` using `HttpResponse.from(CompletionStage)`.
* Converts this `Future` into an `HttpResponse` using `HttpResponse.of(CompletionStage)`.
*/
def toHttpResponse: HttpResponse = HttpResponse.from(FutureConverters.toJava(future))
def toHttpResponse: HttpResponse = HttpResponse.of(FutureConverters.toJava(future))
}

@UnstableApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,16 @@ void requestInvalidDemand() throws Exception {
final DataBufferFactoryWrapper<NettyDataBufferFactory> factoryWrapper = new DataBufferFactoryWrapper<>(
new NettyDataBufferFactory(PooledByteBufAllocator.DEFAULT) {
@Override
public NettyDataBuffer allocateBuffer() {
final NettyDataBuffer buffer = super.allocateBuffer();
public NettyDataBuffer allocateBuffer(int initialCapacity) {
final NettyDataBuffer buffer = super.allocateBuffer(initialCapacity);
allocatedBuffers.offer(buffer);
return buffer;
}
});
final CompletableFuture<HttpResponse> future = new CompletableFuture<>();
final ArmeriaServerHttpResponse response =
new ArmeriaServerHttpResponse(ctx, future, factoryWrapper, null);
response.writeWith(Mono.just(factoryWrapper.delegate().allocateBuffer().write("foo".getBytes())))
response.writeWith(Mono.just(factoryWrapper.delegate().allocateBuffer(3).write("foo".getBytes())))
.then(Mono.defer(response::setComplete)).subscribe();
await().until(future::isDone);
assertThat(future.isCompletedExceptionally()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void getConflict() {
final Mono<ClientResponse> response =
webClient.get()
.uri(uri("/conflict"))
.exchange();
.exchangeToMono(Mono::just);
StepVerifier.create(response)
.assertNext(r -> assertThat(r.statusCode()).isEqualTo(HttpStatus.CONFLICT))
.expectComplete()
Expand Down
Loading

0 comments on commit 3ce0a5f

Please sign in to comment.