Skip to content

Commit

Permalink
Polish "Ensure that MongoClient's EventLoopGroup is shut down during …
Browse files Browse the repository at this point in the history
…context close"

See gh-16087
  • Loading branch information
wilkinsona committed Apr 2, 2019
1 parent ee7bed1 commit f20d9a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -86,19 +86,19 @@ static class NettyDriverConfiguration {

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ public void optionsSslConfig() {

@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
Expand Down

0 comments on commit f20d9a6

Please sign in to comment.