Skip to content

Commit 0bdcca5

Browse files
committed
Add BlockHound to integration tests
Eagerly initialize Schedulers to avoid blocking calls in TzdbZoneRulesProvider. [closes #276]
1 parent c0d01c7 commit 0bdcca5

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
<properties>
3535
<assertj.version>3.15.0</assertj.version>
36+
<blockhound.version>1.0.3.RELEASE</blockhound.version>
3637
<hikari-cp.version>3.4.2</hikari-cp.version>
3738
<java.version>1.8</java.version>
3839
<jsr305.version>3.0.2</jsr305.version>
@@ -161,6 +162,18 @@
161162
<artifactId>reactor-test</artifactId>
162163
<scope>test</scope>
163164
</dependency>
165+
<dependency>
166+
<groupId>io.projectreactor.tools</groupId>
167+
<artifactId>blockhound</artifactId>
168+
<version>${blockhound.version}</version>
169+
<scope>test</scope>
170+
</dependency>
171+
<dependency>
172+
<groupId>io.projectreactor.tools</groupId>
173+
<artifactId>blockhound-junit-platform</artifactId>
174+
<version>${blockhound.version}</version>
175+
<scope>test</scope>
176+
</dependency>
164177
<dependency>
165178
<groupId>io.r2dbc</groupId>
166179
<artifactId>r2dbc-spi-test</artifactId>

src/main/java/io/r2dbc/postgresql/client/ReactorNettyClient.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import reactor.core.publisher.FluxSink;
5858
import reactor.core.publisher.Mono;
5959
import reactor.core.publisher.Operators;
60+
import reactor.core.scheduler.Schedulers;
6061
import reactor.netty.Connection;
6162
import reactor.netty.resources.ConnectionProvider;
6263
import reactor.netty.resources.LoopResources;
@@ -124,6 +125,12 @@ public final class ReactorNettyClient implements Client {
124125

125126
private volatile Version version = new Version("", 0);
126127

128+
static {
129+
130+
// eagerly initialize the scheduler to avoid blocking calls due to TimeZoneDB retrieval
131+
Schedulers.boundedElastic();
132+
}
133+
127134
/**
128135
* Creates a new frame processor connected to a given TCP connection.
129136
*
@@ -369,10 +376,19 @@ public static Mono<ReactorNettyClient> connect(ConnectionProvider connectionProv
369376

370377
private static Mono<? extends Void> registerSslHandler(SSLConfig sslConfig, Connection it) {
371378

372-
if (sslConfig.getSslMode().startSsl()) {
373-
SSLSessionHandlerAdapter sslSessionHandlerAdapter = new SSLSessionHandlerAdapter(it.outbound().alloc(), sslConfig);
374-
it.addHandlerFirst(sslSessionHandlerAdapter);
375-
return sslSessionHandlerAdapter.getHandshake();
379+
try {
380+
if (sslConfig.getSslMode().startSsl()) {
381+
382+
return Mono.defer(() -> {
383+
SSLSessionHandlerAdapter sslSessionHandlerAdapter = new SSLSessionHandlerAdapter(it.outbound().alloc(), sslConfig);
384+
it.addHandlerFirst(sslSessionHandlerAdapter);
385+
return sslSessionHandlerAdapter.getHandshake();
386+
387+
}).subscribeOn(Schedulers.boundedElastic());
388+
}
389+
} catch (Throwable e) {
390+
e.printStackTrace();
391+
throw new RuntimeException(e);
376392
}
377393

378394
return Mono.empty();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.r2dbc.postgresql.util;
18+
19+
import reactor.blockhound.BlockHound;
20+
import reactor.blockhound.integration.BlockHoundIntegration;
21+
22+
import java.security.SecureRandom;
23+
24+
public class BlockhoundExceptions implements BlockHoundIntegration {
25+
26+
@Override
27+
public void applyTo(BlockHound.Builder builder) {
28+
builder.allowBlockingCallsInside(SecureRandom.class.getName(), "next");
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.r2dbc.postgresql.util.BlockhoundExceptions

0 commit comments

Comments
 (0)