Browse Source

Polish "Ensure that MongoClient's EventLoopGroup is shut down during context close"

See gh-16087
pull/16472/head
Andy Wilkinson 7 years ago
parent
commit
f20d9a62ae
  1. 12
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java
  2. 12
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java

12
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 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.
@ -86,19 +86,19 @@ public class MongoReactiveAutoConfiguration { @@ -86,19 +86,19 @@ public class MongoReactiveAutoConfiguration {
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public MongoClientSettingsBuilderCustomizer nettyDriverCustomizer(
public NettyDriverMongoClientSettingsBuilderCustomizer nettyDriverCustomizer(
ObjectProvider<MongoClientSettings> settings) {
return new EventLoopGroupMongoClientSettingsBuilderCustomizer(settings);
return new NettyDriverMongoClientSettingsBuilderCustomizer(settings);
}
private static final class EventLoopGroupMongoClientSettingsBuilderCustomizer
private static final class NettyDriverMongoClientSettingsBuilderCustomizer
implements MongoClientSettingsBuilderCustomizer, DisposableBean {
private final ObjectProvider<MongoClientSettings> settings;
private EventLoopGroup eventLoopGroup;
private volatile EventLoopGroup eventLoopGroup;
private EventLoopGroupMongoClientSettingsBuilderCustomizer(
private NettyDriverMongoClientSettingsBuilderCustomizer(
ObjectProvider<MongoClientSettings> settings) {
this.settings = settings;
}

12
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java

@ -91,17 +91,17 @@ public class MongoReactiveAutoConfigurationTests { @@ -91,17 +91,17 @@ public class MongoReactiveAutoConfigurationTests {
@Test
public void nettyStreamFactoryFactoryIsConfiguredAutomatically() {
AtomicReference<EventLoopGroup> capture = new AtomicReference<>();
AtomicReference<EventLoopGroup> eventLoopGroupReference = new AtomicReference<>();
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(MongoClient.class);
StreamFactoryFactory factory = getSettings(context).getStreamFactoryFactory();
assertThat(factory).isInstanceOf(NettyStreamFactoryFactory.class);
capture.set((EventLoopGroup) ReflectionTestUtils.getField(factory,
"eventLoopGroup"));
assertThat(capture.get()).isNotNull();
assertThat(capture.get().isShutdown()).isFalse();
EventLoopGroup eventLoopGroup = (EventLoopGroup) ReflectionTestUtils
.getField(factory, "eventLoopGroup");
assertThat(eventLoopGroup.isShutdown()).isFalse();
eventLoopGroupReference.set(eventLoopGroup);
});
assertThat(capture.get().isShutdown()).isTrue();
assertThat(eventLoopGroupReference.get().isShutdown()).isTrue();
}
@Test

Loading…
Cancel
Save