Skip to content

Commit

Permalink
Ensure the request counter is updated once when the request is received
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Dec 12, 2024
1 parent d473186 commit c0e1eb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,9 @@ public Context currentContext() {

@Override
public String asShortText() {
String shortId = this.shortId;
if (shortId == null) {
shortId = initShortId();
this.shortId = shortId = initShortId();
}

return shortId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ protected HttpOperations(HttpOperations<INBOUND, OUTBOUND> replaced) {
protected HttpOperations(Connection connection, ConnectionObserver listener, HttpMessageLogFactory httpMessageLogFactory) {
super(connection, listener);
this.httpMessageLogFactory = httpMessageLogFactory;
if (connection instanceof AtomicLong) {
((AtomicLong) connection).incrementAndGet();
}
}

/**
Expand Down Expand Up @@ -372,7 +375,7 @@ protected final boolean markSentHeaderAndBody(Object... objectsToRelease) {
protected final String initShortId() {
Connection connection = connection();
if (connection instanceof AtomicLong) {
return connection.channel().id().asShortText() + '-' + ((AtomicLong) connection).incrementAndGet();
return connection.channel().id().asShortText() + '-' + ((AtomicLong) connection).get();
}
return super.initShortId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -3129,7 +3130,12 @@ void testRemoveRoutes() {
@ParameterizedTest
@ValueSource(ints = {-1, 1, 2})
void testMaxKeepAliveRequests(int maxKeepAliveRequests) {
HttpServer server = createServer().handle((req, res) -> res.sendString(Mono.just("testMaxKeepAliveRequests")));
AtomicLong requestId = new AtomicLong();
HttpServer server = createServer().handle((req, res) -> {
String id = req.requestId();
requestId.set(Integer.parseInt(id.substring(id.lastIndexOf('-') + 1)));
return res.sendString(Mono.just("testMaxKeepAliveRequests"));
});
assertThat(server.configuration().maxKeepAliveRequests()).isEqualTo(-1);

server = server.maxKeepAliveRequests(maxKeepAliveRequests);
Expand All @@ -3154,17 +3160,17 @@ void testMaxKeepAliveRequests(int maxKeepAliveRequests) {
"testMaxKeepAliveRequests".equals(l.get(1).getT1());

if (maxKeepAliveRequests == -1) {
return result &&
return result && requestId.get() == 2 &&
"persistent".equals(l.get(0).getT2()) &&
"persistent".equals(l.get(1).getT2());
}
else if (maxKeepAliveRequests == 1) {
return result &&
return result && requestId.get() == 1 &&
"close".equals(l.get(0).getT2()) &&
"close".equals(l.get(1).getT2());
}
else if (maxKeepAliveRequests == 2) {
return result &&
return result && requestId.get() == 2 &&
"persistent".equals(l.get(0).getT2()) &&
"close".equals(l.get(1).getT2());
}
Expand Down

0 comments on commit c0e1eb5

Please sign in to comment.