SGF-385 - Local region does remote put in addition to local put in client cache.
This commit is contained in:
@@ -49,7 +49,8 @@ import com.gemstone.gemfire.cache.Scope;
|
||||
public class RegionLookupIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void preTestSuiteSetup() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void testSuiteSetup() {
|
||||
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() + " "
|
||||
+ "/org/springframework/data/gemfire/RegionLookupIntegrationTests-server-context.xml");
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -33,22 +34,23 @@ import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "client-cache.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientCacheTest {
|
||||
@Resource(name = "challengeQuestionsRegion")
|
||||
Region<?, ?> region;
|
||||
|
||||
@Autowired
|
||||
ClientCache cache;
|
||||
private ClientCache cache;
|
||||
|
||||
@Resource(name = "challengeQuestionsRegion")
|
||||
private Region<?, ?> region;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertEquals("gemfirePool", region.getAttributes().getPoolName());
|
||||
public void testPoolName() {
|
||||
assertEquals(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME, region.getAttributes().getPoolName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,4 +60,5 @@ public class ClientCacheTest {
|
||||
ctx.close();
|
||||
assertFalse(cache.isClosed());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,21 +21,33 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.ExpirationAttributes;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
|
||||
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.compression.Compressor;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
@@ -56,28 +68,185 @@ public class ClientRegionFactoryBeanTest {
|
||||
factoryBean = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testLookupFallbackFailingToUseProvidedShortcut() throws Exception {
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public void testLookupFallbackUsingDefaultShortcut() throws Exception {
|
||||
final String testRegionName = "TestRegion";
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.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);
|
||||
|
||||
when(mockRegionAttributes.getCloningEnabled()).thenReturn(false);
|
||||
when(mockRegionAttributes.getCompressor()).thenReturn(mock(Compressor.class));
|
||||
when(mockRegionAttributes.getConcurrencyChecksEnabled()).thenReturn(true);
|
||||
when(mockRegionAttributes.getConcurrencyLevel()).thenReturn(8);
|
||||
when(mockRegionAttributes.getCustomEntryIdleTimeout()).thenReturn(null);
|
||||
when(mockRegionAttributes.getCustomEntryTimeToLive()).thenReturn(null);
|
||||
when(mockRegionAttributes.getDiskStoreName()).thenReturn("TestDiskStoreOne");
|
||||
when(mockRegionAttributes.isDiskSynchronous()).thenReturn(false);
|
||||
when(mockRegionAttributes.getEntryIdleTimeout()).thenReturn(mock(ExpirationAttributes.class));
|
||||
when(mockRegionAttributes.getEntryTimeToLive()).thenReturn(mock(ExpirationAttributes.class));
|
||||
when(mockRegionAttributes.getEvictionAttributes()).thenReturn(mock(EvictionAttributes.class));
|
||||
when(mockRegionAttributes.getInitialCapacity()).thenReturn(101);
|
||||
when(mockRegionAttributes.getKeyConstraint()).thenReturn(Long.class);
|
||||
when(mockRegionAttributes.getLoadFactor()).thenReturn(0.75f);
|
||||
when(mockRegionAttributes.getPoolName()).thenReturn("TestPoolOne");
|
||||
when(mockRegionAttributes.getRegionIdleTimeout()).thenReturn(mock(ExpirationAttributes.class));
|
||||
when(mockRegionAttributes.getRegionTimeToLive()).thenReturn(mock(ExpirationAttributes.class));
|
||||
when(mockRegionAttributes.getStatisticsEnabled()).thenReturn(true);
|
||||
when(mockRegionAttributes.getValueConstraint()).thenReturn(Number.class);
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
Pool mockPool = mock(Pool.class);
|
||||
Resource mockSnapshot = mock(Resource.class, "Snapshot");
|
||||
|
||||
when(mockBeanFactory.isTypeMatch(eq("TestPoolTwo"), eq(Pool.class))).thenReturn(true);
|
||||
when(mockBeanFactory.getBean(eq("TestPoolTwo"))).thenReturn(mockPool);
|
||||
when(mockPool.getName()).thenReturn("TestPoolTwo");
|
||||
when(mockSnapshot.getInputStream()).thenReturn(mock(InputStream.class));
|
||||
|
||||
factoryBean.setAttributes(mockRegionAttributes);
|
||||
factoryBean.setBeanFactory(mockBeanFactory);
|
||||
factoryBean.setDiskStoreName("TestDiskStoreTwo");
|
||||
factoryBean.setPersistent(false);
|
||||
factoryBean.setPoolName("TestPoolTwo");
|
||||
factoryBean.setSnapshot(mockSnapshot);
|
||||
factoryBean.setShortcut(null);
|
||||
|
||||
Region actualRegion = factoryBean.lookupFallback(mockClientCache, testRegionName);
|
||||
|
||||
assertSame(mockRegion, actualRegion);
|
||||
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.LOCAL));
|
||||
verify(mockClientRegionFactory, times(1)).setCloningEnabled(eq(false));
|
||||
verify(mockClientRegionFactory, times(1)).setCompressor(any(Compressor.class));
|
||||
verify(mockClientRegionFactory, times(1)).setConcurrencyChecksEnabled(eq(true));
|
||||
verify(mockClientRegionFactory, times(1)).setConcurrencyLevel(eq(8));
|
||||
verify(mockClientRegionFactory, times(1)).setCustomEntryIdleTimeout(null);
|
||||
verify(mockClientRegionFactory, times(1)).setCustomEntryTimeToLive(null);
|
||||
verify(mockClientRegionFactory, times(1)).setDiskStoreName(eq("TestDiskStoreOne"));
|
||||
verify(mockClientRegionFactory, times(1)).setDiskSynchronous(eq(false));
|
||||
verify(mockClientRegionFactory, times(1)).setEntryIdleTimeout(any(ExpirationAttributes.class));
|
||||
verify(mockClientRegionFactory, times(1)).setEntryTimeToLive(any(ExpirationAttributes.class));
|
||||
verify(mockClientRegionFactory, times(1)).setEvictionAttributes(any(EvictionAttributes.class));
|
||||
verify(mockClientRegionFactory, times(1)).setInitialCapacity(eq(101));
|
||||
verify(mockClientRegionFactory, times(1)).setKeyConstraint(eq(Long.class));
|
||||
verify(mockClientRegionFactory, times(1)).setLoadFactor(eq(0.75f));
|
||||
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPoolOne"));
|
||||
verify(mockClientRegionFactory, times(1)).setRegionIdleTimeout(any(ExpirationAttributes.class));
|
||||
verify(mockClientRegionFactory, times(1)).setRegionTimeToLive(any(ExpirationAttributes.class));
|
||||
verify(mockClientRegionFactory, times(1)).setStatisticsEnabled(eq(true));
|
||||
verify(mockClientRegionFactory, times(1)).setValueConstraint(eq(Number.class));
|
||||
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPoolTwo"));
|
||||
verify(mockClientRegionFactory, times(1)).setDiskStoreName(eq("TestDiskStoreTwo"));
|
||||
verify(mockClientRegionFactory, times(1)).create(eq(testRegionName));
|
||||
verify(mockRegion, times(1)).loadSnapshot(any(InputStream.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public void testLookupFallbackUsingDefaultPersistentShortcut() throws Exception {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> mockRegion = mock(Region.class);
|
||||
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_PERSISTENT))).thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
when(mockBeanFactory.isTypeMatch(eq("TestPool"), eq(Pool.class))).thenReturn(false);
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(mockBeanFactory);
|
||||
factoryBean.setPersistent(true);
|
||||
factoryBean.setPoolName("TestPool");
|
||||
factoryBean.setShortcut(null);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestRegion");
|
||||
|
||||
assertSame(mockRegion, actualRegion);
|
||||
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_PERSISTENT));
|
||||
verify(mockClientRegionFactory, times(1)).setPoolName(eq("TestPool"));
|
||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
||||
verify(mockBeanFactory, never()).getBean(eq("TestPool"));
|
||||
verify(mockRegion, never()).loadSnapshot(any(InputStream.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testLookupFallbackWithSpecifiedShortcut() throws Exception {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> mockRegion = mock(Region.class);
|
||||
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY))).thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(null);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
Pool pool = mock(Pool.class);
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestRegion");
|
||||
|
||||
when(beanFactory.getBean(Pool.class)).thenReturn(pool);
|
||||
assertSame(mockRegion, actualRegion);
|
||||
|
||||
factoryBean.setBeanFactory(beanFactory);
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY));
|
||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
||||
}
|
||||
|
||||
ClientCache cache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> clientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> expectedRegion = mock(Region.class);
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testLookupFallbackWithSubRegionCreation() throws Exception {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> mockParentRegion = mock(Region.class, "Parent");
|
||||
Region<Object, Object> mockSubRegion = mock(Region.class, "SubRegion");
|
||||
|
||||
when(cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)).thenReturn(clientRegionFactory);
|
||||
when(clientRegionFactory.create("testRegion")).thenReturn(expectedRegion);
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.PROXY))).thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.createSubregion(eq(mockParentRegion), eq("TestSubRegion"))).thenReturn(mockSubRegion);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(cache, "testRegion");
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(null);
|
||||
factoryBean.setParent(mockParentRegion);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.PROXY);
|
||||
|
||||
assertSame(expectedRegion, actualRegion);
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestSubRegion");
|
||||
|
||||
assertSame(mockSubRegion, actualRegion);
|
||||
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.PROXY));
|
||||
verify(mockClientRegionFactory, times(1)).createSubregion(eq(mockParentRegion), eq("TestSubRegion"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testLookupFallbackWithUnspecifiedPool() throws Exception {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> mockRegion = mock(Region.class);
|
||||
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_HEAP_LRU))).thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(null);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_HEAP_LRU);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestRegion");
|
||||
|
||||
assertSame(mockRegion, actualRegion);
|
||||
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_HEAP_LRU));
|
||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
||||
verify(mockClientRegionFactory, never()).setPoolName(any(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,15 +262,24 @@ public class ClientRegionFactoryBeanTest {
|
||||
try {
|
||||
factoryBean.setDataPolicyName("INVALID");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Data Policy 'INVALID' is invalid.", e.getMessage());
|
||||
throw e;
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Data Policy 'INVALID' is invalid.", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(TestUtils.readField("dataPolicy", factoryBean));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPersistent() {
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
factoryBean.setPersistent(false);
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
factoryBean.setPersistent(true);
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPersistentUnspecified() {
|
||||
assertTrue(factoryBean.isPersistentUnspecified());
|
||||
@@ -113,15 +291,6 @@ public class ClientRegionFactoryBeanTest {
|
||||
assertFalse(factoryBean.isPersistentUnspecified());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsPersistent() {
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
factoryBean.setPersistent(false);
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
factoryBean.setPersistent(true);
|
||||
assertTrue(factoryBean.isPersistent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNotPersistent() {
|
||||
assertFalse(factoryBean.isNotPersistent());
|
||||
@@ -238,9 +407,10 @@ public class ClientRegionFactoryBeanTest {
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Client Region Shortcut 'CACHING_PROXY' is invalid when persistent is true.", e.getMessage());
|
||||
throw e;
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Client Region Shortcut 'CACHING_PROXY' is invalid when persistent is true.",
|
||||
expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,9 +434,10 @@ public class ClientRegionFactoryBeanTest {
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Client Region Shortcut 'LOCAL_PERSISTENT' is invalid when persistent is false.", e.getMessage());
|
||||
throw e;
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Client Region Shortcut 'LOCAL_PERSISTENT' is invalid when persistent is false.",
|
||||
expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,9 +481,9 @@ public class ClientRegionFactoryBeanTest {
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Data Policy 'NORMAL' is invalid when persistent is true.", e.getMessage());
|
||||
throw e;
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Data Policy 'NORMAL' is invalid when persistent is true.", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,9 +507,9 @@ public class ClientRegionFactoryBeanTest {
|
||||
|
||||
factoryBean.resolveClientRegionShortcut();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false.", e.getMessage());
|
||||
throw e;
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false.", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ public class CacheNamespaceTest{
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&no-bean-factory-locator", CacheFactoryBean.class);
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(cacheFactoryBean, "factoryLocator"), is(nullValue()));
|
||||
assertThat(ReflectionTestUtils.getField(cacheFactoryBean, "beanFactoryLocator"), is(nullValue()));
|
||||
|
||||
GemfireBeanFactoryLocator beanFactoryLocator = new GemfireBeanFactoryLocator();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -40,52 +41,60 @@ import com.gemstone.gemfire.cache.client.PoolManager;
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="pool-ns.xml",
|
||||
initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@ContextConfiguration(locations="pool-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class PoolNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
testBasicClient();
|
||||
testComplexPool();
|
||||
}
|
||||
|
||||
private void testBasicClient() throws Exception {
|
||||
public void testBasicClient() throws Exception {
|
||||
assertTrue(context.containsBean("DEFAULT"));
|
||||
assertTrue(context.containsBean("gemfirePool"));
|
||||
//Check old style alias also registered
|
||||
assertTrue(context.containsBean("gemfire-pool"));
|
||||
|
||||
assertEquals(context.getBean("gemfirePool"), PoolManager.find("gemfirePool"));
|
||||
PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&gemfirePool");
|
||||
Collection<InetSocketAddress> locators = TestUtils.readField("locators", pfb);
|
||||
assertEquals(context.getBean("gemfirePool"), PoolManager.find("DEFAULT"));
|
||||
|
||||
PoolFactoryBean poolFactoryBean = (PoolFactoryBean) context.getBean("&gemfirePool");
|
||||
Collection<InetSocketAddress> locators = TestUtils.readField("locators", poolFactoryBean);
|
||||
|
||||
assertNotNull(locators);
|
||||
assertEquals(1, locators.size());
|
||||
|
||||
InetSocketAddress locator = locators.iterator().next();
|
||||
|
||||
assertEquals("localhost", locator.getHostName());
|
||||
assertEquals(40403, locator.getPort());
|
||||
}
|
||||
|
||||
private void testComplexPool() throws Exception {
|
||||
@Test
|
||||
public void testComplexPool() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&complex");
|
||||
assertEquals(30, TestUtils.readField("retryAttempts", pfb));
|
||||
assertEquals(6000, TestUtils.readField("freeConnectionTimeout", pfb));
|
||||
assertEquals(5000l, TestUtils.readField("pingInterval", pfb));
|
||||
assertTrue((Boolean) TestUtils.readField("subscriptionEnabled", pfb));
|
||||
assertFalse((Boolean) TestUtils.readField("multiUserAuthentication", pfb));
|
||||
assertTrue((Boolean) TestUtils.readField("prSingleHopEnabled", pfb));
|
||||
|
||||
Collection<InetSocketAddress> servers = TestUtils.readField("servers", pfb);
|
||||
PoolFactoryBean poolFactoryBean = (PoolFactoryBean) context.getBean("&complex");
|
||||
|
||||
assertEquals(30, TestUtils.readField("retryAttempts", poolFactoryBean));
|
||||
assertEquals(6000, TestUtils.readField("freeConnectionTimeout", poolFactoryBean));
|
||||
assertEquals(5000l, TestUtils.readField("pingInterval", poolFactoryBean));
|
||||
assertTrue((Boolean) TestUtils.readField("subscriptionEnabled", poolFactoryBean));
|
||||
assertFalse((Boolean) TestUtils.readField("multiUserAuthentication", poolFactoryBean));
|
||||
assertTrue((Boolean) TestUtils.readField("prSingleHopEnabled", poolFactoryBean));
|
||||
|
||||
Collection<InetSocketAddress> servers = TestUtils.readField("servers", poolFactoryBean);
|
||||
|
||||
assertNotNull(servers);
|
||||
assertEquals(2, servers.size());
|
||||
|
||||
Iterator<InetSocketAddress> iterator = servers.iterator();
|
||||
InetSocketAddress server = iterator.next();
|
||||
|
||||
assertEquals("localhost", server.getHostName());
|
||||
assertEquals(40404, server.getPort());
|
||||
|
||||
server = iterator.next();
|
||||
|
||||
assertEquals("localhost", server.getHostName());
|
||||
assertEquals(40405, server.getPort());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
public MockCacheFactoryBean(CacheFactoryBean cacheFactoryBean) {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
this.factoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanFactoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.lazyInitialize = cacheFactoryBean.isLazyInitialize();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = cacheFactoryBean.getBeanFactory();
|
||||
|
||||
@@ -29,13 +29,10 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
this.cache = new StubCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bean
|
||||
*/
|
||||
public MockClientCacheFactoryBean(ClientCacheFactoryBean cacheFactoryBean) {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
this.factoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanFactoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = cacheFactoryBean.getBeanFactory();
|
||||
this.beanName = cacheFactoryBean.getBeanName();
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
<!DOCTYPE client-cache PUBLIC "-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN"
|
||||
"http://www.gemstone.com/dtd/cache7_0.dtd">
|
||||
<client-cache>
|
||||
<pool name="DEFAULT" min-connections="0">
|
||||
<server host="localhost" port="54321"/>
|
||||
</pool>
|
||||
<region name="NativeClientRegion" refid="PROXY">
|
||||
<region-attributes cloning-enabled="false"/>
|
||||
</region>
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<gfe:client-cache/>
|
||||
<gfe:client-region data-policy="NORMAL" name="ChallengeQuestions" id="challengeQuestionsRegion"/>
|
||||
<gfe:pool>
|
||||
<gfe:locator host="localhost" port="1234"/>
|
||||
</gfe:pool>
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">ClientCacheTests</prop>
|
||||
<prop key="mcast-port">0</prop>
|
||||
<prop key="log-level">warning</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:pool>
|
||||
<gfe:locator host="localhost" port="1234"/>
|
||||
</gfe:pool>
|
||||
<gfe:client-cache properties-ref="gemfireProperties"/>
|
||||
<gfe:client-region data-policy="NORMAL" name="ChallengeQuestions" id="challengeQuestionsRegion"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user