Skip to content

Commit

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

* Fixes #5931 - SslConnection should implement getBytesIn()/getBytesOut().

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

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet authored Jun 3, 2021
1 parent 121d8c2 commit f902d12
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@

import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.ClientConnectionFactory;
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 @@ -1003,4 +1006,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 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 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())
.header(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());
}
}
6 changes: 6 additions & 0 deletions jetty-io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
Expand Down
Loading

0 comments on commit f902d12

Please sign in to comment.