Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunashok committed Jan 9, 2025
1 parent 77d4bbe commit d953175
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/test/java/io/vertx/core/http/HttpBandwidthLimitingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -208,15 +209,30 @@ public void start(Promise<Void> startPromise) {
@Test
public void testDynamicOutboundRateUpdateSharedServers() throws IOException, InterruptedException
{
int numEventLoops = 5; // We start a shared TCP server with 2 event-loops
List<HttpServer> servers = new ArrayList<>();
int numEventLoops = 5; // We start a shared TCP server with 5 event-loops
List<HttpServer> servers = Collections.synchronizedList(new ArrayList<>());
Future<String> listenLatch = vertx.deployVerticle(() -> new AbstractVerticle() {
@Override
public void start(Promise<Void> startPromise) {
public void start(Promise<Void> startPromise) throws Exception
{
HttpServer testServer = serverFactory.apply(vertx);
servers.add(testServer);
testServer.requestHandler(HANDLERS.getFile(sampleF))
.listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST).<Void>mapEmpty().onComplete(startPromise);
.listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST).onComplete(res -> {
if (res.succeeded()) {
// Apply traffic shaping options after the server has started
TrafficShapingOptions updatedTrafficOptions = new TrafficShapingOptions()
.setInboundGlobalBandwidth(INBOUND_LIMIT)
.setOutboundGlobalBandwidth(2 * OUTBOUND_LIMIT);

for (int i = 0; i < numEventLoops; i++) {
servers.forEach(s -> s.updateTrafficShapingOptions(updatedTrafficOptions));
}
startPromise.complete();
} else {
startPromise.fail(res.cause());
}
});
}
}, new DeploymentOptions().setInstances(numEventLoops));

Expand All @@ -241,16 +257,9 @@ public void start(Promise<Void> startPromise) {
}
}));
awaitLatch(waitForResponse);
TrafficShapingOptions updatedTrafficOptions = new TrafficShapingOptions()
.setInboundGlobalBandwidth(INBOUND_LIMIT) // unchanged
.setOutboundGlobalBandwidth(2 * OUTBOUND_LIMIT);

for (int i = 0; i < numEventLoops; i++) {
servers.forEach(s -> s.updateTrafficShapingOptions(updatedTrafficOptions));
}

long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime.get());
Assert.assertTrue(elapsedMillis > expectedTimeMillis(totalReceivedLength.get(), OUTBOUND_LIMIT));
Assert.assertTrue(elapsedMillis < expectedUpperBoundTimeMillis(totalReceivedLength.get(), OUTBOUND_LIMIT));
}

@Test
Expand Down

0 comments on commit d953175

Please sign in to comment.