Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/io/vertx/core/net/impl/TCPServerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public void updateTrafficShapingOptions(TrafficShapingOptions options) {
if (options == null) {
throw new IllegalArgumentException("Invalid null value passed for traffic shaping options update");
}
if (!listening) {
throw new IllegalStateException("Listening initialization not completed yet");
}
TCPServerBase server = actualServer;
// Update the traffic shaping options only for the actual/main server
if (server != null && server != this) {
Expand Down Expand Up @@ -189,7 +192,6 @@ private synchronized Future<Channel> listen(SocketAddress localAddress, ContextI
}

this.listenContext = context;
this.listening = true;
this.eventLoop = context.nettyEventLoop();

SocketAddress bindAddress;
Expand Down Expand Up @@ -285,7 +287,7 @@ private synchronized Future<Channel> listen(SocketAddress localAddress, ContextI
}
listening = false;
});

this.listening = true;
return bindFuture;
} else {
// Server already exists with that host/port - we will use that
Expand All @@ -298,6 +300,7 @@ private synchronized Future<Channel> listen(SocketAddress localAddress, ContextI
actualServer.channelBalancer.addWorker(eventLoop, worker);
listenContext.addCloseHook(this);
main.bindFuture.onComplete(promise);
this.listening = true;
return promise.future();
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/test/java/io/vertx/core/http/HttpBandwidthLimitingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,28 +213,26 @@ public void testDynamicOutboundRateUpdateSharedServers() throws IOException, Int
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).onComplete(res -> {
if (res.succeeded()) {
servers.add(testServer);
// Apply traffic shaping options after the server has started
TrafficShapingOptions updatedTrafficOptions = new TrafficShapingOptions()
.setInboundGlobalBandwidth(INBOUND_LIMIT)
.setOutboundGlobalBandwidth(2 * OUTBOUND_LIMIT);

List<Promise<Void>> promises = new ArrayList<>();
for (int i = 0; i < numEventLoops; i++) {
servers.forEach(s -> {
Promise<Void> promise = Promise.promise();
try {
s.updateTrafficShapingOptions(updatedTrafficOptions);
promise.complete();
} catch (Exception e) {
promise.fail(e);
}
promises.add(promise);
});
}
servers.forEach(s -> {
Promise<Void> promise = Promise.promise();
try {
s.updateTrafficShapingOptions(updatedTrafficOptions);
promise.complete();
} catch (Exception e) {
promise.fail(e);
}
promises.add(promise);
});
// Ensure all traffic shaping updates complete before resolving the startPromise
Future.all(promises.stream().map(Promise::future).collect(Collectors.toList()))
.onSuccess(v -> startPromise.complete())
Expand Down
Loading