diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java index 569f816b78c..62ce95e47c8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java @@ -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 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 settings; - private EventLoopGroup eventLoopGroup; + private volatile EventLoopGroup eventLoopGroup; - private EventLoopGroupMongoClientSettingsBuilderCustomizer( + private NettyDriverMongoClientSettingsBuilderCustomizer( ObjectProvider settings) { this.settings = settings; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java index 38283855233..a0cedbb3344 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java @@ -91,17 +91,17 @@ public class MongoReactiveAutoConfigurationTests { @Test public void nettyStreamFactoryFactoryIsConfiguredAutomatically() { - AtomicReference capture = new AtomicReference<>(); + AtomicReference 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