DATAGEODE-61 - Do not configure ClientRegionFactory poolName when Pool is set to DEFAULT.
This commit is contained in:
@@ -131,10 +131,10 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
|
|
||||||
applyRegionConfigurers(regionName);
|
applyRegionConfigurers(regionName);
|
||||||
|
|
||||||
ClientCache cache = resolveCache(gemfireCache);
|
ClientCache clientCache = resolveCache(gemfireCache);
|
||||||
|
|
||||||
ClientRegionFactory<K, V> clientRegionFactory =
|
ClientRegionFactory<K, V> clientRegionFactory =
|
||||||
postProcess(configure(createClientRegionFactory(cache, resolveClientRegionShortcut())));
|
postProcess(configure(createClientRegionFactory(clientCache, resolveClientRegionShortcut())));
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
Region<K, V> region = newRegion(clientRegionFactory, getParent(), regionName);
|
Region<K, V> region = newRegion(clientRegionFactory, getParent(), regionName);
|
||||||
@@ -295,17 +295,22 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
|
|
||||||
/* (non-Javadoc) */
|
/* (non-Javadoc) */
|
||||||
private String resolvePoolName() {
|
private String resolvePoolName() {
|
||||||
return Optional.of(getPoolName()).filter(this::isPoolResolvable).orElse(null);
|
|
||||||
|
return getPoolName()
|
||||||
|
.filter(StringUtils::hasText)
|
||||||
|
.filter(this::isNotDefaultPool)
|
||||||
|
.filter(this::isPoolResolvable)
|
||||||
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
/* (non-Javadoc) */
|
||||||
private String getPoolName() {
|
boolean isPoolResolvable(String poolName) {
|
||||||
return Optional.ofNullable(this.poolName).filter(StringUtils::hasText).orElse(GEMFIRE_POOL_NAME);
|
return getBeanFactory().containsBean(poolName) || (PoolManager.find(poolName) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
/* (non-Javadoc) */
|
||||||
private boolean isPoolResolvable(String poolName) {
|
boolean isNotDefaultPool(String poolName) {
|
||||||
return (getBeanFactory().containsBean(poolName) || (PoolManager.find(poolName) != null));
|
return !DEFAULT_POOL_NAME.equals(poolName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc) */
|
/* (non-Javadoc) */
|
||||||
@@ -328,15 +333,17 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
* Constructs a new instance of {@link ClientRegionFactory} using the given {@link ClientCache}
|
* Constructs a new instance of {@link ClientRegionFactory} using the given {@link ClientCache}
|
||||||
* and {@link ClientRegionShortcut}.
|
* and {@link ClientRegionShortcut}.
|
||||||
*
|
*
|
||||||
* @param cache reference to the {@link ClientCache}.
|
* @param clientCache reference to the {@link ClientCache}.
|
||||||
* @param shortcut {@link ClientRegionShortcut} used to specify the client {@link Region} {@link DataPolicy}.
|
* @param shortcut {@link ClientRegionShortcut} used to specify the client {@link Region} {@link DataPolicy}.
|
||||||
* @return a new instance of {@link ClientRegionFactory}.
|
* @return a new instance of {@link ClientRegionFactory}.
|
||||||
* @see org.apache.geode.cache.client.ClientCache#createClientRegionFactory(ClientRegionShortcut)
|
* @see org.apache.geode.cache.client.ClientCache#createClientRegionFactory(ClientRegionShortcut)
|
||||||
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
||||||
* @see org.apache.geode.cache.client.ClientRegionFactory
|
* @see org.apache.geode.cache.client.ClientRegionFactory
|
||||||
*/
|
*/
|
||||||
protected ClientRegionFactory<K, V> createClientRegionFactory(ClientCache cache, ClientRegionShortcut shortcut) {
|
protected ClientRegionFactory<K, V> createClientRegionFactory(ClientCache clientCache,
|
||||||
return cache.createClientRegionFactory(shortcut);
|
ClientRegionShortcut shortcut) {
|
||||||
|
|
||||||
|
return clientCache.createClientRegionFactory(shortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -368,11 +375,18 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
clientRegionFactory.setInitialCapacity(attributes.getInitialCapacity());
|
clientRegionFactory.setInitialCapacity(attributes.getInitialCapacity());
|
||||||
clientRegionFactory.setKeyConstraint(attributes.getKeyConstraint());
|
clientRegionFactory.setKeyConstraint(attributes.getKeyConstraint());
|
||||||
clientRegionFactory.setLoadFactor(attributes.getLoadFactor());
|
clientRegionFactory.setLoadFactor(attributes.getLoadFactor());
|
||||||
clientRegionFactory.setPoolName(attributes.getPoolName());
|
|
||||||
clientRegionFactory.setRegionIdleTimeout(attributes.getRegionIdleTimeout());
|
clientRegionFactory.setRegionIdleTimeout(attributes.getRegionIdleTimeout());
|
||||||
clientRegionFactory.setRegionTimeToLive(attributes.getRegionTimeToLive());
|
clientRegionFactory.setRegionTimeToLive(attributes.getRegionTimeToLive());
|
||||||
clientRegionFactory.setStatisticsEnabled(attributes.getStatisticsEnabled());
|
clientRegionFactory.setStatisticsEnabled(attributes.getStatisticsEnabled());
|
||||||
clientRegionFactory.setValueConstraint(attributes.getValueConstraint());
|
clientRegionFactory.setValueConstraint(attributes.getValueConstraint());
|
||||||
|
|
||||||
|
Optional.ofNullable(attributes.getPoolName())
|
||||||
|
.filter(StringUtils::hasText)
|
||||||
|
.filter(this::isNotDefaultPool)
|
||||||
|
.filter(this::isPoolResolvable)
|
||||||
|
.map(this::eagerlyInitializePool)
|
||||||
|
.ifPresent(clientRegionFactory::setPoolName);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
stream(nullSafeArray(this.cacheListeners, CacheListener.class)).forEach(clientRegionFactory::addCacheListener);
|
stream(nullSafeArray(this.cacheListeners, CacheListener.class)).forEach(clientRegionFactory::addCacheListener);
|
||||||
@@ -384,8 +398,9 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
|
|
||||||
Optional.ofNullable(this.keyConstraint).ifPresent(clientRegionFactory::setKeyConstraint);
|
Optional.ofNullable(this.keyConstraint).ifPresent(clientRegionFactory::setKeyConstraint);
|
||||||
|
|
||||||
Optional.ofNullable(resolvePoolName()).filter(StringUtils::hasText)
|
Optional.ofNullable(resolvePoolName())
|
||||||
.ifPresent(poolName -> clientRegionFactory.setPoolName(eagerlyInitializePool(poolName)));
|
.map(this::eagerlyInitializePool)
|
||||||
|
.ifPresent(clientRegionFactory::setPoolName);
|
||||||
|
|
||||||
Optional.ofNullable(this.valueConstraint).ifPresent(clientRegionFactory::setValueConstraint);
|
Optional.ofNullable(this.valueConstraint).ifPresent(clientRegionFactory::setValueConstraint);
|
||||||
|
|
||||||
@@ -639,22 +654,34 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
/**
|
/**
|
||||||
* Sets the {@link Pool} used by this client {@link Region}.
|
* Sets the {@link Pool} used by this client {@link Region}.
|
||||||
*
|
*
|
||||||
* @param pool GemFire client {@link Pool}.
|
* @param pool client {@link Pool} to be used by this client {@link Region}.
|
||||||
* @see org.apache.geode.cache.client.Pool
|
* @see org.apache.geode.cache.client.Pool
|
||||||
|
* @see #setPoolName(String)
|
||||||
*/
|
*/
|
||||||
public void setPool(Pool pool) {
|
public void setPool(Pool pool) {
|
||||||
setPoolName(Optional.ofNullable(pool).map(Pool::getName)
|
setPoolName(Optional.ofNullable(pool).map(Pool::getName).orElse(null));
|
||||||
.orElseThrow(() -> newIllegalArgumentException("Pool cannot be null")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link Pool} name used by this client {@link Region}.
|
* Sets the {@link String name} of the {@link Pool} used by this client {@link Region}.
|
||||||
*
|
*
|
||||||
* @param poolName String specifying the name of the GemFire client {@link Pool}.
|
* @param poolName {@link String} containing the name of the client {@link Pool} used by this client {@link Region}.
|
||||||
|
* @see #getPoolName()
|
||||||
|
* @see #setPool(Pool)
|
||||||
*/
|
*/
|
||||||
public void setPoolName(String poolName) {
|
public void setPoolName(String poolName) {
|
||||||
this.poolName = Optional.ofNullable(poolName).filter(StringUtils::hasText)
|
this.poolName = poolName;
|
||||||
.orElseThrow(() -> newIllegalArgumentException("Pool name is required"));
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link String name} of the configured {@link Pool} to use with this client {@link Region}.
|
||||||
|
*
|
||||||
|
* @return the {@link Optional} {@link String name} of the configured {@link Pool} to use
|
||||||
|
* with this client {@link Region}.
|
||||||
|
* @see #setPoolName(String)
|
||||||
|
*/
|
||||||
|
public Optional<String> getPoolName() {
|
||||||
|
return Optional.ofNullable(this.poolName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -683,14 +710,21 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the client {@link Region} using a GemFire {@link ClientRegionShortcut}.
|
* Initializes the client {@link Region} using the given {@link ClientRegionShortcut}.
|
||||||
*
|
*
|
||||||
* @param shortcut {@link ClientRegionShortcut} used to initialize this client {@link Region}.
|
* @param shortcut {@link ClientRegionShortcut} used to initialize this client {@link Region}.
|
||||||
|
* @see org.apache.geode.cache.client.ClientRegionShortcut
|
||||||
*/
|
*/
|
||||||
public void setShortcut(ClientRegionShortcut shortcut) {
|
public void setShortcut(ClientRegionShortcut shortcut) {
|
||||||
this.shortcut = shortcut;
|
this.shortcut = shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a {@link Class type} constraint on this {@link Region Region's} values.
|
||||||
|
*
|
||||||
|
* @param valueConstraint {@link Class type} of this client {@link Region Region's} values.
|
||||||
|
* @see java.lang.Class
|
||||||
|
*/
|
||||||
public void setValueConstraint(Class<V> valueConstraint) {
|
public void setValueConstraint(Class<V> valueConstraint) {
|
||||||
this.valueConstraint = valueConstraint;
|
this.valueConstraint = valueConstraint;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,23 +15,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.gemfire.client;
|
package org.springframework.data.gemfire.client;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.inOrder;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -50,10 +51,11 @@ import org.apache.geode.compression.Compressor;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.InOrder;
|
||||||
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.data.gemfire.TestUtils;
|
import org.springframework.data.gemfire.TestUtils;
|
||||||
import org.springframework.data.gemfire.config.xml.GemfireConstants;
|
|
||||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,7 +79,7 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
factoryBean = new ClientRegionFactoryBean<>();
|
factoryBean = spy(new ClientRegionFactoryBean<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -88,7 +90,7 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||||
public void testLookupFallbackUsingDefaultShortcut() throws Exception {
|
public void createRegionUsingDefaultShortcut() throws Exception {
|
||||||
|
|
||||||
String testRegionName = "TestRegion";
|
String testRegionName = "TestRegion";
|
||||||
|
|
||||||
@@ -98,11 +100,11 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
Region mockRegion = mock(Region.class);
|
Region mockRegion = mock(Region.class);
|
||||||
|
|
||||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL))).thenReturn(mockClientRegionFactory);
|
|
||||||
when(mockClientRegionFactory.create(eq(testRegionName))).thenReturn(mockRegion);
|
|
||||||
|
|
||||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL)))
|
||||||
|
.thenReturn(mockClientRegionFactory);
|
||||||
|
when(mockClientRegionFactory.create(eq(testRegionName))).thenReturn(mockRegion);
|
||||||
when(mockRegionAttributes.getCloningEnabled()).thenReturn(false);
|
when(mockRegionAttributes.getCloningEnabled()).thenReturn(false);
|
||||||
when(mockRegionAttributes.getCompressor()).thenReturn(mock(Compressor.class));
|
when(mockRegionAttributes.getCompressor()).thenReturn(mock(Compressor.class));
|
||||||
when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenReturn(true);
|
when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenReturn(true);
|
||||||
@@ -124,9 +126,12 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
when(mockRegionAttributes.getValueConstraint()).thenReturn(Number.class);
|
when(mockRegionAttributes.getValueConstraint()).thenReturn(Number.class);
|
||||||
|
|
||||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
Pool mockPool = mock(Pool.class);
|
Pool mockPool = mock(Pool.class);
|
||||||
|
|
||||||
Resource mockSnapshot = mock(Resource.class, "Snapshot");
|
Resource mockSnapshot = mock(Resource.class, "Snapshot");
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("TestPoolOne"))).thenReturn(false);
|
||||||
when(mockBeanFactory.containsBean(eq("TestPoolTwo"))).thenReturn(true);
|
when(mockBeanFactory.containsBean(eq("TestPoolTwo"))).thenReturn(true);
|
||||||
when(mockBeanFactory.isTypeMatch(eq("TestPoolTwo"), eq(Pool.class))).thenReturn(true);
|
when(mockBeanFactory.isTypeMatch(eq("TestPoolTwo"), eq(Pool.class))).thenReturn(true);
|
||||||
when(mockBeanFactory.getBean(eq("TestPoolTwo"))).thenReturn(mockPool);
|
when(mockBeanFactory.getBean(eq("TestPoolTwo"))).thenReturn(mockPool);
|
||||||
@@ -163,7 +168,7 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
verify(mockClientRegionFactory, times(1)).setInitialCapacity(eq(101));
|
verify(mockClientRegionFactory, times(1)).setInitialCapacity(eq(101));
|
||||||
verify(mockClientRegionFactory, times(1)).setKeyConstraint(eq(Long.class));
|
verify(mockClientRegionFactory, times(1)).setKeyConstraint(eq(Long.class));
|
||||||
verify(mockClientRegionFactory, times(1)).setLoadFactor(eq(0.75f));
|
verify(mockClientRegionFactory, times(1)).setLoadFactor(eq(0.75f));
|
||||||
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPoolOne"));
|
verify(mockClientRegionFactory, never()).setPoolName(eq("TestPoolOne"));
|
||||||
verify(mockClientRegionFactory, times(1)).setRegionIdleTimeout(any(ExpirationAttributes.class));
|
verify(mockClientRegionFactory, times(1)).setRegionIdleTimeout(any(ExpirationAttributes.class));
|
||||||
verify(mockClientRegionFactory, times(1)).setRegionTimeToLive(any(ExpirationAttributes.class));
|
verify(mockClientRegionFactory, times(1)).setRegionTimeToLive(any(ExpirationAttributes.class));
|
||||||
verify(mockClientRegionFactory, times(1)).setStatisticsEnabled(eq(true));
|
verify(mockClientRegionFactory, times(1)).setStatisticsEnabled(eq(true));
|
||||||
@@ -176,7 +181,7 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||||
public void testLookupFallbackUsingDefaultPersistentShortcut() throws Exception {
|
public void createRegionUsingDefaultPersistentShortcut() throws Exception {
|
||||||
|
|
||||||
ClientCache mockClientCache = mock(ClientCache.class);
|
ClientCache mockClientCache = mock(ClientCache.class);
|
||||||
|
|
||||||
@@ -184,7 +189,8 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
Region<Object, Object> mockRegion = mock(Region.class);
|
Region<Object, Object> mockRegion = mock(Region.class);
|
||||||
|
|
||||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_PERSISTENT))).thenReturn(mockClientRegionFactory);
|
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_PERSISTENT)))
|
||||||
|
.thenReturn(mockClientRegionFactory);
|
||||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||||
|
|
||||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
@@ -192,11 +198,9 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
when(mockBeanFactory.containsBean(eq("TestPool"))).thenReturn(true);
|
when(mockBeanFactory.containsBean(eq("TestPool"))).thenReturn(true);
|
||||||
when(mockBeanFactory.isTypeMatch(eq("TestPool"), eq(Pool.class))).thenReturn(false);
|
when(mockBeanFactory.isTypeMatch(eq("TestPool"), eq(Pool.class))).thenReturn(false);
|
||||||
|
|
||||||
factoryBean.setAttributes(null);
|
|
||||||
factoryBean.setBeanFactory(mockBeanFactory);
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
factoryBean.setPersistent(true);
|
factoryBean.setPersistent(true);
|
||||||
factoryBean.setPoolName("TestPool");
|
factoryBean.setPoolName("TestPool");
|
||||||
factoryBean.setShortcut(null);
|
|
||||||
|
|
||||||
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestRegion");
|
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestRegion");
|
||||||
|
|
||||||
@@ -212,7 +216,7 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testLookupFallbackWithSpecifiedShortcut() throws Exception {
|
public void createRegionWithSpecifiedShortcut() throws Exception {
|
||||||
|
|
||||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
@@ -222,12 +226,10 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
Region<Object, Object> mockRegion = mock(Region.class);
|
Region<Object, Object> mockRegion = mock(Region.class);
|
||||||
|
|
||||||
when(mockBeanFactory.containsBean(anyString())).thenReturn(true);
|
|
||||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY)))
|
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY)))
|
||||||
.thenReturn(mockClientRegionFactory);
|
.thenReturn(mockClientRegionFactory);
|
||||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||||
|
|
||||||
factoryBean.setAttributes(null);
|
|
||||||
factoryBean.setBeanFactory(mockBeanFactory);
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||||
|
|
||||||
@@ -235,14 +237,15 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
assertSame(mockRegion, actualRegion);
|
assertSame(mockRegion, actualRegion);
|
||||||
|
|
||||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
verifyZeroInteractions(mockBeanFactory);
|
||||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY));
|
verify(mockClientCache, times(1))
|
||||||
|
.createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY));
|
||||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testLookupFallbackWithSubRegionCreation() throws Exception {
|
public void createRegionWithSubRegionCreation() throws Exception {
|
||||||
|
|
||||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
@@ -253,12 +256,10 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
Region<Object, Object> mockRegion = mock(Region.class, "RootRegion");
|
Region<Object, Object> mockRegion = mock(Region.class, "RootRegion");
|
||||||
Region<Object, Object> mockSubRegion = mock(Region.class, "SubRegion");
|
Region<Object, Object> mockSubRegion = mock(Region.class, "SubRegion");
|
||||||
|
|
||||||
when(mockBeanFactory.containsBean(anyString())).thenReturn(true);
|
|
||||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.PROXY))).thenReturn(mockClientRegionFactory);
|
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.PROXY))).thenReturn(mockClientRegionFactory);
|
||||||
when(mockClientRegionFactory.createSubregion(eq(mockRegion), eq("TestSubRegion"))).thenReturn(mockSubRegion);
|
when(mockClientRegionFactory.createSubregion(eq(mockRegion), eq("TestSubRegion"))).thenReturn(mockSubRegion);
|
||||||
when(mockRegion.getName()).thenReturn("Parent");
|
when(mockRegion.getName()).thenReturn("Parent");
|
||||||
|
|
||||||
factoryBean.setAttributes(null);
|
|
||||||
factoryBean.setBeanFactory(mockBeanFactory);
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
factoryBean.setParent(mockRegion);
|
factoryBean.setParent(mockRegion);
|
||||||
factoryBean.setShortcut(ClientRegionShortcut.PROXY);
|
factoryBean.setShortcut(ClientRegionShortcut.PROXY);
|
||||||
@@ -267,58 +268,383 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
assertSame(mockSubRegion, actualRegion);
|
assertSame(mockSubRegion, actualRegion);
|
||||||
|
|
||||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
verifyZeroInteractions(mockBeanFactory);
|
||||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.PROXY));
|
verify(mockClientCache, times(1))
|
||||||
verify(mockClientRegionFactory, times(1)).createSubregion(eq(mockRegion), eq("TestSubRegion"));
|
.createClientRegionFactory(eq(ClientRegionShortcut.PROXY));
|
||||||
|
verify(mockClientRegionFactory, times(1))
|
||||||
|
.createSubregion(eq(mockRegion), eq("TestSubRegion"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testLookupFallbackWithUnspecifiedPool() throws Exception {
|
public void configurePoolFromRegionAttributesAndEagerlyInitializesPool() {
|
||||||
|
|
||||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
ClientCache mockClientCache = mock(ClientCache.class);
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("TestPool"))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(eq("TestPool"), eq(Pool.class))).thenReturn(true);
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn("TestPool");
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("TestPool"));
|
||||||
|
verify(mockBeanFactory, times(1)).isTypeMatch(eq("TestPool"), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, times(1)).getBean(eq("TestPool"), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPool"));
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void configurePoolFromRegionAttributesThrowsExceptionWhileEagerlyInitializingPool() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
Region<Object, Object> mockRegion = mock(Region.class);
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("TestPool"))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(eq("TestPool"), eq(Pool.class))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.getBean(eq("TestPool"), eq(Pool.class)))
|
||||||
|
.thenThrow(new BeanCreationException("TEST"));
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn("TestPool");
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("TestPool"));
|
||||||
|
verify(mockBeanFactory, times(1)).isTypeMatch(eq("TestPool"), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, times(1)).getBean(eq("TestPool"), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPool"));
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void configurePoolFromRegionAttributesDoesNotEagerlyInitializePoolWhenNotPoolTypeMatch() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("TestPool"))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(eq("TestPool"), eq(Pool.class))).thenReturn(false);
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn("TestPool");
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("TestPool"));
|
||||||
|
verify(mockBeanFactory, times(1)).isTypeMatch(eq("TestPool"), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPool"));
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromRegionAttributesWhenPoolIsUnresolvable() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
|
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
|
||||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_HEAP_LRU))).thenReturn(mockClientRegionFactory);
|
when(mockRegionAttributes.getPoolName()).thenReturn("TestPool");
|
||||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
|
||||||
|
|
||||||
factoryBean.setAttributes(null);
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
factoryBean.setBeanFactory(mockBeanFactory);
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_HEAP_LRU);
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestRegion");
|
verify(mockBeanFactory, times(1)).containsBean(eq("TestPool"));
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
assertSame(mockRegion, actualRegion);
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromRegionAttributesWhenPoolIsDefaultPool() {
|
||||||
|
|
||||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_HEAP_LRU));
|
|
||||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
verify(mockClientRegionFactory, never()).setPoolName(any(String.class));
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn(ClientRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(factoryBean, never()).isPoolResolvable(anyString());
|
||||||
|
verify(mockBeanFactory, never()).containsBean(anyString());
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromRegionAttributesWhenPoolIsEmpty() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn(" ");
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(factoryBean, never()).isNotDefaultPool(anyString());
|
||||||
|
verify(factoryBean, never()).isPoolResolvable(anyString());
|
||||||
|
verify(mockBeanFactory, never()).containsBean(anyString());
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromRegionAttributesWhenPoolIsNull() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn(null);
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(factoryBean, never()).isNotDefaultPool(anyString());
|
||||||
|
verify(factoryBean, never()).isPoolResolvable(anyString());
|
||||||
|
verify(mockBeanFactory, never()).containsBean(anyString());
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
verify(mockRegionAttributes, times(1)).getPoolName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void configurePoolFromClientRegionFactoryBeanAndEagerlyInitializesPool() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("MockPool"))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(eq("MockPool"), eq(Pool.class))).thenReturn(true);
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName("MockPool");
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("MockPool"));
|
||||||
|
verify(mockBeanFactory, times(1)).isTypeMatch(eq("MockPool"), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, times(1)).getBean(eq("MockPool"), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, times(1)).setPoolName(eq("MockPool"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void configurePoolFromClientRegionFactoryBeanThrowsExceptionWhileEagerlyInitializingPool() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("MockPool"))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(eq("MockPool"), eq(Pool.class))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.getBean(eq("MockPool"), eq(Pool.class))).thenThrow(new BeanCreationException("TEST"));
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName("MockPool");
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("MockPool"));
|
||||||
|
verify(mockBeanFactory, times(1)).isTypeMatch(eq("MockPool"), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, times(1)).getBean(eq("MockPool"), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, times(1)).setPoolName(eq("MockPool"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void configurePoolFromClientRegionFactoryBeanDoesNotEagerlyInitializePoolWhenNotPoolTypeMatch() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(eq("MockPool"))).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(anyString(), eq(Pool.class))).thenReturn(false);
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName("MockPool");
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("MockPool"));
|
||||||
|
verify(mockBeanFactory, times(1)).isTypeMatch(eq("MockPool"), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, times(1)).setPoolName(eq("MockPool"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void configuresPoolFromClientRegionFactoryBeanEvenWhenRegionAttributesPoolNameIsSet() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
RegionAttributes<Object, Object> mockRegionAttributes = mock(RegionAttributes.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(anyString())).thenReturn(true);
|
||||||
|
when(mockBeanFactory.isTypeMatch(anyString(), eq(Pool.class))).thenReturn(true);
|
||||||
|
when(mockRegionAttributes.getPoolName()).thenReturn("TestPool");
|
||||||
|
|
||||||
|
factoryBean.setAttributes(mockRegionAttributes);
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName("MockPool");
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
InOrder inOrderVerifier = inOrder(mockBeanFactory, mockClientRegionFactory);
|
||||||
|
|
||||||
|
inOrderVerifier.verify(mockBeanFactory, times(1)).containsBean(eq("TestPool"));
|
||||||
|
inOrderVerifier.verify(mockBeanFactory, times(1)).isTypeMatch(eq("TestPool"), eq(Pool.class));
|
||||||
|
inOrderVerifier.verify(mockBeanFactory, times(1)).getBean(eq("TestPool"), eq(Pool.class));
|
||||||
|
inOrderVerifier.verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPool"));
|
||||||
|
inOrderVerifier.verify(mockBeanFactory, times(1)).containsBean(eq("MockPool"));
|
||||||
|
inOrderVerifier.verify(mockBeanFactory, times(1)).isTypeMatch(eq("MockPool"), eq(Pool.class));
|
||||||
|
inOrderVerifier.verify(mockBeanFactory, times(1)).getBean(eq("MockPool"), eq(Pool.class));
|
||||||
|
inOrderVerifier.verify(mockClientRegionFactory, times(1)).setPoolName(eq("MockPool"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromClientRegionFactoryBeanWhenPoolIsUnresolvable() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName("MockPool");
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(mockBeanFactory, times(1)).containsBean(eq("MockPool"));
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromClientRegionFactoryBeanWhenPoolIsDefaultPool() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName(ClientRegionFactoryBean.DEFAULT_POOL_NAME);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(factoryBean, never()).isPoolResolvable(anyString());
|
||||||
|
verify(mockBeanFactory, never()).containsBean(anyString());
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromClientRegionFactoryBeanWhenPoolIsEmpty() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName("");
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(factoryBean, never()).isNotDefaultPool(anyString());
|
||||||
|
verify(factoryBean, never()).isPoolResolvable(anyString());
|
||||||
|
verify(mockBeanFactory, never()).containsBean(anyString());
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void doesNotConfigurePoolFromClientRegionFactoryBeanWhenPoolIsNull() {
|
||||||
|
|
||||||
|
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||||
|
|
||||||
|
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||||
|
|
||||||
|
factoryBean.setBeanFactory(mockBeanFactory);
|
||||||
|
factoryBean.setPoolName(null);
|
||||||
|
factoryBean.configure(mockClientRegionFactory);
|
||||||
|
|
||||||
|
verify(factoryBean, never()).isNotDefaultPool(anyString());
|
||||||
|
verify(factoryBean, never()).isPoolResolvable(anyString());
|
||||||
|
verify(mockBeanFactory, never()).containsBean(anyString());
|
||||||
|
verify(mockBeanFactory, never()).isTypeMatch(anyString(), eq(Pool.class));
|
||||||
|
verify(mockBeanFactory, never()).getBean(anyString(), eq(Pool.class));
|
||||||
|
verify(mockClientRegionFactory, never()).setPoolName(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void testSetDataPolicyName() throws Exception {
|
public void setDataPolicyName() throws Exception {
|
||||||
|
|
||||||
factoryBean.setDataPolicyName("NORMAL");
|
factoryBean.setDataPolicyName("NORMAL");
|
||||||
|
|
||||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", factoryBean));
|
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", factoryBean));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void testSetDataPolicyNameWithInvalidName() throws Exception {
|
public void setDataPolicyNameWithInvalidName() throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
factoryBean.setDataPolicyName("INVALID");
|
factoryBean.setDataPolicyName("INVALID");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException expected) {
|
catch (IllegalArgumentException expected) {
|
||||||
assertEquals("Data Policy [INVALID] is not valid", expected.getMessage());
|
|
||||||
|
assertThat(expected).hasMessage("Data Policy [INVALID] is not valid");
|
||||||
|
assertThat(expected).hasNoCause();
|
||||||
|
|
||||||
throw expected;
|
throw expected;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -327,34 +653,46 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsPersistent() {
|
public void isPersistentIsCorrect() {
|
||||||
|
|
||||||
assertFalse(factoryBean.isPersistent());
|
assertFalse(factoryBean.isPersistent());
|
||||||
|
|
||||||
factoryBean.setPersistent(false);
|
factoryBean.setPersistent(false);
|
||||||
|
|
||||||
assertFalse(factoryBean.isPersistent());
|
assertFalse(factoryBean.isPersistent());
|
||||||
|
|
||||||
factoryBean.setPersistent(true);
|
factoryBean.setPersistent(true);
|
||||||
|
|
||||||
assertTrue(factoryBean.isPersistent());
|
assertTrue(factoryBean.isPersistent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsPersistentUnspecified() {
|
public void isPersistentUnspecifiedIsCorrect() {
|
||||||
|
|
||||||
assertTrue(factoryBean.isPersistentUnspecified());
|
assertTrue(factoryBean.isPersistentUnspecified());
|
||||||
|
|
||||||
factoryBean.setPersistent(true);
|
factoryBean.setPersistent(true);
|
||||||
|
|
||||||
assertTrue(factoryBean.isPersistent());
|
assertTrue(factoryBean.isPersistent());
|
||||||
assertFalse(factoryBean.isPersistentUnspecified());
|
assertFalse(factoryBean.isPersistentUnspecified());
|
||||||
|
|
||||||
factoryBean.setPersistent(false);
|
factoryBean.setPersistent(false);
|
||||||
|
|
||||||
assertTrue(factoryBean.isNotPersistent());
|
assertTrue(factoryBean.isNotPersistent());
|
||||||
assertFalse(factoryBean.isPersistentUnspecified());
|
assertFalse(factoryBean.isPersistentUnspecified());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotPersistent() {
|
public void isNotPersistentIsCorrect() {
|
||||||
|
|
||||||
assertFalse(factoryBean.isNotPersistent());
|
assertFalse(factoryBean.isNotPersistent());
|
||||||
|
|
||||||
factoryBean.setPersistent(true);
|
factoryBean.setPersistent(true);
|
||||||
|
|
||||||
assertFalse(factoryBean.isNotPersistent());
|
assertFalse(factoryBean.isNotPersistent());
|
||||||
|
|
||||||
factoryBean.setPersistent(false);
|
factoryBean.setPersistent(false);
|
||||||
|
|
||||||
assertTrue(factoryBean.isNotPersistent());
|
assertTrue(factoryBean.isNotPersistent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,7 +935,7 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT, factoryBean.resolveClientRegionShortcut());
|
assertEquals(ClientRegionShortcut.LOCAL_PERSISTENT, factoryBean.resolveClientRegionShortcut());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <K> Interest<K> newInterest(K key) {
|
private <K> Interest<K> newInterest(K key) {
|
||||||
return new Interest<>(key);
|
return new Interest<>(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,22 +950,19 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
|
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
|
||||||
when(mockRegionService.isClosed()).thenReturn(false);
|
when(mockRegionService.isClosed()).thenReturn(false);
|
||||||
|
|
||||||
ClientRegionFactoryBean clientRegionFactoryBean = new ClientRegionFactoryBean() {
|
doReturn(mockRegion).when(factoryBean).getObject();
|
||||||
@Override public Region getObject() throws Exception {
|
|
||||||
return mockRegion;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
clientRegionFactoryBean.setClose(true);
|
factoryBean.setClose(true);
|
||||||
clientRegionFactoryBean.setInterests(ArrayUtils.asArray(newInterest("test")));
|
factoryBean.setInterests(ArrayUtils.asArray(newInterest("test")));
|
||||||
|
|
||||||
assertThat(clientRegionFactoryBean.isClose(), is(true));
|
assertThat(factoryBean.isClose()).isTrue();
|
||||||
assertThat(clientRegionFactoryBean.isDestroy(), is(false));
|
assertThat(factoryBean.isDestroy()).isFalse();
|
||||||
assertThat(clientRegionFactoryBean.getInterests(), is(notNullValue()));
|
assertThat(factoryBean.getInterests()).isNotNull();
|
||||||
assertThat(clientRegionFactoryBean.getInterests().length, is(equalTo(1)));
|
assertThat(factoryBean.getInterests()).hasSize(1);
|
||||||
|
|
||||||
clientRegionFactoryBean.destroy();
|
factoryBean.destroy();
|
||||||
|
|
||||||
|
verify(factoryBean, times(1)).getObject();
|
||||||
verify(mockRegion, times(1)).getRegionService();
|
verify(mockRegion, times(1)).getRegionService();
|
||||||
verify(mockRegionService, times(1)).isClosed();
|
verify(mockRegionService, times(1)).isClosed();
|
||||||
verify(mockRegion, times(1)).close();
|
verify(mockRegion, times(1)).close();
|
||||||
@@ -647,23 +982,20 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
|
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
|
||||||
when(mockRegionService.isClosed()).thenReturn(false);
|
when(mockRegionService.isClosed()).thenReturn(false);
|
||||||
|
|
||||||
ClientRegionFactoryBean clientRegionFactoryBean = new ClientRegionFactoryBean() {
|
doReturn(mockRegion).when(factoryBean).getObject();
|
||||||
@Override public Region getObject() throws Exception {
|
|
||||||
return mockRegion;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
clientRegionFactoryBean.setClose(false);
|
factoryBean.setClose(false);
|
||||||
clientRegionFactoryBean.setDestroy(true);
|
factoryBean.setDestroy(true);
|
||||||
clientRegionFactoryBean.setInterests(ArrayUtils.asArray(newInterest("test")));
|
factoryBean.setInterests(ArrayUtils.asArray(newInterest("test")));
|
||||||
|
|
||||||
assertThat(clientRegionFactoryBean.isClose(), is(false));
|
assertThat(factoryBean.isClose()).isFalse();
|
||||||
assertThat(clientRegionFactoryBean.isDestroy(), is(true));
|
assertThat(factoryBean.isDestroy()).isTrue();
|
||||||
assertThat(clientRegionFactoryBean.getInterests(), is(notNullValue()));
|
assertThat(factoryBean.getInterests()).isNotNull();
|
||||||
assertThat(clientRegionFactoryBean.getInterests().length, is(equalTo(1)));
|
assertThat(factoryBean.getInterests()).hasSize(1);
|
||||||
|
|
||||||
clientRegionFactoryBean.destroy();
|
factoryBean.destroy();
|
||||||
|
|
||||||
|
verify(factoryBean, times(1)).getObject();
|
||||||
verify(mockRegion, never()).getRegionService();
|
verify(mockRegion, never()).getRegionService();
|
||||||
verify(mockRegionService, never()).isClosed();
|
verify(mockRegionService, never()).isClosed();
|
||||||
verify(mockRegion, never()).close();
|
verify(mockRegion, never()).close();
|
||||||
@@ -683,22 +1015,19 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
|
when(mockRegion.getRegionService()).thenReturn(mockRegionService);
|
||||||
when(mockRegionService.isClosed()).thenReturn(true);
|
when(mockRegionService.isClosed()).thenReturn(true);
|
||||||
|
|
||||||
ClientRegionFactoryBean clientRegionFactoryBean = new ClientRegionFactoryBean() {
|
doReturn(mockRegion).when(factoryBean).getObject();
|
||||||
@Override public Region getObject() throws Exception {
|
|
||||||
return mockRegion;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
clientRegionFactoryBean.setClose(true);
|
factoryBean.setClose(true);
|
||||||
clientRegionFactoryBean.setInterests(ArrayUtils.asArray(newInterest("test")));
|
factoryBean.setInterests(ArrayUtils.asArray(newInterest("test")));
|
||||||
|
|
||||||
assertThat(clientRegionFactoryBean.isClose(), is(true));
|
assertThat(factoryBean.isClose()).isTrue();
|
||||||
assertThat(clientRegionFactoryBean.isDestroy(), is(false));
|
assertThat(factoryBean.isDestroy()).isFalse();
|
||||||
assertThat(clientRegionFactoryBean.getInterests(), is(notNullValue()));
|
assertThat(factoryBean.getInterests()).isNotNull();
|
||||||
assertThat(clientRegionFactoryBean.getInterests().length, is(equalTo(1)));
|
assertThat(factoryBean.getInterests()).hasSize(1);
|
||||||
|
|
||||||
clientRegionFactoryBean.destroy();
|
factoryBean.destroy();
|
||||||
|
|
||||||
|
verify(factoryBean, times(1)).getObject();
|
||||||
verify(mockRegion, times(1)).getRegionService();
|
verify(mockRegion, times(1)).getRegionService();
|
||||||
verify(mockRegionService, times(1)).isClosed();
|
verify(mockRegionService, times(1)).isClosed();
|
||||||
verify(mockRegion, never()).close();
|
verify(mockRegion, never()).close();
|
||||||
@@ -713,14 +1042,11 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
|
|
||||||
Region mockRegion = mock(Region.class, "MockRegion");
|
Region mockRegion = mock(Region.class, "MockRegion");
|
||||||
|
|
||||||
ClientRegionFactoryBean clientRegionFactoryBean = new ClientRegionFactoryBean() {
|
doReturn(mockRegion).when(factoryBean).getObject();
|
||||||
@Override public Region getObject() throws Exception {
|
|
||||||
return mockRegion;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
clientRegionFactoryBean.destroy();
|
factoryBean.destroy();
|
||||||
|
|
||||||
|
verify(factoryBean, times(1)).getObject();
|
||||||
verify(mockRegion, never()).getRegionService();
|
verify(mockRegion, never()).getRegionService();
|
||||||
verify(mockRegion, never()).close();
|
verify(mockRegion, never()).close();
|
||||||
verify(mockRegion, never()).destroyRegion();
|
verify(mockRegion, never()).destroyRegion();
|
||||||
@@ -731,12 +1057,10 @@ public class ClientRegionFactoryBeanTest {
|
|||||||
@Test
|
@Test
|
||||||
public void destroyDoesNothingWhenRegionIsNull() throws Exception {
|
public void destroyDoesNothingWhenRegionIsNull() throws Exception {
|
||||||
|
|
||||||
ClientRegionFactoryBean clientRegionFactoryBean = new ClientRegionFactoryBean() {
|
doReturn(null).when(factoryBean).getObject();
|
||||||
@Override public Region getObject() throws Exception {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
clientRegionFactoryBean.destroy();
|
factoryBean.destroy();
|
||||||
|
|
||||||
|
verify(factoryBean, times(1)).getObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 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
|
|
||||||
*
|
|
||||||
* http://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.client;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.apache.geode.cache.DataPolicy;
|
|
||||||
import org.apache.geode.cache.GemFireCache;
|
|
||||||
import org.apache.geode.cache.Region;
|
|
||||||
import org.apache.geode.cache.RegionAttributes;
|
|
||||||
import org.apache.geode.cache.client.ClientRegionShortcut;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
|
||||||
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The LocalOnlyClientCacheIntegrationTest class...
|
|
||||||
*
|
|
||||||
* @author John Blum
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@ContextConfiguration
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class LocalOnlyClientCacheIntegrationTest {
|
|
||||||
|
|
||||||
@Resource(name = "Example")
|
|
||||||
private Region<Long, String> example;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void assertRegionDetails() {
|
|
||||||
assertThat(example, is(notNullValue()));
|
|
||||||
assertThat(example.getName(), is(equalTo("Example")));
|
|
||||||
assertThat(example.getFullPath(), is(equalTo(String.format("%1$sExample", Region.SEPARATOR))));
|
|
||||||
assertThat(example.getAttributes(), is(notNullValue()));
|
|
||||||
assertThat(example.getAttributes().getDataPolicy(), is(equalTo(DataPolicy.NORMAL)));
|
|
||||||
assertThat(example.getAttributes().getKeyConstraint(), is(equalTo(Long.class)));
|
|
||||||
assertThat(example.getAttributes().getValueConstraint(), is(equalTo(String.class)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAndPutsAreSuccessful() {
|
|
||||||
assertThat(example.put(1L, "one"), is(nullValue()));
|
|
||||||
assertThat(example.put(2L, "two"), is(nullValue()));
|
|
||||||
assertThat(example.put(3L, "three"), is(nullValue()));
|
|
||||||
assertThat(example.get(1L), is(equalTo("one")));
|
|
||||||
assertThat(example.get(2L), is(equalTo("two")));
|
|
||||||
assertThat(example.get(3L), is(equalTo("three")));
|
|
||||||
assertThat(example.get(0L), is(nullValue()));
|
|
||||||
assertThat(example.get(4L), is(nullValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
static class GemFireClientCacheConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
|
|
||||||
return new PropertySourcesPlaceholderConfigurer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
Properties gemfireProperties(@Value("${spring.data.gemfire.log.level:warning}") String logLevel) {
|
|
||||||
|
|
||||||
Properties gemfireProperties = new Properties();
|
|
||||||
|
|
||||||
gemfireProperties.setProperty("name", LocalOnlyClientCacheIntegrationTest.class.getSimpleName());
|
|
||||||
gemfireProperties.setProperty("log-level", logLevel);
|
|
||||||
|
|
||||||
return gemfireProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
ClientCacheFactoryBean gemfireCache(@Qualifier("gemfireProperties") Properties gemfireProperties) {
|
|
||||||
|
|
||||||
ClientCacheFactoryBean gemfireCache = new ClientCacheFactoryBean();
|
|
||||||
|
|
||||||
gemfireCache.setClose(true);
|
|
||||||
gemfireCache.setProperties(gemfireProperties);
|
|
||||||
gemfireCache.setUseBeanFactoryLocator(false);
|
|
||||||
|
|
||||||
return gemfireCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "Example")
|
|
||||||
ClientRegionFactoryBean<Long, String> exampleRegion(GemFireCache gemfireCache,
|
|
||||||
RegionAttributes<Long, String> exampleAttributes) {
|
|
||||||
|
|
||||||
ClientRegionFactoryBean<Long, String> exampleRegion = new ClientRegionFactoryBean<>();
|
|
||||||
|
|
||||||
exampleRegion.setCache(gemfireCache);
|
|
||||||
exampleRegion.setAttributes(exampleAttributes);
|
|
||||||
exampleRegion.setName("Example");
|
|
||||||
exampleRegion.setPersistent(false);
|
|
||||||
exampleRegion.setShortcut(ClientRegionShortcut.LOCAL);
|
|
||||||
|
|
||||||
return exampleRegion;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
RegionAttributesFactoryBean exampleRegionAttributes() {
|
|
||||||
|
|
||||||
RegionAttributesFactoryBean exampleRegionAttributes = new RegionAttributesFactoryBean();
|
|
||||||
|
|
||||||
exampleRegionAttributes.setKeyConstraint(Long.class);
|
|
||||||
exampleRegionAttributes.setValueConstraint(String.class);
|
|
||||||
|
|
||||||
return exampleRegionAttributes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012 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
|
||||||
|
*
|
||||||
|
* http://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.client;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.geode.cache.DataPolicy;
|
||||||
|
import org.apache.geode.cache.Region;
|
||||||
|
import org.apache.geode.cache.client.ClientCache;
|
||||||
|
import org.apache.geode.cache.client.ClientRegionShortcut;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.data.gemfire.GemfireUtils;
|
||||||
|
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
|
||||||
|
import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions;
|
||||||
|
import org.springframework.data.gemfire.test.model.Gender;
|
||||||
|
import org.springframework.data.gemfire.test.model.Person;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration tests testing the configuration of a {@link ClientRegionShortcut#LOCAL}
|
||||||
|
* {@link ClientCache} {@link Region}.
|
||||||
|
*
|
||||||
|
* @author John Blum
|
||||||
|
* @see org.junit.Test
|
||||||
|
* @since 1.6.3
|
||||||
|
*/
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@ContextConfiguration
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class LocalOnlyClientCacheIntegrationTests {
|
||||||
|
|
||||||
|
@Resource(name = "People")
|
||||||
|
private Region<Long, Person> people;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void assertPeopleRegionConfiguration() {
|
||||||
|
|
||||||
|
assertThat(this.people).isNotNull();
|
||||||
|
assertThat(this.people.getName()).isEqualTo("People");
|
||||||
|
assertThat(this.people.getFullPath()).isEqualTo(GemfireUtils.toRegionPath("People"));
|
||||||
|
assertThat(this.people.getAttributes()).isNotNull();
|
||||||
|
assertThat(this.people.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.NORMAL);
|
||||||
|
assertThat(this.people.getAttributes().getKeyConstraint()).isEqualTo(Long.class);
|
||||||
|
assertThat(this.people.getAttributes().getValueConstraint()).isEqualTo(Person.class);
|
||||||
|
assertThat(this.people).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void putAndGetPersonIsSuccessful() {
|
||||||
|
|
||||||
|
Person jonDoe = Person.newPerson("Jon", "Doe",
|
||||||
|
Person.newBirthDate(1974, Calendar.MAY, 5), Gender.MALE);
|
||||||
|
|
||||||
|
assertThat(this.people).hasSize(0);
|
||||||
|
assertThat(this.people.put(jonDoe.getId(), jonDoe));
|
||||||
|
assertThat(this.people).hasSize(1);
|
||||||
|
assertThat(this.people.get(jonDoe.getId())).isEqualTo(jonDoe);
|
||||||
|
assertThat(this.people).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClientCacheApplication
|
||||||
|
@EnableEntityDefinedRegions(basePackageClasses = Person.class,
|
||||||
|
clientRegionShortcut = ClientRegionShortcut.LOCAL, strict = true)
|
||||||
|
static class GemFireClientCacheConfiguration {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
package org.springframework.data.gemfire.function.config;
|
package org.springframework.data.gemfire.function.config;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -48,19 +50,24 @@ public class FunctionExecutionClientCacheTests {
|
|||||||
@Test
|
@Test
|
||||||
public void contextCreated() throws Exception {
|
public void contextCreated() throws Exception {
|
||||||
|
|
||||||
ClientCache cache = applicationContext.getBean("gemfireCache", ClientCache.class);
|
ClientCache cache = this.applicationContext.getBean("gemfireCache", ClientCache.class);
|
||||||
Pool pool = applicationContext.getBean("gemfirePool", Pool.class);
|
|
||||||
|
Pool pool = this.applicationContext.getBean("gemfirePool", Pool.class);
|
||||||
|
|
||||||
assertEquals("gemfirePool", pool.getName());
|
assertEquals("gemfirePool", pool.getName());
|
||||||
assertTrue(cache.getDefaultPool().getLocators().isEmpty());
|
assertTrue(cache.getDefaultPool().getLocators().isEmpty());
|
||||||
assertEquals(1, cache.getDefaultPool().getServers().size());
|
assertEquals(1, cache.getDefaultPool().getServers().size());
|
||||||
|
assertTrue(pool.getLocators().isEmpty());
|
||||||
|
assertEquals(1, pool.getServers().size());
|
||||||
assertEquals(pool.getServers().get(0), cache.getDefaultPool().getServers().get(0));
|
assertEquals(pool.getServers().get(0), cache.getDefaultPool().getServers().get(0));
|
||||||
|
|
||||||
Region region = applicationContext.getBean("r1", Region.class);
|
Region region = this.applicationContext.getBean("r1", Region.class);
|
||||||
|
|
||||||
assertEquals("gemfirePool", region.getAttributes().getPoolName());
|
assertEquals("r1", region.getName());
|
||||||
|
assertNotNull(region.getAttributes());
|
||||||
|
assertNull(region.getAttributes().getPoolName());
|
||||||
|
|
||||||
GemfireOnServerFunctionTemplate template = applicationContext.getBean(GemfireOnServerFunctionTemplate.class);
|
GemfireOnServerFunctionTemplate template = this.applicationContext.getBean(GemfireOnServerFunctionTemplate.class);
|
||||||
|
|
||||||
assertTrue(template.getResultCollector() instanceof MyResultCollector);
|
assertTrue(template.getResultCollector() instanceof MyResultCollector);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user