From 5cc569fc9104d4749ef364b180ed9023453088ee Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 2 Mar 2017 14:28:33 +0100 Subject: [PATCH 1/2] Improve execution speed of `CacheAutoConfigurationTests` As of Hazelcast 3.7, the bootstrap is pretty slow by default due to the networking discovery. This commit disables both TCP/IP and multicast discoveries. --- .../src/test/resources/cache/test-hazelcast.xml | 7 +++++++ spring-boot-actuator/src/test/resources/hazelcast.xml | 7 +++++++ spring-boot-autoconfigure/src/test/resources/hazelcast.xml | 7 +++++++ .../boot/autoconfigure/cache/hazelcast-specific.xml | 7 +++++++ .../boot/autoconfigure/hazelcast/hazelcast-specific.xml | 7 +++++++ .../src/main/resources/hazelcast.xml | 7 +++++++ 6 files changed, 42 insertions(+) diff --git a/spring-boot-actuator/src/test/resources/cache/test-hazelcast.xml b/spring-boot-actuator/src/test/resources/cache/test-hazelcast.xml index b1ef4ab3edf..59ba8d06cec 100644 --- a/spring-boot-actuator/src/test/resources/cache/test-hazelcast.xml +++ b/spring-boot-actuator/src/test/resources/cache/test-hazelcast.xml @@ -5,4 +5,11 @@ + + + + + + + diff --git a/spring-boot-actuator/src/test/resources/hazelcast.xml b/spring-boot-actuator/src/test/resources/hazelcast.xml index a7a0f452f46..15665878ac0 100644 --- a/spring-boot-actuator/src/test/resources/hazelcast.xml +++ b/spring-boot-actuator/src/test/resources/hazelcast.xml @@ -5,4 +5,11 @@ + + + + + + + diff --git a/spring-boot-autoconfigure/src/test/resources/hazelcast.xml b/spring-boot-autoconfigure/src/test/resources/hazelcast.xml index a7a0f452f46..15665878ac0 100644 --- a/spring-boot-autoconfigure/src/test/resources/hazelcast.xml +++ b/spring-boot-autoconfigure/src/test/resources/hazelcast.xml @@ -5,4 +5,11 @@ + + + + + + + diff --git a/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml b/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml index bff6302c65f..f7e59aeaead 100644 --- a/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml +++ b/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml @@ -7,4 +7,11 @@ 600 + + + + + + + \ No newline at end of file diff --git a/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml b/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml index 2e0cf474b16..9a0d0513b7d 100644 --- a/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml +++ b/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml @@ -4,4 +4,11 @@ + + + + + + + \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/hazelcast.xml b/spring-boot-samples/spring-boot-sample-cache/src/main/resources/hazelcast.xml index d8d254ef246..2e705476da6 100644 --- a/spring-boot-samples/spring-boot-sample-cache/src/main/resources/hazelcast.xml +++ b/spring-boot-samples/spring-boot-sample-cache/src/main/resources/hazelcast.xml @@ -14,4 +14,11 @@ true + + + + + + + From 3e0e4e81b9fc63b18e3804715f579d7418449f56 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 2 Mar 2017 14:31:31 +0100 Subject: [PATCH 2/2] Polish --- .../cache/CacheAutoConfigurationTests.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 14b8141a85a..1432592157f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -441,7 +441,7 @@ public class CacheAutoConfigurationTests { cacheManager.getCache("defaultCache"); assertThat(cacheManager.getCacheNames()).containsOnly("defaultCache"); assertThat(this.context.getBean(HazelcastInstance.class)) - .isEqualTo(getHazelcastInstance(cacheManager)); + .isEqualTo(cacheManager.getHazelcastInstance()); } @Test @@ -458,7 +458,7 @@ public class CacheAutoConfigurationTests { .getBean(HazelcastInstance.class); HazelcastCacheManager cacheManager = validateCacheManager( HazelcastCacheManager.class); - HazelcastInstance actual = getHazelcastInstance(cacheManager); + HazelcastInstance actual = cacheManager.getHazelcastInstance(); assertThat(actual).isSameAs(hazelcastInstance); assertThat(actual.getConfig().getConfigurationUrl()) .isEqualTo(new ClassPathResource( @@ -481,7 +481,7 @@ public class CacheAutoConfigurationTests { load(HazelcastCustomHazelcastInstance.class, "spring.cache.type=hazelcast"); HazelcastCacheManager cacheManager = validateCacheManager( HazelcastCacheManager.class); - assertThat(getHazelcastInstance(cacheManager)) + assertThat(cacheManager.getHazelcastInstance()) .isEqualTo(this.context.getBean("customHazelcastInstance")); } @@ -499,7 +499,7 @@ public class CacheAutoConfigurationTests { HazelcastCacheManager.class); HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); - assertThat(getHazelcastInstance(cacheManager)).isEqualTo(hazelcastInstance); + assertThat(cacheManager.getHazelcastInstance()).isEqualTo(hazelcastInstance); assertThat(hazelcastInstance.getConfig().getConfigurationFile()) .isEqualTo(new ClassPathResource(mainConfig).getFile()); } @@ -522,8 +522,7 @@ public class CacheAutoConfigurationTests { .getBean(HazelcastInstance.class); HazelcastCacheManager cacheManager = validateCacheManager( HazelcastCacheManager.class); - HazelcastInstance cacheHazelcastInstance = (HazelcastInstance) new DirectFieldAccessor( - cacheManager).getPropertyValue("hazelcastInstance"); + HazelcastInstance cacheHazelcastInstance = cacheManager.getHazelcastInstance(); assertThat(cacheHazelcastInstance).isNotEqualTo(hazelcastInstance); // Our custom assertThat(hazelcastInstance.getConfig().getConfigurationFile()) .isEqualTo(new ClassPathResource(mainConfig).getFile()); @@ -760,12 +759,6 @@ public class CacheAutoConfigurationTests { this.context = applicationContext; } - private static HazelcastInstance getHazelcastInstance( - HazelcastCacheManager cacheManager) { - return (HazelcastInstance) new DirectFieldAccessor(cacheManager) - .getPropertyValue("hazelcastInstance"); - } - @Configuration static class EmptyConfiguration {