SGF-416 - Avoid eager creation of a GemFire DistributedSystem in the PoolFactoryBean by creating a ClientCache first.
(cherry picked from commit 127b62e7220f94e07ed2e46e46b90e5017dde80d) Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -41,13 +45,16 @@ import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.CacheTransactionManager;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
@@ -65,29 +72,144 @@ import com.gemstone.gemfire.pdx.PdxSerializer;
|
||||
* of the CacheFactoryBean class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public class CacheFactoryBeanTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class, "SpringBeanFactory");
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
CacheTransactionManager mockCacheTransactionManager = mock(CacheTransactionManager.class, "GemFireTransactionManager");
|
||||
DistributedMember mockDistributedMember = mock(DistributedMember.class, "GemFireDistributedMember");
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class, "GemFireDistributedSystem");
|
||||
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class, "GemFireGatewayConflictResolver");
|
||||
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class, "GemFirePdxSerializer");
|
||||
Resource mockCacheXml = mock(Resource.class, "GemFireCacheXml");
|
||||
ResourceManager mockResourceManager = mock(ResourceManager.class, "GemFireResourceManager");
|
||||
TransactionListener mockTransactionLister = mock(TransactionListener.class, "GemFireTransactionListener");
|
||||
TransactionWriter mockTransactionWriter = mock(TransactionWriter.class, "GemFireTransactionWriter");
|
||||
final AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
final Properties gemfireProperties = new Properties();
|
||||
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class, "GemFireCacheFactory");
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected void postProcessBeforeCacheInitialization(Properties actualGemfireProperties) {
|
||||
assertThat(actualGemfireProperties, is(sameInstance(gemfireProperties)));
|
||||
postProcessBeforeCacheInitializationCalled.set(true);
|
||||
}
|
||||
};
|
||||
|
||||
cacheFactoryBean.setProperties(gemfireProperties);
|
||||
cacheFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(postProcessBeforeCacheInitializationCalled.get(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationUsingDefaults() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
new CacheFactoryBean().postProcessBeforeCacheInitialization(gemfireProperties);
|
||||
|
||||
assertThat(gemfireProperties.size(), is(equalTo(2)));
|
||||
assertThat(gemfireProperties.containsKey("disable-auto-reconnect"), is(true));
|
||||
assertThat(gemfireProperties.containsKey("use-cluster-configuration"), is(true));
|
||||
assertThat(gemfireProperties.getProperty("disable-auto-reconnect"), is(equalTo("true")));
|
||||
assertThat(gemfireProperties.getProperty("use-cluster-configuration"), is(equalTo("false")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationDisabled() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
cacheFactoryBean.setUseClusterConfiguration(false);
|
||||
cacheFactoryBean.postProcessBeforeCacheInitialization(gemfireProperties);
|
||||
|
||||
assertThat(gemfireProperties.size(), is(equalTo(2)));
|
||||
assertThat(gemfireProperties.containsKey("disable-auto-reconnect"), is(true));
|
||||
assertThat(gemfireProperties.containsKey("use-cluster-configuration"), is(true));
|
||||
assertThat(gemfireProperties.getProperty("disable-auto-reconnect"), is(equalTo("true")));
|
||||
assertThat(gemfireProperties.getProperty("use-cluster-configuration"), is(equalTo("false")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationEnabled() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(true);
|
||||
cacheFactoryBean.setUseClusterConfiguration(true);
|
||||
cacheFactoryBean.postProcessBeforeCacheInitialization(gemfireProperties);
|
||||
|
||||
assertThat(gemfireProperties.size(), is(equalTo(2)));
|
||||
assertThat(gemfireProperties.containsKey("disable-auto-reconnect"), is(true));
|
||||
assertThat(gemfireProperties.containsKey("use-cluster-configuration"), is(true));
|
||||
assertThat(gemfireProperties.getProperty("disable-auto-reconnect"), is(equalTo("false")));
|
||||
assertThat(gemfireProperties.getProperty("use-cluster-configuration"), is(equalTo("true")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectDisabledAndClusterConfigurationEnabled() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
cacheFactoryBean.setUseClusterConfiguration(true);
|
||||
cacheFactoryBean.postProcessBeforeCacheInitialization(gemfireProperties);
|
||||
|
||||
assertThat(gemfireProperties.size(), is(equalTo(2)));
|
||||
assertThat(gemfireProperties.containsKey("disable-auto-reconnect"), is(true));
|
||||
assertThat(gemfireProperties.containsKey("use-cluster-configuration"), is(true));
|
||||
assertThat(gemfireProperties.getProperty("disable-auto-reconnect"), is(equalTo("true")));
|
||||
assertThat(gemfireProperties.getProperty("use-cluster-configuration"), is(equalTo("true")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getObjectCallsInit() throws Exception {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
final AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override Cache init() throws Exception {
|
||||
initCalled.set(true);
|
||||
return mockCache;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(cacheFactoryBean.getObject(), is(sameInstance(mockCache)));
|
||||
assertThat(initCalled.get(), is(true));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getObjectReturnsExistingCache() throws Exception {
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
|
||||
assertThat(cacheFactoryBean.getObject(), is(sameInstance(mockCache)));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheTransactionManager mockCacheTransactionManager = mock(CacheTransactionManager.class);
|
||||
DistributedMember mockDistributedMember = mock(DistributedMember.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class);
|
||||
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class);
|
||||
Resource mockCacheXml = mock(Resource.class);
|
||||
ResourceManager mockResourceManager = mock(ResourceManager.class);
|
||||
TransactionListener mockTransactionLister = mock(TransactionListener.class);
|
||||
TransactionWriter mockTransactionWriter = mock(TransactionWriter.class);
|
||||
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
when(mockCache.getCacheTransactionManager()).thenReturn(mockCacheTransactionManager);
|
||||
@@ -108,8 +230,8 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected Object createFactory(final Properties actualGemfireProperties) {
|
||||
assertSame(gemfireProperties, actualGemfireProperties);
|
||||
assertSame(ClassLoader.getSystemClassLoader(), getBeanClassLoader());
|
||||
assertThat(actualGemfireProperties, is(equalTo(gemfireProperties)));
|
||||
assertThat(getBeanClassLoader(), is(equalTo(ClassLoader.getSystemClassLoader())));
|
||||
return mockCacheFactory;
|
||||
}
|
||||
};
|
||||
@@ -128,36 +250,29 @@ public class CacheFactoryBeanTest {
|
||||
cacheFactoryBean.setLockLease(15000);
|
||||
cacheFactoryBean.setLockTimeout(5000);
|
||||
cacheFactoryBean.setMessageSyncInterval(20000);
|
||||
cacheFactoryBean.setPdxSerializer(mockPdxSerializer);
|
||||
cacheFactoryBean.setPdxReadSerialized(true);
|
||||
cacheFactoryBean.setPdxPersistent(true);
|
||||
cacheFactoryBean.setPdxIgnoreUnreadFields(false);
|
||||
cacheFactoryBean.setPdxDiskStoreName("TestPdxDiskStore");
|
||||
cacheFactoryBean.setPdxIgnoreUnreadFields(false);
|
||||
cacheFactoryBean.setPdxPersistent(true);
|
||||
cacheFactoryBean.setPdxReadSerialized(true);
|
||||
cacheFactoryBean.setPdxSerializer(mockPdxSerializer);
|
||||
cacheFactoryBean.setProperties(gemfireProperties);
|
||||
cacheFactoryBean.setSearchTimeout(45000);
|
||||
cacheFactoryBean.setTransactionListeners(Collections.singletonList(mockTransactionLister));
|
||||
cacheFactoryBean.setTransactionWriter(mockTransactionWriter);
|
||||
cacheFactoryBean.setUseBeanFactoryLocator(true);
|
||||
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
cacheFactoryBean.init();
|
||||
|
||||
cacheFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertEquals(2, gemfireProperties.size());
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(gemfireProperties.containsKey("use-cluster-configuration"));
|
||||
assertEquals("true", gemfireProperties.getProperty("disable-auto-reconnect"));
|
||||
assertEquals("false", gemfireProperties.getProperty("use-cluster-configuration"));
|
||||
assertSame(expectedThreadContextClassLoader, Thread.currentThread().getContextClassLoader());
|
||||
assertThat(Thread.currentThread().getContextClassLoader(), is(sameInstance(expectedThreadContextClassLoader)));
|
||||
|
||||
GemfireBeanFactoryLocator beanFactoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
|
||||
assertNotNull(beanFactoryLocator);
|
||||
assertThat(beanFactoryLocator, is(notNullValue()));
|
||||
|
||||
BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("TestGemFireCache");
|
||||
|
||||
assertNotNull(beanFactoryReference);
|
||||
assertSame(mockBeanFactory, beanFactoryReference.getFactory());
|
||||
assertThat(beanFactoryReference, is(notNullValue()));
|
||||
assertThat(beanFactoryReference.getFactory(), is(sameInstance(mockBeanFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setPdxDiskStore(eq("TestPdxDiskStore"));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
@@ -165,98 +280,96 @@ public class CacheFactoryBeanTest {
|
||||
verify(mockCacheFactory, times(1)).setPdxReadSerialized(eq(true));
|
||||
verify(mockCacheFactory, times(1)).setPdxSerializer(eq(mockPdxSerializer));
|
||||
verify(mockCacheFactory, times(1)).create();
|
||||
verify(mockCache, times(2)).getCacheTransactionManager();
|
||||
verify(mockCache, times(1)).loadCacheXml(any(InputStream.class));
|
||||
verify(mockCache, times(1)).setCopyOnRead(eq(true));
|
||||
verify(mockCache, times(1)).setGatewayConflictResolver(same(mockGatewayConflictResolver));
|
||||
verify(mockCache, times(1)).setLockLease(eq(15000));
|
||||
verify(mockCache, times(1)).setLockTimeout(eq(5000));
|
||||
verify(mockCache, times(1)).setMessageSyncInterval(eq(20000));
|
||||
verify(mockCache, times(1)).setSearchTimeout(eq(45000));
|
||||
verify(mockCache, times(2)).getResourceManager();
|
||||
verify(mockCache, times(1)).setSearchTimeout(eq(45000));
|
||||
verify(mockResourceManager, times(1)).setCriticalHeapPercentage(eq(0.90f));
|
||||
verify(mockResourceManager, times(1)).setEvictionHeapPercentage(eq(0.75f));
|
||||
verify(mockCache, times(2)).getCacheTransactionManager();
|
||||
verify(mockCacheTransactionManager, times(1)).addListener(same(mockTransactionLister));
|
||||
verify(mockCacheTransactionManager, times(1)).setWriter(same(mockTransactionWriter));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessPropertiesBeforeInitializationDefaults() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
public void resolveCacheCallsFetchCacheReturnsMock() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override @SuppressWarnings("unchecked ")
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
return (T) mockCache;
|
||||
}
|
||||
};
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
assertThat(cacheFactoryBean.resolveCache(), is(sameInstance(mockCache)));
|
||||
|
||||
cacheFactoryBean.postProcessPropertiesBeforeInitialization(gemfireProperties);
|
||||
|
||||
assertEquals(2, gemfireProperties.size());
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(gemfireProperties.containsKey("use-cluster-configuration"));
|
||||
assertEquals("true", gemfireProperties.getProperty("disable-auto-reconnect"));
|
||||
assertEquals("false", gemfireProperties.getProperty("use-cluster-configuration"));
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postProcessPropertiesBeforeInitializationDisabled() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
public void resolveCacheCreatesCacheWhenFetchCacheThrowsCacheClosedException() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
throw new CacheClosedException("test");
|
||||
}
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
cacheFactoryBean.setUseClusterConfiguration(false);
|
||||
cacheFactoryBean.postProcessPropertiesBeforeInitialization(gemfireProperties);
|
||||
@Override
|
||||
protected Object createFactory(final Properties gemfireProperties) {
|
||||
assertThat(gemfireProperties, is(sameInstance(getProperties())));
|
||||
return mockCacheFactory;
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals(2, gemfireProperties.size());
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(gemfireProperties.containsKey("use-cluster-configuration"));
|
||||
assertEquals("true", gemfireProperties.getProperty("disable-auto-reconnect"));
|
||||
assertEquals("false", gemfireProperties.getProperty("use-cluster-configuration"));
|
||||
}
|
||||
assertThat(cacheFactoryBean.resolveCache(), is(equalTo(mockCache)));
|
||||
|
||||
@Test
|
||||
public void postProcessPropertiesBeforeInitializationEnabled() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(true);
|
||||
cacheFactoryBean.setUseClusterConfiguration(true);
|
||||
cacheFactoryBean.postProcessPropertiesBeforeInitialization(gemfireProperties);
|
||||
|
||||
assertEquals(2, gemfireProperties.size());
|
||||
assertTrue(gemfireProperties.containsKey("disable-auto-reconnect"));
|
||||
assertTrue(gemfireProperties.containsKey("use-cluster-configuration"));
|
||||
assertEquals("false", gemfireProperties.getProperty("disable-auto-reconnect"));
|
||||
assertEquals("true", gemfireProperties.getProperty("use-cluster-configuration"));
|
||||
verify(mockCacheFactory, times(1)).create();
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetchExistingCache() throws Exception {
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
ReflectionUtils.setField(CacheFactoryBean.class.getDeclaredField("cache"), cacheFactoryBean, mockCache);
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
|
||||
Cache actualCache = cacheFactoryBean.resolveCache();
|
||||
Cache actualCache = cacheFactoryBean.fetchCache();
|
||||
|
||||
assertSame(mockCache, actualCache);
|
||||
assertThat(actualCache, is(sameInstance(mockCache)));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveProperties() {
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(gemfireProperties);
|
||||
|
||||
assertSame(gemfireProperties, cacheFactoryBean.resolveProperties());
|
||||
assertThat(cacheFactoryBean.resolveProperties(), is(sameInstance(gemfireProperties)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenNull() {
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(null);
|
||||
|
||||
Properties gemfireProperties = cacheFactoryBean.resolveProperties();
|
||||
|
||||
assertThat(gemfireProperties, is(notNullValue()));
|
||||
assertThat(gemfireProperties.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -264,87 +377,93 @@ public class CacheFactoryBeanTest {
|
||||
Properties gemfireProperties = new Properties();
|
||||
Object cacheFactoryReference = new CacheFactoryBean().createFactory(gemfireProperties);
|
||||
|
||||
assertTrue(gemfireProperties.isEmpty());
|
||||
assertTrue(cacheFactoryReference instanceof CacheFactory);
|
||||
assertThat(cacheFactoryReference, is(instanceOf(CacheFactory.class)));
|
||||
assertThat(gemfireProperties.isEmpty(), is(true));
|
||||
|
||||
CacheFactory cacheFactory = (CacheFactory) cacheFactoryReference;
|
||||
|
||||
cacheFactory.set("name", "TestCreateCacheFactory");
|
||||
|
||||
assertTrue(gemfireProperties.containsKey("name"));
|
||||
assertEquals("TestCreateCacheFactory", gemfireProperties.getProperty("name"));
|
||||
assertThat(gemfireProperties.containsKey("name"), is(true));
|
||||
assertThat(gemfireProperties.getProperty("name"), is(equalTo("TestCreateCacheFactory")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithUnspecifiedPdxOptions() {
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class, "MockGemFireCacheFactory");
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertSame(mockCacheFactory, new CacheFactoryBean().prepareFactory(mockCacheFactory));
|
||||
assertThat((CacheFactory) new CacheFactoryBean().prepareFactory(mockCacheFactory),
|
||||
is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, never()).setPdxSerializer(any(PdxSerializer.class));
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
verify(mockCacheFactory, never()).setPdxIgnoreUnreadFields(any(Boolean.class));
|
||||
verify(mockCacheFactory, never()).setPdxPersistent(any(Boolean.class));
|
||||
verify(mockCacheFactory, never()).setPdxReadSerialized(any(Boolean.class));
|
||||
verify(mockCacheFactory, never()).setPdxSerializer(any(PdxSerializer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithPartialPdxOptions() {
|
||||
public void prepareFactoryWithSpecificPdxOptions() {
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class, "MockGemFirePdxSerializer"));
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class));
|
||||
cacheFactoryBean.setPdxReadSerialized(true);
|
||||
cacheFactoryBean.setPdxIgnoreUnreadFields(false);
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class, "MockGemFireCacheFactory");
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertSame(mockCacheFactory, cacheFactoryBean.prepareFactory(mockCacheFactory));
|
||||
assertThat((CacheFactory) cacheFactoryBean.prepareFactory(mockCacheFactory),
|
||||
is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setPdxSerializer(any(PdxSerializer.class));
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
verify(mockCacheFactory, never()).setPdxPersistent(any(Boolean.class));
|
||||
verify(mockCacheFactory, times(1)).setPdxReadSerialized(eq(true));
|
||||
verify(mockCacheFactory, times(1)).setPdxSerializer(any(PdxSerializer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithAllPdxOptions() {
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class, "MockGemFirePdxSerializer"));
|
||||
cacheFactoryBean.setPdxDiskStoreName("testPdxDiskStoreName");
|
||||
cacheFactoryBean.setPdxIgnoreUnreadFields(false);
|
||||
cacheFactoryBean.setPdxPersistent(true);
|
||||
cacheFactoryBean.setPdxReadSerialized(true);
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class));
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class, "MockGemFireCacheFactory");
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertSame(mockCacheFactory, cacheFactoryBean.prepareFactory(mockCacheFactory));
|
||||
assertThat((CacheFactory) cacheFactoryBean.prepareFactory(mockCacheFactory),
|
||||
is(sameInstance(mockCacheFactory)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).setPdxSerializer(any(PdxSerializer.class));
|
||||
verify(mockCacheFactory, times(1)).setPdxDiskStore(eq("testPdxDiskStoreName"));
|
||||
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
|
||||
verify(mockCacheFactory, times(1)).setPdxPersistent(eq(true));
|
||||
verify(mockCacheFactory, times(1)).setPdxReadSerialized(eq(true));
|
||||
verify(mockCacheFactory, times(1)).setPdxSerializer(any(PdxSerializer.class));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void prepareFactoryWithInvalidTypeForPdxSerializer() {
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class, "MockGemFireCacheFactory");
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
Object pdxSerializer = new Object();
|
||||
|
||||
try {
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxSerializer(new Object());
|
||||
cacheFactoryBean.setPdxSerializer(pdxSerializer);
|
||||
cacheFactoryBean.setPdxIgnoreUnreadFields(false);
|
||||
cacheFactoryBean.setPdxReadSerialized(true);
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(containsString(String.format(
|
||||
"[%1$s] of type [java.lang.Object] is not a PdxSerializer", pdxSerializer)));
|
||||
|
||||
cacheFactoryBean.prepareFactory(mockCacheFactory);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage().startsWith("Invalid pdx serializer used"));
|
||||
assertNull(expected.getCause());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
verify(mockCacheFactory, never()).setPdxSerializer(any(PdxSerializer.class));
|
||||
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
|
||||
@@ -356,21 +475,22 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createCacheWithExistingCache() throws Exception {
|
||||
Cache mockCache = mock(Cache.class, "MockGemFireCache");
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
ReflectionUtils.setField(CacheFactoryBean.class.getDeclaredField("cache"), cacheFactoryBean, mockCache);
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
|
||||
GemFireCache actualCache = cacheFactoryBean.createCache(null);
|
||||
Cache actualCache = cacheFactoryBean.createCache(null);
|
||||
|
||||
assertSame(mockCache, actualCache);
|
||||
assertThat(actualCache, is(sameInstance(mockCache)));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCacheWithNoExistingCache() {
|
||||
Cache mockCache = mock(Cache.class, "MockGemFireCache");
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class, "MockGemFireCacheFactory");
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
@@ -378,9 +498,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
Cache actualCache = cacheFactoryBean.createCache(mockCacheFactory);
|
||||
|
||||
assertSame(mockCache, actualCache);
|
||||
assertThat(actualCache, is(equalTo(mockCache)));
|
||||
|
||||
verify(mockCacheFactory, times(1)).create();
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -414,27 +535,19 @@ public class CacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getObject() throws Exception {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override public void afterPropertiesSet() throws Exception {
|
||||
this.cache = mockCache;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(cacheFactoryBean.getObject(), is(nullValue()));
|
||||
|
||||
cacheFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(cacheFactoryBean.getObject(), is(equalTo(mockCache)));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getObjectType() {
|
||||
assertThat((Class<Cache>) new CacheFactoryBean().getObjectType(), is(equalTo(Cache.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getObjectType() {
|
||||
assertEquals(Cache.class, new CacheFactoryBean().getObjectType());
|
||||
public void getObjectTypeWithExistingCache() {
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
|
||||
assertThat(cacheFactoryBean.getObjectType(), is(equalTo((Class) mockCache.getClass())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -39,7 +38,7 @@ import com.gemstone.gemfire.cache.Cache;
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "basic-cache.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@ContextConfiguration(locations = "basic-cache.xml")
|
||||
public class CacheIntegrationTest {
|
||||
|
||||
@Autowired ApplicationContext ctx;
|
||||
|
||||
@@ -81,7 +81,6 @@ public class ForkUtil {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Stopping fork...");
|
||||
runCondition.set(false);
|
||||
processStandardInStream = null;
|
||||
|
||||
@@ -91,8 +90,6 @@ public class ForkUtil {
|
||||
}
|
||||
catch (InterruptedException ignore) {
|
||||
}
|
||||
|
||||
System.out.println("Fork stopped");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -16,11 +16,24 @@
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
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.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.distributed.DistributedSystem;
|
||||
import com.gemstone.gemfire.internal.GemFireVersion;
|
||||
|
||||
/**
|
||||
@@ -34,10 +47,102 @@ import com.gemstone.gemfire.internal.GemFireVersion;
|
||||
*/
|
||||
public class GemfireUtilsTest {
|
||||
|
||||
@Test
|
||||
public void isClientWithClientIsTrue() {
|
||||
ClientCache mockClient = mock(ClientCache.class);
|
||||
|
||||
assertThat(GemfireUtils.isClient(mockClient), is(true));
|
||||
|
||||
verifyZeroInteractions(mockClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isClientWithNonClientIsFalse() {
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
assertThat(GemfireUtils.isClient(mockCache), is(false));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDurableWithDurableClientIsTrue() {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
gemfireProperties.setProperty(GemfireUtils.DURABLE_CLIENT_ID_PROPERTY_NAME, "123");
|
||||
|
||||
when(mockClientCache.getDistributedSystem()).thenReturn(mockDistributedSystem);
|
||||
when(mockDistributedSystem.isConnected()).thenReturn(true);
|
||||
when(mockDistributedSystem.getProperties()).thenReturn(gemfireProperties);
|
||||
|
||||
assertThat(GemfireUtils.isDurable(mockClientCache), is(true));
|
||||
|
||||
verify(mockClientCache, times(1)).getDistributedSystem();
|
||||
verify(mockDistributedSystem, times(1)).isConnected();
|
||||
verify(mockDistributedSystem, times(1)).getProperties();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDurableWhenNotDurableClientIsFalse() {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
gemfireProperties.setProperty(GemfireUtils.DURABLE_CLIENT_ID_PROPERTY_NAME, " ");
|
||||
|
||||
when(mockClientCache.getDistributedSystem()).thenReturn(mockDistributedSystem);
|
||||
when(mockDistributedSystem.isConnected()).thenReturn(true);
|
||||
when(mockDistributedSystem.getProperties()).thenReturn(gemfireProperties);
|
||||
|
||||
assertThat(GemfireUtils.isDurable(mockClientCache), is(false));
|
||||
|
||||
verify(mockClientCache, times(1)).getDistributedSystem();
|
||||
verify(mockDistributedSystem, times(1)).isConnected();
|
||||
verify(mockDistributedSystem, times(1)).getProperties();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDurableWhenDistributedSystemIsNotConnectedIsFalse() {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
when(mockClientCache.getDistributedSystem()).thenReturn(mockDistributedSystem);
|
||||
when(mockDistributedSystem.isConnected()).thenReturn(false);
|
||||
|
||||
assertThat(GemfireUtils.isDurable(mockClientCache), is(false));
|
||||
|
||||
verify(mockClientCache, times(1)).getDistributedSystem();
|
||||
verify(mockDistributedSystem, times(1)).isConnected();
|
||||
verify(mockDistributedSystem, never()).getProperties();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPeerWithPeerIsTrue() {
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
assertThat(GemfireUtils.isPeer(mockCache), is(true));
|
||||
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPeerWithNonPeerIsFalse() {
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
assertThat(GemfireUtils.isPeer(mockClientCache), is(false));
|
||||
|
||||
verifyZeroInteractions(mockClientCache);
|
||||
}
|
||||
|
||||
// NOTE implementation is based on a GemFire internal class... com.gemstone.gemfire.internal.GemFireVersion.
|
||||
protected int getGemFireVersion() {
|
||||
try {
|
||||
String gemfireVersion = GemFireVersion.getGemFireVersion();
|
||||
|
||||
return Integer.decode(String.format("%1$d%2$d", GemFireVersion.getMajorVersion(gemfireVersion),
|
||||
GemFireVersion.getMinorVersion(gemfireVersion)));
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.execute.Function;
|
||||
import com.gemstone.gemfire.cache.execute.FunctionContext;
|
||||
|
||||
@@ -52,6 +53,9 @@ import com.gemstone.gemfire.cache.execute.FunctionContext;
|
||||
@SuppressWarnings("unused")
|
||||
public class LazyWiringDeclarableSupportFunctionBasedIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private Cache gemfireCache;
|
||||
|
||||
@Autowired
|
||||
private HelloFunctionExecution helloFunctionExecution;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,24 +15,22 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
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;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
@@ -40,26 +38,27 @@ import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "client-cache.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientCacheTest {
|
||||
|
||||
@Autowired
|
||||
private ClientCache cache;
|
||||
|
||||
@Resource(name = "challengeQuestionsRegion")
|
||||
@Resource(name = "ChallengeQuestions")
|
||||
@SuppressWarnings("all")
|
||||
private Region<?, ?> region;
|
||||
|
||||
@Test
|
||||
public void testPoolName() {
|
||||
assertEquals(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME, region.getAttributes().getPoolName());
|
||||
public void clientCacheIsNotClosed() {
|
||||
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/data/gemfire/client/client-cache-no-close.xml");
|
||||
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
|
||||
context.close();
|
||||
|
||||
assertThat(cache.isClosed(), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoClose() {
|
||||
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/client/client-cache-no-close.xml");
|
||||
Cache cache = ctx.getBean(Cache.class);
|
||||
ctx.close();
|
||||
assertFalse(cache.isClosed());
|
||||
public void poolNameEqualsDefault() {
|
||||
assertThat(region.getAttributes().getPoolName(), is(nullValue()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Lyndon Adams
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "client-cache-ready-for-events.xml",
|
||||
initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientReadyForEventsTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testReadyForEvents() throws Exception {
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = context.getBean("&gemfireCache", ClientCacheFactoryBean.class);
|
||||
Boolean readyForEvents = TestUtils.readField("readyForEvents", clientCacheFactoryBean);
|
||||
assertTrue(readyForEvents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,7 @@ 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.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -42,6 +43,7 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
@@ -189,71 +191,84 @@ public class ClientRegionFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testLookupFallbackWithSpecifiedShortcut() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
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(mockBeanFactory.containsBean(anyString())).thenReturn(true);
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY)))
|
||||
.thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(null);
|
||||
factoryBean.setBeanFactory(mockBeanFactory);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestRegion");
|
||||
|
||||
assertSame(mockRegion, actualRegion);
|
||||
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.CACHING_PROXY));
|
||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
||||
verifyZeroInteractions(mockRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testLookupFallbackWithSubRegionCreation() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> mockParentRegion = mock(Region.class, "Parent");
|
||||
Region<Object, Object> mockRegion = mock(Region.class, "RootRegion");
|
||||
Region<Object, Object> mockSubRegion = mock(Region.class, "SubRegion");
|
||||
|
||||
when(mockBeanFactory.containsBean(anyString())).thenReturn(true);
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.PROXY))).thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.createSubregion(eq(mockParentRegion), eq("TestSubRegion"))).thenReturn(mockSubRegion);
|
||||
when(mockClientRegionFactory.createSubregion(eq(mockRegion), eq("TestSubRegion"))).thenReturn(mockSubRegion);
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(null);
|
||||
factoryBean.setParent(mockParentRegion);
|
||||
factoryBean.setBeanFactory(mockBeanFactory);
|
||||
factoryBean.setParent(mockRegion);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.PROXY);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestSubRegion");
|
||||
|
||||
assertSame(mockSubRegion, actualRegion);
|
||||
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.PROXY));
|
||||
verify(mockClientRegionFactory, times(1)).createSubregion(eq(mockParentRegion), eq("TestSubRegion"));
|
||||
verify(mockClientRegionFactory, times(1)).createSubregion(eq(mockRegion), eq("TestSubRegion"));
|
||||
verifyZeroInteractions(mockRegion);
|
||||
verifyZeroInteractions(mockSubRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testLookupFallbackWithUnspecifiedPool() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
ClientRegionFactory<Object, Object> mockClientRegionFactory = mock(ClientRegionFactory.class);
|
||||
Region<Object, Object> mockRegion = mock(Region.class);
|
||||
|
||||
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
|
||||
when(mockClientCache.createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_HEAP_LRU))).thenReturn(mockClientRegionFactory);
|
||||
when(mockClientRegionFactory.create(eq("TestRegion"))).thenReturn(mockRegion);
|
||||
|
||||
factoryBean.setAttributes(null);
|
||||
factoryBean.setBeanFactory(null);
|
||||
factoryBean.setBeanFactory(mockBeanFactory);
|
||||
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_HEAP_LRU);
|
||||
|
||||
Region<Object, Object> actualRegion = factoryBean.lookupFallback(mockClientCache, "TestRegion");
|
||||
|
||||
assertSame(mockRegion, actualRegion);
|
||||
|
||||
verify(mockBeanFactory, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME));
|
||||
verify(mockClientCache, times(1)).createClientRegionFactory(eq(ClientRegionShortcut.LOCAL_HEAP_LRU));
|
||||
verify(mockClientRegionFactory, times(1)).create(eq("TestRegion"));
|
||||
verify(mockClientRegionFactory, never()).setPoolName(any(String.class));
|
||||
verifyZeroInteractions(mockRegion);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,7 +51,7 @@ import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
/**
|
||||
* The GemFireDataSourceIntegrationTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the <gfe-data:datasource> element in the context of a GemFire cluster running both native,
|
||||
* non-Spring configured GemFire Servers in a addition to Spring configured and bootstrapped GemFire Server.
|
||||
* non-Spring configured GemFire Server(s) in addition to Spring configured and bootstrapped GemFire Server(s).
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -77,17 +77,19 @@ public class GemFireDataSourceIntegrationTest {
|
||||
@Autowired
|
||||
private ClientCache gemfireClientCache;
|
||||
|
||||
@Resource(name = "LocalRegion")
|
||||
private Region localRegion;
|
||||
@Resource(name = "ClientOnlyRegion")
|
||||
private Region clientOnlyRegion;
|
||||
|
||||
@Resource(name = "ServerRegion")
|
||||
private Region serverRegion;
|
||||
@Resource(name = "ClientServerRegion")
|
||||
private Region clientServerRegion;
|
||||
|
||||
@Resource(name = "ExclusiveServerRegion")
|
||||
private Region exclusiveServerRegion;
|
||||
@Resource(name = "ServerOnlyRegion")
|
||||
private Region serverOnlyRegion;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupBeforeClass() throws IOException {
|
||||
System.setProperty("gemfire.log-level", "warning");
|
||||
|
||||
String serverName = "GemFireDataSourceSpringBasedServer";
|
||||
|
||||
File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase());
|
||||
@@ -97,7 +99,7 @@ public class GemFireDataSourceIntegrationTest {
|
||||
List<String> arguments = new ArrayList<String>();
|
||||
|
||||
arguments.add(String.format("-Dgemfire.name=%1$s", serverName));
|
||||
arguments.add("/org/springframework/data/gemfire/client/GemFireDataSourceIntegrationTest-server-context.xml");
|
||||
arguments.add(GemFireDataSourceIntegrationTest.class.getName().replace(".", "/").concat("-server-context.xml"));
|
||||
|
||||
serverProcess = ProcessExecutor.launch(serverWorkingDirectory, ServerProcess.class,
|
||||
arguments.toArray(new String[arguments.size()]));
|
||||
@@ -139,9 +141,9 @@ public class GemFireDataSourceIntegrationTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void clientProxyRegionBeansExist() {
|
||||
assertRegion(localRegion, "LocalRegion");
|
||||
assertRegion(serverRegion, "ServerRegion");
|
||||
assertRegion(exclusiveServerRegion, "ExclusiveServerRegion");
|
||||
assertRegion(clientOnlyRegion, "ClientOnlyRegion");
|
||||
assertRegion(clientServerRegion, "ClientServerRegion");
|
||||
assertRegion(serverOnlyRegion, "ServerOnlyRegion");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ public class GemFireDataSourceUsingNonSpringConfiguredGemFireServerIntegrationTe
|
||||
|
||||
@BeforeClass
|
||||
public static void setupBeforeClass() throws IOException {
|
||||
System.setProperty("gemfire.log-level", "warning");
|
||||
|
||||
String serverName = "GemFireDataSourceGemFireBasedServer";
|
||||
|
||||
File serverWorkingDirectory = new File(FileSystemUtils.WORKING_DIRECTORY, serverName.toLowerCase());
|
||||
|
||||
@@ -16,16 +16,17 @@
|
||||
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -33,22 +34,23 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
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;
|
||||
import org.springframework.data.gemfire.test.support.CollectionUtils;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* The PoolFactoryBeanTest class is a test suite of test cases testing the contract and functionality
|
||||
@@ -60,6 +62,8 @@ import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.client.PoolFactoryBean
|
||||
* @see org.springframework.data.gemfire.support.ConnectionEndpoint
|
||||
* @see com.gemstone.gemfire.cache.GemFireCache
|
||||
* @see com.gemstone.gemfire.cache.client.Pool
|
||||
* @see com.gemstone.gemfire.cache.client.PoolFactory
|
||||
* @since 1.7.0
|
||||
@@ -67,35 +71,33 @@ import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
public class PoolFactoryBeanTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
protected InetSocketAddress newSocketAddress(String host, int port) {
|
||||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
final PoolFactory mockPoolFactory = mock(PoolFactory.class, "MockPoolFactory");
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class, "MockPool");
|
||||
final PoolFactory mockPoolFactory = mock(PoolFactory.class);
|
||||
|
||||
final Properties gemfireProperties = new Properties();
|
||||
|
||||
gemfireProperties.setProperty("name", "testAfterPropertiesSet");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactoryBean.setProperties(gemfireProperties);
|
||||
|
||||
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenReturn(clientCacheFactoryBean);
|
||||
when(mockPoolFactory.create(eq("GemFirePool"))).thenReturn(mockPool);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean() {
|
||||
@Override protected PoolFactory createPoolFactory() {
|
||||
return mockPoolFactory;
|
||||
}
|
||||
|
||||
@Override void doDistributedSystemConnect(Properties properties) {
|
||||
assertThat(properties, is(equalTo(gemfireProperties)));
|
||||
@Override boolean isDistributedSystemPresent() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,25 +108,29 @@ public class PoolFactoryBeanTest {
|
||||
poolFactoryBean.setIdleTimeout(120000l);
|
||||
poolFactoryBean.setKeepAlive(false);
|
||||
poolFactoryBean.setLoadConditioningInterval(15000);
|
||||
poolFactoryBean.setLocators(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), 54321)));
|
||||
poolFactoryBean.setLocators(Collections.singletonList(newConnectionEndpoint("localhost", 54321)));
|
||||
poolFactoryBean.setMaxConnections(50);
|
||||
poolFactoryBean.setMinConnections(5);
|
||||
poolFactoryBean.setMultiUserAuthentication(false);
|
||||
poolFactoryBean.setPingInterval(5000l);
|
||||
poolFactoryBean.setPrSingleHopEnabled(true);
|
||||
poolFactoryBean.setReadTimeout(30000);
|
||||
poolFactoryBean.setRetryAttempts(10);
|
||||
poolFactoryBean.setServerGroup("TestServerGroup");
|
||||
poolFactoryBean.setServers(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), 12345)));
|
||||
poolFactoryBean.setServers(Collections.singletonList(newConnectionEndpoint("localhost", 12345)));
|
||||
poolFactoryBean.setSocketBufferSize(32768);
|
||||
poolFactoryBean.setStatisticInterval(1000);
|
||||
poolFactoryBean.setSubscriptionAckInterval(500);
|
||||
poolFactoryBean.setSubscriptionEnabled(true);
|
||||
poolFactoryBean.setSubscriptionMessageTrackingTimeout(20000);
|
||||
poolFactoryBean.setSubscriptionRedundancy(2);
|
||||
poolFactoryBean.setThreadLocalConnections(false);
|
||||
poolFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertSame(mockPool, poolFactoryBean.getObject());
|
||||
assertThat(poolFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
|
||||
assertThat(poolFactoryBean.getObject(), is(sameInstance(mockPool)));
|
||||
|
||||
verify(mockBeanFactory, times(1)).getBean(eq(ClientCache.class));
|
||||
verify(mockPoolFactory, times(1)).setFreeConnectionTimeout(eq(60000));
|
||||
verify(mockPoolFactory, times(1)).setIdleTimeout(eq(120000l));
|
||||
verify(mockPoolFactory, times(1)).setLoadConditioningInterval(eq(15000));
|
||||
@@ -133,16 +139,18 @@ public class PoolFactoryBeanTest {
|
||||
verify(mockPoolFactory, times(1)).setMultiuserAuthentication(eq(false));
|
||||
verify(mockPoolFactory, times(1)).setPingInterval(eq(5000l));
|
||||
verify(mockPoolFactory, times(1)).setPRSingleHopEnabled(eq(true));
|
||||
verify(mockPoolFactory, times(1)).setReadTimeout(eq(30000));
|
||||
verify(mockPoolFactory, times(1)).setRetryAttempts(eq(10));
|
||||
verify(mockPoolFactory, times(1)).setServerGroup(eq("TestServerGroup"));
|
||||
verify(mockPoolFactory, times(1)).setSocketBufferSize(eq(32768));
|
||||
verify(mockPoolFactory, times(1)).setStatisticInterval(eq(1000));
|
||||
verify(mockPoolFactory, times(1)).setSubscriptionAckInterval(eq(500));
|
||||
verify(mockPoolFactory, times(1)).setSubscriptionEnabled(eq(true));
|
||||
verify(mockPoolFactory, times(1)).setSubscriptionMessageTrackingTimeout(eq(20000));
|
||||
verify(mockPoolFactory, times(1)).setSubscriptionRedundancy(eq(2));
|
||||
verify(mockPoolFactory, times(1)).setThreadLocalConnections(eq(false));
|
||||
verify(mockPoolFactory, times(1)).addLocator(InetAddress.getLocalHost().getHostName(), 54321);
|
||||
verify(mockPoolFactory, times(1)).addServer(InetAddress.getLocalHost().getHostName(), 12345);
|
||||
verify(mockPoolFactory, times(1)).addLocator(eq("localhost"), eq(54321));
|
||||
verify(mockPoolFactory, times(1)).addServer(eq("localhost"), eq(12345));
|
||||
verify(mockPoolFactory, times(1)).create(eq("GemFirePool"));
|
||||
}
|
||||
|
||||
@@ -153,105 +161,50 @@ public class PoolFactoryBeanTest {
|
||||
poolFactoryBean.setBeanName(null);
|
||||
poolFactoryBean.setName(null);
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("Pool 'name' is required");
|
||||
assertThat(poolFactoryBean.getName(), is(nullValue()));
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("Pool 'name' is required");
|
||||
|
||||
poolFactoryBean.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSetWithNoLocatorsOrServersSpecified() throws Exception {
|
||||
public void afterPropertiesSetUsesName() throws Exception {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("GemFirePool");
|
||||
poolFactoryBean.setLocators(null);
|
||||
poolFactoryBean.setServers(Collections.<InetSocketAddress>emptyList());
|
||||
poolFactoryBean.setBeanName("gemfirePool");
|
||||
poolFactoryBean.setName("TestPool");
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("at least one GemFire Locator or Server is required");
|
||||
assertThat(poolFactoryBean.getLocators().isEmpty(), is(true));
|
||||
assertThat(poolFactoryBean.getServers().isEmpty(), is(true));
|
||||
|
||||
poolFactoryBean.afterPropertiesSet();
|
||||
|
||||
assertThat(poolFactoryBean.getName(), is(equalTo("TestPool")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveGemfireProperties() {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenReturn(clientCacheFactoryBean);
|
||||
|
||||
Properties expectedGemfireProperties = new Properties();
|
||||
|
||||
expectedGemfireProperties.setProperty("name", "resolveGemfirePropertiesTest");
|
||||
|
||||
clientCacheFactoryBean.setProperties(expectedGemfireProperties);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSetDefaultsToBeanName() throws Exception {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanFactory(mockBeanFactory);
|
||||
poolFactoryBean.setBeanName("swimPool");
|
||||
|
||||
Properties resolvedGemfireProperties = poolFactoryBean.resolveGemfireProperties();
|
||||
assertThat(poolFactoryBean.getName(), is(nullValue()));
|
||||
assertThat(poolFactoryBean.getLocators().isEmpty(), is(true));
|
||||
assertThat(poolFactoryBean.getServers().isEmpty(), is(true));
|
||||
|
||||
assertThat(resolvedGemfireProperties, is(equalTo(expectedGemfireProperties)));
|
||||
}
|
||||
poolFactoryBean.afterPropertiesSet();
|
||||
|
||||
@Test
|
||||
public void resolveMergedGemfireProperties() {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenReturn(clientCacheFactoryBean);
|
||||
|
||||
Properties poolGemfireProperties = new Properties();
|
||||
Properties expectedGemfireProperties = new Properties();
|
||||
|
||||
poolGemfireProperties.setProperty("name", "resolveMergedGemfirePropertiesTest");
|
||||
poolGemfireProperties.setProperty("log-level", "warning");
|
||||
|
||||
CollectionUtils.mergePropertiesIntoMap(poolGemfireProperties, expectedGemfireProperties);
|
||||
|
||||
expectedGemfireProperties.setProperty("log-level", "config");
|
||||
expectedGemfireProperties.setProperty("durableClientId", "123");
|
||||
expectedGemfireProperties.setProperty("durableClientTimeout", "60");
|
||||
|
||||
clientCacheFactoryBean.setProperties(expectedGemfireProperties);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanFactory(mockBeanFactory);
|
||||
poolFactoryBean.setProperties(poolGemfireProperties);
|
||||
|
||||
Properties resolvedGemfireProperties = poolFactoryBean.resolveGemfireProperties();
|
||||
|
||||
assertThat(resolvedGemfireProperties.getProperty("log-level"), is(equalTo("config")));
|
||||
assertThat(resolvedGemfireProperties, is(equalTo(expectedGemfireProperties)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveUnresolvableGemfireProperties() {
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class, "MockBeanFactory");
|
||||
|
||||
when(mockBeanFactory.getBean(eq(ClientCacheFactoryBean.class))).thenThrow(
|
||||
new NoSuchBeanDefinitionException("TEST"));
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanFactory(mockBeanFactory);
|
||||
|
||||
Properties gemfireProperties = poolFactoryBean.resolveGemfireProperties();
|
||||
|
||||
assertThat(gemfireProperties, is(notNullValue()));
|
||||
assertThat(gemfireProperties.isEmpty(), is(true));
|
||||
assertThat(poolFactoryBean.getName(), is(equalTo("swimPool")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroy() throws Exception {
|
||||
Pool mockPool = mock(Pool.class, "MockPool");
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.isDestroyed()).thenReturn(false);
|
||||
|
||||
@@ -260,7 +213,7 @@ public class PoolFactoryBeanTest {
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
poolFactoryBean.destroy();
|
||||
|
||||
assertNull(TestUtils.readField("pool", poolFactoryBean));
|
||||
assertThat(TestUtils.readField("pool", poolFactoryBean), is(nullValue()));
|
||||
|
||||
verify(mockPool, times(1)).releaseThreadLocalConnection();
|
||||
verify(mockPool, times(1)).destroy(eq(false));
|
||||
@@ -268,7 +221,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void destroyWithNonSpringBasedPool() throws Exception {
|
||||
Pool mockPool = mock(Pool.class, "MockGemFirePool");
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
@@ -278,7 +231,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
verify(mockPool, never()).isDestroyed();
|
||||
verify(mockPool, never()).releaseThreadLocalConnection();
|
||||
verify(mockPool, never()).destroy(any(Boolean.class));
|
||||
verify(mockPool, never()).destroy(anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,4 +252,292 @@ public class PoolFactoryBeanTest {
|
||||
assertTrue(new PoolFactoryBean().isSingleton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addGetAndSetLocators() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
assertThat(poolFactoryBean.getLocators(), is(notNullValue()));
|
||||
assertThat(poolFactoryBean.getLocators().isEmpty(), is(true));
|
||||
|
||||
ConnectionEndpoint localhost = newConnectionEndpoint("localhost", 21668);
|
||||
|
||||
poolFactoryBean.addLocators(localhost);
|
||||
|
||||
assertThat(poolFactoryBean.getLocators().size(), is(equalTo(1)));
|
||||
assertThat(poolFactoryBean.getLocators().findOne("localhost"), is(equalTo(localhost)));
|
||||
|
||||
ConnectionEndpoint skullbox = newConnectionEndpoint("skullbox", 10334);
|
||||
ConnectionEndpoint boombox = newConnectionEndpoint("boombox", 10334);
|
||||
|
||||
poolFactoryBean.addLocators(skullbox, boombox);
|
||||
|
||||
assertThat(poolFactoryBean.getLocators().size(), is(equalTo(3)));
|
||||
assertThat(poolFactoryBean.getLocators().findOne("localhost"), is(equalTo(localhost)));
|
||||
assertThat(poolFactoryBean.getLocators().findOne("skullbox"), is(equalTo(skullbox)));
|
||||
assertThat(poolFactoryBean.getLocators().findOne("boombox"), is(equalTo(boombox)));
|
||||
|
||||
poolFactoryBean.setLocators(SpringUtils.toArray(localhost));
|
||||
|
||||
assertThat(poolFactoryBean.getLocators().size(), is(equalTo(1)));
|
||||
assertThat(poolFactoryBean.getLocators().findOne("localhost"), is(equalTo(localhost)));
|
||||
|
||||
poolFactoryBean.setLocators(Collections.<ConnectionEndpoint>emptyList());
|
||||
|
||||
assertThat(poolFactoryBean.getLocators(), is(notNullValue()));
|
||||
assertThat(poolFactoryBean.getLocators().isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addGetAndSetServers() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
assertThat(poolFactoryBean.getServers(), is(notNullValue()));
|
||||
assertThat(poolFactoryBean.getServers().isEmpty(), is(true));
|
||||
|
||||
ConnectionEndpoint localhost = newConnectionEndpoint("localhost", 21668);
|
||||
|
||||
poolFactoryBean.addServers(localhost);
|
||||
|
||||
assertThat(poolFactoryBean.getServers().size(), is(equalTo(1)));
|
||||
assertThat(poolFactoryBean.getServers().findOne("localhost"), is(equalTo(localhost)));
|
||||
|
||||
ConnectionEndpoint skullbox = newConnectionEndpoint("skullbox", 10334);
|
||||
ConnectionEndpoint boombox = newConnectionEndpoint("boombox", 10334);
|
||||
|
||||
poolFactoryBean.addServers(skullbox, boombox);
|
||||
|
||||
assertThat(poolFactoryBean.getServers().size(), is(equalTo(3)));
|
||||
assertThat(poolFactoryBean.getServers().findOne("localhost"), is(equalTo(localhost)));
|
||||
assertThat(poolFactoryBean.getServers().findOne("skullbox"), is(equalTo(skullbox)));
|
||||
assertThat(poolFactoryBean.getServers().findOne("boombox"), is(equalTo(boombox)));
|
||||
|
||||
poolFactoryBean.setServers(SpringUtils.toArray(localhost));
|
||||
|
||||
assertThat(poolFactoryBean.getServers().size(), is(equalTo(1)));
|
||||
assertThat(poolFactoryBean.getServers().findOne("localhost"), is(equalTo(localhost)));
|
||||
|
||||
poolFactoryBean.setServers(Collections.<ConnectionEndpoint>emptyList());
|
||||
|
||||
assertThat(poolFactoryBean.getServers(), is(notNullValue()));
|
||||
assertThat(poolFactoryBean.getServers().isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolWhenPoolIsSetIsThePool() {
|
||||
Pool mockPool = mock(Pool.class);
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
|
||||
assertThat(poolFactoryBean.getPool(), is(sameInstance(mockPool)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolWhenPoolIsUnsetIsThePoolFactoryBean() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setFreeConnectionTimeout(5000);
|
||||
poolFactoryBean.setIdleTimeout(120000l);
|
||||
poolFactoryBean.setLoadConditioningInterval(300000);
|
||||
poolFactoryBean.setLocators(SpringUtils.toArray(newConnectionEndpoint("skullbox", 11235)));
|
||||
poolFactoryBean.setMaxConnections(500);
|
||||
poolFactoryBean.setMinConnections(50);
|
||||
poolFactoryBean.setMultiUserAuthentication(true);
|
||||
poolFactoryBean.setPingInterval(15000l);
|
||||
poolFactoryBean.setPrSingleHopEnabled(true);
|
||||
poolFactoryBean.setReadTimeout(30000);
|
||||
poolFactoryBean.setRetryAttempts(1);
|
||||
poolFactoryBean.setServerGroup("TestGroup");
|
||||
poolFactoryBean.setServers(SpringUtils.toArray(newConnectionEndpoint("boombox", 12480)));
|
||||
poolFactoryBean.setSocketBufferSize(16384);
|
||||
poolFactoryBean.setStatisticInterval(500);
|
||||
poolFactoryBean.setSubscriptionAckInterval(200);
|
||||
poolFactoryBean.setSubscriptionEnabled(true);
|
||||
poolFactoryBean.setSubscriptionMessageTrackingTimeout(20000);
|
||||
poolFactoryBean.setSubscriptionRedundancy(2);
|
||||
poolFactoryBean.setThreadLocalConnections(false);
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
assertThat(pool.isDestroyed(), is(false));
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(5000)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(120000l)));
|
||||
assertThat(pool.getLoadConditioningInterval(), is(equalTo(300000)));
|
||||
assertThat(pool.getLocators(), is(equalTo(Collections.singletonList(newSocketAddress("skullbox", 11235)))));
|
||||
assertThat(pool.getMaxConnections(), is(equalTo(500)));
|
||||
assertThat(pool.getMinConnections(), is(equalTo(50)));
|
||||
assertThat(pool.getMultiuserAuthentication(), is(equalTo(true)));
|
||||
assertThat(pool.getName(), is(nullValue()));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000l)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(30000)));
|
||||
assertThat(pool.getRetryAttempts(), is(equalTo(1)));
|
||||
assertThat(pool.getServerGroup(), is(equalTo("TestGroup")));
|
||||
assertThat(pool.getServers(), is(equalTo(Collections.singletonList(newSocketAddress("boombox", 12480)))));
|
||||
assertThat(pool.getSocketBufferSize(), is(equalTo(16384)));
|
||||
assertThat(pool.getStatisticInterval(), is(equalTo(500)));
|
||||
assertThat(pool.getSubscriptionAckInterval(), is(equalTo(200)));
|
||||
assertThat(pool.getSubscriptionEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getSubscriptionMessageTrackingTimeout(), is(equalTo(20000)));
|
||||
assertThat(pool.getSubscriptionRedundancy(), is(equalTo(2)));
|
||||
assertThat(pool.getThreadLocalConnections(), is(equalTo(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolNameWhenBeanNameSet() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("PoolBean");
|
||||
poolFactoryBean.setName(null);
|
||||
|
||||
assertThat(poolFactoryBean.getPool().getName(), is(equalTo("PoolBean")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolNameWhenBeanNameAndNameSet() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("PoolBean");
|
||||
poolFactoryBean.setName("TestPool");
|
||||
|
||||
assertThat(poolFactoryBean.getPool().getName(), is(equalTo("TestPool")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolPendingEventCountWithPool() {
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getPendingEventCount()).thenReturn(2);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(not(sameInstance(mockPool))));
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
|
||||
assertThat(pool.getPendingEventCount(), is(equalTo(2)));
|
||||
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolPendingEventCountWithoutPoolThrowsIllegalStateException() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool is not initialized");
|
||||
|
||||
new PoolFactoryBean().getPool().getPendingEventCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolQueryServiceWithPool() {
|
||||
Pool mockPool = mock(Pool.class);
|
||||
QueryService mockQueryService = mock(QueryService.class);
|
||||
|
||||
when(mockPool.getQueryService()).thenReturn(mockQueryService);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(not(sameInstance(mockPool))));
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
|
||||
assertThat(pool.getQueryService(), is(equalTo(mockQueryService)));
|
||||
|
||||
verify(mockPool, times(1)).getQueryService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolQueryServiceWithoutPoolThrowsIllegalStateException() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool is not initialized");
|
||||
|
||||
new PoolFactoryBean().getPool().getQueryService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolAndDestroyWithPool() {
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean() {
|
||||
@Override public void destroy() throws Exception {
|
||||
throw new IllegalStateException("test");
|
||||
}
|
||||
};
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(not(sameInstance(mockPool))));
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
pool.destroy();
|
||||
pool.destroy(true);
|
||||
|
||||
verify(mockPool, times(1)).destroy(eq(false));
|
||||
verify(mockPool, times(1)).destroy(eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolAndDestroyWithoutPool() {
|
||||
final AtomicBoolean destroyCalled = new AtomicBoolean(false);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean() {
|
||||
@Override public void destroy() throws Exception {
|
||||
destroyCalled.set(true);
|
||||
throw new IllegalStateException("test");
|
||||
}
|
||||
};
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
|
||||
pool.destroy();
|
||||
|
||||
assertThat(destroyCalled.get(), is(true));
|
||||
|
||||
destroyCalled.set(false);
|
||||
pool.destroy(true);
|
||||
|
||||
assertThat(destroyCalled.get(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolAndReleaseThreadLocalConnectionWithPool() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
assertThat(pool, is(not(sameInstance(mockPool))));
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
pool.releaseThreadLocalConnection();
|
||||
|
||||
verify(mockPool, times(1)).releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPoolAndReleaseThreadLocalConnectionWithoutPool() {
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool is not initialized");
|
||||
|
||||
pool.releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,109 +18,102 @@ package org.springframework.data.gemfire.client;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.data.gemfire.util.SpringUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
|
||||
/**
|
||||
* The PoolUsingLocatorsAndServersPropertyPlaceholdersTest class...
|
||||
* The PoolUsingLocatorsAndServersPropertyPlaceholdersTest class is a test suite of test cases testing the use of
|
||||
* property placeholder values in the nested <gfe:locator> and <gfe:server> sub-elements
|
||||
* of the <gfe:pool> element as well as the <code>locators</code> and <code>servers</code> attributes.
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.0.0
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see org.springframework.data.gemfire.client.PoolFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.PoolParser
|
||||
* @see <a href="https://jira.spring.io/browse/SGF-433">SGF-433</a>
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class PoolUsingLocatorsAndServersPropertyPlaceholdersTest {
|
||||
|
||||
private static ConnectionEndpointList locatorConnectionEndpoints = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList serverConnectionEndpoints = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList anotherServers = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList locators = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList servers = new ConnectionEndpointList();
|
||||
|
||||
private static PoolFactory mockPoolFactory;
|
||||
@Autowired
|
||||
@Qualifier("locatorPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool locatorPool;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("serverPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool serverPool;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("anotherServerPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool anotherServerPool;
|
||||
|
||||
protected static ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
mockPoolFactory = mock(PoolFactory.class, "MockPoolFactory");
|
||||
|
||||
when(mockPoolFactory.addLocator(anyString(), anyInt())).thenAnswer(new Answer<PoolFactory>() {
|
||||
@Override
|
||||
public PoolFactory answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String host = invocation.getArgumentAt(0, String.class);
|
||||
int port = invocation.getArgumentAt(1, Integer.class);
|
||||
locatorConnectionEndpoints.add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
}
|
||||
});
|
||||
|
||||
when(mockPoolFactory.addServer(anyString(), anyInt())).thenAnswer(new Answer<PoolFactory>() {
|
||||
@Override
|
||||
public PoolFactory answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String host = invocation.getArgumentAt(0, String.class);
|
||||
int port = invocation.getArgumentAt(1, Integer.class);
|
||||
serverConnectionEndpoints.add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected ConnectionEndpointList sort(ConnectionEndpointList list) {
|
||||
List<ConnectionEndpoint> connectionEndpoints = new ArrayList<ConnectionEndpoint>(list.size());
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
connectionEndpoints.add(connectionEndpoint);
|
||||
}
|
||||
|
||||
Collections.sort(connectionEndpoints);
|
||||
|
||||
return new ConnectionEndpointList(connectionEndpoints);
|
||||
}
|
||||
|
||||
protected void assertConnectionEndpoints(ConnectionEndpointList connectionEndpoints, String... expected) {
|
||||
assertThat(connectionEndpoints.isEmpty(), is(false));
|
||||
assertThat(connectionEndpoints.size(), is(equalTo(expected.length)));
|
||||
protected void assertConnectionEndpoints(Iterable<ConnectionEndpoint> connectionEndpoints, String... expected) {
|
||||
assertThat(connectionEndpoints, is(notNullValue()));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : connectionEndpoints) {
|
||||
assertThat(connectionEndpoint.toString(), is(equalTo(expected[index++])));
|
||||
}
|
||||
|
||||
assertThat(index, is(equalTo(expected.length)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anotherServerPoolFactoryConfiguration() {
|
||||
String[] expected = { "boombox[1234]", "jambox[40404]", "toolbox[8181]" };
|
||||
|
||||
assertThat(anotherServers.size(), is(equalTo(expected.length)));
|
||||
|
||||
assertConnectionEndpoints(SpringUtils.sort(anotherServers), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorPoolFactoryConfiguration() {
|
||||
String[] expected = { "backspace[10334]", "jambox[11235]", "mars[30303]", "pluto[20668]", "skullbox[12480]" };
|
||||
|
||||
// System.out.printf("locatorPool is... %1$s%n", locatorConnectionEndpoints);
|
||||
assertThat(locators.size(), is(equalTo(expected.length)));
|
||||
|
||||
assertThat(locatorConnectionEndpoints.isEmpty(), is(false));
|
||||
assertThat(locatorConnectionEndpoints.size(), is(equalTo(expected.length)));
|
||||
|
||||
assertConnectionEndpoints(sort(locatorConnectionEndpoints), expected);
|
||||
assertConnectionEndpoints(SpringUtils.sort(locators), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,34 +121,81 @@ public class PoolUsingLocatorsAndServersPropertyPlaceholdersTest {
|
||||
String[] expected = { "earth[4554]", "jupiter[40404]", "mercury[1234]", "neptune[42424]", "saturn[41414]",
|
||||
"uranis[0]", "venus[9876]" };
|
||||
|
||||
// System.out.printf("serverPool is... %1$s%n", serverConnectionEndpoints);
|
||||
assertThat(servers.size(), is(equalTo(expected.length)));
|
||||
|
||||
assertThat(serverConnectionEndpoints.isEmpty(), is(false));
|
||||
assertThat(serverConnectionEndpoints.size(), is(equalTo(expected.length)));
|
||||
|
||||
assertConnectionEndpoints(sort(serverConnectionEndpoints), expected);
|
||||
assertConnectionEndpoints(SpringUtils.sort(servers), expected);
|
||||
}
|
||||
|
||||
public static class TestBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
BeanDefinition locatorsPoolBeanDefinition = beanFactory.getBeanDefinition("locatorPool");
|
||||
locatorsPoolBeanDefinition.setBeanClassName(TestPoolFactoryBean.class.getName());
|
||||
BeanDefinition serversPoolBeanDefinition = beanFactory.getBeanDefinition("serverPool");
|
||||
serversPoolBeanDefinition.setBeanClassName(TestPoolFactoryBean.class.getName());
|
||||
BeanDefinition anotherServerPoolBeanDefinition = beanFactory.getBeanDefinition("anotherServerPool");
|
||||
anotherServerPoolBeanDefinition.setBeanClassName(AnotherServerPoolFactoryBean.class.getName());
|
||||
BeanDefinition locatorPoolBeanDefinition = beanFactory.getBeanDefinition("locatorPool");
|
||||
locatorPoolBeanDefinition.setBeanClassName(LocatorPoolFactoryBean.class.getName());
|
||||
BeanDefinition serverPoolBeanDefinition = beanFactory.getBeanDefinition("serverPool");
|
||||
serverPoolBeanDefinition.setBeanClassName(ServerPoolFactoryBean.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnotherServerPoolFactoryBean extends TestPoolFactoryBean {
|
||||
@Override ConnectionEndpointList getServerList() {
|
||||
return anotherServers;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LocatorPoolFactoryBean extends TestPoolFactoryBean {
|
||||
@Override ConnectionEndpointList getLocatorList() {
|
||||
return locators;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerPoolFactoryBean extends TestPoolFactoryBean {
|
||||
@Override ConnectionEndpointList getServerList() {
|
||||
return servers;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestPoolFactoryBean extends PoolFactoryBean {
|
||||
|
||||
ConnectionEndpointList getLocatorList() {
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
}
|
||||
|
||||
ConnectionEndpointList getServerList() {
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PoolFactory createPoolFactory() {
|
||||
final PoolFactory mockPoolFactory = mock(PoolFactory.class);
|
||||
|
||||
when(mockPoolFactory.addLocator(anyString(), anyInt())).thenAnswer(new Answer<PoolFactory>() {
|
||||
@Override
|
||||
public PoolFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
String host = invocation.getArgumentAt(0, String.class);
|
||||
int port = invocation.getArgumentAt(1, Integer.class);
|
||||
getLocatorList().add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
}
|
||||
});
|
||||
|
||||
when(mockPoolFactory.addServer(anyString(), anyInt())).thenAnswer(new Answer<PoolFactory>() {
|
||||
@Override
|
||||
public PoolFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
String host = invocation.getArgumentAt(0, String.class);
|
||||
int port = invocation.getArgumentAt(1, Integer.class);
|
||||
getServerList().add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
}
|
||||
});
|
||||
|
||||
return mockPoolFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolveDistributedSystem() {
|
||||
boolean isDistributedSystemPresent() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* 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.support;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.Pool;
|
||||
import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* The DelegatingPoolAdapterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the {@link DelegatingPoolAdapter} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see DelegatingPoolAdapter
|
||||
* @see com.gemstone.gemfire.cache.client.Pool
|
||||
* @see com.gemstone.gemfire.cache.client.PoolFactory
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DelegatingPoolAdapterTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private Pool mockPool;
|
||||
|
||||
@Mock
|
||||
private QueryService mockQueryService;
|
||||
|
||||
protected InetSocketAddress newSocketAddress(String host, int port) {
|
||||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(mockPool.isDestroyed()).thenReturn(false);
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(10000);
|
||||
when(mockPool.getIdleTimeout()).thenReturn(120000l);
|
||||
when(mockPool.getLoadConditioningInterval()).thenReturn(300000);
|
||||
when(mockPool.getLocators()).thenReturn(Collections.singletonList(newSocketAddress("skullbox", 11235)));
|
||||
when(mockPool.getMaxConnections()).thenReturn(500);
|
||||
when(mockPool.getMinConnections()).thenReturn(50);
|
||||
when(mockPool.getMultiuserAuthentication()).thenReturn(true);
|
||||
when(mockPool.getName()).thenReturn("MockPool");
|
||||
when(mockPool.getPendingEventCount()).thenReturn(2);
|
||||
when(mockPool.getPingInterval()).thenReturn(15000l);
|
||||
when(mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(mockPool.getQueryService()).thenReturn(mockQueryService);
|
||||
when(mockPool.getReadTimeout()).thenReturn(30000);
|
||||
when(mockPool.getRetryAttempts()).thenReturn(1);
|
||||
when(mockPool.getServerGroup()).thenReturn("TestGroup");
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(newSocketAddress("xghost", 12480)));
|
||||
when(mockPool.getSocketBufferSize()).thenReturn(16384);
|
||||
when(mockPool.getStatisticInterval()).thenReturn(1000);
|
||||
when(mockPool.getSubscriptionAckInterval()).thenReturn(200);
|
||||
when(mockPool.getSubscriptionEnabled()).thenReturn(true);
|
||||
when(mockPool.getSubscriptionMessageTrackingTimeout()).thenReturn(60000);
|
||||
when(mockPool.getSubscriptionRedundancy()).thenReturn(2);
|
||||
when(mockPool.getThreadLocalConnections()).thenReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegateEqualsMockPool() {
|
||||
assertThat(DelegatingPoolAdapter.from(mockPool).getDelegate(), is(equalTo(mockPool)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockPoolDelegateUsesMockPool() {
|
||||
Pool pool = DelegatingPoolAdapter.from(mockPool);
|
||||
|
||||
assertThat(pool.isDestroyed(), is(equalTo(false)));
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(10000)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(120000l)));
|
||||
assertThat(pool.getLoadConditioningInterval(), is(equalTo(300000)));
|
||||
assertThat(pool.getMaxConnections(), is(equalTo(500)));
|
||||
assertThat(pool.getMinConnections(), is(equalTo(50)));
|
||||
assertThat(pool.getMultiuserAuthentication(), is(equalTo(true)));
|
||||
assertThat(pool.getLocators(), is(equalTo(Collections.singletonList(newSocketAddress("skullbox", 11235)))));
|
||||
assertThat(pool.getName(), is(equalTo("MockPool")));
|
||||
assertThat(pool.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000l)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getQueryService(), is(equalTo(mockQueryService)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(30000)));
|
||||
assertThat(pool.getRetryAttempts(), is(equalTo(1)));
|
||||
assertThat(pool.getServerGroup(), is(equalTo("TestGroup")));
|
||||
assertThat(pool.getServers(), is(equalTo(Collections.singletonList(newSocketAddress("xghost", 12480)))));
|
||||
assertThat(pool.getSocketBufferSize(), is(equalTo(16384)));
|
||||
assertThat(pool.getStatisticInterval(), is(equalTo(1000)));
|
||||
assertThat(pool.getSubscriptionAckInterval(), is(equalTo(200)));
|
||||
assertThat(pool.getSubscriptionEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getSubscriptionMessageTrackingTimeout(), is(equalTo(60000)));
|
||||
assertThat(pool.getSubscriptionRedundancy(), is(equalTo(2)));
|
||||
assertThat(pool.getThreadLocalConnections(), is(equalTo(false)));
|
||||
|
||||
verify(mockPool, times(1)).isDestroyed();
|
||||
verify(mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(mockPool, times(1)).getIdleTimeout();
|
||||
verify(mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(mockPool, times(1)).getLocators();
|
||||
verify(mockPool, times(1)).getMaxConnections();
|
||||
verify(mockPool, times(1)).getMinConnections();
|
||||
verify(mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(mockPool, times(1)).getName();
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
verify(mockPool, times(1)).getPingInterval();
|
||||
verify(mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(mockPool, times(1)).getQueryService();
|
||||
verify(mockPool, times(1)).getReadTimeout();
|
||||
verify(mockPool, times(1)).getRetryAttempts();
|
||||
verify(mockPool, times(1)).getServerGroup();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, times(1)).getSocketBufferSize();
|
||||
verify(mockPool, times(1)).getStatisticInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(mockPool, times(1)).getThreadLocalConnections();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithDelegateCallsDestroy() {
|
||||
DelegatingPoolAdapter.from(mockPool).destroy();
|
||||
verify(mockPool, times(1)).destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithKeepAliveUsingDelegateCallsDestroy() {
|
||||
DelegatingPoolAdapter.from(mockPool).destroy(true);
|
||||
verify(mockPool, times(1)).destroy(eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseThreadLocalConnectionWithDelegateCallsReleaseThreadLocalConnection() {
|
||||
DelegatingPoolAdapter.from(mockPool).releaseThreadLocalConnection();
|
||||
verify(mockPool, times(1)).releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullDelegateUsesDefaultFactorySettings() {
|
||||
Pool pool = DelegatingPoolAdapter.from(null);
|
||||
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(PoolFactory.DEFAULT_IDLE_TIMEOUT)));
|
||||
assertThat(pool.getLoadConditioningInterval(), is(equalTo(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL)));
|
||||
assertThat(pool.getMaxConnections(), is(equalTo(PoolFactory.DEFAULT_MAX_CONNECTIONS)));
|
||||
assertThat(pool.getMinConnections(), is(equalTo(PoolFactory.DEFAULT_MIN_CONNECTIONS)));
|
||||
assertThat(pool.getMultiuserAuthentication(), is(equalTo(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(PoolFactory.DEFAULT_PING_INTERVAL)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(PoolFactory.DEFAULT_READ_TIMEOUT)));
|
||||
assertThat(pool.getRetryAttempts(), is(equalTo(PoolFactory.DEFAULT_RETRY_ATTEMPTS)));
|
||||
assertThat(pool.getServerGroup(), is(equalTo(PoolFactory.DEFAULT_SERVER_GROUP)));
|
||||
assertThat(pool.getSocketBufferSize(), is(equalTo(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE)));
|
||||
assertThat(pool.getStatisticInterval(), is(equalTo(PoolFactory.DEFAULT_STATISTIC_INTERVAL)));
|
||||
assertThat(pool.getSubscriptionAckInterval(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL)));
|
||||
assertThat(pool.getSubscriptionEnabled(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED)));
|
||||
assertThat(pool.getSubscriptionMessageTrackingTimeout(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT)));
|
||||
assertThat(pool.getSubscriptionRedundancy(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY)));
|
||||
assertThat(pool.getThreadLocalConnections(), is(equalTo(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS)));
|
||||
|
||||
verifyZeroInteractions(mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyedWithNullIsUnsupported() {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(is(equalTo(DelegatingPoolAdapter.NOT_IMPLEMENTED)));
|
||||
|
||||
DelegatingPoolAdapter.from(null).isDestroyed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorsWithNullIsEqualToEmptyList() {
|
||||
assertThat(DelegatingPoolAdapter.from(null).getLocators(), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nameWithNullIsEqualToDefault() {
|
||||
assertThat(DelegatingPoolAdapter.from(null).getName(), is(equalTo(DelegatingPoolAdapter.DEFAULT_POOL_NAME)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pendingEventCountWithNullIsEqualToZero() {
|
||||
assertThat(DelegatingPoolAdapter.from(null).getPendingEventCount(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryServiceWithNullIsNull() {
|
||||
assertThat(DelegatingPoolAdapter.from(null).getQueryService(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serversWithNullIsEqualToLocalhostListeningOnDefaultCacheServerPort() {
|
||||
assertThat(DelegatingPoolAdapter.from(null).getServers(), is(equalTo(Collections.singletonList(
|
||||
newSocketAddress("localhost", GemfireUtils.DEFAULT_CACHE_SERVER_PORT)))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithNullIsNoOp() {
|
||||
DelegatingPoolAdapter.from(null).destroy();
|
||||
verify(mockPool, never()).destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithKeepAliveUsingNullIsNoOp() {
|
||||
DelegatingPoolAdapter.from(null).destroy(false);
|
||||
verify(mockPool, never()).destroy(anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseThreadLocalConnectionWithNullIsNoOp() {
|
||||
DelegatingPoolAdapter.from(null).releaseThreadLocalConnection();
|
||||
verify(mockPool, never()).releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.support;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.PoolFactory;
|
||||
|
||||
/**
|
||||
* The FactoryDefaultsPoolAdapterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the {@link FactoryDefaultsPoolAdapter} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see FactoryDefaultsPoolAdapter
|
||||
* @see com.gemstone.gemfire.cache.client.Pool
|
||||
* @see com.gemstone.gemfire.cache.client.PoolFactory
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class FactoryDefaultsPoolAdapterTest {
|
||||
|
||||
protected static final int DEFAULT_CACHE_SERVER_PORT = GemfireUtils.DEFAULT_CACHE_SERVER_PORT;
|
||||
|
||||
private FactoryDefaultsPoolAdapter poolAdapter = new FactoryDefaultsPoolAdapter() { };
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
protected InetSocketAddress newSocketAddress(String host, int port) {
|
||||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPoolAdapterConfigurationPropertiesReturnDefaultFactorySettings() {
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(), is(equalTo(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT)));
|
||||
assertThat(poolAdapter.getIdleTimeout(), is(equalTo(PoolFactory.DEFAULT_IDLE_TIMEOUT)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(), is(equalTo(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL)));
|
||||
assertThat(poolAdapter.getMaxConnections(), is(equalTo(PoolFactory.DEFAULT_MAX_CONNECTIONS)));
|
||||
assertThat(poolAdapter.getMinConnections(), is(equalTo(PoolFactory.DEFAULT_MIN_CONNECTIONS)));
|
||||
assertThat(poolAdapter.getMultiuserAuthentication(), is(equalTo(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION)));
|
||||
assertThat(poolAdapter.getPRSingleHopEnabled(), is(equalTo(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED)));
|
||||
assertThat(poolAdapter.getPingInterval(), is(equalTo(PoolFactory.DEFAULT_PING_INTERVAL)));
|
||||
assertThat(poolAdapter.getReadTimeout(), is(equalTo(PoolFactory.DEFAULT_READ_TIMEOUT)));
|
||||
assertThat(poolAdapter.getRetryAttempts(), is(equalTo(PoolFactory.DEFAULT_RETRY_ATTEMPTS)));
|
||||
assertThat(poolAdapter.getServerGroup(), is(equalTo(PoolFactory.DEFAULT_SERVER_GROUP)));
|
||||
assertThat(poolAdapter.getSocketBufferSize(), is(equalTo(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE)));
|
||||
assertThat(poolAdapter.getStatisticInterval(), is(equalTo(PoolFactory.DEFAULT_STATISTIC_INTERVAL)));
|
||||
assertThat(poolAdapter.getSubscriptionAckInterval(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL)));
|
||||
assertThat(poolAdapter.getSubscriptionEnabled(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED)));
|
||||
assertThat(poolAdapter.getSubscriptionMessageTrackingTimeout(),
|
||||
is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT)));
|
||||
assertThat(poolAdapter.getSubscriptionRedundancy(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY)));
|
||||
assertThat(poolAdapter.getThreadLocalConnections(), is(equalTo(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorsEqualsEmptyList() {
|
||||
assertThat(poolAdapter.getLocators(), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nameEqualsDefault() {
|
||||
assertThat(poolAdapter.getName(), is(equalTo(FactoryDefaultsPoolAdapter.DEFAULT_POOL_NAME)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryServiceIsNull() {
|
||||
assertThat(poolAdapter.getQueryService(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serversEqualsLocalhostListeningOnDefaultCacheServerPort() {
|
||||
assertThat(poolAdapter.getServers(), is(equalTo(Collections.singletonList(
|
||||
newSocketAddress("localhost", DEFAULT_CACHE_SERVER_PORT)))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDestroyedIsUnsupported() {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
poolAdapter.isDestroyed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPendingEventCountIsUnsupported() {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
poolAdapter.getPendingEventCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyedIsUnsupported() {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
poolAdapter.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyedWithKeepAliveIsUnsupported() {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
poolAdapter.destroy(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseThreadLocalConnectionsIsUnsupported() {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
poolAdapter.releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class CacheNamespaceTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectDisabled() {
|
||||
public void testCacheWithAutoReconnectDisabled() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-auto-reconnect-disabled"));
|
||||
|
||||
Cache gemfireCache = context.getBean("cache-with-auto-reconnect-disabled", Cache.class);
|
||||
@@ -147,16 +147,13 @@ public class CacheNamespaceTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectEnabled() {
|
||||
public void testCacheWithAutoReconnectEnabled() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-auto-reconnect-enabled"));
|
||||
|
||||
Cache gemfireCache = context.getBean("cache-with-auto-reconnect-enabled", Cache.class);
|
||||
|
||||
boolean expected = Boolean.getBoolean("org.springframework.data.gemfire.test.GemfireTestRunner.nomock");
|
||||
boolean actual = Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect"));
|
||||
|
||||
assertEquals(String.format("Expected 'disable-auto-reconnect' to be %1$s!", expected), expected, actual);
|
||||
assertFalse(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-auto-reconnect-enabled", CacheFactoryBean.class);
|
||||
|
||||
|
||||
@@ -68,11 +68,11 @@ public class ClientCacheNamespaceTest {
|
||||
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.isKeepAlive(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPdxIgnoreUnreadFields(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPdxPersistent(), is(false));
|
||||
assertThat(clientCacheFactoryBean.getPdxReadSerialized(), is(true));
|
||||
assertThat(clientCacheFactoryBean.isKeepAlive(), is(true));
|
||||
assertThat((PdxSerializer) clientCacheFactoryBean.getPdxSerializer(), is(equalTo(reflectionPdxSerializer)));
|
||||
assertThat(TestUtils.<String>readField("poolName", clientCacheFactoryBean), is(equalTo("serverPool")));
|
||||
assertThat(clientCacheFactoryBean.getReadyForEvents(), is(false));
|
||||
}
|
||||
|
||||
@@ -22,25 +22,17 @@ 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 static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isNotNull;
|
||||
import static org.mockito.Matchers.same;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
@@ -76,7 +68,7 @@ public class ClientCacheParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doParseSetsPropertiesAndRegistersClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor() {
|
||||
public void doParseSetsProperties() {
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
@@ -87,24 +79,8 @@ public class ClientCacheParserTest {
|
||||
when(mockElement.getAttribute(eq("ready-for-events"))).thenReturn(null);
|
||||
when(mockElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
|
||||
final AtomicReference<BeanDefinition> beanDefinitionReference = new AtomicReference<BeanDefinition>(null);
|
||||
|
||||
final BeanDefinitionRegistry mockRegistry = mock(BeanDefinitionRegistry.class);
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
BeanDefinition beanFactoryPostProcessorBeanDefinition =
|
||||
invocation.getArgumentAt(1, BeanDefinition.class);
|
||||
|
||||
if (ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessor.class.getName().equals(
|
||||
beanFactoryPostProcessorBeanDefinition.getBeanClassName())) {
|
||||
beanDefinitionReference.compareAndSet(null, beanFactoryPostProcessorBeanDefinition);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}).when(mockRegistry).registerBeanDefinition(isNotNull(String.class), any(BeanDefinition.class));
|
||||
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
@@ -129,15 +105,12 @@ public class ClientCacheParserTest {
|
||||
assertThat((String) propertyValues.getPropertyValue("keepAlive").getValue(), is(equalTo("false")));
|
||||
assertThat((String) propertyValues.getPropertyValue("poolName").getValue(), is(equalTo("testPool")));
|
||||
assertThat(propertyValues.getPropertyValue("readyForEvents"), is(nullValue()));
|
||||
assertThat(beanDefinitionReference.get(), is(notNullValue()));
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq("durable-client-id"));
|
||||
verify(mockElement, times(1)).getAttribute(eq("durable-client-timeout"));
|
||||
verify(mockElement, times(1)).getAttribute(eq("keep-alive"));
|
||||
verify(mockElement, times(1)).getAttribute(eq("pool-name"));
|
||||
verify(mockElement, times(1)).getAttribute(eq("ready-for-events"));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(isNotNull(String.class),
|
||||
same(beanDefinitionReference.get()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ClientCachePoolGemfirePropertiesSyncingBeanFactoryPostProcessorTest {
|
||||
|
||||
protected static final String PROPERTIES_PROPERTY_NAME_SHORTCUT =
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -78,7 +77,7 @@ import com.gemstone.gemfire.compression.Compressor;
|
||||
* @see org.springframework.data.gemfire.config.ClientRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="client-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@ContextConfiguration(locations="client-ns.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class ClientRegionNamespaceTest {
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -36,6 +40,7 @@ import org.springframework.data.gemfire.ScopeConverter;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.wan.OrderPolicyConverter;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
@@ -57,12 +62,13 @@ import com.gemstone.gemfire.cache.wan.GatewaySender;
|
||||
public class CustomEditorRegistrationBeanFactoryPostProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testCustomEditorRegistration() {
|
||||
ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class,
|
||||
"testCustomEditorRegistration.MockBeanFactory");
|
||||
public void customEditorRegistration() {
|
||||
ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class);
|
||||
|
||||
new CustomEditorRegistrationBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
|
||||
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class), eq(
|
||||
CustomEditorRegistrationBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class),
|
||||
eq(EvictionActionConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class),
|
||||
@@ -71,7 +77,8 @@ public class CustomEditorRegistrationBeanFactoryPostProcessorTest {
|
||||
eq(ExpirationActionConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexMaintenancePolicyType.class),
|
||||
eq(IndexMaintenancePolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexType.class), eq(IndexTypeConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexType.class),
|
||||
eq(IndexTypeConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestPolicy.class),
|
||||
eq(InterestPolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestResultPolicy.class),
|
||||
@@ -79,8 +86,35 @@ public class CustomEditorRegistrationBeanFactoryPostProcessorTest {
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(GatewaySender.OrderPolicy.class),
|
||||
eq(OrderPolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class),
|
||||
eq(SubscriptionEvictionPolicyConverter.class));
|
||||
}
|
||||
|
||||
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void connectionEndpointArrayToIterableConversion() {
|
||||
ConnectionEndpoint[] array = {
|
||||
newConnectionEndpoint("localhost", 10334),
|
||||
newConnectionEndpoint("localhost", 40404)
|
||||
};
|
||||
|
||||
Iterable<ConnectionEndpoint> iterable = new CustomEditorRegistrationBeanFactoryPostProcessor
|
||||
.ConnectionEndpointArrayToIterableConverter().convert(array);
|
||||
|
||||
assertThat(iterable, is(notNullValue()));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : iterable) {
|
||||
assertThat(connectionEndpoint, is(equalTo(array[index++])));
|
||||
}
|
||||
|
||||
assertThat(index, is(equalTo(2)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.client.PoolManager;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
@@ -61,10 +59,8 @@ public class PoolNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testBasicClient() throws Exception {
|
||||
assertThat(context.containsBean("DEFAULT"), is(true));
|
||||
assertThat(context.containsBean("gemfirePool"), is(true));
|
||||
assertThat(context.containsBean("gemfire-pool"), is(true));
|
||||
assertThat(PoolManager.find("DEFAULT"), is(equalTo(context.getBean("gemfirePool"))));
|
||||
|
||||
PoolFactoryBean poolFactoryBean = context.getBean("&gemfirePool", PoolFactoryBean.class);
|
||||
|
||||
@@ -82,17 +78,17 @@ public class PoolNamespaceTest {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = context.getBean("&simple", PoolFactoryBean.class);
|
||||
|
||||
ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean);
|
||||
|
||||
assertThat(locators, is(notNullValue()));
|
||||
assertThat(locators.size(), is(equalTo(1)));
|
||||
|
||||
assertConnectionEndpoint(locators.iterator().next(), PoolParser.DEFAULT_HOST, PoolParser.DEFAULT_LOCATOR_PORT);
|
||||
|
||||
ConnectionEndpointList servers = TestUtils.readField("servers", poolFactoryBean);
|
||||
|
||||
assertThat(servers, is(notNullValue()));
|
||||
assertThat(servers.isEmpty(), is(true));
|
||||
assertThat(servers.size(), is(equalTo(1)));
|
||||
|
||||
assertConnectionEndpoint(servers.iterator().next(), PoolParser.DEFAULT_HOST, PoolParser.DEFAULT_SERVER_PORT);
|
||||
|
||||
ConnectionEndpointList locators = TestUtils.readField("locators", poolFactoryBean);
|
||||
|
||||
assertThat(locators, is(notNullValue()));
|
||||
assertThat(locators.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -17,15 +17,20 @@
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Matchers.notNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -34,14 +39,27 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.MethodInvokingBean;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.client.PoolFactoryBean;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
@@ -51,13 +69,30 @@ import org.w3c.dom.NodeList;
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.runners.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.client.PoolFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.PoolParser
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PoolParserTest {
|
||||
|
||||
private PoolParser parser = new PoolParser();
|
||||
@Mock
|
||||
private BeanDefinitionRegistry mockRegistry;
|
||||
|
||||
private PoolParser parser;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
parser = new PoolParser() {
|
||||
@Override BeanDefinitionRegistry getRegistry(final ParserContext parserContext) {
|
||||
return mockRegistry;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void assertBeanDefinition(BeanDefinition beanDefinition, String expectedHost, String expectedPort) {
|
||||
assertThat(beanDefinition, is(notNullValue()));
|
||||
@@ -69,6 +104,18 @@ public class PoolParserTest {
|
||||
is(equalTo(expectedPort)));
|
||||
}
|
||||
|
||||
protected void assertPropertyValue(PropertyValues propertyValues, String propertyName, Object propertyValue) {
|
||||
assertThat(propertyValues.getPropertyValue(propertyName).getValue(), is(equalTo(propertyValue)));
|
||||
}
|
||||
|
||||
protected String generatedBeanName(Class<?> type) {
|
||||
return generatedBeanName(type.getName());
|
||||
}
|
||||
|
||||
protected String generatedBeanName(String beanClassName) {
|
||||
return String.format("%1$s%2$s%3$d", beanClassName, BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getBeanClass() {
|
||||
@@ -79,27 +126,46 @@ public class PoolParserTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doParse() {
|
||||
Element mockPoolElement = mock(Element.class, "testDoParse.MockPoolElement");
|
||||
Element mockLocatorOneElement = mock(Element.class, "testDoParse.MockLocatorOneElement");
|
||||
Element mockLocatorTwoElement = mock(Element.class, "testDoParse.MockLocatorTwoElement");
|
||||
Element mockLocatorElementOne = mock(Element.class, "testDoParse.MockLocatorElementOne");
|
||||
Element mockLocatorElementTwo = mock(Element.class, "testDoParse.MockLocatorElementTwo");
|
||||
Element mockServerElement = mock(Element.class, "testDoParse.MockServerElement");
|
||||
|
||||
NodeList mockNodeList = mock(NodeList.class, "testDoParse.MockNodeList");
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
when(mockPoolElement.getAttribute(eq("free-connection-timeout"))).thenReturn("5000");
|
||||
when(mockPoolElement.getAttribute(eq("idle-timeout"))).thenReturn("120000");
|
||||
when(mockPoolElement.getAttribute(eq("keep-alive"))).thenReturn("true");
|
||||
when(mockPoolElement.getAttribute(eq("load-conditioning-interval"))).thenReturn("300000");
|
||||
when(mockPoolElement.getAttribute(eq("max-connections"))).thenReturn("500");
|
||||
when(mockPoolElement.getAttribute(eq("min-connections"))).thenReturn("50");
|
||||
when(mockPoolElement.getAttribute(eq("multi-user-authentication"))).thenReturn("true");
|
||||
when(mockPoolElement.getAttribute(eq("ping-interval"))).thenReturn("15000");
|
||||
when(mockPoolElement.getAttribute(eq("pr-single-hop-enabled"))).thenReturn("true");
|
||||
when(mockPoolElement.getAttribute(eq("read-timeout"))).thenReturn("20000");
|
||||
when(mockPoolElement.getAttribute(eq("retry-attempts"))).thenReturn("1");
|
||||
when(mockPoolElement.getAttribute(eq("server-group"))).thenReturn("TestGroup");
|
||||
when(mockPoolElement.getAttribute(eq("socket-buffer-size"))).thenReturn("16384");
|
||||
when(mockPoolElement.getAttribute(eq("statistic-interval"))).thenReturn("500");
|
||||
when(mockPoolElement.getAttribute(eq("subscription-ack-interval"))).thenReturn("200");
|
||||
when(mockPoolElement.getAttribute(eq("subscription-enabled"))).thenReturn("true");
|
||||
when(mockPoolElement.getAttribute(eq("subscription-message-tracking-timeout"))).thenReturn("30000");
|
||||
when(mockPoolElement.getAttribute(eq("subscription-redundancy"))).thenReturn("2");
|
||||
when(mockPoolElement.getAttribute(eq("thread-local-connections"))).thenReturn("false");
|
||||
when(mockPoolElement.hasAttribute(PoolParser.LOCATORS_ATTRIBUTE_NAME)).thenReturn(true);
|
||||
when(mockPoolElement.getAttribute(PoolParser.LOCATORS_ATTRIBUTE_NAME)).thenReturn("nebula[1234]");
|
||||
when(mockPoolElement.hasAttribute(PoolParser.SERVERS_ATTRIBUTE_NAME)).thenReturn(true);
|
||||
when(mockPoolElement.getAttribute(PoolParser.SERVERS_ATTRIBUTE_NAME)).thenReturn("skullbox[9876], backspace");
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(3);
|
||||
when(mockNodeList.item(eq(0))).thenReturn(mockLocatorOneElement);
|
||||
when(mockNodeList.item(eq(0))).thenReturn(mockLocatorElementOne);
|
||||
when(mockNodeList.item(eq(1))).thenReturn(mockServerElement);
|
||||
when(mockNodeList.item(eq(2))).thenReturn(mockLocatorTwoElement);
|
||||
when(mockLocatorOneElement.getLocalName()).thenReturn(PoolParser.LOCATOR_ELEMENT_NAME);
|
||||
when(mockLocatorOneElement.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("comet");
|
||||
when(mockLocatorOneElement.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn("1025");
|
||||
when(mockLocatorTwoElement.getLocalName()).thenReturn(PoolParser.LOCATOR_ELEMENT_NAME);
|
||||
when(mockLocatorTwoElement.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("quasar");
|
||||
when(mockLocatorTwoElement.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn(" ");
|
||||
when(mockNodeList.item(eq(2))).thenReturn(mockLocatorElementTwo);
|
||||
when(mockLocatorElementOne.getLocalName()).thenReturn(PoolParser.LOCATOR_ELEMENT_NAME);
|
||||
when(mockLocatorElementOne.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("comet");
|
||||
when(mockLocatorElementOne.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn("1025");
|
||||
when(mockLocatorElementTwo.getLocalName()).thenReturn(PoolParser.LOCATOR_ELEMENT_NAME);
|
||||
when(mockLocatorElementTwo.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("quasar");
|
||||
when(mockLocatorElementTwo.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn(" ");
|
||||
when(mockServerElement.getLocalName()).thenReturn(PoolParser.SERVER_ELEMENT_NAME);
|
||||
when(mockServerElement.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("rightshift");
|
||||
when(mockServerElement.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn("4556");
|
||||
@@ -107,20 +173,38 @@ public class PoolParserTest {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, builder);
|
||||
parser.doParse(mockPoolElement, null, builder);
|
||||
|
||||
BeanDefinition poolDefinition = builder.getBeanDefinition();
|
||||
|
||||
assertThat(poolDefinition, is(notNullValue()));
|
||||
|
||||
PropertyValues poolPropertyValues = poolDefinition.getPropertyValues();
|
||||
|
||||
assertThat(poolDefinition, is(notNullValue()));
|
||||
assertThat(poolPropertyValues.contains("locatorEndpoints"), is(true));
|
||||
assertThat(poolPropertyValues.contains("locatorEndpointList"), is(false));
|
||||
assertThat(poolPropertyValues.contains("serverEndpoints"), is(true));
|
||||
assertThat(poolPropertyValues.contains("serverEndpointList"), is(false));
|
||||
assertPropertyValue(poolPropertyValues, "freeConnectionTimeout", "5000");
|
||||
assertPropertyValue(poolPropertyValues, "idleTimeout", "120000");
|
||||
assertPropertyValue(poolPropertyValues, "keepAlive", "true");
|
||||
assertPropertyValue(poolPropertyValues, "loadConditioningInterval", "300000");
|
||||
assertPropertyValue(poolPropertyValues, "maxConnections", "500");
|
||||
assertPropertyValue(poolPropertyValues, "minConnections", "50");
|
||||
assertPropertyValue(poolPropertyValues, "multiUserAuthentication", "true");
|
||||
assertPropertyValue(poolPropertyValues, "pingInterval", "15000");
|
||||
assertPropertyValue(poolPropertyValues, "prSingleHopEnabled", "true");
|
||||
assertPropertyValue(poolPropertyValues, "readTimeout", "20000");
|
||||
assertPropertyValue(poolPropertyValues, "retryAttempts", "1");
|
||||
assertPropertyValue(poolPropertyValues, "serverGroup", "TestGroup");
|
||||
assertPropertyValue(poolPropertyValues, "socketBufferSize", "16384");
|
||||
assertPropertyValue(poolPropertyValues, "statisticInterval", "500");
|
||||
assertPropertyValue(poolPropertyValues, "subscriptionAckInterval", "200");
|
||||
assertPropertyValue(poolPropertyValues, "subscriptionEnabled", "true");
|
||||
assertPropertyValue(poolPropertyValues, "subscriptionMessageTrackingTimeout", "30000");
|
||||
assertPropertyValue(poolPropertyValues, "subscriptionRedundancy", "2");
|
||||
assertPropertyValue(poolPropertyValues, "threadLocalConnections", "false");
|
||||
assertThat(poolPropertyValues.contains("locators"), is(true));
|
||||
assertThat(poolPropertyValues.contains("servers"), is(true));
|
||||
|
||||
ManagedList<BeanDefinition> locators = (ManagedList<BeanDefinition>)
|
||||
poolPropertyValues.getPropertyValue("locatorEndpoints").getValue();
|
||||
poolPropertyValues.getPropertyValue("locators").getValue();
|
||||
|
||||
assertThat(locators, is(notNullValue()));
|
||||
assertThat(locators.size(), is(equalTo(3)));
|
||||
@@ -129,7 +213,7 @@ public class PoolParserTest {
|
||||
assertBeanDefinition(locators.get(2), "nebula", "1234");
|
||||
|
||||
ManagedList<BeanDefinition> servers = (ManagedList<BeanDefinition>) poolDefinition.getPropertyValues()
|
||||
.getPropertyValue("serverEndpoints").getValue();
|
||||
.getPropertyValue("servers").getValue();
|
||||
|
||||
assertThat(servers, is(notNullValue()));
|
||||
assertThat(servers.size(), is(equalTo(3)));
|
||||
@@ -137,6 +221,25 @@ public class PoolParserTest {
|
||||
assertBeanDefinition(servers.get(1), "skullbox", "9876");
|
||||
assertBeanDefinition(servers.get(2), "backspace", String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("free-connection-timeout"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("idle-timeout"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("keep-alive"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("load-conditioning-interval"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("max-connections"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("min-connections"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("multi-user-authentication"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("ping-interval"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("pr-single-hop-enabled"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("read-timeout"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("retry-attempts"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("server-group"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("socket-buffer-size"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("statistic-interval"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("subscription-ack-interval"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("subscription-enabled"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("subscription-message-tracking-timeout"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("subscription-redundancy"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("thread-local-connections"));
|
||||
verify(mockPoolElement, times(1)).getChildNodes();
|
||||
verify(mockNodeList, times(4)).getLength();
|
||||
verify(mockNodeList, times(1)).item(eq(0));
|
||||
@@ -146,12 +249,12 @@ public class PoolParserTest {
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME));
|
||||
verify(mockPoolElement, never()).hasAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME));
|
||||
verify(mockLocatorOneElement, times(1)).getLocalName();
|
||||
verify(mockLocatorOneElement, times(1)).getAttribute(PoolParser.HOST_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorOneElement, times(1)).getAttribute(PoolParser.PORT_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorTwoElement, times(1)).getLocalName();
|
||||
verify(mockLocatorTwoElement, times(1)).getAttribute(PoolParser.HOST_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorTwoElement, times(1)).getAttribute(PoolParser.PORT_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorElementOne, times(1)).getLocalName();
|
||||
verify(mockLocatorElementOne, times(1)).getAttribute(PoolParser.HOST_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorElementOne, times(1)).getAttribute(PoolParser.PORT_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorElementTwo, times(1)).getLocalName();
|
||||
verify(mockLocatorElementTwo, times(1)).getAttribute(PoolParser.HOST_ATTRIBUTE_NAME);
|
||||
verify(mockLocatorElementTwo, times(1)).getAttribute(PoolParser.PORT_ATTRIBUTE_NAME);
|
||||
verify(mockServerElement, times(1)).getLocalName();
|
||||
verify(mockServerElement, times(1)).getAttribute(PoolParser.HOST_ATTRIBUTE_NAME);
|
||||
verify(mockServerElement, times(1)).getAttribute(PoolParser.PORT_ATTRIBUTE_NAME);
|
||||
@@ -160,38 +263,36 @@ public class PoolParserTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void doParseWithNoLocatorsOrServersSpecified() {
|
||||
Element mockPoolElement = mock(Element.class, "testDoParseWithNoLocatorsOrServersSpecified.MockPoolElement");
|
||||
Element mockPoolElement = mock(Element.class);
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
NodeList mockNodeList = mock(NodeList.class, "testDoParseWithNoLocatorsOrServersSpecified.MockNodeList");
|
||||
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockPoolElement.hasAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn(false);
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn("");
|
||||
when(mockPoolElement.hasAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn(false);
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn("");
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, poolBuilder);
|
||||
parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
|
||||
BeanDefinition poolDefinition = poolBuilder.getBeanDefinition();
|
||||
|
||||
assertThat(poolDefinition, is(notNullValue()));
|
||||
|
||||
PropertyValues poolPropertyValues = poolDefinition.getPropertyValues();
|
||||
|
||||
assertThat(poolDefinition, is(notNullValue()));
|
||||
assertThat(poolPropertyValues.contains("locatorEndpoints"), is(true));
|
||||
assertThat(poolPropertyValues.contains("locatorEndpointList"), is(false));
|
||||
assertThat(poolPropertyValues.contains("serverEndpoints"), is(false));
|
||||
assertThat(poolPropertyValues.contains("serverEndpointList"), is(false));
|
||||
assertThat(poolPropertyValues.contains("locators"), is(false));
|
||||
assertThat(poolPropertyValues.contains("servers"), is(true));
|
||||
|
||||
ManagedList<BeanDefinition> locators = (ManagedList<BeanDefinition>)
|
||||
poolPropertyValues.getPropertyValue("locatorEndpoints").getValue();
|
||||
ManagedList<BeanDefinition> servers = (ManagedList<BeanDefinition>)
|
||||
poolPropertyValues.getPropertyValue("servers").getValue();
|
||||
|
||||
assertThat(locators, is(notNullValue()));
|
||||
assertThat(locators.size(), is(equalTo(1)));
|
||||
assertBeanDefinition(locators.get(0), PoolParser.DEFAULT_HOST, String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
assertThat(servers, is(notNullValue()));
|
||||
assertThat(servers.size(), is(equalTo(1)));
|
||||
assertBeanDefinition(servers.get(0), PoolParser.DEFAULT_HOST, String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
|
||||
verify(mockPoolElement, times(1)).getChildNodes();
|
||||
verify(mockNodeList, times(1)).getLength();
|
||||
@@ -204,54 +305,88 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void doParseWithServersAttributeValueSpecifiedAsAPropertyPlaceholder() {
|
||||
Element mockPoolElement = mock(Element.class, "testDoParseWithServersAttributeValueSpecifiedAsAPropertyPlaceholder.MockPoolElement");
|
||||
Element mockPoolElement = mock(Element.class);
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
NodeList mockNodeList = mock(NodeList.class, "testDoParseWithServersAttributeValueSpecifiedAsAPropertyPlaceholder.MockNodeList");
|
||||
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockPoolElement.getAttribute(PoolParser.ID_ATTRIBUTE)).thenReturn("TestPool");
|
||||
when(mockPoolElement.hasAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn(false);
|
||||
when(mockPoolElement.hasAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn(true);
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn("");
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn("${gemfire.server.hosts-and-ports}");
|
||||
when(mockPoolElement.hasAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn(true);
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn(
|
||||
"${gemfire.server.hosts-and-ports}");
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, poolBuilder);
|
||||
parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
|
||||
BeanDefinition poolDefinition = poolBuilder.getBeanDefinition();
|
||||
|
||||
assertThat(poolDefinition, is(notNullValue()));
|
||||
|
||||
PropertyValues poolPropertyValues = poolDefinition.getPropertyValues();
|
||||
|
||||
assertThat(poolDefinition, is(notNullValue()));
|
||||
assertThat(poolPropertyValues.contains("locatorEndpoints"), is(false));
|
||||
assertThat(poolPropertyValues.contains("locatorEndpointList"), is(false));
|
||||
assertThat(poolPropertyValues.contains("serverEndpoints"), is(false));
|
||||
assertThat(poolPropertyValues.contains("serverEndpointList"), is(true));
|
||||
assertThat(poolPropertyValues.contains("locators"), is(false));
|
||||
assertThat(poolPropertyValues.contains("servers"), is(false));
|
||||
|
||||
BeanDefinition servers = (BeanDefinition) poolPropertyValues.getPropertyValue("serverEndpointList").getValue();
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
assertThat(servers, is(notNullValue()));
|
||||
assertThat(servers.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
assertThat(servers.getFactoryMethodName(), is(equalTo("parse")));
|
||||
assertThat(servers.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue().toString(),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT))));
|
||||
assertThat(servers.getConstructorArgumentValues().getArgumentValue(1, String.class).getValue().toString(),
|
||||
is(equalTo("${gemfire.server.hosts-and-ports}")));
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String generatedName = invocation.getArgumentAt(0, String.class);
|
||||
BeanDefinition addServersDefinition = invocation.getArgumentAt(1, BeanDefinition.class);
|
||||
|
||||
verify(mockPoolElement, times(1)).getChildNodes();
|
||||
verify(mockNodeList, times(1)).getLength();
|
||||
verify(mockNodeList, never()).item(anyInt());
|
||||
assertThat(StringUtils.hasText(generatedName), is(true));
|
||||
assertThat(generatedName, is(equalTo(generatedBeanName(addServersDefinition.getBeanClassName()))));
|
||||
assertThat(addServersDefinition, is(notNull()));
|
||||
assertThat(addServersDefinition.getBeanClassName(), is(equalTo(MethodInvokingBean.class.getName())));
|
||||
|
||||
PropertyValues addServersPropertyValues = addServersDefinition.getPropertyValues();
|
||||
|
||||
assertThat(addServersPropertyValues, is(notNullValue()));
|
||||
assertPropertyValue(addServersPropertyValues, "targetObject", new RuntimeBeanReference("&TestPool"));
|
||||
assertPropertyValue(addServersPropertyValues, "targetMethod", "addServers");
|
||||
|
||||
Object arguments = addServersPropertyValues.getPropertyValue("arguments").getValue();
|
||||
|
||||
assertThat(arguments, is(instanceOf(BeanDefinition.class)));
|
||||
|
||||
BeanDefinition argumentsDefinition = (BeanDefinition) arguments;
|
||||
|
||||
assertThat(argumentsDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
|
||||
ConstructorArgumentValues constructorArguments = argumentsDefinition.getConstructorArgumentValues();
|
||||
|
||||
assertThat(constructorArguments, is(notNullValue()));
|
||||
assertThat(constructorArguments.getArgumentCount(), is(equalTo(2)));
|
||||
assertThat((Integer) constructorArguments.getArgumentValue(0, Integer.class).getValue(),
|
||||
is(equalTo(PoolParser.DEFAULT_SERVER_PORT)));
|
||||
assertThat(String.valueOf(constructorArguments.getArgumentValue(1, String.class).getValue()),
|
||||
is(equalTo("${gemfire.server.hosts-and-ports}")));
|
||||
|
||||
return null;
|
||||
}
|
||||
}).when(mockRegistry).registerBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq(PoolParser.ID_ATTRIBUTE));
|
||||
verify(mockPoolElement, times(1)).hasAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME));
|
||||
verify(mockPoolElement, times(1)).hasAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME));
|
||||
verify(mockPoolElement, times(1)).getChildNodes();
|
||||
verify(mockNodeList, times(1)).getLength();
|
||||
verify(mockNodeList, never()).item(anyInt());
|
||||
verify(mockRegistry, times(1)).containsBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)),
|
||||
isA(BeanDefinition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasAttributesReturnsTrueAndShortcircuts() {
|
||||
Element mockElement = mock(Element.class, "testHasAttributesIsTrue.MockElement");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute("attributeOne")).thenReturn(true);
|
||||
when(mockElement.hasAttribute("attributeTwo")).thenReturn(true);
|
||||
@@ -265,7 +400,7 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void hasAttributesReturnsFalse() {
|
||||
Element mockElement = mock(Element.class, "testHasAttributesIsTrue.MockElement");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.hasAttribute(anyString())).thenReturn(false);
|
||||
|
||||
@@ -283,11 +418,13 @@ public class PoolParserTest {
|
||||
|
||||
assertThat(beanDefinition, is(notNullValue()));
|
||||
assertThat(beanDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
assertThat(
|
||||
beanDefinition.getConstructorArgumentValues().getArgumentValue(0, Integer.class).getValue().toString(),
|
||||
|
||||
ConstructorArgumentValues constructorArguments = beanDefinition.getConstructorArgumentValues();
|
||||
|
||||
assertThat(constructorArguments, is(notNullValue()));
|
||||
assertThat(constructorArguments.getArgumentValue(0, Integer.class).getValue().toString(),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT))));
|
||||
assertThat(
|
||||
beanDefinition.getConstructorArgumentValues().getArgumentValue(1, String.class).getValue().toString(),
|
||||
assertThat(constructorArguments.getArgumentValue(1, String.class).getValue().toString(),
|
||||
is(equalTo("${test}")));
|
||||
}
|
||||
|
||||
@@ -297,9 +434,13 @@ public class PoolParserTest {
|
||||
|
||||
assertThat(beanDefinition, is(notNullValue()));
|
||||
assertThat(beanDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
assertThat(beanDefinition.getConstructorArgumentValues().getArgumentValue(0, Integer.class).getValue().toString(),
|
||||
|
||||
ConstructorArgumentValues constructorArguments = beanDefinition.getConstructorArgumentValues();
|
||||
|
||||
assertThat(constructorArguments, is(notNullValue()));
|
||||
assertThat(constructorArguments.getArgumentValue(0, Integer.class).getValue().toString(),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT))));
|
||||
assertThat(beanDefinition.getConstructorArgumentValues().getArgumentValue(1, String.class).getValue().toString(),
|
||||
assertThat(constructorArguments.getArgumentValue(1, String.class).getValue().toString(),
|
||||
is(equalTo("${test}")));
|
||||
}
|
||||
|
||||
@@ -406,7 +547,7 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseLocator() {
|
||||
Element mockElement = mock(Element.class, "testParseLocator.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME))).thenReturn("skullbox");
|
||||
when(mockElement.getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME))).thenReturn("1234");
|
||||
@@ -419,7 +560,7 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseLocatorWithNoHostPort() {
|
||||
Element mockElement = mock(Element.class, "testParseLocatorWithNoHostPort.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("");
|
||||
when(mockElement.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn(null);
|
||||
@@ -432,12 +573,12 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseLocators() {
|
||||
Element mockElement = mock(Element.class, "testParseLocators.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn(
|
||||
"jupiter, saturn[1234], [9876] ");
|
||||
|
||||
List<BeanDefinition> locators = parser.parseLocators(mockElement, null);
|
||||
List<BeanDefinition> locators = parser.parseLocators(mockElement, mockRegistry);
|
||||
|
||||
assertThat(locators, is(notNullValue()));
|
||||
assertThat(locators.size(), is(equalTo(3)));
|
||||
@@ -450,36 +591,66 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseLocatorsWithPropertyPlaceholder() {
|
||||
Element mockElement = mock(Element.class, "testParseLocatorsWithPropertyPlaceholder.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.ID_ATTRIBUTE))).thenReturn(null);
|
||||
when(mockElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn(
|
||||
"${gemfire.locators.hosts-and-ports}");
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
BeanDefinitionBuilder locatorsBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockElement));
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String generatedName = invocation.getArgumentAt(0, String.class);
|
||||
BeanDefinition addServersDefinition = invocation.getArgumentAt(1, BeanDefinition.class);
|
||||
|
||||
List<BeanDefinition> locators = parser.parseLocators(mockElement, locatorsBuilder);
|
||||
assertThat(StringUtils.hasText(generatedName), is(true));
|
||||
assertThat(generatedName, is(equalTo(generatedBeanName(addServersDefinition.getBeanClassName()))));
|
||||
assertThat(addServersDefinition, is(notNullValue()));
|
||||
assertThat(addServersDefinition.getBeanClassName(), is(equalTo(MethodInvokingBean.class.getName())));
|
||||
|
||||
PropertyValues addServersPropertyValues = addServersDefinition.getPropertyValues();
|
||||
|
||||
assertThat(addServersPropertyValues, is(notNullValue()));
|
||||
assertPropertyValue(addServersPropertyValues, "targetObject", new RuntimeBeanReference("&gemfirePool"));
|
||||
assertPropertyValue(addServersPropertyValues, "targetMethod", "addLocators");
|
||||
|
||||
Object arguments = addServersPropertyValues.getPropertyValue("arguments").getValue();
|
||||
|
||||
assertThat(arguments, is(instanceOf(BeanDefinition.class)));
|
||||
|
||||
BeanDefinition argumentsDefinition = (BeanDefinition) arguments;
|
||||
|
||||
assertThat(argumentsDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
|
||||
ConstructorArgumentValues constructorArguments = argumentsDefinition.getConstructorArgumentValues();
|
||||
|
||||
assertThat(constructorArguments, is(notNullValue()));
|
||||
assertThat(constructorArguments.getArgumentCount(), is(equalTo(2)));
|
||||
assertThat(String.valueOf(constructorArguments.getArgumentValue(0, Integer.class).getValue()),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT))));
|
||||
assertThat(String.valueOf(constructorArguments.getArgumentValue(1, String.class).getValue()),
|
||||
is(equalTo("${gemfire.locators.hosts-and-ports}")));
|
||||
|
||||
return null;
|
||||
}
|
||||
}).when(mockRegistry).registerBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
List<BeanDefinition> locators = parser.parseLocators(mockElement, mockRegistry);
|
||||
|
||||
assertThat(locators, is(notNullValue()));
|
||||
assertThat(locators.isEmpty(), is(true));
|
||||
|
||||
BeanDefinition locatorDefinition = (BeanDefinition) locatorsBuilder.getBeanDefinition()
|
||||
.getPropertyValues().getPropertyValue("locatorEndpointList").getValue();
|
||||
|
||||
assertThat(locatorDefinition, is(notNullValue()));
|
||||
assertThat(locatorDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
assertThat(locatorDefinition.getFactoryMethodName(), is(equalTo("parse")));
|
||||
assertThat(locatorDefinition.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue().toString(),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT))));
|
||||
assertThat(locatorDefinition.getConstructorArgumentValues().getArgumentValue(1, String.class).getValue().toString(),
|
||||
is(equalTo("${gemfire.locators.hosts-and-ports}")));
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.ID_ATTRIBUTE));
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME));
|
||||
verify(mockRegistry, times(1)).containsBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)),
|
||||
isA(BeanDefinition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseServer() {
|
||||
Element mockElement = mock(Element.class, "testParseServer.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME))).thenReturn("plato");
|
||||
when(mockElement.getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME))).thenReturn("9876");
|
||||
@@ -492,7 +663,7 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseServerWithNoHostPort() {
|
||||
Element mockElement = mock(Element.class, "testParseServerWithNoHostPort.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME))).thenReturn(" ");
|
||||
when(mockElement.getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME))).thenReturn("");
|
||||
@@ -505,11 +676,11 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseServers() {
|
||||
Element mockElement = mock(Element.class, "testParseServers.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn(" neptune[], venus[9876]");
|
||||
|
||||
List<BeanDefinition> servers = parser.parseServers(mockElement, null);
|
||||
List<BeanDefinition> servers = parser.parseServers(mockElement, mockRegistry);
|
||||
|
||||
assertNotNull(servers);
|
||||
assertFalse(servers.isEmpty());
|
||||
@@ -520,31 +691,61 @@ public class PoolParserTest {
|
||||
|
||||
@Test
|
||||
public void parseServersWithPropertyPlaceholder() {
|
||||
Element mockElement = mock(Element.class, "testParseServersWithPropertyPlaceholder.Element");
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.ID_ATTRIBUTE))).thenReturn(null);
|
||||
when(mockElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn(
|
||||
"${gemfire.servers.hosts-and-ports}");
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
BeanDefinitionBuilder serversBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockElement));
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override public Void answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String generatedName = invocation.getArgumentAt(0, String.class);
|
||||
BeanDefinition addServersDefinition = invocation.getArgumentAt(1, BeanDefinition.class);
|
||||
|
||||
List<BeanDefinition> servers = parser.parseServers(mockElement, serversBuilder);
|
||||
assertThat(StringUtils.hasText(generatedName), is(true));
|
||||
assertThat(generatedName, is(equalTo(generatedBeanName(addServersDefinition.getBeanClassName()))));
|
||||
assertThat(addServersDefinition, is(notNullValue()));
|
||||
assertThat(addServersDefinition.getBeanClassName(), is(equalTo(MethodInvokingBean.class.getName())));
|
||||
|
||||
PropertyValues addServersPropertyValues = addServersDefinition.getPropertyValues();
|
||||
|
||||
assertThat(addServersPropertyValues, is(notNullValue()));
|
||||
assertPropertyValue(addServersPropertyValues, "targetObject", new RuntimeBeanReference("&gemfirePool"));
|
||||
assertPropertyValue(addServersPropertyValues, "targetMethod", "addServers");
|
||||
|
||||
Object arguments = addServersPropertyValues.getPropertyValue("arguments").getValue();
|
||||
|
||||
assertThat(arguments, is(instanceOf(BeanDefinition.class)));
|
||||
|
||||
BeanDefinition argumentsDefinition = (BeanDefinition) arguments;
|
||||
|
||||
assertThat(argumentsDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
|
||||
ConstructorArgumentValues constructorArguments = argumentsDefinition.getConstructorArgumentValues();
|
||||
|
||||
assertThat(constructorArguments, is(notNullValue()));
|
||||
assertThat(constructorArguments.getArgumentCount(), is(equalTo(2)));
|
||||
assertThat(String.valueOf(constructorArguments.getArgumentValue(0, Object.class).getValue()),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT))));
|
||||
assertThat(String.valueOf(constructorArguments.getArgumentValue(1, String.class).getValue()),
|
||||
is(equalTo("${gemfire.servers.hosts-and-ports}")));
|
||||
|
||||
return null;
|
||||
}
|
||||
}).when(mockRegistry).registerBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
List<BeanDefinition> servers = parser.parseServers(mockElement, mockRegistry);
|
||||
|
||||
assertThat(servers, is(notNullValue()));
|
||||
assertThat(servers.isEmpty(), is(true));
|
||||
|
||||
BeanDefinition serverDefinition = (BeanDefinition) serversBuilder.getBeanDefinition()
|
||||
.getPropertyValues().getPropertyValue("serverEndpointList").getValue();
|
||||
|
||||
assertThat(serverDefinition, is(notNullValue()));
|
||||
assertThat(serverDefinition.getBeanClassName(), is(equalTo(ConnectionEndpointList.class.getName())));
|
||||
assertThat(serverDefinition.getFactoryMethodName(), is(equalTo("parse")));
|
||||
assertThat(serverDefinition.getConstructorArgumentValues().getArgumentValue(0, String.class).getValue().toString(),
|
||||
is(equalTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT))));
|
||||
assertThat(serverDefinition.getConstructorArgumentValues().getArgumentValue(1, String.class).getValue().toString(),
|
||||
is(equalTo("${gemfire.servers.hosts-and-ports}")));
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.ID_ATTRIBUTE));
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME));
|
||||
verify(mockRegistry, times(1)).containsBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(eq(generatedBeanName(MethodInvokingBean.class)),
|
||||
isA(BeanDefinition.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,32 +42,34 @@ import com.gemstone.gemfire.distributed.DistributedMember;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { TestClientCacheConfig.class })
|
||||
public class FunctionExecutionClientCacheTests {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void testContextCreated() throws Exception {
|
||||
|
||||
public void contextCreated() throws Exception {
|
||||
ClientCache cache = context.getBean("gemfireCache", ClientCache.class);
|
||||
Pool pool = context.getBean("gemfirePool", Pool.class);
|
||||
|
||||
assertEquals("gemfirePool", pool.getName());
|
||||
assertTrue(cache.getDefaultPool().getLocators().isEmpty());
|
||||
assertEquals(1, cache.getDefaultPool().getServers().size());
|
||||
assertEquals(pool.getServers().get(0), cache.getDefaultPool().getServers().get(0));
|
||||
|
||||
context.getBean("r1", Region.class);
|
||||
Region region = context.getBean("r1", Region.class);
|
||||
|
||||
assertEquals("gemfirePool", region.getAttributes().getPoolName());
|
||||
|
||||
GemfireOnServerFunctionTemplate template = context.getBean(GemfireOnServerFunctionTemplate.class);
|
||||
|
||||
assertTrue(template.getResultCollector() instanceof MyResultCollector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionCacheClientTests-context.xml")
|
||||
@EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.three", excludeFilters = {
|
||||
/*@ComponentScan.Filter(type=FilterType.ANNOTATION, value=OnRegion.class),
|
||||
@ComponentScan.Filter(type=FilterType.ANNOTATION, value=OnServer.class)*/
|
||||
})
|
||||
@Configuration
|
||||
@ImportResource("/org/springframework/data/gemfire/function/config/FunctionExecutionCacheClientTests-context.xml")
|
||||
@EnableGemfireFunctionExecutions(basePackages = "org.springframework.data.gemfire.function.config.three")
|
||||
class TestClientCacheConfig {
|
||||
@Bean
|
||||
MyResultCollector myResultCollector() {
|
||||
@@ -83,8 +85,6 @@ class MyResultCollector implements ResultCollector {
|
||||
*/
|
||||
@Override
|
||||
public void addResult(DistributedMember arg0, Object arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -92,8 +92,6 @@ class MyResultCollector implements ResultCollector {
|
||||
*/
|
||||
@Override
|
||||
public void clearResults() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -101,8 +99,6 @@ class MyResultCollector implements ResultCollector {
|
||||
*/
|
||||
@Override
|
||||
public void endResults() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -110,7 +106,6 @@ class MyResultCollector implements ResultCollector {
|
||||
*/
|
||||
@Override
|
||||
public Object getResult() throws FunctionException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -119,7 +114,6 @@ class MyResultCollector implements ResultCollector {
|
||||
*/
|
||||
@Override
|
||||
public Object getResult(long arg0, TimeUnit arg1) throws FunctionException, InterruptedException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,14 @@ import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.ForkUtil;
|
||||
import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer;
|
||||
import org.springframework.data.gemfire.test.GemfireProfileValueSource;
|
||||
import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
@@ -45,6 +47,8 @@ import com.gemstone.gemfire.cache.query.CqQuery;
|
||||
@IfProfileValue(name = GemfireProfileValueSource.PRODUCT_NAME_KEY,
|
||||
value = GemfireProfileValueSource.PIVOTAL_GEMFIRE_PRODUCT_NAME)
|
||||
@ProfileValueSourceConfiguration(GemfireProfileValueSource.class)
|
||||
@ContextConfiguration("/org/springframework/data/gemfire/listener/container.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class ContainerXmlSetupTest {
|
||||
|
||||
@BeforeClass
|
||||
@@ -57,38 +61,32 @@ public class ContainerXmlSetupTest {
|
||||
ForkUtil.sendSignal();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testContainerSetup() throws Exception {
|
||||
GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(
|
||||
"/org/springframework/data/gemfire/listener/container.xml");
|
||||
public void containerSetup() throws Exception {
|
||||
ContinuousQueryListenerContainer container = applicationContext.getBean(
|
||||
ContinuousQueryListenerContainer.class);
|
||||
|
||||
try {
|
||||
ContinuousQueryListenerContainer container = applicationContext.getBean(
|
||||
ContinuousQueryListenerContainer.class);
|
||||
assertNotNull(container);
|
||||
assertTrue(container.isRunning());
|
||||
|
||||
assertNotNull(container);
|
||||
assertTrue(container.isRunning());
|
||||
// test getting container listener by bean ID
|
||||
ContinuousQueryListenerContainer container2 = applicationContext.getBean("testContainerId",
|
||||
ContinuousQueryListenerContainer.class);
|
||||
|
||||
// test getting container listener by bean ID
|
||||
ContinuousQueryListenerContainer container2 = applicationContext.getBean("testContainerId",
|
||||
ContinuousQueryListenerContainer.class);
|
||||
assertSame(container, container2);
|
||||
|
||||
assertSame(container, container2);
|
||||
Cache cache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
Pool pool = applicationContext.getBean("client", Pool.class);
|
||||
|
||||
Cache cache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
Pool pool = applicationContext.getBean("client", Pool.class);
|
||||
CqQuery[] cqs = cache.getQueryService().getCqs();
|
||||
CqQuery[] poolCqs = pool.getQueryService().getCqs();
|
||||
|
||||
CqQuery[] cqs = cache.getQueryService().getCqs();
|
||||
CqQuery[] poolCqs = pool.getQueryService().getCqs();
|
||||
|
||||
assertTrue(pool.getQueryService().getCq("test-bean-1") != null);
|
||||
assertEquals(3, cqs.length);
|
||||
assertEquals(3, poolCqs.length);
|
||||
}
|
||||
finally {
|
||||
ForkUtil.sendSignal();
|
||||
applicationContext.close();
|
||||
}
|
||||
assertTrue(pool.getQueryService().getCq("test-bean-1") != null);
|
||||
assertEquals(3, cqs.length);
|
||||
assertEquals(3, poolCqs.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,18 +30,20 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class RepositoryClientRegionTests {
|
||||
|
||||
@Autowired
|
||||
PersonRepository repository;
|
||||
|
||||
@BeforeClass
|
||||
public static void startUp() throws Exception {
|
||||
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() + " "
|
||||
+ "/org/springframework/data/gemfire/repository/config/RepositoryClientRegionTests-server-context.xml");
|
||||
System.setProperty("gemfire.log-level", "warning");
|
||||
ForkUtil.startCacheServer(String.format("%1$s %2$s", SpringCacheServerProcess.class.getName(),
|
||||
"/org/springframework/data/gemfire/repository/config/RepositoryClientRegionTests-server-context.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,36 +14,26 @@ package org.springframework.data.gemfire.support;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.ForkUtil;
|
||||
import org.springframework.data.gemfire.fork.SpringCacheServerProcess;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("/org/springframework/data/gemfire/support/cache-manager-client-cache.xml")
|
||||
public class ClientCacheManagerTest {
|
||||
|
||||
@Autowired
|
||||
GemfireCacheManager cacheManager;
|
||||
@BeforeClass
|
||||
public static void startUp() throws Exception {
|
||||
ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() + " "
|
||||
+ "/org/springframework/data/gemfire/client/datasource-server.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertNotNull(cacheManager.getCache("r1"));
|
||||
}
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ForkUtil.sendSignal();
|
||||
public void cacheManagerUsesConfiguredGemFireRegionAsCache() {
|
||||
assertNotNull(cacheManager.getCache("Example"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.data.gemfire.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
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.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -36,15 +37,18 @@ import org.junit.rules.ExpectedException;
|
||||
* of the ConnectionEndpointList class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.net.InetSocketAddress
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see org.springframework.data.gemfire.support.ConnectionEndpoint
|
||||
* @see org.springframework.data.gemfire.support.ConnectionEndpointList
|
||||
* @since 1.6.3
|
||||
*/
|
||||
public class ConnectionEndpointListTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
@@ -77,6 +81,26 @@ public class ConnectionEndpointListTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromConnectionEndpoints() {
|
||||
ConnectionEndpoint[] connectionEndpoints = {
|
||||
newConnectionEndpoint("boombox", 10334),
|
||||
newConnectionEndpoint("skullbox", 40404),
|
||||
newConnectionEndpoint("toolbox", 1099)
|
||||
};
|
||||
|
||||
ConnectionEndpointList list = ConnectionEndpointList.from(connectionEndpoints);
|
||||
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.size(), is(equalTo(connectionEndpoints.length)));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
assertThat(connectionEndpoint, is(equalTo(connectionEndpoints[index++])));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromInetSocketAddresses() {
|
||||
InetSocketAddress[] inetSocketAddresses = {
|
||||
@@ -84,15 +108,14 @@ public class ConnectionEndpointListTest {
|
||||
new InetSocketAddress("localhost", 9876)
|
||||
};
|
||||
|
||||
ConnectionEndpointList connectionEndpoints = ConnectionEndpointList.from(inetSocketAddresses);
|
||||
ConnectionEndpointList list = ConnectionEndpointList.from(inetSocketAddresses);
|
||||
|
||||
assertThat(connectionEndpoints, is(notNullValue()));
|
||||
assertThat(connectionEndpoints.isEmpty(), is(false));
|
||||
assertThat(connectionEndpoints.size(), is(equalTo(2)));
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.size(), is(equalTo(inetSocketAddresses.length)));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : connectionEndpoints) {
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
assertThat(connectionEndpoint.getHost(), is(equalTo(inetSocketAddresses[index].getHostString())));
|
||||
assertThat(connectionEndpoint.getPort(), is(equalTo(inetSocketAddresses[index++].getPort())));
|
||||
}
|
||||
@@ -101,46 +124,44 @@ public class ConnectionEndpointListTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void fromIterableInetSocketAddressesIsNullSafe() {
|
||||
ConnectionEndpointList connectionEndpoints = ConnectionEndpointList.from((Iterable) null);
|
||||
ConnectionEndpointList list = ConnectionEndpointList.from((Iterable) null);
|
||||
|
||||
assertThat(connectionEndpoints, is(notNullValue()));
|
||||
assertThat(connectionEndpoints.isEmpty(), is(true));
|
||||
assertThat(connectionEndpoints.size(), is(equalTo(0)));
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse() {
|
||||
ConnectionEndpointList connectionEndpoints = ConnectionEndpointList
|
||||
.parse(24842, "mercury[11235]", "venus", "[12480]",
|
||||
"[]", "jupiter[]", "saturn[1, 2-Hundred and 34.zero5]", "neptune[four]");
|
||||
ConnectionEndpointList list = ConnectionEndpointList.parse(24842, "mercury[11235]", "venus", "[12480]", "[]",
|
||||
"jupiter[]", "saturn[1, 2-Hundred and 34.zero5]", "neptune[four]");
|
||||
|
||||
String[] expectedHostPorts = { "mercury[11235]", "venus[24842]", "localhost[12480]", "localhost[24842]",
|
||||
"jupiter[24842]", "saturn[12345]", "neptune[24842]" };
|
||||
|
||||
assertThat(connectionEndpoints, is(notNullValue()));
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.size(), is(equalTo(expectedHostPorts.length)));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : connectionEndpoints) {
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
assertThat(connectionEndpoint.toString(), is(equalTo(expectedHostPorts[index++])));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithEmptyHostsPortsArgument() {
|
||||
ConnectionEndpointList connectionEndpoints = ConnectionEndpointList.parse(1234);
|
||||
ConnectionEndpointList list = ConnectionEndpointList.parse(1234);
|
||||
|
||||
assertThat(connectionEndpoints, is(notNullValue()));
|
||||
assertThat(connectionEndpoints.isEmpty(), is(true));
|
||||
assertThat(connectionEndpoints.size(), is(equalTo(0)));
|
||||
assertThat(list, is(notNullValue()));
|
||||
assertThat(list.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addAdditionalConnectionEndpoints() {
|
||||
ConnectionEndpointList connectionEndpointList = new ConnectionEndpointList();
|
||||
ConnectionEndpointList list = new ConnectionEndpointList();
|
||||
|
||||
assertThat(connectionEndpointList.isEmpty(), is(true));
|
||||
assertThat(list.isEmpty(), is(true));
|
||||
|
||||
ConnectionEndpoint[] connectionEndpointsArray = { newConnectionEndpoint("Mercury", 1111) };
|
||||
|
||||
@@ -155,8 +176,8 @@ public class ConnectionEndpointListTest {
|
||||
newConnectionEndpoint("Pluto", 9999)
|
||||
);
|
||||
|
||||
assertThat(connectionEndpointList.add(connectionEndpointsArray).add(connectionEndpointsIterable),
|
||||
is(sameInstance(connectionEndpointList)));
|
||||
assertThat(list.add(connectionEndpointsArray).add(connectionEndpointsIterable),
|
||||
is(sameInstance(list)));
|
||||
|
||||
List<ConnectionEndpoint> expected = new ArrayList<ConnectionEndpoint>(9);
|
||||
|
||||
@@ -165,14 +186,14 @@ public class ConnectionEndpointListTest {
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : connectionEndpointList) {
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
assertThat(connectionEndpoint, is(equalTo(expected.get(index++))));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByHostName() {
|
||||
ConnectionEndpointList connectionEndpoints = new ConnectionEndpointList(
|
||||
ConnectionEndpointList list = new ConnectionEndpointList(
|
||||
newConnectionEndpoint("Earth", 10334),
|
||||
newConnectionEndpoint("Earth", 40404),
|
||||
newConnectionEndpoint("Mars", 10334),
|
||||
@@ -181,39 +202,38 @@ public class ConnectionEndpointListTest {
|
||||
newConnectionEndpoint("Neptune", 12345)
|
||||
);
|
||||
|
||||
assertThat(connectionEndpoints.isEmpty(), is(false));
|
||||
assertThat(connectionEndpoints.size(), is(equalTo(6)));
|
||||
assertThat(list.size(), is(equalTo(6)));
|
||||
|
||||
ConnectionEndpointList actual = connectionEndpoints.findBy("Earth");
|
||||
ConnectionEndpointList result = list.findBy("Earth");
|
||||
|
||||
assertThat(actual, is(notNullValue()));
|
||||
assertThat(actual.isEmpty(), is(false));
|
||||
assertThat(actual.size(), is(equalTo(2)));
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.size(), is(equalTo(2)));
|
||||
|
||||
String[] expected = { "Earth[10334]", "Earth[40404]" };
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : actual) {
|
||||
for (ConnectionEndpoint connectionEndpoint : result) {
|
||||
assertThat(connectionEndpoint.toString(), is(equalTo(expected[index++])));
|
||||
}
|
||||
|
||||
actual = connectionEndpoints.findBy("Saturn");
|
||||
result = list.findBy("Saturn");
|
||||
|
||||
assertThat(actual, is(notNullValue()));
|
||||
assertThat(actual.isEmpty(), is(false));
|
||||
assertThat(actual.size(), is(equalTo(1)));
|
||||
assertThat(actual.iterator().next().toString(), is(equalTo("Saturn[9876]")));
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.isEmpty(), is(false));
|
||||
assertThat(result.size(), is(equalTo(1)));
|
||||
assertThat(result.iterator().next().toString(), is(equalTo("Saturn[9876]")));
|
||||
|
||||
actual = connectionEndpoints.findBy("Pluto");
|
||||
result = list.findBy("Pluto");
|
||||
|
||||
assertThat(actual, is(notNullValue()));
|
||||
assertThat(actual.isEmpty(), is(true));
|
||||
assertThat(actual.size(), is(equalTo(0)));
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.isEmpty(), is(true));
|
||||
assertThat(result.size(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByPortNumber() {
|
||||
ConnectionEndpointList connectionEndpoints = new ConnectionEndpointList(
|
||||
ConnectionEndpointList list = new ConnectionEndpointList(
|
||||
newConnectionEndpoint("Earth", 10334),
|
||||
newConnectionEndpoint("Earth", 40404),
|
||||
newConnectionEndpoint("Mars", 10334),
|
||||
@@ -222,42 +242,150 @@ public class ConnectionEndpointListTest {
|
||||
newConnectionEndpoint("Neptune", 12345)
|
||||
);
|
||||
|
||||
assertThat(connectionEndpoints.isEmpty(), is(false));
|
||||
assertThat(connectionEndpoints.size(), is(equalTo(6)));
|
||||
assertThat(list.size(), is(equalTo(6)));
|
||||
|
||||
ConnectionEndpointList actual = connectionEndpoints.findBy(10334);
|
||||
ConnectionEndpointList result = list.findBy(10334);
|
||||
|
||||
assertThat(actual, is(notNullValue()));
|
||||
assertThat(actual.isEmpty(), is(false));
|
||||
assertThat(actual.size(), is(equalTo(2)));
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.size(), is(equalTo(2)));
|
||||
|
||||
String[] expected = { "Earth[10334]", "Mars[10334]" };
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : actual) {
|
||||
for (ConnectionEndpoint connectionEndpoint : result) {
|
||||
assertThat(connectionEndpoint.toString(), is(equalTo(expected[index++])));
|
||||
}
|
||||
|
||||
actual = connectionEndpoints.findBy(1234);
|
||||
result = list.findBy(1234);
|
||||
|
||||
assertThat(actual, is(notNullValue()));
|
||||
assertThat(actual.isEmpty(), is(false));
|
||||
assertThat(actual.size(), is(equalTo(1)));
|
||||
assertThat(actual.iterator().next().toString(), is(equalTo("Jupiter[1234]")));
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.size(), is(equalTo(1)));
|
||||
assertThat(result.iterator().next().toString(), is(equalTo("Jupiter[1234]")));
|
||||
|
||||
actual = connectionEndpoints.findBy(80);
|
||||
result = list.findBy(80);
|
||||
|
||||
assertThat(actual, is(notNullValue()));
|
||||
assertThat(actual.isEmpty(), is(true));
|
||||
assertThat(actual.size(), is(equalTo(0)));
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringRepresentation() {
|
||||
ConnectionEndpointList connectionEndpoints = ConnectionEndpointList.parse(10334,
|
||||
public void findOneByHostName() {
|
||||
ConnectionEndpointList list = new ConnectionEndpointList();
|
||||
|
||||
assertThat(list.findOne("localhost"), is(nullValue()));
|
||||
|
||||
list.add(newConnectionEndpoint("skullbox", 11235));
|
||||
|
||||
assertThat(list.findOne("localhost"), is(nullValue()));
|
||||
assertThat(list.findOne("skullbox"), is(equalTo(newConnectionEndpoint("skullbox", 11235))));
|
||||
|
||||
list.add(newConnectionEndpoint("toolbox", 12480));
|
||||
|
||||
assertThat(list.findOne("boombox"), is(nullValue()));
|
||||
assertThat(list.findOne("localhost"), is(nullValue()));
|
||||
assertThat(list.findOne("skullbox"), is(equalTo(newConnectionEndpoint("skullbox", 11235))));
|
||||
assertThat(list.findOne("toolbox"), is(equalTo(newConnectionEndpoint("toolbox", 12480))));
|
||||
|
||||
list.add(newConnectionEndpoint("skullbox", 10334));
|
||||
|
||||
assertThat(list.findOne("localhost"), is(nullValue()));
|
||||
assertThat(list.findOne("boombox"), is(nullValue()));
|
||||
assertThat(list.findOne("skullbox"), is(equalTo(newConnectionEndpoint("skullbox", 11235))));
|
||||
assertThat(list.findOne("toolbox"), is(equalTo(newConnectionEndpoint("toolbox", 12480))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOneByPortNumber() {
|
||||
ConnectionEndpointList list = new ConnectionEndpointList();
|
||||
|
||||
assertThat(list.findOne(10334), is(nullValue()));
|
||||
|
||||
list.add(newConnectionEndpoint("skullbox", 11235));
|
||||
|
||||
assertThat(list.findOne(10334), is(nullValue()));
|
||||
assertThat(list.findOne(11235), is(equalTo(newConnectionEndpoint("skullbox", 11235))));
|
||||
|
||||
list.add(newConnectionEndpoint("toolbox", 12480));
|
||||
|
||||
assertThat(list.findOne(10334), is(nullValue()));
|
||||
assertThat(list.findOne(40404), is(nullValue()));
|
||||
assertThat(list.findOne(11235), is(equalTo(newConnectionEndpoint("skullbox", 11235))));
|
||||
assertThat(list.findOne(12480), is(equalTo(newConnectionEndpoint("toolbox", 12480))));
|
||||
|
||||
list.add(newConnectionEndpoint("boombox", 11235));
|
||||
|
||||
assertThat(list.findOne(10334), is(nullValue()));
|
||||
assertThat(list.findOne(40404), is(nullValue()));
|
||||
assertThat(list.findOne(11235), is(equalTo(newConnectionEndpoint("skullbox", 11235))));
|
||||
assertThat(list.findOne(12480), is(equalTo(newConnectionEndpoint("toolbox", 12480))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toArrayFromList() {
|
||||
ConnectionEndpointList list = ConnectionEndpointList.from(
|
||||
newConnectionEndpoint("boombox", 11235),
|
||||
newConnectionEndpoint("skullbox", 12480),
|
||||
newConnectionEndpoint("toolbox", 10334));
|
||||
|
||||
ConnectionEndpoint[] connectionEndpointArray = list.toArray();
|
||||
|
||||
assertThat(connectionEndpointArray, is(notNullValue()));
|
||||
assertThat(connectionEndpointArray.length, is(equalTo(list.size())));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
assertThat(connectionEndpointArray[index++], is(equalTo(connectionEndpoint)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toArrayFromEmptyList() {
|
||||
ConnectionEndpoint[] connectionEndpoints = new ConnectionEndpointList().toArray();
|
||||
|
||||
assertThat(connectionEndpoints, is(notNullValue()));
|
||||
assertThat(connectionEndpoints.length, is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toInetSocketAddressesFromList() {
|
||||
ConnectionEndpointList list = ConnectionEndpointList.from(
|
||||
newConnectionEndpoint("localhost", 10334),
|
||||
newConnectionEndpoint("localhost", 40404));
|
||||
|
||||
List<InetSocketAddress> socketAddresses = list.toInetSocketAddresses();
|
||||
|
||||
assertThat(socketAddresses, is(notNullValue()));
|
||||
assertThat(socketAddresses.size(), is(equalTo(list.size())));
|
||||
|
||||
int index = 0;
|
||||
|
||||
for (ConnectionEndpoint connectionEndpoint : list) {
|
||||
assertThat(socketAddresses.get(index).getHostName(), is(equalTo(connectionEndpoint.getHost())));
|
||||
assertThat(socketAddresses.get(index++).getPort(), is(equalTo(connectionEndpoint.getPort())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toInetSocketAddressesFromEmptyList() {
|
||||
List<InetSocketAddress> socketAddresses = new ConnectionEndpointList().toInetSocketAddresses();
|
||||
|
||||
assertThat(socketAddresses, is(notNullValue()));
|
||||
assertThat(socketAddresses.isEmpty(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringFromList() {
|
||||
ConnectionEndpointList list = ConnectionEndpointList.parse(10334,
|
||||
"skullbox[12480]", "saturn[ 1 12 3 5]", "neptune");
|
||||
|
||||
assertThat(connectionEndpoints.toString(), is(equalTo("[skullbox[12480], saturn[11235], neptune[10334]]")));
|
||||
assertThat(list.toString(), is(equalTo("[skullbox[12480], saturn[11235], neptune[10334]]")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringFromEmptyList() {
|
||||
assertThat(new ConnectionEndpointList().toString(), is(equalTo("[]")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.data.gemfire.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
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.hamcrest.number.OrderingComparison.greaterThan;
|
||||
import static org.hamcrest.number.OrderingComparison.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -45,7 +45,7 @@ import org.junit.rules.ExpectedException;
|
||||
public class ConnectionEndpointTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void fromInetSocketAddress() {
|
||||
@@ -150,33 +150,33 @@ public class ConnectionEndpointTest {
|
||||
|
||||
@Test
|
||||
public void parseWithBlankHost() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("'hostPort' must be specified");
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("'hostPort' must be specified");
|
||||
ConnectionEndpoint.parse(" ", 12345);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithEmptyHost() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("'hostPort' must be specified");
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("'hostPort' must be specified");
|
||||
ConnectionEndpoint.parse("", 12345);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithNullHost() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("'hostPort' must be specified");
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("'hostPort' must be specified");
|
||||
ConnectionEndpoint.parse(null, 12345);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithInvalidDefaultPort() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("port number (-1248) must be between 0 and 65535");
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("port number (-1248) must be between 0 and 65535");
|
||||
ConnectionEndpoint.parse("localhost", -1248);
|
||||
}
|
||||
|
||||
@@ -217,9 +217,9 @@ public class ConnectionEndpointTest {
|
||||
|
||||
@Test
|
||||
public void constructConnectionEndpointWithInvalidPort() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectCause(is(nullValue(Throwable.class)));
|
||||
expectedException.expectMessage("port number (-1) must be between 0 and 65535");
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("port number (-1) must be between 0 and 65535");
|
||||
new ConnectionEndpoint("localhost", -1);
|
||||
}
|
||||
|
||||
@@ -253,4 +253,18 @@ public class ConnectionEndpointTest {
|
||||
assertThat(connectionEndpointThree.compareTo(connectionEndpointThree), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toInetSocketAddressEqualsHostPort() {
|
||||
ConnectionEndpoint connectionEndpoint = new ConnectionEndpoint("localhost", 12345);
|
||||
|
||||
assertThat(connectionEndpoint.getHost(), is(equalTo("localhost")));
|
||||
assertThat(connectionEndpoint.getPort(), is(equalTo(12345)));
|
||||
|
||||
InetSocketAddress socketAddress = connectionEndpoint.toInetSocketAddress();
|
||||
|
||||
assertThat(socketAddress, is(notNullValue()));
|
||||
assertThat(socketAddress.getHostName(), is(equalTo(connectionEndpoint.getHost())));
|
||||
assertThat(socketAddress.getPort(), is(equalTo(connectionEndpoint.getPort())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GemfireTestBeanPostProcessor implements BeanPostProcessor {
|
||||
? new MockClientCacheFactoryBean((ClientCacheFactoryBean) bean)
|
||||
: new MockCacheFactoryBean((CacheFactoryBean) bean));
|
||||
|
||||
logger.info(String.format("Replacing the '%1$s' bean definition having type '%2$s' with mock (%3$s)...",
|
||||
logger.info(String.format("Replacing the [%1$s] bean definition having type [%2$s] with mock [%3$s]...",
|
||||
beanName, beanTypeName, bean.getClass().getName()));
|
||||
}
|
||||
else if (bean instanceof CacheServerFactoryBean) {
|
||||
|
||||
@@ -13,65 +13,59 @@
|
||||
|
||||
package org.springframework.data.gemfire.test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
|
||||
public MockCacheFactoryBean() {
|
||||
this.cache = new StubCache();
|
||||
this.useBeanFactoryLocator = false;
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MockCacheFactoryBean(CacheFactoryBean cacheFactoryBean) {
|
||||
this();
|
||||
setUseBeanFactoryLocator(false);
|
||||
|
||||
if (cacheFactoryBean != null) {
|
||||
this.beanFactoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = cacheFactoryBean.getBeanFactory();
|
||||
this.beanName = cacheFactoryBean.getBeanName();
|
||||
this.cacheXml = cacheFactoryBean.getCacheXml();
|
||||
this.properties = cacheFactoryBean.getProperties();
|
||||
this.copyOnRead = cacheFactoryBean.getCopyOnRead();
|
||||
this.criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
this.evictionHeapPercentage = cacheFactoryBean.getEvictionHeapPercentage();
|
||||
this.dynamicRegionSupport = cacheFactoryBean.getDynamicRegionSupport();
|
||||
this.enableAutoReconnect = cacheFactoryBean.getEnableAutoReconnect();
|
||||
this.gatewayConflictResolver = cacheFactoryBean.getGatewayConflictResolver();
|
||||
this.jndiDataSources = cacheFactoryBean.getJndiDataSources();
|
||||
this.lockLease = cacheFactoryBean.getLockLease();
|
||||
this.lockTimeout = cacheFactoryBean.getLockTimeout();
|
||||
this.messageSyncInterval = cacheFactoryBean.getMessageSyncInterval();
|
||||
this.pdxDiskStoreName = cacheFactoryBean.getPdxDiskStoreName();
|
||||
this.pdxIgnoreUnreadFields = cacheFactoryBean.getPdxIgnoreUnreadFields();
|
||||
this.pdxPersistent = cacheFactoryBean.getPdxPersistent();
|
||||
this.pdxReadSerialized = cacheFactoryBean.getPdxReadSerialized();
|
||||
this.pdxSerializer = cacheFactoryBean.getPdxSerializer();
|
||||
this.searchTimeout = cacheFactoryBean.getSearchTimeout();
|
||||
this.transactionListeners = cacheFactoryBean.getTransactionListeners();
|
||||
this.transactionWriter = cacheFactoryBean.getTransactionWriter();
|
||||
setBeanClassLoader(cacheFactoryBean.getBeanClassLoader());
|
||||
setBeanFactory(cacheFactoryBean.getBeanFactory());
|
||||
setBeanName(cacheFactoryBean.getBeanName());
|
||||
setCacheXml(cacheFactoryBean.getCacheXml());
|
||||
setPhase(cacheFactoryBean.getPhase());
|
||||
setProperties(cacheFactoryBean.getProperties());
|
||||
setClose(cacheFactoryBean.getClose());
|
||||
setCopyOnRead(cacheFactoryBean.getCopyOnRead());
|
||||
setCriticalHeapPercentage(cacheFactoryBean.getCriticalHeapPercentage());
|
||||
setDynamicRegionSupport(cacheFactoryBean.getDynamicRegionSupport());
|
||||
setEnableAutoReconnect(cacheFactoryBean.getEnableAutoReconnect());
|
||||
setEvictionHeapPercentage(cacheFactoryBean.getEvictionHeapPercentage());
|
||||
setGatewayConflictResolver(cacheFactoryBean.getGatewayConflictResolver());
|
||||
setJndiDataSources(cacheFactoryBean.getJndiDataSources());
|
||||
setLockLease(cacheFactoryBean.getLockLease());
|
||||
setLockTimeout(cacheFactoryBean.getLockTimeout());
|
||||
setMessageSyncInterval(cacheFactoryBean.getMessageSyncInterval());
|
||||
setPdxDiskStoreName(cacheFactoryBean.getPdxDiskStoreName());
|
||||
setPdxIgnoreUnreadFields(cacheFactoryBean.getPdxIgnoreUnreadFields());
|
||||
setPdxPersistent(cacheFactoryBean.getPdxPersistent());
|
||||
setPdxReadSerialized(cacheFactoryBean.getPdxReadSerialized());
|
||||
setPdxSerializer(cacheFactoryBean.getPdxSerializer());
|
||||
setSearchTimeout(cacheFactoryBean.getSearchTimeout());
|
||||
setTransactionListeners(cacheFactoryBean.getTransactionListeners());
|
||||
setTransactionWriter(cacheFactoryBean.getTransactionWriter());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties gemfireProperties) {
|
||||
setProperties(gemfireProperties);
|
||||
return new CacheFactory(gemfireProperties);
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
StubCache stubCache = new StubCache();
|
||||
stubCache.setProperties(getProperties());
|
||||
return (T) stubCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected GemFireCache fetchCache() {
|
||||
((StubCache) cache).setProperties(getProperties());
|
||||
return cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,69 +12,57 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author Lyndon Adams
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
|
||||
public MockClientCacheFactoryBean() {
|
||||
this.cache = new StubCache();
|
||||
}
|
||||
|
||||
public MockClientCacheFactoryBean(ClientCacheFactoryBean clientCacheFactoryBean) {
|
||||
this();
|
||||
setUseBeanFactoryLocator(false);
|
||||
|
||||
if (clientCacheFactoryBean != null) {
|
||||
this.beanFactoryLocator = clientCacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanClassLoader = clientCacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = clientCacheFactoryBean.getBeanFactory();
|
||||
this.beanName = clientCacheFactoryBean.getBeanName();
|
||||
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();
|
||||
this.jndiDataSources = clientCacheFactoryBean.getJndiDataSources();
|
||||
this.keepAlive = clientCacheFactoryBean.isKeepAlive();
|
||||
this.lockLease = clientCacheFactoryBean.getLockLease();
|
||||
this.lockTimeout = clientCacheFactoryBean.getLockTimeout();
|
||||
this.messageSyncInterval = clientCacheFactoryBean.getMessageSyncInterval();
|
||||
this.pdxDiskStoreName = clientCacheFactoryBean.getPdxDiskStoreName();
|
||||
this.pdxIgnoreUnreadFields = clientCacheFactoryBean.getPdxIgnoreUnreadFields();
|
||||
this.pdxPersistent = clientCacheFactoryBean.getPdxPersistent();
|
||||
this.pdxReadSerialized = clientCacheFactoryBean.getPdxReadSerialized();
|
||||
this.pdxSerializer = clientCacheFactoryBean.getPdxSerializer();
|
||||
this.poolName = clientCacheFactoryBean.getPoolName();
|
||||
this.properties = clientCacheFactoryBean.getProperties();
|
||||
this.readyForEvents = clientCacheFactoryBean.getReadyForEvents();
|
||||
this.searchTimeout = clientCacheFactoryBean.getSearchTimeout();
|
||||
this.transactionListeners = clientCacheFactoryBean.getTransactionListeners();
|
||||
this.transactionWriter = clientCacheFactoryBean.getTransactionWriter();
|
||||
setBeanClassLoader(clientCacheFactoryBean.getBeanClassLoader());
|
||||
setBeanFactory(clientCacheFactoryBean.getBeanFactory());
|
||||
setBeanName(clientCacheFactoryBean.getBeanName());
|
||||
setCacheXml(clientCacheFactoryBean.getCacheXml());
|
||||
setCopyOnRead(clientCacheFactoryBean.getCopyOnRead());
|
||||
setCriticalHeapPercentage(clientCacheFactoryBean.getCriticalHeapPercentage());
|
||||
setDurableClientId(clientCacheFactoryBean.getDurableClientId());
|
||||
setDurableClientTimeout(clientCacheFactoryBean.getDurableClientTimeout());
|
||||
setDynamicRegionSupport(clientCacheFactoryBean.getDynamicRegionSupport());
|
||||
setEvictionHeapPercentage(clientCacheFactoryBean.getEvictionHeapPercentage());
|
||||
setGatewayConflictResolver(clientCacheFactoryBean.getGatewayConflictResolver());
|
||||
setJndiDataSources(clientCacheFactoryBean.getJndiDataSources());
|
||||
setKeepAlive(clientCacheFactoryBean.isKeepAlive());
|
||||
setLockLease(clientCacheFactoryBean.getLockLease());
|
||||
setLockTimeout(clientCacheFactoryBean.getLockTimeout());
|
||||
setMessageSyncInterval(clientCacheFactoryBean.getMessageSyncInterval());
|
||||
setPdxDiskStoreName(clientCacheFactoryBean.getPdxDiskStoreName());
|
||||
setPdxIgnoreUnreadFields(clientCacheFactoryBean.getPdxIgnoreUnreadFields());
|
||||
setPdxPersistent(clientCacheFactoryBean.getPdxPersistent());
|
||||
setPdxReadSerialized(clientCacheFactoryBean.getPdxReadSerialized());
|
||||
setPdxSerializer(clientCacheFactoryBean.getPdxSerializer());
|
||||
setPoolName(clientCacheFactoryBean.getPoolName());
|
||||
setProperties(clientCacheFactoryBean.getProperties());
|
||||
setReadyForEvents(clientCacheFactoryBean.getReadyForEvents());
|
||||
setSearchTimeout(clientCacheFactoryBean.getSearchTimeout());
|
||||
setTransactionListeners(clientCacheFactoryBean.getTransactionListeners());
|
||||
setTransactionWriter(clientCacheFactoryBean.getTransactionWriter());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties gemfireProperties) {
|
||||
setProperties(gemfireProperties);
|
||||
return new ClientCacheFactory(gemfireProperties);
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T extends GemFireCache> T fetchCache() {
|
||||
StubCache stubCache = new StubCache();
|
||||
stubCache.setProperties(getProperties());
|
||||
return (T) stubCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GemFireCache fetchCache() {
|
||||
((StubCache) cache).setProperties(getProperties());
|
||||
return cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.data.gemfire.config.GemfireConstants;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.CacheListener;
|
||||
@@ -239,7 +238,7 @@ public class MockClientRegionFactory<K, V> extends MockRegionFactory<K, V> {
|
||||
new Answer<ClientRegionFactory>() {
|
||||
@Override public ClientRegionFactory answer(final InvocationOnMock invocation) throws Throwable {
|
||||
String poolName = invocation.getArgumentAt(0, String.class);
|
||||
poolName = (StringUtils.hasText(poolName) ? poolName : GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME);
|
||||
poolName = (StringUtils.hasText(poolName) ? poolName : null);
|
||||
attributesFactory.setPoolName(poolName);
|
||||
return mockClientRegionFactory;
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ public class StubCache implements Cache, ClientCache {
|
||||
public DistributedSystem getDistributedSystem() {
|
||||
if (distributedSystem == null) {
|
||||
distributedSystem = mockDistributedSystem();
|
||||
|
||||
}
|
||||
|
||||
return distributedSystem;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class StubCache implements Cache, ClientCache {
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.properties == null? null: (String)this.properties.get("name");
|
||||
return (this.properties != null ? this.properties.getProperty("name") : null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -33,7 +33,9 @@ import com.gemstone.gemfire.cache.control.ResourceManager;
|
||||
public class StubResourceManager implements ResourceManager {
|
||||
|
||||
private float criticalHeapPercentage;
|
||||
private float criticalOffHeapPercentage;
|
||||
private float evictionHeapPercentage;
|
||||
private float evictionOffHeapPercentage;
|
||||
|
||||
@Override
|
||||
public void setCriticalHeapPercentage(final float heapPercentage) {
|
||||
@@ -45,6 +47,16 @@ public class StubResourceManager implements ResourceManager {
|
||||
return criticalHeapPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCriticalOffHeapPercentage(final float offHeapPercentage) {
|
||||
this.criticalHeapPercentage = offHeapPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCriticalOffHeapPercentage() {
|
||||
return criticalOffHeapPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEvictionHeapPercentage(final float heapPercentage) {
|
||||
this.evictionHeapPercentage = heapPercentage;
|
||||
@@ -55,6 +67,16 @@ public class StubResourceManager implements ResourceManager {
|
||||
return this.evictionHeapPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEvictionOffHeapPercentage(final float offHeapPercentage) {
|
||||
this.evictionOffHeapPercentage = offHeapPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEvictionOffHeapPercentage() {
|
||||
return evictionOffHeapPercentage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RebalanceFactory createRebalanceFactory() {
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
|
||||
Reference in New Issue
Block a user