Refactor configureTopology(..) to delegate to configureEnvironment(:Environment).

The new 'configureEnvironment(:Environment) method attempts to add a custom PropertySource to the Environment if the Environment is configurable, otherwise proceeds in setting a Java System Property as before.

The idea is, the Environment is more recycable than Java System Properties, particularly if the Spring ApplicationContext is refreshed.

Renames DEFAULT_CLUSTER_CONDITION_MATCH to DEFAULT_CLUSTER_AWARE_CONDITION_MATCH.

Renames DEFAULT_CLUSTER_CONDITION_STRICT_MATCH to DEFAULT_CLUSTER_AWARE_CONDITION_STRICT_MATCH.
This commit is contained in:
John Blum
2021-01-25 12:51:28 -08:00
parent c9996c29da
commit ee242bece8
5 changed files with 42 additions and 21 deletions

View File

@@ -66,6 +66,7 @@ import org.springframework.data.gemfire.tests.integration.IntegrationTestsSuppor
import org.springframework.geode.config.annotation.ClusterAwareConfiguration.PoolConnectionEndpoint;
import org.springframework.geode.config.annotation.ClusterAwareConfiguration.SocketCreationException;
import org.springframework.lang.NonNull;
import org.springframework.mock.env.MockEnvironment;
import org.slf4j.Logger;
@@ -160,14 +161,14 @@ public class ClusterAwareConfigurationUnitTests extends IntegrationTestsSupport
doReturn(mockEnvironment).when(mockConditionContext).getEnvironment();
doReturn(true).when(mockEnvironment)
.getProperty(eq(ClusterAwareConfiguration.SPRING_BOOT_DATA_GEMFIRE_CLUSTER_CONDITION_MATCH_PROPERTY),
eq(Boolean.class), eq(ClusterAwareConfiguration.DEFAULT_CLUSTER_CONDITION_MATCH));
eq(Boolean.class), eq(ClusterAwareConfiguration.DEFAULT_CLUSTER_AWARE_CONDITION_MATCH));
assertThat(this.condition.isMatch(mockConditionContext)).isTrue();
verify(mockConditionContext, times(1)).getEnvironment();
verify(mockEnvironment, times(1))
.getProperty(eq(ClusterAwareConfiguration.SPRING_BOOT_DATA_GEMFIRE_CLUSTER_CONDITION_MATCH_PROPERTY),
eq(Boolean.class), eq(ClusterAwareConfiguration.DEFAULT_CLUSTER_CONDITION_MATCH));
eq(Boolean.class), eq(ClusterAwareConfiguration.DEFAULT_CLUSTER_AWARE_CONDITION_MATCH));
verifyNoMoreInteractions(mockConditionContext, mockEnvironment);
}
@@ -727,18 +728,19 @@ public class ClusterAwareConfigurationUnitTests extends IntegrationTestsSupport
assertThat(System.getProperties())
.doesNotContainKey(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY);
ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class);
MockEnvironment mockEnvironment = spy(new MockEnvironment());
ConnectionEndpointList connectionEndpoints =
new ConnectionEndpointList(new ConnectionEndpoint("localhost", 1234));
this.condition.configureTopology(mockEnvironment, connectionEndpoints,0);
assertThat(System.getProperty(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY))
assertThat(mockEnvironment.getProperty(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY))
.isEqualTo("LOCAL");
verify(mockEnvironment, times(1))
.containsProperty(eq(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY));
verify(mockEnvironment, times(1)).getPropertySources();
}
@Test

View File

@@ -23,7 +23,6 @@ import org.junit.AfterClass;
import org.junit.Test;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.NestedExceptionUtils;
@@ -90,8 +89,8 @@ public class PropertyConfiguredStrictMatchingClusterNotAvailableConfigurationInt
throw expected;
}
finally {
assertThat(System.getProperty(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY))
.isEqualTo(ClientRegionShortcut.LOCAL.name());
assertThat(System.getProperties())
.doesNotContainKeys(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY);
}
}

View File

@@ -21,7 +21,6 @@ import org.junit.AfterClass;
import org.junit.Test;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
@@ -71,8 +70,8 @@ public class StrictMatchingClusterNotAvailableConfigurationIntegrationTests
throw expected;
}
finally {
assertThat(System.getProperty(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY))
.isEqualTo(ClientRegionShortcut.LOCAL.name());
assertThat(System.getProperties())
.doesNotContainKeys(ClusterAwareConfiguration.SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY);
}
}