Skip to content

Commit db41fb1

Browse files
committedSep 3, 2015
Polish Hazelcast auto-configuration
Extract a HazelcastInstanceFactory class and cleanup some formatting. See spring-projectsgh-2942
1 parent 138d667 commit db41fb1

File tree

10 files changed

+176
-127
lines changed

10 files changed

+176
-127
lines changed
 

‎spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import net.sf.ehcache.CacheManager;
2121

2222
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.boot.autoconfigure.condition.ResourceCondition;
2423
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2524
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
25+
import org.springframework.boot.autoconfigure.condition.ResourceCondition;
2626
import org.springframework.cache.ehcache.EhCacheCacheManager;
2727
import org.springframework.cache.ehcache.EhCacheManagerUtils;
2828
import org.springframework.context.annotation.Bean;

‎spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastCacheConfiguration.java

+25-24
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,38 @@
1919
import java.io.Closeable;
2020
import java.io.IOException;
2121

22-
import com.hazelcast.core.Hazelcast;
23-
import com.hazelcast.core.HazelcastInstance;
24-
import com.hazelcast.spring.cache.HazelcastCacheManager;
25-
2622
import org.springframework.beans.factory.annotation.Autowired;
2723
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2824
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2925
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3026
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
3127
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
3228
import org.springframework.boot.autoconfigure.hazelcast.HazelcastConfigResourceCondition;
29+
import org.springframework.boot.autoconfigure.hazelcast.HazelcastInstanceFactory;
3330
import org.springframework.cache.CacheManager;
3431
import org.springframework.context.annotation.Bean;
3532
import org.springframework.context.annotation.Conditional;
3633
import org.springframework.context.annotation.Configuration;
3734
import org.springframework.core.io.Resource;
3835

36+
import com.hazelcast.core.Hazelcast;
37+
import com.hazelcast.core.HazelcastInstance;
38+
import com.hazelcast.spring.cache.HazelcastCacheManager;
39+
3940
/**
40-
* Hazelcast cache configuration. Can either reuse the {@link HazelcastInstance} that
41-
* has been configured by the general {@link HazelcastAutoConfiguration} or create
42-
* a separate one if the {@code spring.cache.hazelcast.config} property has been set.
41+
* Hazelcast cache configuration. Can either reuse the {@link HazelcastInstance} that has
42+
* been configured by the general {@link HazelcastAutoConfiguration} or create a separate
43+
* one if the {@code spring.cache.hazelcast.config} property has been set.
4344
* <p>
44-
* If the {@link HazelcastAutoConfiguration} has been disabled, an attempt to configure
45-
* a default {@link HazelcastInstance} is still made, using the same defaults.
45+
* If the {@link HazelcastAutoConfiguration} has been disabled, an attempt to configure a
46+
* default {@link HazelcastInstance} is still made, using the same defaults.
4647
*
4748
* @author Stephane Nicoll
4849
* @since 1.3.0
4950
* @see HazelcastConfigResourceCondition
5051
*/
5152
@Configuration
52-
@ConditionalOnClass({HazelcastInstance.class, HazelcastCacheManager.class})
53+
@ConditionalOnClass({ HazelcastInstance.class, HazelcastCacheManager.class })
5354
@ConditionalOnMissingBean(CacheManager.class)
5455
@Conditional(CacheCondition.class)
5556
@AutoConfigureAfter(HazelcastAutoConfiguration.class)
@@ -63,19 +64,16 @@ static class ExistingHazelcastInstanceConfiguration {
6364
private CacheProperties cacheProperties;
6465

6566
@Bean
66-
public HazelcastCacheManager cacheManager(HazelcastInstance existingHazelcastInstance)
67-
throws IOException {
68-
Resource location = this.cacheProperties
69-
.resolveConfigLocation(this.cacheProperties.getHazelcast().getConfig());
67+
public HazelcastCacheManager cacheManager(
68+
HazelcastInstance existingHazelcastInstance) throws IOException {
69+
Resource config = this.cacheProperties.getHazelcast().getConfig();
70+
Resource location = this.cacheProperties.resolveConfigLocation(config);
7071
if (location != null) {
71-
HazelcastInstance cacheHazelcastInstance =
72-
HazelcastAutoConfiguration.createHazelcastInstance(location);
72+
HazelcastInstance cacheHazelcastInstance = new HazelcastInstanceFactory(
73+
location).getHazelcastInstance();
7374
return new CloseableHazelcastCacheManager(cacheHazelcastInstance);
7475
}
75-
else {
76-
return new HazelcastCacheManager(existingHazelcastInstance);
77-
}
78-
76+
return new HazelcastCacheManager(existingHazelcastInstance);
7977
}
8078
}
8179

@@ -89,10 +87,10 @@ static class DefaultHazelcastInstanceConfiguration {
8987

9088
@Bean
9189
public HazelcastInstance hazelcastInstance() throws IOException {
92-
Resource location = this.cacheProperties
93-
.resolveConfigLocation(this.cacheProperties.getHazelcast().getConfig());
90+
Resource config = this.cacheProperties.getHazelcast().getConfig();
91+
Resource location = this.cacheProperties.resolveConfigLocation(config);
9492
if (location != null) {
95-
HazelcastAutoConfiguration.createHazelcastInstance(location);
93+
new HazelcastInstanceFactory(location).getHazelcastInstance();
9694
}
9795
return Hazelcast.newHazelcastInstance();
9896
}
@@ -116,7 +114,9 @@ public ConfigAvailableCondition() {
116114

117115
}
118116

119-
private static class CloseableHazelcastCacheManager extends HazelcastCacheManager implements Closeable {
117+
private static class CloseableHazelcastCacheManager extends HazelcastCacheManager
118+
implements Closeable {
119+
120120
private final HazelcastInstance hazelcastInstance;
121121

122122
public CloseableHazelcastCacheManager(HazelcastInstance hazelcastInstance) {
@@ -128,6 +128,7 @@ public CloseableHazelcastCacheManager(HazelcastInstance hazelcastInstance) {
128128
public void close() throws IOException {
129129
this.hazelcastInstance.shutdown();
130130
}
131+
131132
}
132133

133134
}

‎spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ResourceCondition.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
6060
AnnotatedTypeMetadata metadata) {
6161
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
6262
context.getEnvironment(), this.prefix);
63-
if (resolver.containsProperty(propertyName)) {
64-
return ConditionOutcome.match("A '" + this.prefix + propertyName +"' "
63+
if (resolver.containsProperty(this.propertyName)) {
64+
return ConditionOutcome.match("A '" + this.prefix + this.propertyName + "' "
6565
+ "property is specified");
6666
}
6767
return getResourceOutcome(context, metadata);

‎spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java

+8-41
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
package org.springframework.boot.autoconfigure.hazelcast;
1818

1919
import java.io.IOException;
20-
import java.net.URL;
21-
22-
import com.hazelcast.config.Config;
23-
import com.hazelcast.config.XmlConfigBuilder;
24-
import com.hazelcast.core.Hazelcast;
25-
import com.hazelcast.core.HazelcastInstance;
2620

2721
import org.springframework.beans.factory.annotation.Autowired;
2822
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -34,9 +28,10 @@
3428
import org.springframework.context.annotation.Conditional;
3529
import org.springframework.context.annotation.Configuration;
3630
import org.springframework.core.io.Resource;
37-
import org.springframework.util.Assert;
38-
import org.springframework.util.ResourceUtils;
39-
import org.springframework.util.StringUtils;
31+
32+
import com.hazelcast.config.Config;
33+
import com.hazelcast.core.Hazelcast;
34+
import com.hazelcast.core.HazelcastInstance;
4035

4136
/**
4237
* {@link EnableAutoConfiguration Auto-configuration} for Hazelcast. Creates a
@@ -53,37 +48,8 @@
5348
@EnableConfigurationProperties(HazelcastProperties.class)
5449
public class HazelcastAutoConfiguration {
5550

56-
57-
/**
58-
* Create a {@link HazelcastInstance} based on the specified configuration location.
59-
* @param location the location of the configuration file
60-
* @return a {@link HazelcastInstance} for the specified configuration
61-
* @throws IOException the configuration file could not be read
62-
*/
63-
public static HazelcastInstance createHazelcastInstance(Resource location)
64-
throws IOException {
65-
Assert.notNull(location, "Config must not be null");
66-
URL configUrl = location.getURL();
67-
Config config = new XmlConfigBuilder(configUrl).build();
68-
if (ResourceUtils.isFileURL(configUrl)) {
69-
config.setConfigurationFile(location.getFile());
70-
}
71-
else {
72-
config.setConfigurationUrl(configUrl);
73-
}
74-
return createHazelcastInstance(config);
75-
}
76-
77-
private static HazelcastInstance createHazelcastInstance(Config config) {
78-
if (StringUtils.hasText(config.getInstanceName())) {
79-
return Hazelcast.getOrCreateHazelcastInstance(config);
80-
}
81-
return Hazelcast.newHazelcastInstance(config);
82-
}
83-
84-
8551
@Configuration
86-
@ConditionalOnMissingBean({HazelcastInstance.class, Config.class})
52+
@ConditionalOnMissingBean({ HazelcastInstance.class, Config.class })
8753
@Conditional(ConfigAvailableCondition.class)
8854
static class HazelcastConfigFileConfiguration {
8955

@@ -95,7 +61,7 @@ static class HazelcastConfigFileConfiguration {
9561
public HazelcastInstance hazelcastInstance() throws IOException {
9662
Resource config = this.hazelcastProperties.resolveConfigLocation();
9763
if (config != null) {
98-
return createHazelcastInstance(config);
64+
return new HazelcastInstanceFactory(config).getHazelcastInstance();
9965
}
10066
return Hazelcast.newHazelcastInstance();
10167
}
@@ -109,7 +75,7 @@ static class HazelcastConfigConfiguration {
10975

11076
@Bean
11177
public HazelcastInstance hazelcastInstance(Config config) {
112-
return createHazelcastInstance(config);
78+
return new HazelcastInstanceFactory(config).getHazelcastInstance();
11379
}
11480

11581
}
@@ -123,6 +89,7 @@ static class ConfigAvailableCondition extends HazelcastConfigResourceCondition {
12389
public ConfigAvailableCondition() {
12490
super("spring.hazelcast", "config");
12591
}
92+
12693
}
12794

12895
}

‎spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import org.springframework.core.type.AnnotatedTypeMetadata;
2424

2525
/**
26-
* {@link SpringBootCondition} used to check if the Hazelcast configuration is
27-
* available. This either kicks in if a default configuration has been found or
28-
* if configurable property referring to the resource to use has been set.
26+
* {@link SpringBootCondition} used to check if the Hazelcast configuration is available.
27+
* This either kicks in if a default configuration has been found or if configurable
28+
* property referring to the resource to use has been set.
2929
*
3030
* @author Stephane Nicoll
3131
* @since 1.3.0
@@ -43,8 +43,8 @@ protected HazelcastConfigResourceCondition(String prefix, String propertyName) {
4343
protected ConditionOutcome getResourceOutcome(ConditionContext context,
4444
AnnotatedTypeMetadata metadata) {
4545
if (System.getProperty(CONFIG_SYSTEM_PROPERTY) != null) {
46-
return ConditionOutcome.match("System property '"
47-
+ CONFIG_SYSTEM_PROPERTY + "' is set.");
46+
return ConditionOutcome.match("System property '" + CONFIG_SYSTEM_PROPERTY
47+
+ "' is set.");
4848
}
4949
return super.getResourceOutcome(context, metadata);
5050
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright 2012-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.hazelcast;
18+
19+
import java.io.IOException;
20+
import java.net.URL;
21+
22+
import org.springframework.core.io.Resource;
23+
import org.springframework.util.Assert;
24+
import org.springframework.util.ResourceUtils;
25+
import org.springframework.util.StringUtils;
26+
27+
import com.hazelcast.config.Config;
28+
import com.hazelcast.config.XmlConfigBuilder;
29+
import com.hazelcast.core.Hazelcast;
30+
import com.hazelcast.core.HazelcastInstance;
31+
32+
/**
33+
* Factory that can be used to create a {@link HazelcastInstance}.
34+
*
35+
* @author Stephane Nicoll
36+
* @author Phillip Webb
37+
* @since 1.3.0
38+
*/
39+
public class HazelcastInstanceFactory {
40+
41+
private Config config;
42+
43+
/**
44+
* Create a {@link HazelcastInstanceFactory} for the specified configuration location.
45+
* @param configLocation the location of the configuration file
46+
* @throws IOException if the configuration location could not be read
47+
*/
48+
public HazelcastInstanceFactory(Resource configLocation) throws IOException {
49+
Assert.notNull(configLocation, "ConfigLocation must not be null");
50+
this.config = getConfig(configLocation);
51+
}
52+
53+
/**
54+
* Create a {@link HazelcastInstanceFactory} for the specified configuration.
55+
* @param config the configuration
56+
*/
57+
public HazelcastInstanceFactory(Config config) {
58+
Assert.notNull(config, "Config must not be null");
59+
this.config = config;
60+
}
61+
62+
private Config getConfig(Resource configLocation) throws IOException {
63+
URL configUrl = configLocation.getURL();
64+
Config config = new XmlConfigBuilder(configUrl).build();
65+
if (ResourceUtils.isFileURL(configUrl)) {
66+
config.setConfigurationFile(configLocation.getFile());
67+
}
68+
else {
69+
config.setConfigurationUrl(configUrl);
70+
}
71+
return config;
72+
}
73+
74+
/**
75+
* Get the {@link HazelcastInstance}.
76+
* @return the {@link HazelcastInstance}
77+
*/
78+
public HazelcastInstance getHazelcastInstance() {
79+
if (StringUtils.hasText(this.config.getInstanceName())) {
80+
return Hazelcast.getOrCreateHazelcastInstance(this.config);
81+
}
82+
return Hazelcast.newHazelcastInstance(this.config);
83+
}
84+
85+
}

‎spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastProperties.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public void setConfig(Resource config) {
4949
* location
5050
*/
5151
public Resource resolveConfigLocation() {
52-
if (this.config != null) {
53-
Assert.isTrue(this.config.exists(), "Hazelcast configuration does not exist '"
54-
+ this.config.getDescription() + "'");
55-
return this.config;
52+
if (this.config == null) {
53+
return null;
5654
}
57-
return null;
55+
Assert.isTrue(this.config.exists(), "Hazelcast configuration does not exist '"
56+
+ this.config.getDescription() + "'");
57+
return this.config;
5858
}
5959

6060
}

‎spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

+13-18
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,12 @@ public void hazelcastCacheWithMainHazelcastAutoConfiguration() throws IOExceptio
375375
Collection<Class<?>> configs = new ArrayList<Class<?>>();
376376
configs.add(DefaultCacheConfiguration.class);
377377
configs.add(HazelcastAutoConfiguration.class);
378-
String mainConfig =
379-
"org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
380-
doLoad(configs, "spring.cache.type=hazelcast",
381-
"spring.hazelcast.config=" + mainConfig);
382-
378+
String mainConfig = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
379+
doLoad(configs, "spring.cache.type=hazelcast", "spring.hazelcast.config="
380+
+ mainConfig);
383381
HazelcastCacheManager cacheManager = validateCacheManager(HazelcastCacheManager.class);
384-
HazelcastInstance hazelcastInstance = this.context.getBean(HazelcastInstance.class);
382+
HazelcastInstance hazelcastInstance = this.context
383+
.getBean(HazelcastInstance.class);
385384
assertThat(
386385
new DirectFieldAccessor(cacheManager)
387386
.getPropertyValue("hazelcastInstance"),
@@ -398,17 +397,14 @@ public void hazelcastCacheWithMainHazelcastAutoConfigurationAndSeparateCacheConf
398397
configs.add(HazelcastAutoConfiguration.class);
399398
String mainConfig = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
400399
String cacheConfig = "org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml";
401-
doLoad(configs, "spring.cache.type=hazelcast",
402-
"spring.cache.hazelcast.config=" + cacheConfig,
403-
"spring.hazelcast.config=" + mainConfig);
404-
HazelcastInstance hazelcastInstance = this.context.getBean(HazelcastInstance.class);
400+
doLoad(configs, "spring.cache.type=hazelcast", "spring.cache.hazelcast.config="
401+
+ cacheConfig, "spring.hazelcast.config=" + mainConfig);
402+
HazelcastInstance hazelcastInstance = this.context
403+
.getBean(HazelcastInstance.class);
405404
HazelcastCacheManager cacheManager = validateCacheManager(HazelcastCacheManager.class);
406-
HazelcastInstance cacheHazelcastInstance = (HazelcastInstance)
407-
new DirectFieldAccessor(cacheManager).getPropertyValue("hazelcastInstance");
408-
409-
assertThat(
410-
cacheHazelcastInstance,
411-
is(not(hazelcastInstance))); // Our custom cache instance
405+
HazelcastInstance cacheHazelcastInstance = (HazelcastInstance) new DirectFieldAccessor(
406+
cacheManager).getPropertyValue("hazelcastInstance");
407+
assertThat(cacheHazelcastInstance, is(not(hazelcastInstance))); // Our custom
412408
assertThat(hazelcastInstance.getConfig().getConfigurationFile(),
413409
is(new ClassPathResource(mainConfig).getFile()));
414410
assertThat(cacheHazelcastInstance.getConfig().getConfigurationFile(),
@@ -552,8 +548,7 @@ private void load(Class<?> config, String... environment) {
552548
doLoad(configs, environment);
553549
}
554550

555-
private void doLoad(Collection<Class<?>> configs,
556-
String... environment) {
551+
private void doLoad(Collection<Class<?>> configs, String... environment) {
557552
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
558553
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
559554
for (Class<?> config : configs) {

‎spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.junit.After;
2020
import org.junit.Test;
21-
2221
import org.springframework.boot.test.EnvironmentTestUtils;
2322
import org.springframework.context.ConfigurableApplicationContext;
2423
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -92,8 +91,7 @@ public String foo() {
9291
}
9392
}
9493

95-
private static class DefaultLocationResourceCondition extends
96-
ResourceCondition {
94+
private static class DefaultLocationResourceCondition extends ResourceCondition {
9795

9896
public DefaultLocationResourceCondition() {
9997
super("test", "spring.foo.test.", "config", "classpath:/logging.properties");

‎spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java

+31-28
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
import java.io.IOException;
2020
import java.util.Map;
2121

22-
import com.hazelcast.config.Config;
23-
import com.hazelcast.config.QueueConfig;
24-
import com.hazelcast.core.Hazelcast;
25-
import com.hazelcast.core.HazelcastInstance;
2622
import org.junit.After;
2723
import org.junit.Rule;
2824
import org.junit.Test;
2925
import org.junit.rules.ExpectedException;
30-
3126
import org.springframework.beans.factory.BeanCreationException;
3227
import org.springframework.boot.test.EnvironmentTestUtils;
3328
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3429
import org.springframework.context.annotation.Bean;
3530
import org.springframework.context.annotation.Configuration;
3631
import org.springframework.core.io.ClassPathResource;
3732

33+
import com.hazelcast.config.Config;
34+
import com.hazelcast.config.QueueConfig;
35+
import com.hazelcast.core.Hazelcast;
36+
import com.hazelcast.core.HazelcastInstance;
37+
3838
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
3939
import static org.hamcrest.collection.IsMapContaining.hasKey;
4040
import static org.hamcrest.core.Is.is;
@@ -62,8 +62,8 @@ public void closeContext() {
6262
@Test
6363
public void defaultConfigFile() throws IOException {
6464
load(); // hazelcast.xml present in root classpath
65-
HazelcastInstance hazelcastInstance = this.context.getBean(
66-
HazelcastInstance.class);
65+
HazelcastInstance hazelcastInstance = this.context
66+
.getBean(HazelcastInstance.class);
6767
assertThat(hazelcastInstance.getConfig().getConfigurationUrl(),
6868
is(new ClassPathResource("hazelcast.xml").getURL()));
6969
}
@@ -74,9 +74,10 @@ public void systemProperty() throws IOException {
7474
"classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml");
7575
try {
7676
load();
77-
HazelcastInstance hazelcastInstance = this.context.getBean(
78-
HazelcastInstance.class);
79-
Map<String, QueueConfig> queueConfigs = hazelcastInstance.getConfig().getQueueConfigs();
77+
HazelcastInstance hazelcastInstance = this.context
78+
.getBean(HazelcastInstance.class);
79+
Map<String, QueueConfig> queueConfigs = hazelcastInstance.getConfig()
80+
.getQueueConfigs();
8081
assertThat(queueConfigs.values(), hasSize(1));
8182
assertThat(queueConfigs, hasKey("foobar"));
8283
}
@@ -87,20 +88,21 @@ public void systemProperty() throws IOException {
8788

8889
@Test
8990
public void explicitConfigFile() throws IOException {
90-
load("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/" +
91-
"hazelcast-specific.xml");
92-
HazelcastInstance hazelcastInstance = this.context.getBean(
93-
HazelcastInstance.class);
91+
load("spring.hazelcast.config=org/springframework/boot/autoconfigure/hazelcast/"
92+
+ "hazelcast-specific.xml");
93+
HazelcastInstance hazelcastInstance = this.context
94+
.getBean(HazelcastInstance.class);
9495
assertThat(hazelcastInstance.getConfig().getConfigurationFile(),
95-
is(new ClassPathResource("org/springframework/boot/autoconfigure/hazelcast" +
96-
"/hazelcast-specific.xml").getFile()));
96+
is(new ClassPathResource(
97+
"org/springframework/boot/autoconfigure/hazelcast"
98+
+ "/hazelcast-specific.xml").getFile()));
9799
}
98100

99101
@Test
100102
public void explicitConfigUrl() throws IOException {
101103
load("spring.hazelcast.config=hazelcast-default.xml");
102-
HazelcastInstance hazelcastInstance = this.context.getBean(
103-
HazelcastInstance.class);
104+
HazelcastInstance hazelcastInstance = this.context
105+
.getBean(HazelcastInstance.class);
104106
assertThat(hazelcastInstance.getConfig().getConfigurationUrl(),
105107
is(new ClassPathResource("hazelcast-default.xml").getURL()));
106108
}
@@ -115,13 +117,15 @@ public void unknownConfigFile() {
115117
@Test
116118
public void configInstanceWithName() {
117119
Config config = new Config("my-test-instance");
118-
HazelcastInstance existingHazelcastInstance = Hazelcast.newHazelcastInstance(config);
120+
HazelcastInstance existingHazelcastInstance = Hazelcast
121+
.newHazelcastInstance(config);
119122
try {
120123
load(HazelcastConfigWithName.class,
121124
"spring.hazelcast.config=this-is-ignored.xml");
122-
HazelcastInstance hazelcastInstance = this.context.getBean(
123-
HazelcastInstance.class);
124-
assertThat(hazelcastInstance.getConfig().getInstanceName(), is("my-test-instance"));
125+
HazelcastInstance hazelcastInstance = this.context
126+
.getBean(HazelcastInstance.class);
127+
assertThat(hazelcastInstance.getConfig().getInstanceName(),
128+
is("my-test-instance"));
125129
// Should reuse any existing instance by default.
126130
assertThat(hazelcastInstance, is(existingHazelcastInstance));
127131
}
@@ -132,11 +136,11 @@ public void configInstanceWithName() {
132136

133137
@Test
134138
public void configInstanceWithoutName() {
135-
load(HazelcastConfigNoName.class,
136-
"spring.hazelcast.config=this-is-ignored.xml");
137-
HazelcastInstance hazelcastInstance = this.context.getBean(
138-
HazelcastInstance.class);
139-
Map<String, QueueConfig> queueConfigs = hazelcastInstance.getConfig().getQueueConfigs();
139+
load(HazelcastConfigNoName.class, "spring.hazelcast.config=this-is-ignored.xml");
140+
HazelcastInstance hazelcastInstance = this.context
141+
.getBean(HazelcastInstance.class);
142+
Map<String, QueueConfig> queueConfigs = hazelcastInstance.getConfig()
143+
.getQueueConfigs();
140144
assertThat(queueConfigs.values(), hasSize(1));
141145
assertThat(queueConfigs, hasKey("another-queue"));
142146
}
@@ -156,7 +160,6 @@ private void load(Class<?> config, String... environment) {
156160
this.context = applicationContext;
157161
}
158162

159-
160163
@Configuration
161164
static class HazelcastConfigWithName {
162165

0 commit comments

Comments
 (0)
Please sign in to comment.