Polish
This commit is contained in:
parent
4c71e8124d
commit
faeda6f917
|
|
@ -221,10 +221,9 @@ public final class ConnectionFactoryBuilder {
|
||||||
String[] protocols = protocol.split(COLON, 2);
|
String[] protocols = protocol.split(COLON, 2);
|
||||||
String driverDelegate = protocols[0];
|
String driverDelegate = protocols[0];
|
||||||
String protocolDelegate = (protocols.length != 2) ? "" : protocols[1];
|
String protocolDelegate = (protocols.length != 2) ? "" : protocols[1];
|
||||||
ConnectionFactoryOptions newOptions = ConnectionFactoryOptions.builder().from(options)
|
return ConnectionFactoryOptions.builder().from(options)
|
||||||
.option(ConnectionFactoryOptions.DRIVER, driverDelegate)
|
.option(ConnectionFactoryOptions.DRIVER, driverDelegate)
|
||||||
.option(ConnectionFactoryOptions.PROTOCOL, protocolDelegate).build();
|
.option(ConnectionFactoryOptions.PROTOCOL, protocolDelegate).build();
|
||||||
return newOptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionPoolConfiguration connectionPoolConfiguration(ConnectionFactoryOptions options,
|
ConnectionPoolConfiguration connectionPoolConfiguration(ConnectionFactoryOptions options,
|
||||||
|
|
@ -253,8 +252,7 @@ public final class ConnectionFactoryBuilder {
|
||||||
map.from(options.getValue(PoolingConnectionFactoryProvider.VALIDATION_QUERY)).to(builder::validationQuery);
|
map.from(options.getValue(PoolingConnectionFactoryProvider.VALIDATION_QUERY)).to(builder::validationQuery);
|
||||||
map.from((Object) options.getValue(PoolingConnectionFactoryProvider.VALIDATION_DEPTH))
|
map.from((Object) options.getValue(PoolingConnectionFactoryProvider.VALIDATION_DEPTH))
|
||||||
.as(this::toValidationDepth).to(builder::validationDepth);
|
.as(this::toValidationDepth).to(builder::validationDepth);
|
||||||
ConnectionPoolConfiguration build = builder.build();
|
return builder.build();
|
||||||
return build;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer toInteger(Object object) {
|
private Integer toInteger(Object object) {
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ class ConnectionFactoryBuilderTests {
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@MethodSource("poolingConnectionProviderOptions")
|
@MethodSource("poolingConnectionProviderOptions")
|
||||||
void optionIsMappedWhenCreatingPoolConfiguration(Option option) {
|
void optionIsMappedWhenCreatingPoolConfiguration(Option option) {
|
||||||
String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID().toString();
|
String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID();
|
||||||
ExpectedOption expectedOption = ExpectedOption.get(option);
|
ExpectedOption expectedOption = ExpectedOption.get(option);
|
||||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url).configure((builder) -> builder
|
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url).configure((builder) -> builder
|
||||||
.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName").option(option, expectedOption.value))
|
.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName").option(option, expectedOption.value))
|
||||||
|
|
@ -202,7 +202,7 @@ class ConnectionFactoryBuilderTests {
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@MethodSource("poolingConnectionProviderOptions")
|
@MethodSource("poolingConnectionProviderOptions")
|
||||||
void stringlyTypedOptionIsMappedWhenCreatingPoolConfiguration(Option option) {
|
void stringlyTypedOptionIsMappedWhenCreatingPoolConfiguration(Option option) {
|
||||||
String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID().toString();
|
String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID();
|
||||||
ExpectedOption expectedOption = ExpectedOption.get(option);
|
ExpectedOption expectedOption = ExpectedOption.get(option);
|
||||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url)
|
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url)
|
||||||
.configure((builder) -> builder.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName")
|
.configure((builder) -> builder.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName")
|
||||||
|
|
@ -213,6 +213,14 @@ class ConnectionFactoryBuilderTests {
|
||||||
assertThat(configuration).extracting(expectedOption.property).isEqualTo(expectedOption.value);
|
assertThat(configuration).extracting(expectedOption.property).isEqualTo(expectedOption.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Iterable<Arguments> poolingConnectionProviderOptions() {
|
||||||
|
List<Arguments> arguments = new ArrayList<>();
|
||||||
|
ReflectionUtils.doWithFields(PoolingConnectionFactoryProvider.class,
|
||||||
|
(field) -> arguments.add(Arguments.of(ReflectionUtils.getField(field, null))),
|
||||||
|
(field) -> Option.class.equals(field.getType()));
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
|
||||||
private void assertMatchingOptions(ConnectionFactoryOptions actualOptions, ConnectionFactoryOptions expectedOptions,
|
private void assertMatchingOptions(ConnectionFactoryOptions actualOptions, ConnectionFactoryOptions expectedOptions,
|
||||||
Option<?>... optionsToCheck) {
|
Option<?>... optionsToCheck) {
|
||||||
for (Option<?> option : optionsToCheck) {
|
for (Option<?> option : optionsToCheck) {
|
||||||
|
|
@ -220,14 +228,6 @@ class ConnectionFactoryBuilderTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Iterable<Arguments> poolingConnectionProviderOptions() {
|
|
||||||
List<Arguments> arguments = new ArrayList<>();
|
|
||||||
ReflectionUtils.doWithFields(PoolingConnectionFactoryProvider.class,
|
|
||||||
(field) -> arguments.add(Arguments.of((Option<?>) ReflectionUtils.getField(field, null))),
|
|
||||||
(field) -> Option.class.equals(field.getType()));
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum ExpectedOption {
|
private enum ExpectedOption {
|
||||||
|
|
||||||
ACQUIRE_RETRY(PoolingConnectionFactoryProvider.ACQUIRE_RETRY, 4, "acquireRetry"),
|
ACQUIRE_RETRY(PoolingConnectionFactoryProvider.ACQUIRE_RETRY, 4, "acquireRetry"),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue