Skip to content

Commit

Permalink
Use MemorySize in Rest Client maxChunkSize
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Dec 20, 2023
1 parent 8a991b3 commit ef70f02
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.quarkus.runtime.annotations.ConfigDocDefault;
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.configuration.MemorySize;
import io.smallrye.config.SmallRyeConfig;

@ConfigGroup
Expand Down Expand Up @@ -258,8 +259,8 @@ public class RestClientConfig {
* This property is applicable to reactive REST clients only.
*/
@ConfigItem
@ConfigDocDefault("8096")
public Optional<Integer> maxChunkSize;
@ConfigDocDefault("8K")
public Optional<MemorySize> maxChunkSize;

/**
* If the Application-Layer Protocol Negotiation is enabled, the client will negotiate which protocol to use over the
Expand Down Expand Up @@ -308,7 +309,7 @@ public static RestClientConfig load(String configKey) {
instance.name = getConfigValue(configKey, "name", String.class);
instance.userAgent = getConfigValue(configKey, "user-agent", String.class);
instance.http2 = getConfigValue(configKey, "http2", Boolean.class);
instance.maxChunkSize = getConfigValue(configKey, "max-chunk-size", Integer.class);
instance.maxChunkSize = getConfigValue(configKey, "max-chunk-size", MemorySize.class);
instance.captureStacktrace = getConfigValue(configKey, "capture-stacktrace", Boolean.class);

instance.multipart = new RestClientMultipartConfig();
Expand Down Expand Up @@ -348,7 +349,7 @@ public static RestClientConfig load(Class<?> interfaceClass) {
instance.name = getConfigValue(interfaceClass, "name", String.class);
instance.userAgent = getConfigValue(interfaceClass, "user-agent", String.class);
instance.http2 = getConfigValue(interfaceClass, "http2", Boolean.class);
instance.maxChunkSize = getConfigValue(interfaceClass, "max-chunk-size", Integer.class);
instance.maxChunkSize = getConfigValue(interfaceClass, "max-chunk-size", MemorySize.class);
instance.alpn = getConfigValue(interfaceClass, "alpn", Boolean.class);
instance.captureStacktrace = getConfigValue(interfaceClass, "capture-stacktrace", Boolean.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.configuration.MemorySize;

@ConfigRoot(name = "rest-client", phase = ConfigPhase.RUN_TIME)
public class RestClientsConfig {
Expand Down Expand Up @@ -299,8 +300,8 @@ public class RestClientsConfig {
* Can be overwritten by client-specific settings.
*/
@ConfigItem
@ConfigDocDefault("8096")
public Optional<Integer> maxChunkSize;
@ConfigDocDefault("8k")
public Optional<MemorySize> maxChunkSize;

/**
* If the Application-Layer Protocol Negotiation is enabled, the client will negotiate which protocol to use over the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.math.BigInteger;
import java.net.URL;
import java.util.Optional;

Expand Down Expand Up @@ -51,7 +52,7 @@ private void verifyConfig(RestClientConfig config) {
assertThat(config.connectionTTL.get()).isEqualTo(30000);
assertThat(config.connectionPoolSize).isPresent();
assertThat(config.connectionPoolSize.get()).isEqualTo(10);
assertThat(config.maxChunkSize.get()).isEqualTo(1024);
assertThat(config.maxChunkSize.get().asBigInteger()).isEqualTo(BigInteger.valueOf(1024));
}

private static SmallRyeConfig createMPConfig() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
if (maxChunkSize != null) {
clientBuilder.maxChunkSize(maxChunkSize);
} else if (restClientsConfig.maxChunkSize.isPresent()) {
clientBuilder.maxChunkSize(restClientsConfig.maxChunkSize.get());
clientBuilder.maxChunkSize((int) restClientsConfig.maxChunkSize.get().asLongValue());
} else if (restClientsConfig.multipart.maxChunkSize.isPresent()) {
clientBuilder.maxChunkSize(restClientsConfig.multipart.maxChunkSize.get());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import javax.net.ssl.HostnameVerifier;

Expand All @@ -28,6 +29,7 @@
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder;
import io.quarkus.restclient.config.RestClientConfig;
import io.quarkus.restclient.config.RestClientsConfig;
import io.quarkus.runtime.configuration.MemorySize;

public class RestClientCDIDelegateBuilder<T> {

Expand Down Expand Up @@ -123,11 +125,11 @@ private void configureCustomProperties(QuarkusRestClientBuilder builder) {
}

Optional<Integer> maxChunkSize = oneOf(
clientConfigByClassName().maxChunkSize,
clientConfigByClassName().maxChunkSize.map(intChunkSize()),
clientConfigByClassName().multipart.maxChunkSize,
clientConfigByConfigKey().maxChunkSize,
clientConfigByConfigKey().maxChunkSize.map(intChunkSize()),
clientConfigByConfigKey().multipart.maxChunkSize,
configRoot.maxChunkSize,
configRoot.maxChunkSize.map(intChunkSize()),
configRoot.multipart.maxChunkSize);
builder.property(QuarkusRestClientProperties.MAX_CHUNK_SIZE, maxChunkSize.orElse(DEFAULT_MAX_CHUNK_SIZE));

Expand All @@ -146,6 +148,10 @@ private void configureCustomProperties(QuarkusRestClientBuilder builder) {
builder.property(QuarkusRestClientProperties.CAPTURE_STACKTRACE, captureStacktrace);
}

private static Function<MemorySize, Integer> intChunkSize() {
return m -> (int) m.asLongValue();
}

private void configureProxy(QuarkusRestClientBuilder builder) {
Optional<String> maybeProxy = oneOf(clientConfigByClassName().proxyAddress, clientConfigByConfigKey().proxyAddress,
configRoot.proxyAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -29,6 +30,7 @@
import io.quarkus.restclient.config.RestClientConfig;
import io.quarkus.restclient.config.RestClientMultipartConfig;
import io.quarkus.restclient.config.RestClientsConfig;
import io.quarkus.runtime.configuration.MemorySize;

@SuppressWarnings({ "SameParameterValue" })
public class RestClientCDIDelegateBuilderTest {
Expand Down Expand Up @@ -189,6 +191,7 @@ private static RestClientsConfig createSampleConfigRoot() {
configRoot.multipart = new RestClientMultipartConfig();
configRoot.multipart.maxChunkSize = Optional.of(1024);
configRoot.followRedirects = Optional.of(true);
configRoot.maxChunkSize = Optional.of(new MemorySize(BigInteger.valueOf(1024)));
configRoot.providers = Optional
.of("io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilderTest$MyResponseFilter2");
configRoot.queryParamStyle = Optional.of(QueryParamStyle.MULTI_PAIRS);
Expand Down Expand Up @@ -227,7 +230,7 @@ private static RestClientConfig createSampleClientConfig() {
clientConfig.maxRedirects = Optional.of(104);
clientConfig.followRedirects = Optional.of(true);
clientConfig.multipart = new RestClientMultipartConfig();
clientConfig.maxChunkSize = Optional.of(1024);
clientConfig.maxChunkSize = Optional.of(new MemorySize(BigInteger.valueOf(1024)));
clientConfig.providers = Optional
.of("io.quarkus.rest.client.reactive.runtime.RestClientCDIDelegateBuilderTest$MyResponseFilter1");
clientConfig.queryParamStyle = Optional.of(QueryParamStyle.COMMA_SEPARATED);
Expand Down

0 comments on commit ef70f02

Please sign in to comment.