Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -20,6 +20,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.io.Resource;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.Assert;

Expand All @@ -35,6 +36,8 @@
*/
public abstract class HazelcastConfigResourceCondition extends ResourceCondition {

private static final String HAZELCAST_JET_CONFIG_FILE = "classpath:/hazelcast-jet-default.yaml";

private final String configSystemProperty;

protected HazelcastConfigResourceCondition(String configSystemProperty, String... resourceLocations) {
Expand All @@ -43,6 +46,16 @@ protected HazelcastConfigResourceCondition(String configSystemProperty, String..
this.configSystemProperty = configSystemProperty;
}

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't match with the javadoc or name of HazelcastConfigResourceCondition so it shouldn't be located there.

Resource resource = context.getResourceLoader().getResource(HAZELCAST_JET_CONFIG_FILE);
if (resource.exists()) {
return ConditionOutcome.noMatch(
startConditionMessage().because("Found Hazelcast Jet default config file on the classpath."));
}
return super.getMatchOutcome(context, metadata);
}

@Override
protected ConditionOutcome getResourceOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (System.getProperty(this.configSystemProperty) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2012-2019 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
*
* https://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 com.hazelcast.core.HazelcastInstance;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Test for {@link HazelcastAutoConfiguration} when Hazelcast Jet is present. Spring Boot
* should not auto-create Hazelcast IMDG instances when Hazelcast Jet is present.
*
* @author Ali Gurbuz
*/
@ClassPathOverrides("com.hazelcast.jet:hazelcast-jet:4.0")
Copy link
Member

@snicoll snicoll Mar 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer no to refer to a concept if we can avoid doing so. This test could be put in the main test with a special ClassLoader that returns the expected resource and shows the hazelcast instance is not created.

class HazelcastAutoConfigurationJetTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class));

@Test
void testHazelcastInstanceNotCreatedWhenJetIsPresent() {
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(HazelcastInstance.class));
}

}