Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HttpConnectionProvider mutate method (#2463) #2463

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -262,9 +262,8 @@ default Map<SocketAddress, Integer> maxConnectionsPerHost() {
* @return a builder to mutate properties of this {@link ConnectionProvider}
* @since 1.0.14
*/
@Nullable
default Builder mutate() {
return null;
return new Builder("");
}

/**
Expand Down
Expand Up @@ -56,6 +56,15 @@ else if (http1ConnectionProvider == null) {
}
}

@Override
public Builder mutate() {
if (this.http1ConnectionProvider == null) {
return ConnectionProvider.super.mutate();
}

return this.http1ConnectionProvider.mutate();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that I haven't considered h2ConnectionProvider yet.
I'd like to hear the opinion of the maintainer.

}

@Override
public void disposeWhen(SocketAddress address) {
http1ConnectionProvider().disposeWhen(address);
Expand Down
Expand Up @@ -92,4 +92,64 @@ void maxConnectionsPerHostDefaultConnectionProvider() {
.isEqualTo(HttpResources.get().getOrCreateHttp2ConnectionProvider(HTTP2_CONNECTION_PROVIDER_FACTORY)
.maxConnectionsPerHost());
}

@Test
void configuredConnectionProviderShouldReturnTheOriginalConnectionProvider() {
ConnectionProvider provider = ConnectionProvider.create("provider");
try {
HttpClient client = HttpClient.create(provider);
HttpConnectionProvider configuredConnectionProvider =
(HttpConnectionProvider) client.configuration().connectionProvider();
assertThat(provider.getClass().getName())
.isEqualTo(configuredConnectionProvider.http1ConnectionProvider.getClass().getName());
}
finally {
provider.disposeLater()
.block(Duration.ofSeconds(5));
}
}

@Test
void mergeConnectionProviderUsingMutate() {
ConnectionProvider beforeProvider = ConnectionProvider
.builder("beforeProvider")
.maxConnections(1)
.disposeTimeout(Duration.ofSeconds(1L))
.pendingAcquireTimeout(Duration.ofSeconds(1L))
.maxIdleTime(Duration.ofSeconds(1L))
.maxLifeTime(Duration.ofSeconds(10L))
.lifo()
.build();
HttpClient client1 = HttpClient.create(beforeProvider);

ConnectionProvider mergedProvider = client1.configuration().connectionProvider()
.mutate()
.pendingAcquireTimeout(Duration.ofSeconds(2L))
.maxIdleTime(Duration.ofSeconds(2L))
.maxLifeTime(Duration.ofSeconds(20L))
.build();

assertThat(beforeProvider.maxConnections()).isEqualTo(mergedProvider.maxConnections());
assertThat(beforeProvider.name()).isEqualTo(mergedProvider.name());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to compare more values, but it was inaccessible.


beforeProvider.disposeLater().block(Duration.ofSeconds(5));
mergedProvider.disposeLater().block(Duration.ofSeconds(5));
}

@Test
void mergeDefaultConnectionProviderUsingMutate() {
HttpClient client = HttpClient.create();

ConnectionProvider mergedProvider = client.configuration().connectionProvider()
.mutate()
.name("mergedProvider")
.pendingAcquireTimeout(Duration.ofSeconds(2L))
.maxIdleTime(Duration.ofSeconds(2L))
.maxLifeTime(Duration.ofSeconds(20L))
.build();

assertThat(mergedProvider.name()).isEqualTo("mergedProvider");

mergedProvider.disposeLater().block(Duration.ofSeconds(5));
}
}