From b9cfe21193b1a5eb6473150f934e5691f5bb5b58 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 24 Jul 2017 12:21:00 -0700 Subject: [PATCH 1/4] Make @ImportAutoConfiguration not register package Update `@ImportAutoConfiguration` so that it is no longer annotated with `@AutoConfigurationPackage` and as such isn't a marker for `AutoConfigurationPackages`. Having `@ImportAutoConfiguration` marked as an auto-configuration package is particularly problematic in tests since it frequently breaks context caching. Fixes gh-9282 --- .../autoconfigure/ImportAutoConfiguration.java | 1 - ...mportAutoConfigurationImportSelectorTests.java | 15 ++++++++++++++- ...stomizerFactoryWithAutoConfigurationTests.java | 8 +++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java index af55f05b8d..7d72a2fd2d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ImportAutoConfiguration.java @@ -46,7 +46,6 @@ import org.springframework.core.annotation.AliasFor; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@AutoConfigurationPackage @Import(ImportAutoConfigurationImportSelector.class) public @interface ImportAutoConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java index 3dfc9183b4..3c1d17980c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java @@ -37,6 +37,7 @@ import org.springframework.core.env.Environment; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; +import org.springframework.util.ClassUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verifyZeroInteractions; @@ -125,7 +126,6 @@ public class ImportAutoConfigurationImportSelectorTests { public void exclusionsAliasesAreApplied() throws Exception { AnnotationMetadata annotationMetadata = getAnnotationMetadata( ImportWithSelfAnnotatingAnnotationExclude.class); - String[] imports = this.importSelector.selectImports(annotationMetadata); assertThat(imports).isEmpty(); } @@ -182,6 +182,19 @@ public class ImportAutoConfigurationImportSelectorTests { assertThat(set1).isNotEqualTo(set2); } + @Test + public void determineImportsShouldNotSetPackageImport() throws Exception { + Class packageImportClass = ClassUtils.resolveClassName( + "org.springframework.boot.autoconfigure.AutoConfigurationPackages.PackageImport", + null); + Set selectedImports = this.importSelector + .determineImports(getAnnotationMetadata( + ImportMetaAutoConfigurationExcludeWithUnrelatedOne.class)); + for (Object selectedImport : selectedImports) { + assertThat(selectedImport).isNotInstanceOf(packageImportClass); + } + } + private AnnotationMetadata getAnnotationMetadata(Class source) throws IOException { return new SimpleMetadataReaderFactory().getMetadataReader(source.getName()) .getAnnotationMetadata(); diff --git a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java index 45d5dbbfdc..7399043c90 100644 --- a/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java +++ b/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/cache/ImportsContextCustomizerFactoryWithAutoConfigurationTests.java @@ -24,6 +24,7 @@ import org.junit.runner.notification.RunNotifier; import org.junit.runners.model.InitializationError; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -94,8 +95,8 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { } - @ContextConfiguration(classes = EmptyConfig.class) @DataJpaTest + @ContextConfiguration(classes = EmptyConfig.class) @Unrelated2 public static class DataJpaTest2 { @@ -109,8 +110,8 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { } - @ContextConfiguration(classes = EmptyConfig.class) @DataJpaTest + @ContextConfiguration(classes = EmptyConfig.class) @Unrelated1 public static class DataJpaTest3 { @@ -124,8 +125,8 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { } - @ContextConfiguration(classes = EmptyConfig.class) @DataJpaTest(showSql = false) + @ContextConfiguration(classes = EmptyConfig.class) @Unrelated1 public static class DataJpaTest4 { @@ -151,6 +152,7 @@ public class ImportsContextCustomizerFactoryWithAutoConfigurationTests { @Configuration @EntityScan(basePackageClasses = ExampleEntity.class) + @AutoConfigurationPackage static class EmptyConfig { } From 28dad44e2d81b69b818c9ec1b7829213132a00a8 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 24 Jul 2017 12:36:34 -0700 Subject: [PATCH 2/4] Be defensive about JUL calls from JAR Handler Update nested JAR support to only obtain JUL loggers when absolutely necessary and to defensively deal with failures. Prior to this commit it was not possible to override `java.util.logging.manager` to use a nested JAR as the logger implementation. Fixes gh-9848 --- .../boot/loader/jar/Handler.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java index 949504b4ff..4a64223cc0 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -71,8 +71,6 @@ public class Handler extends URLStreamHandler { rootFileCache = new SoftReference>(null); } - private final Logger logger = Logger.getLogger(getClass().getName()); - private final JarFile jarFile; private URLStreamHandler fallbackHandler; @@ -105,10 +103,10 @@ public class Handler extends URLStreamHandler { } catch (Exception ex) { if (reason instanceof IOException) { - this.logger.log(Level.FINEST, "Unable to open fallback handler", ex); + log(false, "Unable to open fallback handler", ex); throw (IOException) reason; } - this.logger.log(Level.WARNING, "Unable to open fallback handler", ex); + log(true, "Unable to open fallback handler", ex); if (reason instanceof RuntimeException) { throw (RuntimeException) reason; } @@ -116,6 +114,18 @@ public class Handler extends URLStreamHandler { } } + private void log(boolean warning, String message, Exception cause) { + try { + Logger.getLogger(getClass().getName()) + .log((warning ? Level.WARNING : Level.FINEST), message, cause); + } + catch (Exception ex) { + if (warning) { + System.err.println("WARNING: " + message); + } + } + } + private URLStreamHandler getFallbackHandler() { if (this.fallbackHandler != null) { return this.fallbackHandler; From 66619bbe2ba298edd97c0a9f751e12966dfec56e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 24 Jul 2017 12:50:49 -0700 Subject: [PATCH 3/4] Formatting --- ...ctiveMQConnectionFactoryConfiguration.java | 20 ++-- .../jms/activemq/ActiveMQProperties.java | 7 +- ...iveMQXAConnectionFactoryConfiguration.java | 6 +- .../ActiveMQAutoConfigurationTests.java | 108 +++++++++--------- .../jms/activemq/ActiveMQPropertiesTests.java | 24 ++-- 5 files changed, 85 insertions(+), 80 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index dfc5710a74..1b7a941814 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -50,8 +50,8 @@ class ActiveMQConnectionFactoryConfiguration { public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties, ObjectProvider> factoryCustomizers) { return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.getIfAvailable()).createConnectionFactory( - ActiveMQConnectionFactory.class); + factoryCustomizers.getIfAvailable()) + .createConnectionFactory(ActiveMQConnectionFactory.class); } @ConditionalOnClass(PooledConnectionFactory.class) @@ -69,21 +69,21 @@ class ActiveMQConnectionFactoryConfiguration { ActiveMQConnectionFactory.class)); ActiveMQProperties.Pool pool = properties.getPool(); pooledConnectionFactory.setBlockIfSessionPoolIsFull(pool.isBlockIfFull()); - pooledConnectionFactory.setBlockIfSessionPoolIsFullTimeout( - pool.getBlockIfFullTimeout()); - pooledConnectionFactory.setCreateConnectionOnStartup( - pool.isCreateConnectionOnStartup()); + pooledConnectionFactory + .setBlockIfSessionPoolIsFullTimeout(pool.getBlockIfFullTimeout()); + pooledConnectionFactory + .setCreateConnectionOnStartup(pool.isCreateConnectionOnStartup()); pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeout()); pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeout()); pooledConnectionFactory.setMaxConnections(pool.getMaxConnections()); pooledConnectionFactory.setMaximumActiveSessionPerConnection( pool.getMaximumActiveSessionPerConnection()); - pooledConnectionFactory.setReconnectOnException( - pool.isReconnectOnException()); + pooledConnectionFactory + .setReconnectOnException(pool.isReconnectOnException()); pooledConnectionFactory.setTimeBetweenExpirationCheckMillis( pool.getTimeBetweenExpirationCheck()); - pooledConnectionFactory.setUseAnonymousProducers( - pool.isUseAnonymousProducers()); + pooledConnectionFactory + .setUseAnonymousProducers(pool.isUseAnonymousProducers()); return pooledConnectionFactory; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java index 664ff12d1b..5ea0df18cd 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java @@ -158,8 +158,8 @@ public class ActiveMQProperties { private boolean blockIfFull = true; /** - * Blocking period, in milliseconds, before throwing an exception if the pool - * is still full. + * Blocking period, in milliseconds, before throwing an exception if the pool is + * still full. */ private long blockIfFullTimeout = -1; @@ -265,7 +265,8 @@ public class ActiveMQProperties { return this.maximumActiveSessionPerConnection; } - public void setMaximumActiveSessionPerConnection(int maximumActiveSessionPerConnection) { + public void setMaximumActiveSessionPerConnection( + int maximumActiveSessionPerConnection) { this.maximumActiveSessionPerConnection = maximumActiveSessionPerConnection; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java index e12a51a554..84f65f44ef 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java @@ -54,7 +54,7 @@ class ActiveMQXAConnectionFactoryConfiguration { XAConnectionFactoryWrapper wrapper) throws Exception { ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory( properties, factoryCustomizers.getIfAvailable()) - .createConnectionFactory(ActiveMQXAConnectionFactory.class); + .createConnectionFactory(ActiveMQXAConnectionFactory.class); return wrapper.wrapConnectionFactory(connectionFactory); } @@ -64,8 +64,8 @@ class ActiveMQXAConnectionFactoryConfiguration { ActiveMQProperties properties, ObjectProvider> factoryCustomizers) { return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.getIfAvailable()).createConnectionFactory( - ActiveMQConnectionFactory.class); + factoryCustomizers.getIfAvailable()) + .createConnectionFactory(ActiveMQConnectionFactory.class); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java index 1ff93f0240..3a585d011c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java @@ -64,78 +64,79 @@ public class ActiveMQAutoConfigurationTests { @Test public void defaultsConnectionFactoryAreApplied() { load(EmptyConfiguration.class, "spring.activemq.pool.enabled=false"); - assertThat(this.context.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1); - ActiveMQConnectionFactory connectionFactory = this.context.getBean( - ActiveMQConnectionFactory.class); + assertThat(this.context.getBeansOfType(ActiveMQConnectionFactory.class)) + .hasSize(1); + ActiveMQConnectionFactory connectionFactory = this.context + .getBean(ActiveMQConnectionFactory.class); ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory( "vm://localhost?broker.persistent=false"); - assertThat(connectionFactory.getUserName()).isEqualTo( - defaultFactory.getUserName()); - assertThat(connectionFactory.getPassword()).isEqualTo( - defaultFactory.getPassword()); - assertThat(connectionFactory.getCloseTimeout()).isEqualTo( - defaultFactory.getCloseTimeout()); - assertThat(connectionFactory.isNonBlockingRedelivery()).isEqualTo( - defaultFactory.isNonBlockingRedelivery()); - assertThat(connectionFactory.getSendTimeout()).isEqualTo( - defaultFactory.getSendTimeout()); - assertThat(connectionFactory.isTrustAllPackages()).isEqualTo( - defaultFactory.isTrustAllPackages()); + assertThat(connectionFactory.getUserName()) + .isEqualTo(defaultFactory.getUserName()); + assertThat(connectionFactory.getPassword()) + .isEqualTo(defaultFactory.getPassword()); + assertThat(connectionFactory.getCloseTimeout()) + .isEqualTo(defaultFactory.getCloseTimeout()); + assertThat(connectionFactory.isNonBlockingRedelivery()) + .isEqualTo(defaultFactory.isNonBlockingRedelivery()); + assertThat(connectionFactory.getSendTimeout()) + .isEqualTo(defaultFactory.getSendTimeout()); + assertThat(connectionFactory.isTrustAllPackages()) + .isEqualTo(defaultFactory.isTrustAllPackages()); assertThat(connectionFactory.getTrustedPackages()).containsExactly( - defaultFactory.getTrustedPackages().toArray(new String[]{})); + defaultFactory.getTrustedPackages().toArray(new String[] {})); } @Test public void customConnectionFactoryAreApplied() { load(EmptyConfiguration.class, "spring.activemq.pool.enabled=false", "spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false", - "spring.activemq.user=foo", - "spring.activemq.password=bar", + "spring.activemq.user=foo", "spring.activemq.password=bar", "spring.activemq.closeTimeout=500", "spring.activemq.nonBlockingRedelivery=true", "spring.activemq.sendTimeout=1000", "spring.activemq.packages.trust-all=false", "spring.activemq.packages.trusted=com.example.acme"); - assertThat(this.context.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1); - ActiveMQConnectionFactory connectionFactory = this.context.getBean( - ActiveMQConnectionFactory.class); + assertThat(this.context.getBeansOfType(ActiveMQConnectionFactory.class)) + .hasSize(1); + ActiveMQConnectionFactory connectionFactory = this.context + .getBean(ActiveMQConnectionFactory.class); assertThat(connectionFactory.getUserName()).isEqualTo("foo"); assertThat(connectionFactory.getPassword()).isEqualTo("bar"); assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500); assertThat(connectionFactory.isNonBlockingRedelivery()).isEqualTo(true); assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000); assertThat(connectionFactory.isTrustAllPackages()).isFalse(); - assertThat(connectionFactory.getTrustedPackages()).containsExactly( - "com.example.acme"); + assertThat(connectionFactory.getTrustedPackages()) + .containsExactly("com.example.acme"); } @Test public void defaultsPooledConnectionFactoryAreApplied() { load(EmptyConfiguration.class, "spring.activemq.pool.enabled=true"); assertThat(this.context.getBeansOfType(PooledConnectionFactory.class)).hasSize(1); - PooledConnectionFactory connectionFactory = this.context.getBean( - PooledConnectionFactory.class); + PooledConnectionFactory connectionFactory = this.context + .getBean(PooledConnectionFactory.class); PooledConnectionFactory defaultFactory = new PooledConnectionFactory(); - assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isEqualTo( - defaultFactory.isBlockIfSessionPoolIsFull()); - assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo( - defaultFactory.getBlockIfSessionPoolIsFullTimeout()); - assertThat(connectionFactory.isCreateConnectionOnStartup()).isEqualTo( - defaultFactory.isCreateConnectionOnStartup()); - assertThat(connectionFactory.getExpiryTimeout()).isEqualTo( - defaultFactory.getExpiryTimeout()); - assertThat(connectionFactory.getIdleTimeout()).isEqualTo( - defaultFactory.getIdleTimeout()); - assertThat(connectionFactory.getMaxConnections()).isEqualTo( - defaultFactory.getMaxConnections()); - assertThat(connectionFactory.getMaximumActiveSessionPerConnection()).isEqualTo( - defaultFactory.getMaximumActiveSessionPerConnection()); - assertThat(connectionFactory.isReconnectOnException()).isEqualTo( - defaultFactory.isReconnectOnException()); - assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()).isEqualTo( - defaultFactory.getTimeBetweenExpirationCheckMillis()); - assertThat(connectionFactory.isUseAnonymousProducers()).isEqualTo( - defaultFactory.isUseAnonymousProducers()); + assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) + .isEqualTo(defaultFactory.isBlockIfSessionPoolIsFull()); + assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) + .isEqualTo(defaultFactory.getBlockIfSessionPoolIsFullTimeout()); + assertThat(connectionFactory.isCreateConnectionOnStartup()) + .isEqualTo(defaultFactory.isCreateConnectionOnStartup()); + assertThat(connectionFactory.getExpiryTimeout()) + .isEqualTo(defaultFactory.getExpiryTimeout()); + assertThat(connectionFactory.getIdleTimeout()) + .isEqualTo(defaultFactory.getIdleTimeout()); + assertThat(connectionFactory.getMaxConnections()) + .isEqualTo(defaultFactory.getMaxConnections()); + assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) + .isEqualTo(defaultFactory.getMaximumActiveSessionPerConnection()); + assertThat(connectionFactory.isReconnectOnException()) + .isEqualTo(defaultFactory.isReconnectOnException()); + assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) + .isEqualTo(defaultFactory.getTimeBetweenExpirationCheckMillis()); + assertThat(connectionFactory.isUseAnonymousProducers()) + .isEqualTo(defaultFactory.isUseAnonymousProducers()); } @Test @@ -152,8 +153,8 @@ public class ActiveMQAutoConfigurationTests { "spring.activemq.pool.timeBetweenExpirationCheck=2048", "spring.activemq.pool.useAnonymousProducers=false"); assertThat(this.context.getBeansOfType(PooledConnectionFactory.class)).hasSize(1); - PooledConnectionFactory connectionFactory = this.context.getBean( - PooledConnectionFactory.class); + PooledConnectionFactory connectionFactory = this.context + .getBean(PooledConnectionFactory.class); assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isEqualTo(false); assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64); assertThat(connectionFactory.isCreateConnectionOnStartup()).isEqualTo(false); @@ -183,8 +184,8 @@ public class ActiveMQAutoConfigurationTests { "spring.activemq.pool.configuration.timeBetweenExpirationCheckMillis=2048", "spring.activemq.pool.configuration.useAnonymousProducers=false"); assertThat(this.context.getBeansOfType(PooledConnectionFactory.class)).hasSize(1); - PooledConnectionFactory connectionFactory = this.context.getBean( - PooledConnectionFactory.class); + PooledConnectionFactory connectionFactory = this.context + .getBean(PooledConnectionFactory.class); assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isEqualTo(false); assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64); assertThat(connectionFactory.isCreateConnectionOnStartup()).isEqualTo(false); @@ -212,10 +213,10 @@ public class ActiveMQAutoConfigurationTests { @Test public void customizerOverridesAutConfig() { load(CustomizerConfiguration.class); - ActiveMQConnectionFactory connectionFactory = this.context.getBean( - ActiveMQConnectionFactory.class); - assertThat(connectionFactory.getBrokerURL()).isEqualTo( - "vm://localhost?useJmx=false&broker.persistent=false"); + ActiveMQConnectionFactory connectionFactory = this.context + .getBean(ActiveMQConnectionFactory.class); + assertThat(connectionFactory.getBrokerURL()) + .isEqualTo("vm://localhost?useJmx=false&broker.persistent=false"); assertThat(connectionFactory.getUserName()).isEqualTo("foobar"); } @@ -263,6 +264,7 @@ public class ActiveMQAutoConfigurationTests { } }; } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java index 90280f5f70..fb3bb861cc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java @@ -40,37 +40,38 @@ public class ActiveMQPropertiesTests { @Test public void getBrokerUrlIsInMemoryByDefault() { - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - DEFAULT_EMBEDDED_BROKER_URL); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo(DEFAULT_EMBEDDED_BROKER_URL); } @Test public void getBrokerUrlUseExplicitBrokerUrl() { this.properties.setBrokerUrl("vm://foo-bar"); - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - "vm://foo-bar"); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo("vm://foo-bar"); } @Test public void getBrokerUrlWithInMemorySetToFalse() { this.properties.setInMemory(false); - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - DEFAULT_NETWORK_BROKER_URL); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo(DEFAULT_NETWORK_BROKER_URL); } @Test public void getExplicitBrokerUrlAlwaysWins() { this.properties.setBrokerUrl("vm://foo-bar"); this.properties.setInMemory(false); - assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo( - "vm://foo-bar"); + assertThat(createFactory(this.properties).determineBrokerUrl()) + .isEqualTo("vm://foo-bar"); } @Test public void setTrustAllPackages() { this.properties.getPackages().setTrustAll(true); - assertThat(createFactory(this.properties).createConnectionFactory( - ActiveMQConnectionFactory.class).isTrustAllPackages()).isEqualTo(true); + assertThat(createFactory(this.properties) + .createConnectionFactory(ActiveMQConnectionFactory.class) + .isTrustAllPackages()).isEqualTo(true); } @Test @@ -84,7 +85,8 @@ public class ActiveMQPropertiesTests { assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package"); } - private ActiveMQConnectionFactoryFactory createFactory(ActiveMQProperties properties) { + private ActiveMQConnectionFactoryFactory createFactory( + ActiveMQProperties properties) { return new ActiveMQConnectionFactoryFactory(properties, Collections.emptyList()); } From dca463c7d95a1e1aad40e4d1f26d6366545a7625 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 24 Jul 2017 12:53:55 -0700 Subject: [PATCH 4/4] Polish --- .../boot/autoconfigure/web/ServerProperties.java | 1 + .../boot/autoconfigure/web/ServerPropertiesTests.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 5fa0645b0a..f15dc35a42 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -865,6 +865,7 @@ public class ServerProperties factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override + @SuppressWarnings("deprecation") public void customize(Connector connector) { ProtocolHandler handler = connector.getProtocolHandler(); if (handler instanceof AbstractProtocol) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 96e1576b97..205283fc51 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -528,7 +528,7 @@ public class ServerPropertiesTests { embeddedContainer.start(); try { assertThat(((AbstractProtocol) embeddedContainer.getTomcat().getConnector() - .getProtocolHandler()).getBacklog()).isEqualTo(10); + .getProtocolHandler()).getAcceptCount()).isEqualTo(10); } finally { embeddedContainer.stop();