Skip to content

Commit

Permalink
Fixes #5931 - SslConnection should implement getBytesIn()/getBytesOut…
Browse files Browse the repository at this point in the history
…(). (#6335)

Updated ConnectionStatistics to report both the stats of all connections,
and the stats grouped by connection class.

Signed-off-by: Simone Bordet <[email protected]>
(cherry picked from commit f902d12)
  • Loading branch information
sbordet committed Jun 3, 2021
1 parent 9464c39 commit 6c52326
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.ClientConnectionFactory;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
import org.eclipse.jetty.io.ssl.SslConnection;
Expand Down Expand Up @@ -1019,4 +1021,49 @@ public void testForcedNonDomainSNI() throws Exception
assertEquals(HttpStatus.OK_200, response3.getStatus());
}
}

@Test
public void testBytesInBytesOut() throws Exception
{
// Two connections will be closed: SslConnection and HttpConnection.
// Two on the server, two on the client.
CountDownLatch latch = new CountDownLatch(4);
SslContextFactory.Server serverTLSFactory = createServerSslContextFactory();
startServer(serverTLSFactory, new EmptyServerHandler());
ConnectionStatistics serverStats = new ConnectionStatistics()
{
@Override
public void onClosed(Connection connection)
{
super.onClosed(connection);
latch.countDown();
}
};
connector.addManaged(serverStats);

SslContextFactory.Client clientTLSFactory = createClientSslContextFactory();
startClient(clientTLSFactory);
ConnectionStatistics clientStats = new ConnectionStatistics()
{
@Override
public void onClosed(Connection connection)
{
super.onClosed(connection);
latch.countDown();
}
};
client.addManaged(clientStats);

ContentResponse response = client.newRequest("https://localhost:" + connector.getLocalPort())
.headers(httpFields -> httpFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString()))
.send();
assertEquals(HttpStatus.OK_200, response.getStatus());

assertTrue(latch.await(5, TimeUnit.SECONDS));

assertThat(clientStats.getSentBytes(), Matchers.greaterThan(0L));
assertEquals(clientStats.getSentBytes(), serverStats.getReceivedBytes());
assertThat(clientStats.getReceivedBytes(), Matchers.greaterThan(0L));
assertEquals(clientStats.getReceivedBytes(), serverStats.getSentBytes());
}
}
10 changes: 8 additions & 2 deletions jetty-io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
<spotbugs.onlyAnalyze>org.eclipse.jetty.io.*</spotbugs.onlyAnalyze>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand Down
3 changes: 3 additions & 0 deletions jetty-io/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@

requires transitive org.eclipse.jetty.util;
requires org.slf4j;

// Only required if using JMX.
requires static org.eclipse.jetty.jmx;
}
Loading

0 comments on commit 6c52326

Please sign in to comment.