diff --git a/src/test/java/io/r2dbc/postgresql/client/DowntimeIntegrationTests.java b/src/test/java/io/r2dbc/postgresql/client/DowntimeIntegrationTests.java index d00b52a1..1326b399 100644 --- a/src/test/java/io/r2dbc/postgresql/client/DowntimeIntegrationTests.java +++ b/src/test/java/io/r2dbc/postgresql/client/DowntimeIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,30 +32,6 @@ public class DowntimeIntegrationTests { - // Simulate server downtime, where connections are accepted and then closed immediately - static DisposableServer newServer() { - return TcpServer.create() - .doOnConnection(DisposableChannel::dispose) - .bindNow(); - } - - static PostgresqlConnectionFactory newConnectionFactory(DisposableServer server, SSLMode sslMode) { - return new PostgresqlConnectionFactory( - PostgresqlConnectionConfiguration.builder() - .host(server.host()) - .port(server.port()) - .username("test") - .sslMode(sslMode) - .build()); - } - - static void verifyError(SSLMode sslMode, Consumer assertions) { - DisposableServer server = newServer(); - PostgresqlConnectionFactory connectionFactory = newConnectionFactory(server, sslMode); - connectionFactory.create().as(StepVerifier::create).verifyErrorSatisfies(assertions); - server.disposeNow(); - } - @Test void failSslHandshakeIfInboundClosed() { verifyError(SSLMode.REQUIRE, error -> @@ -72,11 +48,38 @@ void failSslTunnelIfInboundClosed() { .cause() .isInstanceOf(ClosedChannelException.class); - assertThat(error.getCause().getSuppressed().length).isOne(); + assertThat(error.getCause().getSuppressed()).hasSize(1); assertThat(error.getCause().getSuppressed()[0]) .hasMessage("Connection closed while SSL/TLS handshake was in progress"); }); } + // Simulate server downtime, where connections are accepted and then closed immediately + static DisposableServer newServer() { + return TcpServer.create() + .doOnConnection(DisposableChannel::dispose) + .bindNow(); + } + + static PostgresqlConnectionFactory newConnectionFactory(DisposableServer server, SSLMode sslMode) { + return new PostgresqlConnectionFactory( + PostgresqlConnectionConfiguration.builder() + .host(server.host()) + .port(server.port()) + .username("test") + .sslMode(sslMode) + .build()); + } + + static void verifyError(SSLMode sslMode, Consumer assertions) { + DisposableServer server = newServer(); + PostgresqlConnectionFactory connectionFactory = newConnectionFactory(server, sslMode); + try { + connectionFactory.create().as(StepVerifier::create).verifyErrorSatisfies(assertions); + } finally { + server.disposeNow(); + } + } + }