Skip to content

Commit f20d9a6

Browse files
committed
Polish "Ensure that MongoClient's EventLoopGroup is shut down during context close"
See gh-16087
1 parent ee7bed1 commit f20d9a6

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -86,19 +86,19 @@ static class NettyDriverConfiguration {
8686

8787
@Bean
8888
@Order(Ordered.HIGHEST_PRECEDENCE)
89-
public MongoClientSettingsBuilderCustomizer nettyDriverCustomizer(
89+
public NettyDriverMongoClientSettingsBuilderCustomizer nettyDriverCustomizer(
9090
ObjectProvider<MongoClientSettings> settings) {
91-
return new EventLoopGroupMongoClientSettingsBuilderCustomizer(settings);
91+
return new NettyDriverMongoClientSettingsBuilderCustomizer(settings);
9292
}
9393

94-
private static final class EventLoopGroupMongoClientSettingsBuilderCustomizer
94+
private static final class NettyDriverMongoClientSettingsBuilderCustomizer
9595
implements MongoClientSettingsBuilderCustomizer, DisposableBean {
9696

9797
private final ObjectProvider<MongoClientSettings> settings;
9898

99-
private EventLoopGroup eventLoopGroup;
99+
private volatile EventLoopGroup eventLoopGroup;
100100

101-
private EventLoopGroupMongoClientSettingsBuilderCustomizer(
101+
private NettyDriverMongoClientSettingsBuilderCustomizer(
102102
ObjectProvider<MongoClientSettings> settings) {
103103
this.settings = settings;
104104
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ public void optionsSslConfig() {
9191

9292
@Test
9393
public void nettyStreamFactoryFactoryIsConfiguredAutomatically() {
94-
AtomicReference<EventLoopGroup> capture = new AtomicReference<>();
94+
AtomicReference<EventLoopGroup> eventLoopGroupReference = new AtomicReference<>();
9595
this.contextRunner.run((context) -> {
9696
assertThat(context).hasSingleBean(MongoClient.class);
9797
StreamFactoryFactory factory = getSettings(context).getStreamFactoryFactory();
9898
assertThat(factory).isInstanceOf(NettyStreamFactoryFactory.class);
99-
capture.set((EventLoopGroup) ReflectionTestUtils.getField(factory,
100-
"eventLoopGroup"));
101-
assertThat(capture.get()).isNotNull();
102-
assertThat(capture.get().isShutdown()).isFalse();
99+
EventLoopGroup eventLoopGroup = (EventLoopGroup) ReflectionTestUtils
100+
.getField(factory, "eventLoopGroup");
101+
assertThat(eventLoopGroup.isShutdown()).isFalse();
102+
eventLoopGroupReference.set(eventLoopGroup);
103103
});
104-
assertThat(capture.get().isShutdown()).isTrue();
104+
assertThat(eventLoopGroupReference.get().isShutdown()).isTrue();
105105
}
106106

107107
@Test

0 commit comments

Comments
 (0)