Skip to content

Commit fa4d247

Browse files
committed
Enable Locator applications configured and bootstrapped with Spring to be optionally configured with Apache Geode's Cluster Configuration Service.
Configuration with Aapche Geode's Cluster Configuration Service is now disabled by default, to be consistent with peer Cache applications. Closes #622.
1 parent 075a0f4 commit fa4d247

File tree

5 files changed

+94
-35
lines changed

5 files changed

+94
-35
lines changed

Diff for: spring-data-geode/src/main/java/org/springframework/data/gemfire/LocatorFactoryBean.java

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class LocatorFactoryBean extends AbstractFactoryBeanSupport<Locator> impl
6262
public static final String LOG_LEVEL_PROPERTY = GemFireProperties.LOG_LEVEL.getName();
6363

6464
private boolean useBeanFactoryLocator = false;
65+
private boolean useClusterConfigurationService = false;
6566

6667
private Integer port = DEFAULT_PORT;
6768

@@ -148,6 +149,9 @@ protected LocatorLauncher.Builder configureGemfireProperties(LocatorLauncher.Bui
148149
gemfireProperties.stringPropertyNames().stream()
149150
.forEach(propertyName -> locatorBuilder.set(propertyName, gemfireProperties.getProperty(propertyName)));
150151

152+
locatorBuilder.set(GemFireProperties.USE_CLUSTER_CONFIGURATION.getName(),
153+
String.valueOf(isUseClusterConfigurationService()));
154+
151155
return locatorBuilder;
152156
}
153157

@@ -293,4 +297,12 @@ public void setUseBeanFactoryLocator(boolean useBeanFactoryLocator) {
293297
public boolean isUseBeanFactoryLocator() {
294298
return this.useBeanFactoryLocator;
295299
}
300+
301+
public void setUseClusterConfigurationService(boolean useClusterConfigurationService) {
302+
this.useClusterConfigurationService = useClusterConfigurationService;
303+
}
304+
305+
public boolean isUseClusterConfigurationService() {
306+
return this.useClusterConfigurationService;
307+
}
296308
}

Diff for: spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorApplication.java

+14
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@
3535
* application to become a {@link Locator} based application.
3636
*
3737
* @author John Blum
38+
* @see java.lang.annotation.Annotation
3839
* @see java.lang.annotation.Documented
3940
* @see java.lang.annotation.Inherited
4041
* @see java.lang.annotation.Retention
4142
* @see java.lang.annotation.Target
43+
* @see org.apache.geode.distributed.Locator
4244
* @see org.springframework.context.annotation.Configuration
4345
* @see org.springframework.context.annotation.Import
4446
* @see org.springframework.data.gemfire.config.annotation.LocatorApplicationConfiguration
47+
* @see org.springframework.data.gemfire.support.GemfireBeanFactoryLocator
4548
* @since 2.2.0
4649
*/
4750
@Target(ElementType.TYPE)
@@ -123,4 +126,15 @@
123126
*/
124127
boolean useBeanFactoryLocator() default LocatorApplicationConfiguration.DEFAULT_USE_BEAN_FACTORY_LOCATOR;
125128

129+
/**
130+
* Configures whether the Spring-based {@link Locator} will pull configuration metadata from the Apache Geode
131+
* cluster-based, Cluster Configuration Service.
132+
*
133+
* Defaults to {@literal false}.
134+
*
135+
* Use {@literal spring.data.gemfire.locator.use-cluster-configuration} property
136+
* in {@literal application.properties}.
137+
*/
138+
boolean useClusterConfiguration() default LocatorApplicationConfiguration.DEFAULT_USE_CLUSTER_CONFIGURATTION_SERVICE;
139+
126140
}

Diff for: spring-data-geode/src/main/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfiguration.java

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
public class LocatorApplicationConfiguration extends AbstractAnnotationConfigSupport implements ImportAware {
6868

6969
public static final boolean DEFAULT_USE_BEAN_FACTORY_LOCATOR = false;
70+
public static final boolean DEFAULT_USE_CLUSTER_CONFIGURATTION_SERVICE = false;
7071

7172
public static final int DEFAULT_PORT = 10334;
7273

@@ -86,6 +87,7 @@ public class LocatorApplicationConfiguration extends AbstractAnnotationConfigSup
8687
Arrays.asList(CacheFactoryBean.class.getName(), ClientCacheFactoryBean.class.getName());
8788

8889
private boolean useBeanFactoryLocator = DEFAULT_USE_BEAN_FACTORY_LOCATOR;
90+
private boolean useClusterConfigurationService = DEFAULT_USE_CLUSTER_CONFIGURATTION_SERVICE;
8991

9092
private int port = DEFAULT_PORT;
9193

@@ -189,6 +191,9 @@ public void setImportMetadata(@NonNull AnnotationMetadata importMetadata) {
189191

190192
setUseBeanFactoryLocator(resolveProperty("use-bean-factory-locator", Boolean.class,
191193
locatorApplicationAnnotationAttributes.getBoolean("useBeanFactoryLocator")));
194+
195+
setUseClusterConfigurationService(resolveProperty(locatorProperty("use-cluster-configuration"),
196+
Boolean.class, locatorApplicationAnnotationAttributes.getBoolean("useClusterConfiguration")));
192197
}
193198
}
194199

@@ -205,6 +210,7 @@ public LocatorFactoryBean locatorApplication() {
205210
locatorFactoryBean.setName(getName());
206211
locatorFactoryBean.setPort(getPort());
207212
locatorFactoryBean.setUseBeanFactoryLocator(isUseBeanFactoryLocator());
213+
locatorFactoryBean.setUseClusterConfigurationService(isUseClusterConfigurationService());
208214

209215
return locatorFactoryBean;
210216
}
@@ -272,4 +278,12 @@ public boolean isUseBeanFactoryLocator() {
272278
public void setUseBeanFactoryLocator(boolean useBeanFactoryLocator) {
273279
this.useBeanFactoryLocator = useBeanFactoryLocator;
274280
}
281+
282+
public void setUseClusterConfigurationService(boolean useClusterConfigurationService) {
283+
this.useClusterConfigurationService = useClusterConfigurationService;
284+
}
285+
286+
public boolean isUseClusterConfigurationService() {
287+
return useClusterConfigurationService;
288+
}
275289
}

Diff for: spring-data-geode/src/test/java/org/springframework/data/gemfire/LocatorFactoryBeanUnitTests.java

+51-34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package org.springframework.data.gemfire;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
20+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
1921
import static org.mockito.ArgumentMatchers.any;
2022
import static org.mockito.ArgumentMatchers.eq;
2123
import static org.mockito.Mockito.doAnswer;
@@ -26,6 +28,7 @@
2628
import static org.mockito.Mockito.spy;
2729
import static org.mockito.Mockito.times;
2830
import static org.mockito.Mockito.verify;
31+
import static org.mockito.Mockito.verifyNoMoreInteractions;
2932
import static org.mockito.Mockito.when;
3033

3134
import java.net.InetAddress;
@@ -63,7 +66,6 @@ public class LocatorFactoryBeanUnitTests {
6366

6467
@Before
6568
public void setup() {
66-
6769
this.locatorFactoryBean = spy(new LocatorFactoryBean());
6870
}
6971

@@ -169,9 +171,9 @@ public void configuresLocatorLauncherBuilderGemFireProperties() {
169171

170172
Properties gemfireProperties = new Properties();
171173

172-
gemfireProperties.setProperty("name", "TEST");
173-
gemfireProperties.setProperty("log-level", "config");
174-
gemfireProperties.setProperty("locators", "localhost[11235],skullbox[12480]");
174+
gemfireProperties.setProperty(GemFireProperties.NAME.getName(), "TEST");
175+
gemfireProperties.setProperty(GemFireProperties.LOG_LEVEL.getName(), "config");
176+
gemfireProperties.setProperty(GemFireProperties.LOCATORS.getName(), "localhost[11235],skullbox[12480]");
175177

176178
LocatorLauncher.Builder locatorBuilderSpy = spy(new LocatorLauncher.Builder());
177179

@@ -181,6 +183,11 @@ public void configuresLocatorLauncherBuilderGemFireProperties() {
181183
gemfireProperties.stringPropertyNames().forEach(propertyName ->
182184
verify(locatorBuilderSpy, times(1))
183185
.set(eq(propertyName), eq(gemfireProperties.getProperty(propertyName))));
186+
187+
verify(locatorBuilderSpy, times(1))
188+
.set(eq(GemFireProperties.USE_CLUSTER_CONFIGURATION.getName()), eq("false"));
189+
190+
verifyNoMoreInteractions(locatorBuilderSpy);
184191
}
185192

186193
@Test
@@ -195,19 +202,13 @@ public void getObjectReturnsLocator() throws Exception {
195202
verify(this.locatorFactoryBean, times(1)).getLocator();
196203
}
197204

198-
@Test(expected = IllegalStateException.class)
205+
@Test
199206
public void getObjectThrowsIllegalStateException() throws Exception {
200207

201-
try {
202-
this.locatorFactoryBean.getObject();
203-
}
204-
catch (IllegalStateException expected) {
205-
206-
assertThat(expected).hasMessage("Locator was not configured and initialized");
207-
assertThat(expected).hasNoCause();
208-
209-
throw expected;
210-
}
208+
assertThatIllegalStateException()
209+
.isThrownBy(() -> this.locatorFactoryBean.getObject())
210+
.withMessage("Locator was not configured and initialized")
211+
.withNoCause();
211212
}
212213

213214
@Test
@@ -385,33 +386,49 @@ public void setPortToValidValue() {
385386
assertThat(this.locatorFactoryBean.getPort()).isEqualTo(54321);
386387
}
387388

388-
@Test(expected = IllegalArgumentException.class)
389+
@Test
389390
public void setPortToOverflowValue() {
390391

391-
try {
392-
this.locatorFactoryBean.setPort(65536);
393-
}
394-
catch (IllegalArgumentException expected) {
392+
assertThatIllegalArgumentException()
393+
.isThrownBy(() -> this.locatorFactoryBean.setPort(65536))
394+
.withMessage("Network port [65536] is not valid")
395+
.withNoCause();
396+
}
395397

396-
assertThat(expected).hasMessage("Network port [65536] is not valid");
397-
assertThat(expected).hasNoCause();
398+
@Test
399+
public void setPortToUnderflowValue() {
398400

399-
throw expected;
400-
}
401+
assertThatIllegalArgumentException()
402+
.isThrownBy(() -> this.locatorFactoryBean.setPort(-1))
403+
.withMessage("Network port [-1] is not valid")
404+
.withNoCause();
401405
}
402406

403-
@Test(expected = IllegalArgumentException.class)
404-
public void setPortToUnderflowValue() {
407+
@Test
408+
public void locatorFactoryBeanUseOfBeanFactoryLocator() {
409+
410+
assertThat(this.locatorFactoryBean.isUseBeanFactoryLocator()).isFalse();
411+
412+
this.locatorFactoryBean.setUseBeanFactoryLocator(true);
413+
414+
assertThat(this.locatorFactoryBean.isUseBeanFactoryLocator()).isTrue();
415+
416+
this.locatorFactoryBean.setUseBeanFactoryLocator(false);
417+
418+
assertThat(this.locatorFactoryBean.isUseBeanFactoryLocator()).isFalse();
419+
}
420+
421+
@Test
422+
public void locatorFactoryBeanUseOfClusterConfigurationService() {
423+
424+
assertThat(this.locatorFactoryBean.isUseClusterConfigurationService()).isFalse();
425+
426+
this.locatorFactoryBean.setUseClusterConfigurationService(true);
405427

406-
try {
407-
this.locatorFactoryBean.setPort(-1);
408-
}
409-
catch (IllegalArgumentException expected) {
428+
assertThat(this.locatorFactoryBean.isUseClusterConfigurationService()).isTrue();
410429

411-
assertThat(expected).hasMessage("Network port [-1] is not valid");
412-
assertThat(expected).hasNoCause();
430+
this.locatorFactoryBean.setUseClusterConfigurationService(false);
413431

414-
throw expected;
415-
}
432+
assertThat(this.locatorFactoryBean.isUseClusterConfigurationService()).isFalse();
416433
}
417434
}

Diff for: spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/LocatorApplicationConfigurationIntegrationTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void locatorFactoryBeanWasConfiguredFromAnnotationAttributes() {
6767
assertThat(this.locatorFactoryBean.getName().orElse(null)).isEqualTo("MockLocator");
6868
assertThat(this.locatorFactoryBean.getPort()).isEqualTo(9876);
6969
assertThat(this.locatorFactoryBean.isUseBeanFactoryLocator()).isTrue();
70+
assertThat(this.locatorFactoryBean.isUseClusterConfigurationService()).isTrue();
7071
}
7172

7273
@EnableGemFireMockObjects
@@ -77,7 +78,8 @@ public void locatorFactoryBeanWasConfiguredFromAnnotationAttributes() {
7778
logLevel = "WARN",
7879
name = "MockLocator",
7980
port = 9876,
80-
useBeanFactoryLocator = true
81+
useBeanFactoryLocator = true,
82+
useClusterConfiguration = true
8183
)
8284
static class TestConfiguration {
8385

0 commit comments

Comments
 (0)