-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Increase default pool size in Rest Client Reactive #20977
Merged
geoand
merged 1 commit into
quarkusio:main
from
michalszynkiewicz:inc-default-conn-size-rcr
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
...tive/deployment/src/test/java/io/quarkus/rest/client/reactive/ConnectionPoolSizeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package io.quarkus.rest.client.reactive; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.RestClientBuilder; | ||
import org.jboss.resteasy.reactive.client.api.QuarkusRestClientProperties; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.rest.client.reactive.headers.ClientHeaderParamFromPropertyTest; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.core.Vertx; | ||
|
||
public class ConnectionPoolSizeTest { | ||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClasses(ClientHeaderParamFromPropertyTest.Client.class)); | ||
|
||
@TestHTTPResource | ||
URI uri; | ||
|
||
@Test | ||
void shouldPerform20CallsWithoutQueuing() throws InterruptedException { | ||
Client client = RestClientBuilder.newBuilder().baseUri(uri) | ||
.build(Client.class); | ||
|
||
CountDownLatch latch = executeCalls(client, 20); | ||
|
||
assertThat(latch.await(2, TimeUnit.SECONDS)) | ||
.overridingErrorMessage("Failed to do 20 calls in 2 seconds") | ||
.isTrue(); | ||
} | ||
|
||
@Test | ||
@Timeout(5) | ||
void shouldPerform21CallsWithQueuing() throws InterruptedException { | ||
Client client = RestClientBuilder.newBuilder().baseUri(uri) | ||
.build(Client.class); | ||
|
||
long start = System.currentTimeMillis(); | ||
CountDownLatch latch = executeCalls(client, 21); | ||
latch.await(); | ||
|
||
assertThat(System.currentTimeMillis() - start).isLessThan(3000).isGreaterThanOrEqualTo(2000); | ||
} | ||
|
||
@Test | ||
@Timeout(5) | ||
void shouldPerform5CallsWithoutQueueingOnQueue6() throws InterruptedException { | ||
Client client = RestClientBuilder.newBuilder().baseUri(uri) | ||
.property(QuarkusRestClientProperties.CONNECTION_POOL_SIZE, 6) | ||
.build(Client.class); | ||
|
||
long start = System.currentTimeMillis(); | ||
CountDownLatch latch = executeCalls(client, 5); | ||
latch.await(); | ||
|
||
assertThat(System.currentTimeMillis() - start).isLessThan(2000); | ||
} | ||
|
||
@Test | ||
@Timeout(5) | ||
void shouldPerform5CallsWithQueueingOnQueue4() throws InterruptedException { | ||
Client client = RestClientBuilder.newBuilder().baseUri(uri) | ||
.property(QuarkusRestClientProperties.CONNECTION_POOL_SIZE, 4) | ||
.build(Client.class); | ||
|
||
long start = System.currentTimeMillis(); | ||
CountDownLatch latch = executeCalls(client, 5); | ||
latch.await(); | ||
|
||
assertThat(System.currentTimeMillis() - start).isLessThan(3000).isGreaterThanOrEqualTo(2000); | ||
} | ||
|
||
private CountDownLatch executeCalls(Client client, int callAmount) { | ||
ExecutorService executorService = Executors.newFixedThreadPool(callAmount); | ||
CountDownLatch latch = new CountDownLatch(callAmount); | ||
for (int i = 0; i < callAmount; i++) { | ||
executorService.execute(() -> { | ||
String result = client.get(); | ||
latch.countDown(); | ||
assertThat(result).isEqualTo("hello, world!"); | ||
}); | ||
} | ||
return latch; | ||
} | ||
|
||
@Path("/hello") | ||
public interface Client { | ||
@GET | ||
String get(); | ||
} | ||
|
||
@Path("/hello") | ||
public static class SlowResource { | ||
@Inject | ||
Vertx vertx; | ||
|
||
@GET | ||
public Uni<String> getSlowly() { | ||
return Uni.createFrom().emitter(emitter -> vertx.setTimer(1000 /* ms */, | ||
val -> emitter.complete("hello, world!"))); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something tells me that these tests are going to a little flaky on CI, but let's see how it goes :)