SGF-439 - Add 'durable-client-id' and 'durable-client-timeout' attributes to the <gfe:client-cache> namespace element for convenience.

(cherry picked from commit e74768f006d59210ddd3d4fe5294a60ca505674f)

Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
John Blum
2015-10-15 16:39:12 -07:00
parent 23374a583f
commit 1bb8e7b7a9
14 changed files with 303 additions and 99 deletions

View File

@@ -16,11 +16,13 @@
package org.springframework.data.gemfire.client;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
@@ -42,6 +44,7 @@ import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.util.DistributedSystemUtils;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.GemFireCache;
@@ -60,13 +63,21 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
* @see org.mockito.Mockito
* @see org.junit.Test
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
* @see com.gemstone.gemfire.cache.GemFireCache
* @see com.gemstone.gemfire.cache.client.ClientCache
* @see com.gemstone.gemfire.cache.client.ClientCacheFactory
* @see com.gemstone.gemfire.cache.client.Pool
* @see com.gemstone.gemfire.distributed.DistributedSystem
* @since 1.7.0
*/
public class ClientCacheFactoryBeanTest {
protected Properties createProperties(String key, String value) {
Properties properties = new Properties();
return addProperty(null, key, value);
}
protected Properties addProperty(Properties properties, String key, String value) {
properties = (properties != null ? properties : new Properties());
properties.setProperty(key, value);
return properties;
}
@@ -101,12 +112,52 @@ public class ClientCacheFactoryBeanTest {
Properties resolvedProperties = clientCacheFactoryBean.resolveProperties();
assertNotNull(resolvedProperties);
assertNotSame(gemfireProperties, resolvedProperties);
assertNotSame(distributedSystemProperties, resolvedProperties);
assertEquals(2, resolvedProperties.size());
assertEquals("test", resolvedProperties.getProperty("gf"));
assertEquals("mock", resolvedProperties.getProperty("ds"));
assertThat(resolvedProperties, is(notNullValue()));
assertThat(resolvedProperties, is(not(sameInstance(gemfireProperties))));
assertThat(resolvedProperties, is(not(sameInstance(distributedSystemProperties))));
assertThat(resolvedProperties.size(), is(equalTo(2)));
assertThat(resolvedProperties.containsKey(DistributedSystemUtils.DURABLE_CLIENT_ID_PROPERTY_NAME), is(false));
assertThat(resolvedProperties.containsKey(DistributedSystemUtils.DURABLE_CLIENT_TIMEOUT_PROPERTY_NAME), is(false));
assertThat(resolvedProperties.getProperty("gf"), is(equalTo("test")));
assertThat(resolvedProperties.getProperty("ds"), is(equalTo("mock")));
verify(mockDistributedSystem, times(1)).isConnected();
verify(mockDistributedSystem, times(1)).getProperties();
}
@Test
public void resolvePropertiesWhenDistributedSystemIsConnectedAndClientIsDurable() {
Properties gemfireProperties = DistributedSystemUtils.configureDurableClient(createProperties("gf", "test"),
"123", 600);
Properties distributedSystemProperties = DistributedSystemUtils.configureDurableClient(
createProperties("ds", "mock"), "987", 300);
final DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, "MockDistributedSystem");
when(mockDistributedSystem.isConnected()).thenReturn(true);
when(mockDistributedSystem.getProperties()).thenReturn(distributedSystemProperties);
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
@SuppressWarnings("unchecked") @Override <T extends DistributedSystem> T getDistributedSystem() {
return (T) mockDistributedSystem;
}
};
clientCacheFactoryBean.setProperties(gemfireProperties);
Properties resolvedProperties = clientCacheFactoryBean.resolveProperties();
assertThat(resolvedProperties, is(notNullValue()));
assertThat(resolvedProperties, is(not(sameInstance(gemfireProperties))));
assertThat(resolvedProperties, is(not(sameInstance(distributedSystemProperties))));
assertThat(resolvedProperties.size(), is(equalTo(4)));
assertThat(resolvedProperties.getProperty("gf"), is(equalTo("test")));
assertThat(resolvedProperties.getProperty("ds"), is(equalTo("mock")));
assertThat(resolvedProperties.getProperty(DistributedSystemUtils.DURABLE_CLIENT_ID_PROPERTY_NAME),
is(equalTo("123")));
assertThat(resolvedProperties.getProperty(DistributedSystemUtils.DURABLE_CLIENT_TIMEOUT_PROPERTY_NAME),
is(equalTo("600")));
verify(mockDistributedSystem, times(1)).isConnected();
verify(mockDistributedSystem, times(1)).getProperties();
@@ -252,10 +303,13 @@ public class ClientCacheFactoryBeanTest {
@Test
public void createCache() {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockSpringBeanFactory");
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class, "MockGemFireClientCacheFactory");
ClientCache mockClientCache = mock(ClientCache.class, "MockGemFireClientCache");
Pool mockPool = mock(Pool.class, "MockGemFirePool");
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class, "MockClientCacheFactory");
ClientCache mockClientCache = mock(ClientCache.class, "MockClientCache");
Pool mockPool = mock(Pool.class, "MockPool");
when(mockClientCacheFactory.create()).thenReturn(mockClientCache);
when(mockBeanFactory.isTypeMatch(eq("testCreateCache.Pool"), eq(Pool.class))).thenReturn(true);

View File

@@ -46,7 +46,8 @@ import com.gemstone.gemfire.cache.LoaderHelper;
import com.gemstone.gemfire.cache.Region;
/**
* The ClientCacheSecurityTest class...
* The ClientCacheSecurityTest class is a test suite with test cases testing SSL configuration between a GemFire client
* and server using the cluster-ssl-* GemFire System properties.
*
* @author John Blum
* @see org.junit.Test

View File

@@ -47,6 +47,7 @@ import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.process.ProcessWrapper;
import org.springframework.data.gemfire.test.AbstractGemFireClientServerIntegrationTest;
import org.springframework.data.gemfire.test.support.ThreadUtils;
import org.springframework.data.gemfire.util.DistributedSystemUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -95,6 +96,8 @@ public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServ
private static final String CLIENT_CACHE_INTERESTS_RESULT_POLICY_SYSTEM_PROPERTY =
"gemfire.cache.client.interests.result-policy";
private static final String DURABLE_CLIENT_TIMEOUT_SYSTEM_PROPERTY = "gemfire.cache.client.durable-client-timeout";
private static final String SERVER_HOST = "localhost";
@Autowired
@@ -119,6 +122,14 @@ public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServ
@Before
public void setup() {
assertThat(clientCache.getDistributedSystem().getProperties().getProperty(
DistributedSystemUtils.DURABLE_CLIENT_ID_PROPERTY_NAME),
is(equalTo(DurableClientCacheIntegrationTest.class.getSimpleName())));
assertThat(clientCache.getDistributedSystem().getProperties().getProperty(
DistributedSystemUtils.DURABLE_CLIENT_TIMEOUT_PROPERTY_NAME),
is(equalTo(RUN_COUNT.get() == 1 ? "300" : "600")));
assertRegion(example, "Example", DataPolicy.NORMAL);
}
@@ -127,8 +138,7 @@ public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServ
if (RUN_COUNT.get() == 1) {
closeApplicationContext();
runClientCacheProducer();
System.setProperty(CLIENT_CACHE_INTERESTS_RESULT_POLICY_SYSTEM_PROPERTY,
InterestResultPolicyType.NONE.name());
setSystemProperties();
RUN_COUNT.incrementAndGet();
}
@@ -162,6 +172,11 @@ public class DurableClientCacheIntegrationTest extends AbstractGemFireClientServ
}
}
protected void setSystemProperties() {
System.setProperty(CLIENT_CACHE_INTERESTS_RESULT_POLICY_SYSTEM_PROPERTY, InterestResultPolicyType.NONE.name());
System.setProperty(DURABLE_CLIENT_TIMEOUT_SYSTEM_PROPERTY, "600");
}
protected void waitForRegionEntryEvents() {
ThreadUtils.timedWait(TimeUnit.SECONDS.toMillis(5), TimeUnit.MILLISECONDS.toMillis(500),
new ThreadUtils.WaitCondition() {

View File

@@ -16,6 +16,8 @@
package org.springframework.data.gemfire.client;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@@ -30,11 +32,12 @@ import static org.mockito.Mockito.when;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Collections;
import java.util.Properties;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.data.gemfire.TestUtils;
@@ -57,26 +60,24 @@ import com.gemstone.gemfire.cache.client.PoolFactory;
*/
public class PoolFactoryBeanTest {
@Test
public void testGetObjectType() {
assertEquals(Pool.class, new PoolFactoryBean().getObjectType());
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testIsSingleton() {
assertTrue(new PoolFactoryBean().isSingleton());
}
@SuppressWarnings("deprecation")
public void afterPropertiesSet() throws Exception {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
@Test
public void testAfterPropertiesSet() throws Exception {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockSpringBeanFactory");
final PoolFactory mockPoolFactory = mock(PoolFactory.class, "MockGemFirePoolFactory");
Pool mockPool = mock(Pool.class, "GemFirePool");
final PoolFactory mockPoolFactory = mock(PoolFactory.class, "MockPoolFactory");
Pool mockPool = mock(Pool.class, "MockPool");
final Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("name", "testAfterPropertiesSet");
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
clientCacheFactoryBean.setProperties(gemfireProperties);
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenReturn(clientCacheFactoryBean);
@@ -139,39 +140,40 @@ public class PoolFactoryBeanTest {
verify(mockPoolFactory, times(1)).create(eq("GemFirePool"));
}
@Test(expected = IllegalArgumentException.class)
public void testAfterPropertiesSetWithNoLocatorsServersSpecified() throws Exception {
try {
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
@Test
public void afterPropertiesSetWithUnspecifiedName() throws Exception {
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
poolFactoryBean.setName("GemFirePool");
poolFactoryBean.setLocators((Collection) null);
poolFactoryBean.setServers(Collections.<InetSocketAddress>emptyList());
poolFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("at least one GemFire Locator or Server is required", expected.getMessage());
throw expected;
}
}
poolFactoryBean.setBeanName(null);
poolFactoryBean.setName(null);
@Test(expected = IllegalArgumentException.class)
public void testAfterPropertiesSetWithUnspecifiedName() throws Exception {
try {
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
poolFactoryBean.setBeanName(null);
poolFactoryBean.setName(null);
poolFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("Pool 'name' is required", expected.getMessage());
throw expected;
}
expectedException.expect(IllegalArgumentException.class);
expectedException.expectCause(is(nullValue(Throwable.class)));
expectedException.expectMessage("Pool 'name' is required");
poolFactoryBean.afterPropertiesSet();
}
@Test
public void testResolveGemfireProperties() {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockSpringBeanFactory");
@SuppressWarnings("deprecation")
public void afterPropertiesSetWithNoLocatorsOrServersSpecified() throws Exception {
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
poolFactoryBean.setBeanName("GemFirePool");
poolFactoryBean.setLocators(null);
poolFactoryBean.setServers(Collections.<InetSocketAddress>emptyList());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectCause(is(nullValue(Throwable.class)));
expectedException.expectMessage("at least one GemFire Locator or Server is required");
poolFactoryBean.afterPropertiesSet();
}
@Test
public void resolveGemfireProperties() {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenReturn(clientCacheFactoryBean);
@@ -191,8 +193,8 @@ public class PoolFactoryBeanTest {
}
@Test
public void testResolveUnresolvableGemfireProperties() {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockSpringBeanFactory");
public void resolveUnresolvableGemfireProperties() {
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenThrow(
new NoSuchBeanDefinitionException("TEST"));
@@ -205,8 +207,8 @@ public class PoolFactoryBeanTest {
}
@Test
public void testDestroy() throws Exception {
Pool mockPool = mock(Pool.class, "MockGemFirePool");
public void destroy() throws Exception {
Pool mockPool = mock(Pool.class, "MockPool");
when(mockPool.isDestroyed()).thenReturn(false);
@@ -222,7 +224,7 @@ public class PoolFactoryBeanTest {
}
@Test
public void testDestroyNonSpringBasedPool() throws Exception {
public void destroyWithNonSpringBasedPool() throws Exception {
Pool mockPool = mock(Pool.class, "MockGemFirePool");
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
@@ -237,11 +239,21 @@ public class PoolFactoryBeanTest {
}
@Test
public void testDestroyWithUninitializedPool() throws Exception {
public void destroyWithUninitializedPool() throws Exception {
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
poolFactoryBean.setPool(null);
poolFactoryBean.destroy();
}
@Test
public void getObjectType() {
assertEquals(Pool.class, new PoolFactoryBean().getObjectType());
}
@Test
public void isSingleton() {
assertTrue(new PoolFactoryBean().isSingleton());
}
}

View File

@@ -67,6 +67,8 @@ public class ClientCacheNamespaceTest {
assertThat(clientCacheFactoryBean.isLazyInitialize(), is(true));
assertThat(clientCacheFactoryBean.getCopyOnRead(), is(true));
assertThat(clientCacheFactoryBean.getCriticalHeapPercentage(), is(equalTo(0.85f)));
assertThat(clientCacheFactoryBean.getDurableClientId(), is(equalTo("TestDurableClientId")));
assertThat(clientCacheFactoryBean.getDurableClientTimeout(), is(equalTo(600)));
assertThat(clientCacheFactoryBean.getEvictionHeapPercentage(), is(equalTo(0.65f)));
assertThat((PdxSerializer) clientCacheFactoryBean.getPdxSerializer(), is(equalTo(reflectionPdxSerializer)));
assertThat(clientCacheFactoryBean.getPdxIgnoreUnreadFields(), is(true));

View File

@@ -40,6 +40,8 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
this.cacheXml = clientCacheFactoryBean.getCacheXml();
this.copyOnRead = clientCacheFactoryBean.getCopyOnRead();
this.criticalHeapPercentage = clientCacheFactoryBean.getCriticalHeapPercentage();
this.durableClientId = clientCacheFactoryBean.getDurableClientId();
this.durableClientTimeout = clientCacheFactoryBean.getDurableClientTimeout();
this.dynamicRegionSupport = clientCacheFactoryBean.getDynamicRegionSupport();
this.evictionHeapPercentage = clientCacheFactoryBean.getEvictionHeapPercentage();
this.gatewayConflictResolver = clientCacheFactoryBean.getGatewayConflictResolver();