Create HazelCastClient if necessary
This commit makes sure to create a HazelcastClient if an instance name is provided in configuration and if no such client already exists. This harmonizes the behaviour with of the server counter-part. See gh-20109
This commit is contained in:
parent
e8b97dbc75
commit
67dd9ad537
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -72,7 +72,7 @@ public class HazelcastClientFactory {
|
|||
*/
|
||||
public HazelcastInstance getHazelcastInstance() {
|
||||
if (StringUtils.hasText(this.clientConfig.getInstanceName())) {
|
||||
return HazelcastClient.getHazelcastClientByName(this.clientConfig.getInstanceName());
|
||||
return HazelcastClient.getOrCreateHazelcastClient(this.clientConfig);
|
||||
}
|
||||
return HazelcastClient.newHazelcastClient(this.clientConfig);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
|
@ -124,6 +124,15 @@ class HazelcastAutoConfigurationClientTests {
|
|||
.getBean(HazelcastInstance.class).isInstanceOf(HazelcastClientProxy.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientConfigWithInstanceName() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.hazelcast.config=classpath:org/springframework/"
|
||||
+ "boot/autoconfigure/hazelcast/hazelcast-client-instance.xml")
|
||||
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
|
||||
.extracting(HazelcastInstance::getName).isEqualTo("spring-boot"));
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertSpecificHazelcastClient(String label) {
|
||||
return (context) -> assertThat(context).getBean(HazelcastInstance.class).isInstanceOf(HazelcastInstance.class)
|
||||
.has(labelEqualTo(label));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?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.12.xsd">
|
||||
|
||||
<instance-name>spring-boot</instance-name>
|
||||
</hazelcast-client>
|
||||
Loading…
Reference in New Issue