Polish "Ensure that MongoClient's EventLoopGroup is shut down during context close"
See gh-16087
This commit is contained in:
parent
ee7bed1849
commit
f20d9a62ae
|
@ -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 {
|
|||
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue