Skip to content

Commit 0d612f8

Browse files
committed
Polishing.
[#595][#596] Signed-off-by: Mark Paluch <[email protected]>
1 parent b402400 commit 0d612f8

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/test/java/io/r2dbc/postgresql/client/DowntimeIntegrationTests.java

+29-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,30 +32,6 @@
3232

3333
public class DowntimeIntegrationTests {
3434

35-
// Simulate server downtime, where connections are accepted and then closed immediately
36-
static DisposableServer newServer() {
37-
return TcpServer.create()
38-
.doOnConnection(DisposableChannel::dispose)
39-
.bindNow();
40-
}
41-
42-
static PostgresqlConnectionFactory newConnectionFactory(DisposableServer server, SSLMode sslMode) {
43-
return new PostgresqlConnectionFactory(
44-
PostgresqlConnectionConfiguration.builder()
45-
.host(server.host())
46-
.port(server.port())
47-
.username("test")
48-
.sslMode(sslMode)
49-
.build());
50-
}
51-
52-
static void verifyError(SSLMode sslMode, Consumer<Throwable> assertions) {
53-
DisposableServer server = newServer();
54-
PostgresqlConnectionFactory connectionFactory = newConnectionFactory(server, sslMode);
55-
connectionFactory.create().as(StepVerifier::create).verifyErrorSatisfies(assertions);
56-
server.disposeNow();
57-
}
58-
5935
@Test
6036
void failSslHandshakeIfInboundClosed() {
6137
verifyError(SSLMode.REQUIRE, error ->
@@ -72,11 +48,38 @@ void failSslTunnelIfInboundClosed() {
7248
.cause()
7349
.isInstanceOf(ClosedChannelException.class);
7450

75-
assertThat(error.getCause().getSuppressed().length).isOne();
51+
assertThat(error.getCause().getSuppressed()).hasSize(1);
7652

7753
assertThat(error.getCause().getSuppressed()[0])
7854
.hasMessage("Connection closed while SSL/TLS handshake was in progress");
7955
});
8056
}
8157

58+
// Simulate server downtime, where connections are accepted and then closed immediately
59+
static DisposableServer newServer() {
60+
return TcpServer.create()
61+
.doOnConnection(DisposableChannel::dispose)
62+
.bindNow();
63+
}
64+
65+
static PostgresqlConnectionFactory newConnectionFactory(DisposableServer server, SSLMode sslMode) {
66+
return new PostgresqlConnectionFactory(
67+
PostgresqlConnectionConfiguration.builder()
68+
.host(server.host())
69+
.port(server.port())
70+
.username("test")
71+
.sslMode(sslMode)
72+
.build());
73+
}
74+
75+
static void verifyError(SSLMode sslMode, Consumer<Throwable> assertions) {
76+
DisposableServer server = newServer();
77+
PostgresqlConnectionFactory connectionFactory = newConnectionFactory(server, sslMode);
78+
try {
79+
connectionFactory.create().as(StepVerifier::create).verifyErrorSatisfies(assertions);
80+
} finally {
81+
server.disposeNow();
82+
}
83+
}
84+
8285
}

0 commit comments

Comments
 (0)