Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HazelcastClientFactory can return null instead of HazelcastInstance if there is no HazelcastClient for the given name #19709

Closed
nosan opened this issue Jan 14, 2020 · 4 comments
Labels
status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@nosan
Copy link
Contributor

nosan commented Jan 14, 2020

Hello,

When I was working on #19669 I found that
HazelcastAutoConfiguration may create a NullBean instead of HazelcastInstance.

When HazelcastClientFactory tries to find the HazelcastInstance by name and there is no instance with that name, the null will be returned. It happens only when ClientConfig has an instance's name.

Test to reproduce:

// - HazelcastAutoConfigurationClientTests
@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"));
}
<?xml version="1.0" encoding="UTF-8"?>
<!--hazelcast-client-instance.xml-->
<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>

The test fails due to:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'hazelcastInstance' is expected to be of type 'com.hazelcast.core.HazelcastInstance' but was actually of type 'org.springframework.beans.factory.support.NullBean'

This issue can be fixed with a new method which was provided by Hazelcast (hazelcast/hazelcast#16362), there is also a back-port (hazelcast/hazelcast#16363), so that method should be available in Hazelcast 3.12.6

My idea is change HazelcastClient.getHazelcastClientByName(Name) to HazelcastClient. getOrCreateHazelcastClient(Config) in HazelcastClientFactory when a new version of Hazelcast will be released.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 14, 2020
@wilkinsona
Copy link
Member

Thanks, @nosan. What you have proposed sounds reasonable to me. WDYT, @snicoll?

@snicoll
Copy link
Member

snicoll commented Jan 14, 2020

Dmytro and I already chatted about that offline so it's all good from my perspective. We should add a test that exercises the new behaviour as part of fixing this.

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 14, 2020
@wilkinsona wilkinsona added this to the 2.2.x milestone Jan 14, 2020
@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label Jan 14, 2020
@snicoll snicoll modified the milestones: 2.2.x, 2.3.x Feb 4, 2020
@snicoll
Copy link
Member

snicoll commented Feb 4, 2020

Fixing this would require Hazelcast 3.12.6 as a minimum version and I am a bit nervous doing that so late in the 2.2.x cycle. I've moved the fix to 2.3.x

nosan added a commit to nosan/spring-boot that referenced this issue Feb 4, 2020
nosan added a commit to nosan/spring-boot that referenced this issue Feb 9, 2020
@snicoll
Copy link
Member

snicoll commented Feb 10, 2020

Closing in favour of PR #20109

@snicoll snicoll closed this as completed Feb 10, 2020
@snicoll snicoll added status: superseded An issue that has been superseded by another and removed status: blocked An issue that's blocked on an external project change labels Feb 10, 2020
@snicoll snicoll removed this from the 2.3.x milestone Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants