Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3fbf1a2e
Commit
3fbf1a2e
authored
Jan 31, 2016
by
Vedran Pavic
Committed by
Stephane Nicoll
May 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auto-configuration support for Hazelcast client
See gh-7469
parent
ae3225e7
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
412 additions
and
81 deletions
+412
-81
pom.xml
spring-boot-autoconfigure/pom.xml
+5
-0
HazelcastAutoConfiguration.java
...t/autoconfigure/hazelcast/HazelcastAutoConfiguration.java
+10
-47
HazelcastClientConfiguration.java
...autoconfigure/hazelcast/HazelcastClientConfiguration.java
+83
-0
HazelcastConfigResourceCondition.java
...configure/hazelcast/HazelcastConfigResourceCondition.java
+10
-5
HazelcastInstanceFactory.java
...oot/autoconfigure/hazelcast/HazelcastInstanceFactory.java
+45
-25
HazelcastServerConfiguration.java
...autoconfigure/hazelcast/HazelcastServerConfiguration.java
+84
-0
CacheAutoConfigurationTests.java
...boot/autoconfigure/cache/CacheAutoConfigurationTests.java
+5
-0
HazelcastAutoConfigurationClientTests.java
...gure/hazelcast/HazelcastAutoConfigurationClientTests.java
+155
-0
HazelcastAutoConfigurationServerTests.java
...gure/hazelcast/HazelcastAutoConfigurationServerTests.java
+9
-4
hazelcast-client-specific.xml
...oot/autoconfigure/hazelcast/hazelcast-client-specific.xml
+6
-0
No files found.
spring-boot-autoconfigure/pom.xml
View file @
3fbf1a2e
...
...
@@ -75,6 +75,11 @@
<artifactId>
hazelcast
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.hazelcast
</groupId>
<artifactId>
hazelcast-client
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.hazelcast
</groupId>
<artifactId>
hazelcast-spring
</artifactId>
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java
View file @
3fbf1a2e
...
...
@@ -16,21 +16,15 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
hazelcast
;
import
java.io.IOException
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.client.HazelcastClient
;
import
com.hazelcast.core.HazelcastInstance
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.co
re.io.Resource
;
import
org.springframework.co
ntext.annotation.Import
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Hazelcast. Creates a
...
...
@@ -38,58 +32,27 @@ import org.springframework.core.io.Resource;
* configuration file is found in the environment.
*
* @author Stephane Nicoll
* @author
Madhura Bhave
* @author
Vedran Pavic
* @since 1.3.0
* @see HazelcastConfigResourceCondition
*/
@Configuration
@ConditionalOnClass
(
HazelcastInstance
.
class
)
@ConditionalOnMissingBean
(
HazelcastInstance
.
class
)
@EnableConfigurationProperties
(
HazelcastProperties
.
class
)
public
class
HazelcastAutoConfiguration
{
@Configuration
@ConditionalOnMissingBean
(
Config
.
class
)
@Conditional
(
ConfigAvailableCondition
.
class
)
static
class
HazelcastConfigFileConfiguration
{
private
final
HazelcastProperties
hazelcastProperties
;
HazelcastConfigFileConfiguration
(
HazelcastProperties
hazelcastProperties
)
{
this
.
hazelcastProperties
=
hazelcastProperties
;
}
@Bean
public
HazelcastInstance
hazelcastInstance
()
throws
IOException
{
Resource
config
=
this
.
hazelcastProperties
.
resolveConfigLocation
();
if
(
config
!=
null
)
{
return
new
HazelcastInstanceFactory
(
config
).
getHazelcastInstance
();
}
return
Hazelcast
.
newHazelcastInstance
();
}
@ConditionalOnMissingBean
(
HazelcastInstance
.
class
)
@Import
(
HazelcastServerConfiguration
.
class
)
static
class
ServerConfiguration
{
}
@Configuration
@ConditionalOnSingleCandidate
(
Config
.
class
)
static
class
HazelcastConfigConfiguration
{
@Bean
public
HazelcastInstance
hazelcastInstance
(
Config
config
)
{
return
new
HazelcastInstanceFactory
(
config
).
getHazelcastInstance
();
}
}
/**
* {@link HazelcastConfigResourceCondition} that checks if the
* {@code spring.hazelcast.config} configuration key is defined.
*/
static
class
ConfigAvailableCondition
extends
HazelcastConfigResourceCondition
{
ConfigAvailableCondition
()
{
super
(
"spring.hazelcast.config"
);
}
@ConditionalOnClass
(
HazelcastClient
.
class
)
@ConditionalOnMissingBean
(
HazelcastInstance
.
class
)
@Import
(
HazelcastClientConfiguration
.
class
)
static
class
ClientConfiguration
{
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastClientConfiguration.java
0 → 100644
View file @
3fbf1a2e
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
hazelcast
;
import
java.io.IOException
;
import
com.hazelcast.client.HazelcastClient
;
import
com.hazelcast.client.config.ClientConfig
;
import
com.hazelcast.core.HazelcastInstance
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.Resource
;
/**
* Configuration for Hazelcast client.
*
* @author Vedran Pavic
* @since 2.0.0
*/
class
HazelcastClientConfiguration
{
static
final
String
CONFIG_SYSTEM_PROPERTY
=
"hazelcast.client.config"
;
@Configuration
@ConditionalOnMissingBean
(
ClientConfig
.
class
)
@Conditional
(
ConfigAvailableCondition
.
class
)
static
class
HazelcastClientConfigFileConfiguration
{
@Bean
public
HazelcastInstance
hazelcastInstance
(
HazelcastProperties
properties
)
throws
IOException
{
Resource
config
=
properties
.
resolveConfigLocation
();
if
(
config
!=
null
)
{
return
HazelcastInstanceFactory
.
createHazelcastClient
(
config
);
}
return
HazelcastClient
.
newHazelcastClient
();
}
}
@Configuration
@ConditionalOnSingleCandidate
(
ClientConfig
.
class
)
static
class
HazelcastClientConfigConfiguration
{
@Bean
public
HazelcastInstance
hazelcastInstance
(
ClientConfig
config
)
{
return
HazelcastInstanceFactory
.
createHazelcastClient
(
config
);
}
}
/**
* {@link HazelcastConfigResourceCondition} that checks if the
* {@code spring.hazelcast.config} configuration key is defined.
*/
static
class
ConfigAvailableCondition
extends
HazelcastConfigResourceCondition
{
ConfigAvailableCondition
()
{
super
(
CONFIG_SYSTEM_PROPERTY
,
"file:./hazelcast-client.xml"
,
"classpath:/hazelcast-client.xml"
);
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java
View file @
3fbf1a2e
...
...
@@ -21,6 +21,7 @@ import org.springframework.boot.autoconfigure.condition.ResourceCondition;
import
org.springframework.boot.autoconfigure.condition.SpringBootCondition
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.util.Assert
;
/**
* {@link SpringBootCondition} used to check if the Hazelcast configuration is available.
...
...
@@ -29,22 +30,26 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
*
* @author Stephane Nicoll
* @author Madhura Bhave
* @author Vedran Pavic
* @since 1.3.0
*/
public
abstract
class
HazelcastConfigResourceCondition
extends
ResourceCondition
{
static
final
String
CONFIG_SYSTEM_PROPERTY
=
"hazelcast.config"
;
private
final
String
configSystemProperty
;
protected
HazelcastConfigResourceCondition
(
String
property
)
{
super
(
"Hazelcast"
,
property
,
"file:./hazelcast.xml"
,
"classpath:/hazelcast.xml"
);
protected
HazelcastConfigResourceCondition
(
String
configSystemProperty
,
String
...
resourceLocations
)
{
super
(
"Hazelcast"
,
"spring.hazelcast.config"
,
resourceLocations
);
Assert
.
notNull
(
configSystemProperty
,
"ConfigSystemProperty must not be null"
);
this
.
configSystemProperty
=
configSystemProperty
;
}
@Override
protected
ConditionOutcome
getResourceOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
if
(
System
.
getProperty
(
CONFIG_SYSTEM_PROPERTY
)
!=
null
)
{
if
(
System
.
getProperty
(
this
.
configSystemProperty
)
!=
null
)
{
return
ConditionOutcome
.
match
(
startConditionMessage
()
.
because
(
"System property '"
+
CONFIG_SYSTEM_PROPERTY
+
"' is set."
));
.
because
(
"System property '"
+
this
.
configSystemProperty
+
"' is set."
));
}
return
super
.
getResourceOutcome
(
context
,
metadata
);
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastInstanceFactory.java
View file @
3fbf1a2e
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -19,6 +19,9 @@ package org.springframework.boot.autoconfigure.hazelcast;
import
java.io.IOException
;
import
java.net.URL
;
import
com.hazelcast.client.HazelcastClient
;
import
com.hazelcast.client.config.ClientConfig
;
import
com.hazelcast.client.config.XmlClientConfigBuilder
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.config.XmlConfigBuilder
;
import
com.hazelcast.core.Hazelcast
;
...
...
@@ -34,32 +37,33 @@ import org.springframework.util.StringUtils;
*
* @author Stephane Nicoll
* @author Phillip Webb
* @author Vedran Pavic
* @since 1.3.0
*/
public
class
HazelcastInstanceFactory
{
private
Config
config
;
/**
* Create a {@link HazelcastInstanceFactory} for the specified configuration location.
* @param configLocation the location of the configuration file
* @throws IOException if the configuration location could not be read
*/
public
HazelcastInstanceFactory
(
Resource
configLocation
)
throws
IOException
{
Assert
.
notNull
(
configLocation
,
"ConfigLocation must not be null"
);
this
.
config
=
getConfig
(
configLocation
);
}
public
abstract
class
HazelcastInstanceFactory
{
/**
*
Create a {@link HazelcastInstanceFactory} for the specified configuration
.
*
Get the {@link HazelcastInstance}
.
* @param config the configuration
* @return the {@link HazelcastInstance}
*/
public
HazelcastInstanceFactory
(
Config
config
)
{
public
static
HazelcastInstance
createHazelcastInstance
(
Config
config
)
{
Assert
.
notNull
(
config
,
"Config must not be null"
);
this
.
config
=
config
;
if
(
StringUtils
.
hasText
(
config
.
getInstanceName
()))
{
return
Hazelcast
.
getOrCreateHazelcastInstance
(
config
);
}
return
Hazelcast
.
newHazelcastInstance
(
config
);
}
private
Config
getConfig
(
Resource
configLocation
)
throws
IOException
{
/**
* Get the {@link HazelcastInstance}.
* @param configLocation the location of the configuration file
* @return the {@link HazelcastInstance}
* @throws IOException if the configuration location could not be read
*/
public
static
HazelcastInstance
createHazelcastInstance
(
Resource
configLocation
)
throws
IOException
{
Assert
.
notNull
(
configLocation
,
"ConfigLocation must not be null"
);
URL
configUrl
=
configLocation
.
getURL
();
Config
config
=
new
XmlConfigBuilder
(
configUrl
).
build
();
if
(
ResourceUtils
.
isFileURL
(
configUrl
))
{
...
...
@@ -68,18 +72,34 @@ public class HazelcastInstanceFactory {
else
{
config
.
setConfigurationUrl
(
configUrl
);
}
return
c
onfig
;
return
c
reateHazelcastInstance
(
config
)
;
}
/**
* Get the {@link HazelcastInstance}.
* @return the {@link HazelcastInstance}
* Get the client {@link HazelcastInstance}.
* @param config the client configuration
* @return the client {@link HazelcastInstance}
*/
public
HazelcastInstance
getHazelcastInstance
()
{
if
(
StringUtils
.
hasText
(
this
.
config
.
getInstanceName
()))
{
return
Hazelcast
.
getOrCreateHazelcastInstance
(
this
.
config
);
public
static
HazelcastInstance
createHazelcastClient
(
ClientConfig
config
)
{
Assert
.
notNull
(
config
,
"Config must not be null"
);
if
(
StringUtils
.
hasText
(
config
.
getInstanceName
()))
{
return
HazelcastClient
.
getHazelcastClientByName
(
config
.
getInstanceName
());
}
return
Hazelcast
.
newHazelcastInstance
(
this
.
config
);
return
HazelcastClient
.
newHazelcastClient
(
config
);
}
/**
* Get the client {@link HazelcastInstance}.
* @param configLocation the location of the client configuration file
* @return the client {@link HazelcastInstance}
* @throws IOException if the configuration location could not be read
*/
public
static
HazelcastInstance
createHazelcastClient
(
Resource
configLocation
)
throws
IOException
{
Assert
.
notNull
(
configLocation
,
"ConfigLocation must not be null"
);
URL
configUrl
=
configLocation
.
getURL
();
ClientConfig
config
=
new
XmlClientConfigBuilder
(
configUrl
).
build
();
return
createHazelcastClient
(
config
);
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration.java
0 → 100644
View file @
3fbf1a2e
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
hazelcast
;
import
java.io.IOException
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.core.HazelcastInstance
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.Resource
;
/**
* Configuration for Hazelcast server.
*
* @author Stephane Nicoll
* @author Vedran Pavic
* @since 2.0.0
*/
class
HazelcastServerConfiguration
{
static
final
String
CONFIG_SYSTEM_PROPERTY
=
"hazelcast.config"
;
@Configuration
@ConditionalOnMissingBean
(
Config
.
class
)
@Conditional
(
ConfigAvailableCondition
.
class
)
static
class
HazelcastServerConfigFileConfiguration
{
@Bean
public
HazelcastInstance
hazelcastInstance
(
HazelcastProperties
properties
)
throws
IOException
{
Resource
config
=
properties
.
resolveConfigLocation
();
if
(
config
!=
null
)
{
return
HazelcastInstanceFactory
.
createHazelcastInstance
(
config
);
}
return
Hazelcast
.
newHazelcastInstance
();
}
}
@Configuration
@ConditionalOnSingleCandidate
(
Config
.
class
)
static
class
HazelcastServerConfigConfiguration
{
@Bean
public
HazelcastInstance
hazelcastInstance
(
Config
config
)
{
return
HazelcastInstanceFactory
.
createHazelcastInstance
(
config
);
}
}
/**
* {@link HazelcastConfigResourceCondition} that checks if the
* {@code spring.hazelcast.config} configuration key is defined.
*/
static
class
ConfigAvailableCondition
extends
HazelcastConfigResourceCondition
{
ConfigAvailableCondition
()
{
super
(
CONFIG_SYSTEM_PROPERTY
,
"file:./hazelcast.xml"
,
"classpath:/hazelcast.xml"
);
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java
View file @
3fbf1a2e
...
...
@@ -49,12 +49,15 @@ import org.junit.After;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.DirectFieldAccessor
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.boot.autoconfigure.cache.support.MockCachingProvider
;
import
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration
;
import
org.springframework.boot.junit.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.CacheManager
;
...
...
@@ -91,6 +94,8 @@ import static org.mockito.Mockito.verify;
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"hazelcast-client-*.jar"
)
public
class
CacheAutoConfigurationTests
{
@Rule
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java
0 → 100644
View file @
3fbf1a2e
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
hazelcast
;
import
java.io.IOException
;
import
com.hazelcast.client.config.ClientConfig
;
import
com.hazelcast.client.impl.HazelcastClientProxy
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.core.HazelcastInstance
;
import
org.junit.After
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for client {@link HazelcastAutoConfiguration}.
*
* @author Vedran Pavic
*/
public
class
HazelcastAutoConfigurationClientTests
{
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
private
AnnotationConfigApplicationContext
context
;
@After
public
void
closeContext
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
private
static
HazelcastInstance
hazelcastInstance
;
@BeforeClass
public
static
void
init
()
{
hazelcastInstance
=
Hazelcast
.
newHazelcastInstance
();
}
@AfterClass
public
static
void
close
()
{
if
(
hazelcastInstance
!=
null
)
{
hazelcastInstance
.
shutdown
();
}
}
@Test
public
void
systemProperty
()
throws
IOException
{
System
.
setProperty
(
HazelcastClientConfiguration
.
CONFIG_SYSTEM_PROPERTY
,
"classpath:org/springframework/boot/autoconfigure/hazelcast/"
+
"hazelcast-client-specific.xml"
);
try
{
load
();
HazelcastInstance
hazelcastInstance
=
this
.
context
.
getBean
(
HazelcastInstance
.
class
);
assertThat
(
hazelcastInstance
).
isInstanceOf
(
HazelcastClientProxy
.
class
);
assertThat
(
hazelcastInstance
.
getName
()).
startsWith
(
"hz.client_"
);
}
finally
{
System
.
clearProperty
(
HazelcastClientConfiguration
.
CONFIG_SYSTEM_PROPERTY
);
}
}
@Test
public
void
explicitConfigFile
()
throws
IOException
{
load
(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+
"hazelcast/hazelcast-client-specific.xml"
);
HazelcastInstance
hazelcastInstance
=
this
.
context
.
getBean
(
HazelcastInstance
.
class
);
assertThat
(
hazelcastInstance
).
isInstanceOf
(
HazelcastClientProxy
.
class
);
assertThat
(
hazelcastInstance
.
getName
()).
startsWith
(
"hz.client_"
);
}
@Test
public
void
explicitConfigUrl
()
throws
IOException
{
load
(
"spring.hazelcast.config=hazelcast-client-default.xml"
);
HazelcastInstance
hazelcastInstance
=
this
.
context
.
getBean
(
HazelcastInstance
.
class
);
assertThat
(
hazelcastInstance
).
isInstanceOf
(
HazelcastClientProxy
.
class
);
assertThat
(
hazelcastInstance
.
getName
()).
startsWith
(
"hz.client_"
);
}
@Test
public
void
unknownConfigFile
()
{
this
.
thrown
.
expect
(
BeanCreationException
.
class
);
this
.
thrown
.
expectMessage
(
"foo/bar/unknown.xml"
);
load
(
"spring.hazelcast.config=foo/bar/unknown.xml"
);
}
@Test
public
void
clientConfigHasPriority
()
{
load
(
HazelcastServerAndClientConfig
.
class
,
"spring.hazelcast.config=this-is-ignored.xml"
);
HazelcastInstance
hazelcastInstance
=
this
.
context
.
getBean
(
HazelcastInstance
.
class
);
assertThat
(
hazelcastInstance
).
isInstanceOf
(
HazelcastClientProxy
.
class
);
}
private
void
load
(
String
...
environment
)
{
load
(
null
,
environment
);
}
private
void
load
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
applicationContext
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
applicationContext
,
environment
);
if
(
config
!=
null
)
{
applicationContext
.
register
(
config
);
}
applicationContext
.
register
(
HazelcastAutoConfiguration
.
class
);
applicationContext
.
refresh
();
this
.
context
=
applicationContext
;
}
@Configuration
static
class
HazelcastServerAndClientConfig
{
@Bean
public
Config
config
()
{
return
new
Config
();
}
@Bean
public
ClientConfig
clientConfig
()
{
return
new
ClientConfig
();
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java
→
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration
Server
Tests.java
View file @
3fbf1a2e
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -27,8 +27,11 @@ import org.junit.After;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.junit.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -42,7 +45,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
*/
public
class
HazelcastAutoConfigurationTests
{
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"hazelcast-client-*.jar"
)
public
class
HazelcastAutoConfigurationServerTests
{
@Rule
public
final
ExpectedException
thrown
=
ExpectedException
.
none
();
...
...
@@ -67,7 +72,7 @@ public class HazelcastAutoConfigurationTests {
@Test
public
void
systemProperty
()
throws
IOException
{
System
.
setProperty
(
Hazelcast
ConfigResourceCondi
tion
.
CONFIG_SYSTEM_PROPERTY
,
System
.
setProperty
(
Hazelcast
ServerConfigura
tion
.
CONFIG_SYSTEM_PROPERTY
,
"classpath:org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"
);
try
{
load
();
...
...
@@ -78,7 +83,7 @@ public class HazelcastAutoConfigurationTests {
assertThat
(
queueConfigs
).
hasSize
(
1
).
containsKey
(
"foobar"
);
}
finally
{
System
.
clearProperty
(
Hazelcast
ConfigResourceCondi
tion
.
CONFIG_SYSTEM_PROPERTY
);
System
.
clearProperty
(
Hazelcast
ServerConfigura
tion
.
CONFIG_SYSTEM_PROPERTY
);
}
}
...
...
spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/hazelcast/hazelcast-client-specific.xml
0 → 100644
View file @
3fbf1a2e
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast-client
xmlns=
"http://www.hazelcast.com/schema/client-config"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.8.xsd"
>
</hazelcast-client>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment