Skip to content

Commit 8f3e197

Browse files
committed
Add support for Spring configured and bootstrapped Locator-based applications.
Resolves gh-37.
1 parent f9be520 commit 8f3e197

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

spring-geode-autoconfigure/src/main/java/org/springframework/geode/boot/autoconfigure/ClientCacheAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.geode.cache.GemFireCache;
2020
import org.apache.geode.cache.client.ClientCache;
21+
import org.apache.geode.distributed.Locator;
2122
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -32,6 +33,7 @@
3233
* @author John Blum
3334
* @see org.apache.geode.cache.GemFireCache
3435
* @see org.apache.geode.cache.client.ClientCache
36+
* @see org.apache.geode.distributed.Locator
3537
* @see org.springframework.boot.autoconfigure.EnableAutoConfiguration
3638
* @see org.springframework.context.annotation.Configuration
3739
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
@@ -40,7 +42,7 @@
4042
*/
4143
@Configuration
4244
@ConditionalOnClass({ ClientCacheFactoryBean.class, ClientCache.class })
43-
@ConditionalOnMissingBean(GemFireCache.class)
45+
@ConditionalOnMissingBean({ GemFireCache.class, Locator.class })
4446
@ClientCacheApplication
4547
public class ClientCacheAutoConfiguration {
4648

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
* or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
package org.springframework.geode.boot.autoconfigure.locator;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mockito.Mockito.mock;
20+
21+
import org.apache.geode.cache.GemFireCache;
22+
import org.apache.geode.cache.client.ClientCache;
23+
import org.apache.geode.distributed.Locator;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
30+
import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration;
31+
import org.springframework.test.context.ContextConfiguration;
32+
import org.springframework.test.context.junit4.SpringRunner;
33+
34+
/**
35+
* Integration Tests asserting that a {@link ClientCache} is not auto-configured by SBDG if a {{@link Locator} bean
36+
* is present in the Spring container.
37+
*
38+
* @author John Blum
39+
* @see org.junit.Test
40+
* @see org.apache.geode.cache.GemFireCache
41+
* @see org.apache.geode.cache.client.ClientCache
42+
* @see org.apache.geode.distributed.Locator
43+
* @see org.springframework.boot.autoconfigure.SpringBootApplication
44+
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
45+
* @see org.springframework.test.context.ContextConfiguration
46+
* @see org.springframework.test.context.junit4.SpringRunner
47+
* @since 1.1.0
48+
*/
49+
@RunWith(SpringRunner.class)
50+
@ContextConfiguration
51+
@SuppressWarnings("unused")
52+
public class SpringBootLocatorApplicationIntegrationTests {
53+
54+
@Autowired(required = false)
55+
private GemFireCache clientCache;
56+
57+
@Autowired
58+
private Locator mockLocator;
59+
60+
@Test
61+
public void noCacheInstanceIsAutoConfiguredWhenLocatorBeanIsPresent() {
62+
63+
assertThat(this.clientCache).isNull();
64+
assertThat(this.mockLocator).isNotNull();
65+
}
66+
67+
@EnableGemFireMockObjects
68+
@SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class)
69+
static class TestConfiguration {
70+
71+
@Bean
72+
Locator mockLocator() {
73+
return mock(Locator.class);
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)