Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -72,7 +72,7 @@ private ClientConfig getClientConfig(Resource clientConfigLocation) throws IOExc
*/
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -124,6 +124,15 @@ void clientConfigTakesPrecedence() {
.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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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>