Fix failing tests.
Polish. Resolves gh-493.
This commit is contained in:
@@ -130,7 +130,11 @@ public abstract class AbstractResolvableCacheFactoryBean extends AbstractBasicCa
|
||||
|
||||
this.cacheResolutionMessagePrefix = "Found existing";
|
||||
|
||||
return fetchCache();
|
||||
T cache = fetchCache();
|
||||
|
||||
cache = postProcess(cache);
|
||||
|
||||
return cache;
|
||||
}
|
||||
catch (CacheClosedException cause) {
|
||||
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.data.gemfire.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.data.Offset.offset;
|
||||
import static org.springframework.data.gemfire.support.GemfireBeanFactoryLocator.newBeanFactoryLocator;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.util.GatewayConflictHelper;
|
||||
import org.apache.geode.cache.util.GatewayConflictResolver;
|
||||
import org.apache.geode.cache.util.TimestampedEntryEvent;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration Tests for {@link CacheParser}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.CacheParser
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class CacheNamespaceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unused")
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testNoNamedCache() {
|
||||
|
||||
assertThat(applicationContext.containsBean("gemfireCache")).isTrue();
|
||||
assertThat(applicationContext.containsBean("gemfire-cache")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheXml()).isNull();
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.getProperties();
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(cacheFactoryBean.getEnableAutoReconnect()).isFalse();
|
||||
assertThat(gemfireProperties.containsKey("disable-auto-reconnect")).isTrue();
|
||||
assertThat(Boolean.parseBoolean(gemfireProperties.getProperty("disable-auto-reconnect"))).isTrue();
|
||||
assertThat(cacheFactoryBean.getUseClusterConfiguration()).isFalse();
|
||||
assertThat(gemfireProperties.containsKey("use-cluster-configuration")).isTrue();
|
||||
assertThat(Boolean.parseBoolean(gemfireProperties.getProperty("use-cluster-configuration"))).isFalse();
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertThat(gemfireCache).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem()).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem().getProperties()).isNotNull();
|
||||
assertThat(gemfireCache.getDistributedSystem().getProperties().containsKey("disable-auto-reconnect")).isNotNull();
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedCache() {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-name")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-name", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getCacheXml()).isNull();
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.getProperties();
|
||||
|
||||
assertThat(gemfireProperties).isNotNull();
|
||||
assertThat(cacheFactoryBean.getEnableAutoReconnect()).isFalse();
|
||||
assertThat(gemfireProperties.containsKey("disable-auto-reconnect")).isTrue();
|
||||
assertThat(Boolean.parseBoolean(gemfireProperties.getProperty("disable-auto-reconnect"))).isTrue();
|
||||
assertThat(cacheFactoryBean.getUseClusterConfiguration()).isFalse();
|
||||
assertThat(gemfireProperties.containsKey("use-cluster-configuration")).isTrue();
|
||||
assertThat(Boolean.parseBoolean(gemfireProperties.getProperty("use-cluster-configuration"))).isFalse();
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect"))).isTrue();
|
||||
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("use-cluster-configuration"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectDisabled() {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-auto-reconnect-disabled")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-auto-reconnect-disabled", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getEnableAutoReconnect()).isFalse();
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("cache-with-auto-reconnect-disabled", Cache.class);
|
||||
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectEnabled() {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-auto-reconnect-enabled")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-auto-reconnect-enabled", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getEnableAutoReconnect()).isTrue();
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("cache-with-auto-reconnect-enabled", Cache.class);
|
||||
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithGatewayConflictResolver() {
|
||||
|
||||
Cache cache = applicationContext.getBean("cache-with-gateway-conflict-resolver", Cache.class);
|
||||
|
||||
assertThat(cache.getGatewayConflictResolver()).isInstanceOf(TestGatewayConflictResolver.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testCacheWithNoBeanFactoryLocator() {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-no-bean-factory-locator")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-no-bean-factory-locator", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getBeanFactoryLocator()).isNull();
|
||||
|
||||
newBeanFactoryLocator().useBeanFactory("cache-with-no-bean-factory-locator");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithUseClusterConfigurationDisabled() {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-use-cluster-configuration-disabled")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-use-cluster-configuration-disabled", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getEnableAutoReconnect()).isFalse();
|
||||
|
||||
Cache gemfireCache =
|
||||
applicationContext.getBean("cache-with-use-cluster-configuration-disabled", Cache.class);
|
||||
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("use-cluster-configuration"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithUseClusterConfigurationEnabled() {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-use-cluster-configuration-enabled")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-use-cluster-configuration-enabled", CacheFactoryBean.class);
|
||||
|
||||
assertThat(cacheFactoryBean.getUseClusterConfiguration()).isTrue();
|
||||
|
||||
Cache gemfireCache =
|
||||
applicationContext.getBean("cache-with-use-cluster-configuration-enabled", Cache.class);
|
||||
|
||||
assertThat(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("use-cluster-configuration"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithXmlAndProperties() throws Exception {
|
||||
|
||||
assertThat(applicationContext.containsBean("cache-with-xml-and-props")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-xml-and-props", CacheFactoryBean.class);
|
||||
|
||||
Resource cacheXmlResource = cacheFactoryBean.getCacheXml();
|
||||
|
||||
assertThat(cacheXmlResource.getFilename()).isEqualTo("gemfire-cache.xml");
|
||||
assertThat(applicationContext.containsBean("gemfireProperties")).isTrue();
|
||||
assertThat(TestUtils.<Properties>readField("properties", cacheFactoryBean))
|
||||
.isEqualTo(applicationContext.getBean("gemfireProperties"));
|
||||
assertThat(TestUtils.<Boolean>readField("pdxReadSerialized", cacheFactoryBean)).isEqualTo(Boolean.TRUE);
|
||||
assertThat(TestUtils.<Boolean>readField("pdxIgnoreUnreadFields", cacheFactoryBean)).isEqualTo(Boolean.FALSE);
|
||||
assertThat(TestUtils.<Boolean>readField("pdxPersistent", cacheFactoryBean)).isEqualTo(Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeapTunedCache() {
|
||||
|
||||
assertThat(applicationContext.containsBean("heap-tuned-cache")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
Float evictionHeapPercentage = cacheFactoryBean.getEvictionHeapPercentage();
|
||||
|
||||
assertThat(criticalHeapPercentage).isCloseTo(70.0f, offset(0.0001f));
|
||||
assertThat(evictionHeapPercentage).isCloseTo(60.0f, offset(0.0001f));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffHeapTunedCache() {
|
||||
|
||||
assertThat(applicationContext.containsBean("off-heap-tuned-cache")).isTrue();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&off-heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalOffHeapPercentage = cacheFactoryBean.getCriticalOffHeapPercentage();
|
||||
Float evictionOffHeapPercentage = cacheFactoryBean.getEvictionOffHeapPercentage();
|
||||
|
||||
assertThat(criticalOffHeapPercentage).isCloseTo(90.0f, offset(0.0001f));
|
||||
assertThat(evictionOffHeapPercentage).isCloseTo(50.0f, offset(0.0001f));
|
||||
}
|
||||
|
||||
public static class TestGatewayConflictResolver implements GatewayConflictResolver {
|
||||
|
||||
@Override
|
||||
public void onEvent(TimestampedEntryEvent event, GatewayConflictHelper helper) {
|
||||
throw new UnsupportedOperationException("Not Implemented!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.data.gemfire.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.data.gemfire.support.GemfireBeanFactoryLocator.newBeanFactoryLocator;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.util.GatewayConflictHelper;
|
||||
import org.apache.geode.cache.util.GatewayConflictResolver;
|
||||
import org.apache.geode.cache.util.TimestampedEntryEvent;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CacheParser}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.springframework.data.gemfire.config.xml.CacheParser
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "cache-ns.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheNamespaceTest{
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testNoNamedCache() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("gemfireCache"));
|
||||
assertTrue(applicationContext.containsBean("gemfire-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertNull(cacheFactoryBean.getCacheXml());
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.getProperties();
|
||||
|
||||
assertNotNull(gemfireProperties);
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(Boolean.parseBoolean(gemfireProperties.getProperty("disable-auto-reconnect")));
|
||||
assertFalse(cacheFactoryBean.getUseClusterConfiguration());
|
||||
assertTrue(gemfireProperties.containsKey("use-cluster-configuration"));
|
||||
assertFalse(Boolean.parseBoolean(gemfireProperties.getProperty("use-cluster-configuration")));
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertNotNull(gemfireCache);
|
||||
assertNotNull(gemfireCache.getDistributedSystem());
|
||||
assertNotNull(gemfireCache.getDistributedSystem().getProperties());
|
||||
assertNotNull(gemfireCache.getDistributedSystem().getProperties().containsKey("disable-auto-reconnect"));
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedCache() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-name"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-name", CacheFactoryBean.class);
|
||||
|
||||
assertNull(cacheFactoryBean.getCacheXml());
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.getProperties();
|
||||
|
||||
assertNotNull(gemfireProperties);
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(Boolean.parseBoolean(gemfireProperties.getProperty("disable-auto-reconnect")));
|
||||
assertFalse(cacheFactoryBean.getUseClusterConfiguration());
|
||||
assertTrue(gemfireProperties.containsKey("use-cluster-configuration"));
|
||||
assertFalse(Boolean.parseBoolean(gemfireProperties.getProperty("use-cluster-configuration")));
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
assertFalse(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("use-cluster-configuration")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectDisabled() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-auto-reconnect-disabled"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-auto-reconnect-disabled", CacheFactoryBean.class);
|
||||
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("cache-with-auto-reconnect-disabled", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectEnabled() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-auto-reconnect-enabled"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-auto-reconnect-enabled", CacheFactoryBean.class);
|
||||
|
||||
assertTrue(cacheFactoryBean.getEnableAutoReconnect());
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("cache-with-auto-reconnect-enabled", Cache.class);
|
||||
|
||||
assertFalse(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithGatewayConflictResolver() {
|
||||
|
||||
Cache cache = applicationContext.getBean("cache-with-gateway-conflict-resolver", Cache.class);
|
||||
|
||||
assertTrue(cache.getGatewayConflictResolver() instanceof TestGatewayConflictResolver);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testCacheWithNoBeanFactoryLocator() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-no-bean-factory-locator"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-no-bean-factory-locator", CacheFactoryBean.class);
|
||||
|
||||
assertNull(cacheFactoryBean.getBeanFactoryLocator());
|
||||
|
||||
newBeanFactoryLocator().useBeanFactory("cache-with-no-bean-factory-locator");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithUseClusterConfigurationDisabled() {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-use-cluster-configuration-disabled"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-use-cluster-configuration-disabled", CacheFactoryBean.class);
|
||||
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
|
||||
Cache gemfireCache =
|
||||
applicationContext.getBean("cache-with-use-cluster-configuration-disabled", Cache.class);
|
||||
|
||||
assertFalse(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("use-cluster-configuration")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithUseClusterConfigurationEnabled() {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-use-cluster-configuration-enabled"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-use-cluster-configuration-enabled", CacheFactoryBean.class);
|
||||
|
||||
assertTrue(cacheFactoryBean.getUseClusterConfiguration());
|
||||
|
||||
Cache gemfireCache =
|
||||
applicationContext.getBean("cache-with-use-cluster-configuration-enabled", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("use-cluster-configuration")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithXmlAndProperties() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("cache-with-xml-and-props"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&cache-with-xml-and-props", CacheFactoryBean.class);
|
||||
|
||||
Resource cacheXmlResource = cacheFactoryBean.getCacheXml();
|
||||
|
||||
assertEquals("gemfire-cache.xml", cacheXmlResource.getFilename());
|
||||
assertTrue(applicationContext.containsBean("gemfireProperties"));
|
||||
assertEquals(applicationContext.getBean("gemfireProperties"), TestUtils.readField("properties", cacheFactoryBean));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxReadSerialized", cacheFactoryBean));
|
||||
assertEquals(Boolean.FALSE, TestUtils.readField("pdxIgnoreUnreadFields", cacheFactoryBean));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxPersistent", cacheFactoryBean));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeapTunedCache() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("heap-tuned-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
Float evictionHeapPercentage = cacheFactoryBean.getEvictionHeapPercentage();
|
||||
|
||||
assertEquals(70.0f, criticalHeapPercentage, 0.0001);
|
||||
assertEquals(60.0f, evictionHeapPercentage, 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffHeapTunedCache() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("off-heap-tuned-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&off-heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalOffHeapPercentage = cacheFactoryBean.getCriticalOffHeapPercentage();
|
||||
Float evictionOffHeapPercentage = cacheFactoryBean.getEvictionOffHeapPercentage();
|
||||
|
||||
assertEquals(90.0f, criticalOffHeapPercentage, 0.0001);
|
||||
assertEquals(50.0f, evictionOffHeapPercentage, 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedClientCacheWithNoPropertiesAndNoCacheXml() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("client-cache-with-name"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
applicationContext.getBean("&client-cache-with-name", ClientCacheFactoryBean.class);
|
||||
|
||||
assertNull(clientCacheFactoryBean.getCacheXml());
|
||||
assertNull(clientCacheFactoryBean.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientCacheWithXmlNoProperties() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("client-cache-with-xml"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
applicationContext.getBean("&client-cache-with-xml", ClientCacheFactoryBean.class);
|
||||
|
||||
Resource cacheXmlResource = clientCacheFactoryBean.getCacheXml();
|
||||
|
||||
assertEquals("gemfire-client-cache.xml", cacheXmlResource.getFilename());
|
||||
|
||||
assertNull(clientCacheFactoryBean.getProperties());
|
||||
}
|
||||
|
||||
public static class TestGatewayConflictResolver implements GatewayConflictResolver {
|
||||
|
||||
@Override
|
||||
public void onEvent(TimestampedEntryEvent arg0, GatewayConflictHelper arg1) {
|
||||
throw new UnsupportedOperationException("Not Implemented!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.data.gemfire.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration Tests for {@link ClientCacheParser}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.ClientCacheParser
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.6.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientCacheNamespaceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("&client-cache-with-no-name")
|
||||
private ClientCacheFactoryBean clientCacheFactoryBean;
|
||||
|
||||
@Autowired
|
||||
private PdxSerializer reflectionBaseAutoSerializer;
|
||||
|
||||
@Autowired
|
||||
private Properties gemfireProperties;
|
||||
|
||||
@Test
|
||||
public void clientCacheFactoryBeanConfiguration() throws Exception {
|
||||
|
||||
assertThat(clientCacheFactoryBean.getCacheXml().toString()).contains("empty-client-cache.xml");
|
||||
assertThat(clientCacheFactoryBean.getProperties()).isEqualTo(gemfireProperties);
|
||||
assertThat(clientCacheFactoryBean.getCopyOnRead()).isTrue();
|
||||
assertThat(clientCacheFactoryBean.getCriticalHeapPercentage()).isEqualTo(0.85f);
|
||||
assertThat(clientCacheFactoryBean.getDurableClientId()).isEqualTo("TestDurableClientId");
|
||||
assertThat(clientCacheFactoryBean.getDurableClientTimeout()).isEqualTo(600);
|
||||
assertThat(clientCacheFactoryBean.getEvictionHeapPercentage()).isEqualTo(0.65f);
|
||||
assertThat(clientCacheFactoryBean.isKeepAlive()).isTrue();
|
||||
assertThat(clientCacheFactoryBean.getPdxIgnoreUnreadFields()).isTrue();
|
||||
assertThat(clientCacheFactoryBean.getPdxPersistent()).isFalse();
|
||||
assertThat(clientCacheFactoryBean.getPdxReadSerialized()).isTrue();
|
||||
assertThat(clientCacheFactoryBean.getPdxSerializer()).isEqualTo(reflectionBaseAutoSerializer);
|
||||
assertThat(TestUtils.<String>readField("poolName", clientCacheFactoryBean)).isEqualTo("serverPool");
|
||||
assertThat(clientCacheFactoryBean.getReadyForEvents()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedClientCacheWithNoPropertiesAndNoCacheXml() {
|
||||
|
||||
assertThat(applicationContext.containsBean("client-cache-with-name")).isTrue();
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
applicationContext.getBean("&client-cache-with-name", ClientCacheFactoryBean.class);
|
||||
|
||||
assertThat(clientCacheFactoryBean.getCacheXml()).isNull();
|
||||
assertThat(clientCacheFactoryBean.getProperties()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientCacheWithXmlNoProperties() {
|
||||
|
||||
assertThat(applicationContext.containsBean("client-cache-with-xml")).isTrue();
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
applicationContext.getBean("&client-cache-with-xml", ClientCacheFactoryBean.class);
|
||||
|
||||
Resource cacheXmlResource = clientCacheFactoryBean.getCacheXml();
|
||||
|
||||
assertThat(cacheXmlResource.getFilename()).isEqualTo("gemfire-client-cache.xml");
|
||||
|
||||
assertThat(clientCacheFactoryBean.getProperties()).isNull();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.data.gemfire.config.xml;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.geode.pdx.PdxSerializer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* The ClientCacheNamespaceTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the Spring Data GemFire ClientCacheParser.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.6.3
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientCacheNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ClientCacheFactoryBean clientCacheFactoryBean;
|
||||
|
||||
@Autowired
|
||||
private Properties gemfireProperties;
|
||||
|
||||
@Autowired
|
||||
private PdxSerializer reflectionPdxSerializer;
|
||||
|
||||
@Test
|
||||
public void clientCacheFactoryBeanConfiguration() throws Exception {
|
||||
assertThat(clientCacheFactoryBean.getCacheXml().toString(), containsString("empty-client-cache.xml"));
|
||||
assertThat(clientCacheFactoryBean.getProperties(), is(equalTo(gemfireProperties)));
|
||||
assertThat(clientCacheFactoryBean.getCopyOnRead(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getCriticalHeapPercentage(), is(equalTo(0.85f)));
|
||||
assertThat(clientCacheFactoryBean.getDurableClientId(), is(equalTo("TestDurableClientId")));
|
||||
assertThat(clientCacheFactoryBean.getDurableClientTimeout(), is(equalTo(600)));
|
||||
assertThat(clientCacheFactoryBean.getEvictionHeapPercentage(), is(equalTo(0.65f)));
|
||||
assertThat(clientCacheFactoryBean.isKeepAlive(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPdxIgnoreUnreadFields(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPdxPersistent(), is(false));
|
||||
assertThat(clientCacheFactoryBean.getPdxReadSerialized(), is(true));
|
||||
assertThat((PdxSerializer) clientCacheFactoryBean.getPdxSerializer(), is(equalTo(reflectionPdxSerializer)));
|
||||
assertThat(TestUtils.<String>readField("poolName", clientCacheFactoryBean), is(equalTo("serverPool")));
|
||||
assertThat(clientCacheFactoryBean.getReadyForEvents(), is(false));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,46 +18,47 @@ package org.springframework.data.gemfire.config.xml;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.Cache;
|
||||
import org.apache.geode.cache.TransactionEvent;
|
||||
import org.apache.geode.cache.TransactionListener;
|
||||
import org.apache.geode.cache.TransactionWriter;
|
||||
import org.apache.geode.cache.TransactionWriterException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="tx-listeners-and-writers.xml",
|
||||
initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(
|
||||
locations="tx-listeners-and-writers.xml",
|
||||
initializers = GemfireTestApplicationContextInitializer.class
|
||||
)
|
||||
@SuppressWarnings("unused")
|
||||
public class TxEventHandlersTest {
|
||||
|
||||
@Autowired
|
||||
TestListener txListener1;
|
||||
TestTransactionListener txListener1;
|
||||
|
||||
@Autowired
|
||||
TestListener txListener2;
|
||||
private TestTransactionListener txListener2;
|
||||
|
||||
@Autowired
|
||||
TestWriter txWriter;
|
||||
private TestTransactionWriter txWriter;
|
||||
|
||||
@Resource(name = "gemfireCache")
|
||||
Cache cache;
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
public void transactionEventHandlersConfiguredCorrectly() {
|
||||
|
||||
TransactionListener[] listeners = cache.getCacheTransactionManager().getListeners();
|
||||
|
||||
assertEquals(2, listeners.length);
|
||||
@@ -66,7 +67,7 @@ public class TxEventHandlersTest {
|
||||
assertSame(txWriter, cache.getCacheTransactionManager().getWriter());
|
||||
}
|
||||
|
||||
public static class TestListener implements TransactionListener, BeanNameAware {
|
||||
public static class TestTransactionListener implements TransactionListener, BeanNameAware {
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -77,51 +78,46 @@ public class TxEventHandlersTest {
|
||||
public boolean afterCommit;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
closed = true;
|
||||
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCommit(TransactionEvent arg0) {
|
||||
public void afterCommit(TransactionEvent event) {
|
||||
afterCommit = true;
|
||||
value = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterFailedCommit(TransactionEvent arg0) {
|
||||
}
|
||||
public void afterFailedCommit(TransactionEvent event) { }
|
||||
|
||||
@Override
|
||||
public void afterRollback(TransactionEvent arg0) {
|
||||
}
|
||||
public void afterRollback(TransactionEvent event) { }
|
||||
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
};
|
||||
public void close() {
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestWriter implements TransactionWriter, BeanNameAware {
|
||||
public static class TestTransactionWriter implements TransactionWriter, BeanNameAware {
|
||||
|
||||
private String name;
|
||||
|
||||
public String value;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeCommit(TransactionEvent arg0) throws TransactionWriterException {
|
||||
this.value = name;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
this.name = name;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeCommit(TransactionEvent event) {
|
||||
this.value = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,17 @@
|
||||
* 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.data.gemfire.test;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Spring {@link ApplicationContextInitializer} used to configure the Spring Data GemFire test suite
|
||||
* Spring {@link ApplicationContextInitializer} used to configure the Spring Data for Apache Geode test suite
|
||||
* with mocking enabled or disabled.
|
||||
*
|
||||
* @author David Turanski
|
||||
@@ -29,7 +28,8 @@ import org.springframework.util.StringUtils;
|
||||
* @see org.springframework.context.ApplicationContextInitializer
|
||||
* @see org.springframework.context.ConfigurableApplicationContext
|
||||
*/
|
||||
public class GemfireTestApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
public class GemfireTestApplicationContextInitializer
|
||||
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
public static final String GEMFIRE_TEST_RUNNER_DISABLED =
|
||||
"org.springframework.data.gemfire.test.GemfireTestRunner.nomock";
|
||||
@@ -45,7 +45,7 @@ public class GemfireTestApplicationContextInitializer implements ApplicationCont
|
||||
String gemfireTestRunnerDisabled = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED, Boolean.FALSE.toString());
|
||||
|
||||
if (isGemFireTestRunnerDisabled(gemfireTestRunnerDisabled)) {
|
||||
logger.warn("WARNING - Mocks disabled; Using real GemFire components [{} = {}]",
|
||||
logger.warn("WARNING - Mock objects disabled; Using real Apache Geode objects [{} = {}]",
|
||||
GEMFIRE_TEST_RUNNER_DISABLED, gemfireTestRunnerDisabled);
|
||||
}
|
||||
else {
|
||||
@@ -53,10 +53,10 @@ public class GemfireTestApplicationContextInitializer implements ApplicationCont
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private boolean isGemFireTestRunnerDisabled(String systemPropertyValue) {
|
||||
return (Boolean.valueOf(StringUtils.trimAllWhitespace(systemPropertyValue))
|
||||
|
||||
return Boolean.parseBoolean(StringUtils.trimAllWhitespace(systemPropertyValue))
|
||||
|| "yes".equalsIgnoreCase(systemPropertyValue)
|
||||
|| "y".equalsIgnoreCase(systemPropertyValue));
|
||||
|| "y".equalsIgnoreCase(systemPropertyValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,39 +12,42 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.test;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.data.gemfire.AbstractBasicCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Spring {@link BeanPostProcessor} to enable GemFire/Geode Mock Objects for testing.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
|
||||
*/
|
||||
public class GemfireTestBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GemfireTestBeanPostProcessor.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(GemfireTestBeanPostProcessor.class);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
|
||||
if (bean instanceof CacheFactoryBean) {
|
||||
if (bean instanceof AbstractBasicCacheFactoryBean) {
|
||||
|
||||
String beanTypeName = bean.getClass().getName();
|
||||
|
||||
bean = (bean instanceof ClientCacheFactoryBean
|
||||
bean = bean instanceof ClientCacheFactoryBean
|
||||
? new MockClientCacheFactoryBean((ClientCacheFactoryBean) bean)
|
||||
: new MockCacheFactoryBean((CacheFactoryBean) bean));
|
||||
: new MockCacheFactoryBean((CacheFactoryBean) bean);
|
||||
|
||||
logger.info("Replacing the [{}] bean definition having type [{}] with mock [{}]...",
|
||||
logger.info("Replacing the [{}] bean definition of type [{}] with mock [{}]...",
|
||||
beanName, beanTypeName, bean.getClass().getName());
|
||||
}
|
||||
else if (bean instanceof CacheServerFactoryBean) {
|
||||
@@ -53,13 +56,4 @@ public class GemfireTestBeanPostProcessor implements BeanPostProcessor {
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
* 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.data.gemfire.test;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -20,7 +19,7 @@ import org.apache.geode.cache.GemFireCache;
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
|
||||
/**
|
||||
* Mock {@link CacheFactoryBean} used in Unit Tests.
|
||||
* Mock {@link CacheFactoryBean} used in tests.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
@@ -69,7 +68,7 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
protected <T extends GemFireCache> T doFetchCache() {
|
||||
StubCache stubCache = new StubCache();
|
||||
stubCache.setProperties(getProperties());
|
||||
return (T) stubCache;
|
||||
|
||||
@@ -25,7 +25,7 @@ default-lazy-init="true">
|
||||
|
||||
<gfe:cache id="cache-with-gateway-conflict-resolver" properties-ref="gemfireProperties">
|
||||
<gfe:gateway-conflict-resolver>
|
||||
<bean class="org.springframework.data.gemfire.config.xml.CacheNamespaceTest.TestGatewayConflictResolver"/>
|
||||
<bean class="org.springframework.data.gemfire.config.xml.CacheNamespaceIntegrationTests.TestGatewayConflictResolver"/>
|
||||
</gfe:gateway-conflict-resolver>
|
||||
</gfe:cache>
|
||||
|
||||
@@ -43,12 +43,4 @@ default-lazy-init="true">
|
||||
|
||||
<gfe:cache id="off-heap-tuned-cache" properties-ref="gemfireProperties" critical-off-heap-percentage="90.0" eviction-off-heap-percentage="50.0"/>
|
||||
|
||||
<gfe:client-cache id="client-cache-with-name"/>
|
||||
|
||||
<gfe:client-cache id="client-cache-with-xml" cache-xml-location="classpath:gemfire-client-cache.xml"/>
|
||||
|
||||
<gfe:pool>
|
||||
<gfe:server host="localhost" port="1234"/>
|
||||
</gfe:pool>
|
||||
|
||||
</beans>
|
||||
@@ -15,12 +15,16 @@
|
||||
<prop key="log-level">error</prop>
|
||||
</util:properties>
|
||||
|
||||
<bean id="reflectionPdxSerializer" class="org.apache.geode.pdx.ReflectionBasedAutoSerializer"/>
|
||||
<bean id="reflectionBasedAutoSerializer" class="org.apache.geode.pdx.ReflectionBasedAutoSerializer"/>
|
||||
|
||||
<gfe:client-cache cache-xml-location="empty-client-cache.xml" properties-ref="gemfireProperties"
|
||||
<gfe:client-cache id="client-cache-with-no-name" cache-xml-location="empty-client-cache.xml" properties-ref="gemfireProperties"
|
||||
durable-client-id="TestDurableClientId" durable-client-timeout="600"
|
||||
copy-on-read="true" critical-heap-percentage="0.85" eviction-heap-percentage="0.65"
|
||||
pdx-serializer-ref="reflectionPdxSerializer" pdx-ignore-unread-fields="true" pdx-persistent="false"
|
||||
pdx-serializer-ref="reflectionBasedAutoSerializer" pdx-ignore-unread-fields="true" pdx-persistent="false"
|
||||
pdx-read-serialized="true" keep-alive="true" pool-name="serverPool" ready-for-events="false"/>
|
||||
|
||||
<gfe:client-cache id="client-cache-with-name"/>
|
||||
|
||||
<gfe:client-cache id="client-cache-with-xml" cache-xml-location="classpath:gemfire-client-cache.xml"/>
|
||||
|
||||
</beans>
|
||||
@@ -26,8 +26,8 @@
|
||||
<gfe:transaction-writer ref="txWriter"/>
|
||||
</gfe:client-cache>
|
||||
|
||||
<bean id="txListener1" class="org.springframework.data.gemfire.config.xml.TxEventHandlersTest.TestListener"/>
|
||||
<bean id="txListener2" class="org.springframework.data.gemfire.config.xml.TxEventHandlersTest.TestListener"/>
|
||||
<bean id="txWriter" class="org.springframework.data.gemfire.config.xml.TxEventHandlersTest.TestWriter"/>
|
||||
<bean id="txListener1" class="org.springframework.data.gemfire.config.xml.TxEventHandlersTest.TestTransactionListener"/>
|
||||
<bean id="txListener2" class="org.springframework.data.gemfire.config.xml.TxEventHandlersTest.TestTransactionListener"/>
|
||||
<bean id="txWriter" class="org.springframework.data.gemfire.config.xml.TxEventHandlersTest.TestTransactionWriter"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user