SGF-657 - Add missing configuration support for Off-Heap.
This commit is contained in:
@@ -28,7 +28,6 @@ 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.junit.Assume.assumeTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -100,8 +99,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
final AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
final Properties gemfireProperties = new Properties();
|
||||
|
||||
AtomicBoolean postProcessBeforeCacheInitializationCalled = new AtomicBoolean(false);
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
|
||||
@@ -120,7 +121,6 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationUsingDefaults() {
|
||||
assumeTrue(GemfireUtils.isGemfireVersion8OrAbove());
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
@@ -135,9 +135,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationDisabled() {
|
||||
assumeTrue(GemfireUtils.isGemfireVersion8OrAbove());
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
@@ -153,9 +153,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectAndClusterConfigurationEnabled() {
|
||||
assumeTrue(GemfireUtils.isGemfireVersion8OrAbove());
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(true);
|
||||
@@ -171,9 +171,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void postProcessBeforeCacheInitializationWithAutoReconnectDisabledAndClusterConfigurationEnabled() {
|
||||
assumeTrue(GemfireUtils.isGemfireVersion8OrAbove());
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
@@ -189,9 +189,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectCallsInit() throws Exception {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
final AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
AtomicBoolean initCalled = new AtomicBoolean(false);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override Cache init() {
|
||||
@@ -208,7 +209,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectReturnsExistingCache() throws Exception {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -221,6 +224,7 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void init() throws Exception {
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
Cache mockCache = mock(Cache.class);
|
||||
CacheTransactionManager mockCacheTransactionManager = mock(CacheTransactionManager.class);
|
||||
@@ -233,7 +237,7 @@ public class CacheFactoryBeanTest {
|
||||
TransactionListener mockTransactionLister = mock(TransactionListener.class);
|
||||
TransactionWriter mockTransactionWriter = mock(TransactionWriter.class);
|
||||
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockBeanFactory.getAliases(anyString())).thenReturn(new String[0]);
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
@@ -254,9 +258,13 @@ public class CacheFactoryBeanTest {
|
||||
final Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected Object createFactory(final Properties actualGemfireProperties) {
|
||||
|
||||
@Override
|
||||
protected Object createFactory(final Properties actualGemfireProperties) {
|
||||
|
||||
assertThat(actualGemfireProperties, is(equalTo(gemfireProperties)));
|
||||
assertThat(getBeanClassLoader(), is(equalTo(ClassLoader.getSystemClassLoader())));
|
||||
|
||||
return mockCacheFactory;
|
||||
}
|
||||
};
|
||||
@@ -267,9 +275,11 @@ public class CacheFactoryBeanTest {
|
||||
cacheFactoryBean.setCacheXml(mockCacheXml);
|
||||
cacheFactoryBean.setCopyOnRead(true);
|
||||
cacheFactoryBean.setCriticalHeapPercentage(0.90f);
|
||||
cacheFactoryBean.setCriticalOffHeapPercentage(0.95f);
|
||||
cacheFactoryBean.setDynamicRegionSupport(null);
|
||||
cacheFactoryBean.setEnableAutoReconnect(false);
|
||||
cacheFactoryBean.setEvictionHeapPercentage(0.75f);
|
||||
cacheFactoryBean.setEvictionOffHeapPercentage(0.90f);
|
||||
cacheFactoryBean.setGatewayConflictResolver(mockGatewayConflictResolver);
|
||||
cacheFactoryBean.setJndiDataSources(null);
|
||||
cacheFactoryBean.setLockLease(15000);
|
||||
@@ -313,17 +323,20 @@ public class CacheFactoryBeanTest {
|
||||
verify(mockCache, times(1)).setLockLease(eq(15000));
|
||||
verify(mockCache, times(1)).setLockTimeout(eq(5000));
|
||||
verify(mockCache, times(1)).setMessageSyncInterval(eq(20000));
|
||||
verify(mockCache, times(2)).getResourceManager();
|
||||
verify(mockCache, times(4)).getResourceManager();
|
||||
verify(mockCache, times(1)).setSearchTimeout(eq(45000));
|
||||
verify(mockResourceManager, times(1)).setCriticalHeapPercentage(eq(0.90f));
|
||||
verify(mockResourceManager, times(1)).setCriticalOffHeapPercentage(eq(0.95f));
|
||||
verify(mockResourceManager, times(1)).setEvictionHeapPercentage(eq(0.75f));
|
||||
verify(mockResourceManager, times(1)).setEvictionOffHeapPercentage(eq(0.90f));
|
||||
verify(mockCacheTransactionManager, times(1)).addListener(same(mockTransactionLister));
|
||||
verify(mockCacheTransactionManager, times(1)).setWriter(same(mockTransactionWriter));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveCacheCallsFetchCacheReturnsMock() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override @SuppressWarnings("unchecked ")
|
||||
@@ -339,8 +352,10 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveCacheCreatesCacheWhenFetchCacheThrowsCacheClosedException() {
|
||||
final Cache mockCache = mock(Cache.class);
|
||||
final CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
|
||||
@@ -364,7 +379,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void fetchExistingCache() throws Exception {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -378,7 +395,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolveProperties() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(gemfireProperties);
|
||||
@@ -388,6 +407,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenNull() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setProperties(null);
|
||||
@@ -400,7 +420,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createFactory() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
Object cacheFactoryReference = new CacheFactoryBean().createFactory(gemfireProperties);
|
||||
|
||||
assertThat(cacheFactoryReference, is(instanceOf(CacheFactory.class)));
|
||||
@@ -416,6 +438,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithUnspecifiedPdxOptions() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
assertThat(new CacheFactoryBean().prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
|
||||
@@ -429,6 +452,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithSpecificPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxSerializer(mock(PdxSerializer.class));
|
||||
@@ -448,6 +472,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void prepareFactoryWithAllPdxOptions() {
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setPdxDiskStoreName("testPdxDiskStoreName");
|
||||
@@ -469,7 +494,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createCacheWithExistingCache() throws Exception {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -486,6 +513,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createCacheWithNoExistingCache() {
|
||||
|
||||
CacheFactory mockCacheFactory = mock(CacheFactory.class);
|
||||
|
||||
when(mockCacheFactory.create()).thenReturn(mockCache);
|
||||
@@ -509,7 +537,26 @@ public class CacheFactoryBeanTest {
|
||||
cacheFactoryBean.postProcess(mockCache);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("criticalHeapPercentage [200.0] is not valid; must be > 0.0 and <= 100.0",
|
||||
assertEquals("criticalHeapPercentage [200.0] is not valid; must be >= 0.0 and <= 100.0",
|
||||
expected.getMessage());
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidCriticalOffHeapPercentage() throws Exception {
|
||||
try {
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCriticalOffHeapPercentage(200.0f);
|
||||
cacheFactoryBean.postProcess(mockCache);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("criticalOffHeapPercentage [200.0] is not valid; must be >= 0.0 and <= 100.0",
|
||||
expected.getMessage());
|
||||
|
||||
throw expected;
|
||||
@@ -528,7 +575,26 @@ public class CacheFactoryBeanTest {
|
||||
cacheFactoryBean.postProcess(mockCache);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("evictionHeapPercentage [-75.0] is not valid; must be > 0.0 and <= 100.0",
|
||||
assertEquals("evictionHeapPercentage [-75.0] is not valid; must be >= 0.0 and <= 100.0",
|
||||
expected.getMessage());
|
||||
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
verifyZeroInteractions(mockCache);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void postProcessCacheWithInvalidEvictionOffHeapPercentage() throws Exception {
|
||||
try {
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setEvictionOffHeapPercentage(-75.0f);
|
||||
cacheFactoryBean.postProcess(mockCache);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("evictionOffHeapPercentage [-75.0] is not valid; must be >= 0.0 and <= 100.0",
|
||||
expected.getMessage());
|
||||
|
||||
throw expected;
|
||||
@@ -546,7 +612,9 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getObjectTypeWithExistingCache() {
|
||||
|
||||
Cache mockCache = mock(Cache.class);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
|
||||
|
||||
cacheFactoryBean.setCache(mockCache);
|
||||
@@ -562,8 +630,10 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroy() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
final Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
GemfireBeanFactoryLocator mockGemfireBeanFactoryLocator = mock(GemfireBeanFactoryLocator.class);
|
||||
|
||||
@@ -593,10 +663,11 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroyWhenCacheIsNull() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected GemFireCache fetchCache() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
fetchCacheCalled.set(true);
|
||||
return null;
|
||||
}
|
||||
@@ -612,13 +683,15 @@ public class CacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void destroyWhenCacheClosedIsTrue() throws Exception {
|
||||
final AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
final Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
AtomicBoolean fetchCacheCalled = new AtomicBoolean(false);
|
||||
|
||||
Cache mockCache = mock(Cache.class, "GemFireCache");
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
|
||||
@Override protected GemFireCache fetchCache() {
|
||||
@Override @SuppressWarnings("unchecked") protected <T extends GemFireCache> T fetchCache() {
|
||||
fetchCacheCalled.set(true);
|
||||
return mockCache;
|
||||
return (T) mockCache;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -634,6 +707,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void closeCache() {
|
||||
|
||||
GemFireCache mockCache = mock(GemFireCache.class, "testCloseCache.MockCache");
|
||||
|
||||
new CacheFactoryBean().close(mockCache);
|
||||
@@ -643,6 +717,7 @@ public class CacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void setAndGetCacheFactoryBeanProperties() throws Exception {
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class, "SpringBeanFactory");
|
||||
GatewayConflictResolver mockGatewayConflictResolver = mock(GatewayConflictResolver.class, "GemFireGatewayConflictResolver");
|
||||
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class, "GemFirePdxSerializer");
|
||||
@@ -665,7 +740,9 @@ public class CacheFactoryBeanTest {
|
||||
cacheFactoryBean.setDynamicRegionSupport(new CacheFactoryBean.DynamicRegionSupport());
|
||||
cacheFactoryBean.setEnableAutoReconnect(true);
|
||||
cacheFactoryBean.setCriticalHeapPercentage(0.95f);
|
||||
cacheFactoryBean.setCriticalOffHeapPercentage(0.99f);
|
||||
cacheFactoryBean.setEvictionHeapPercentage(0.70f);
|
||||
cacheFactoryBean.setEvictionOffHeapPercentage(0.80f);
|
||||
cacheFactoryBean.setGatewayConflictResolver(mockGatewayConflictResolver);
|
||||
cacheFactoryBean.setJndiDataSources(Collections.singletonList(new CacheFactoryBean.JndiDataSource()));
|
||||
cacheFactoryBean.setLockLease(15000);
|
||||
@@ -691,9 +768,11 @@ public class CacheFactoryBeanTest {
|
||||
assertTrue(Boolean.FALSE.equals(TestUtils.readField("close", cacheFactoryBean)));
|
||||
assertTrue(cacheFactoryBean.getCopyOnRead());
|
||||
assertEquals(0.95f, cacheFactoryBean.getCriticalHeapPercentage(), 0.0f);
|
||||
assertEquals(0.99f, cacheFactoryBean.getCriticalOffHeapPercentage(), 0.0f);
|
||||
assertNotNull(cacheFactoryBean.getDynamicRegionSupport());
|
||||
assertTrue(cacheFactoryBean.getEnableAutoReconnect());
|
||||
assertEquals(0.70f, cacheFactoryBean.getEvictionHeapPercentage(), 0.0f);
|
||||
assertEquals(0.80f, cacheFactoryBean.getEvictionOffHeapPercentage(), 0.0f);
|
||||
assertSame(mockGatewayConflictResolver, cacheFactoryBean.getGatewayConflictResolver());
|
||||
assertNotNull(cacheFactoryBean.getJndiDataSources());
|
||||
assertEquals(1, cacheFactoryBean.getJndiDataSources().size());
|
||||
|
||||
@@ -24,6 +24,9 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyFloat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.same;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -81,7 +84,9 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig defaultConfig() {
|
||||
|
||||
return new RegionFactoryBeanConfig(new TestRegionFactoryBean(), "default") {
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
}
|
||||
@@ -96,7 +101,9 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private RegionFactoryBeanConfig persistentConfig() {
|
||||
|
||||
return new RegionFactoryBeanConfig(new TestRegionFactoryBean(), "persistent") {
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setPersistent(true);
|
||||
@@ -112,7 +119,9 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
private RegionFactoryBeanConfig invalidPersistentConfig() {
|
||||
|
||||
return new RegionFactoryBeanConfig(new TestRegionFactoryBean(), "invalid-persistence") {
|
||||
|
||||
@Override
|
||||
public void configureRegionFactoryBean() {
|
||||
regionFactoryBean.setDataPolicy("persistent_replicate");
|
||||
@@ -136,8 +145,9 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
}
|
||||
|
||||
protected PartitionAttributes createPartitionAttributes(final String colocatedWith, final int localMaxMemory,
|
||||
final long recoveryDelay, final int redundantCopies, final long startupRecoveryDelay,
|
||||
final long totalMaxMemory, final int totalNumberOfBuckets) throws Exception {
|
||||
|
||||
long recoveryDelay, final int redundantCopies, final long startupRecoveryDelay,
|
||||
long totalMaxMemory, final int totalNumberOfBuckets) throws Exception {
|
||||
|
||||
PartitionAttributesFactoryBean partitionAttributesFactoryBean = new PartitionAttributesFactoryBean();
|
||||
|
||||
@@ -153,9 +163,12 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
return partitionAttributesFactoryBean.getObject();
|
||||
}
|
||||
|
||||
protected RegionAttributes createMockRegionAttributes(final DataPolicy... dataPolicies) {
|
||||
protected RegionAttributes createMockRegionAttributes(DataPolicy... dataPolicies) {
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
when(mockRegionAttributes.getDataPolicy()).thenReturn(ArrayUtils.getFirst(dataPolicies, DataPolicy.DEFAULT));
|
||||
|
||||
return mockRegionAttributes;
|
||||
}
|
||||
|
||||
@@ -166,9 +179,10 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
protected RegionFactory<?, ?> createTestRegionFactory() {
|
||||
return new TestRegionFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertDataPolicyAndPersistentAttributesAreCompatible() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<>();
|
||||
|
||||
factoryBean.setPersistent(null);
|
||||
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.PARTITION);
|
||||
@@ -186,7 +200,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAssertNonPersistentDataPolicyWithPersistentAttribute() {
|
||||
try {
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<>();
|
||||
factoryBean.setPersistent(true);
|
||||
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.REPLICATE);
|
||||
}
|
||||
@@ -199,7 +213,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAssertPersistentDataPolicyWithNonPersistentAttribute() {
|
||||
try {
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<>();
|
||||
factoryBean.setPersistent(false);
|
||||
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.PERSISTENT_PARTITION);
|
||||
}
|
||||
@@ -212,7 +226,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testIsPersistent() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<>();
|
||||
|
||||
assertFalse(factoryBean.isPersistent());
|
||||
|
||||
@@ -227,7 +241,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testIsPersistentUnspecified() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<>();
|
||||
|
||||
assertTrue(factoryBean.isPersistentUnspecified());
|
||||
|
||||
@@ -246,7 +260,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testIsNotPersistent() {
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<Object, Object>();
|
||||
RegionFactoryBean<?, ?> factoryBean = new TestRegionFactoryBean<>();
|
||||
|
||||
assertFalse(factoryBean.isNotPersistent());
|
||||
|
||||
@@ -338,14 +352,21 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergeRegionAttributes() throws Exception {
|
||||
|
||||
EvictionAttributes testEvictionAttributes = EvictionAttributes.createLRUEntryAttributes();
|
||||
|
||||
ExpirationAttributes testExpirationAttributes = new ExpirationAttributes(120, ExpirationAction.LOCAL_DESTROY);
|
||||
|
||||
MembershipAttributes testMembershipAttributes = new MembershipAttributes();
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion", 1024000, 15000l, 0,
|
||||
45000l, 2048000000l, 97);
|
||||
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion",
|
||||
1024000, 15000L, 0, 45000L,
|
||||
2048000000L, 97);
|
||||
|
||||
SubscriptionAttributes testSubscriptionAttributes = new SubscriptionAttributes();
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory<Long, String> mockRegionFactory = (RegionFactory<Long, String>) createMockRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getCloningEnabled()).thenReturn(false);
|
||||
@@ -367,6 +388,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
when(mockRegionAttributes.isLockGrantor()).thenReturn(true);
|
||||
when(mockRegionAttributes.getMembershipAttributes()).thenReturn(testMembershipAttributes);
|
||||
when(mockRegionAttributes.getMulticastEnabled()).thenReturn(false);
|
||||
when(mockRegionAttributes.getOffHeap()).thenReturn(true);
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(testPartitionAttributes);
|
||||
when(mockRegionAttributes.getPoolName()).thenReturn("swimming");
|
||||
when(mockRegionAttributes.getRegionIdleTimeout()).thenReturn(testExpirationAttributes);
|
||||
@@ -375,11 +397,14 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
when(mockRegionAttributes.getSubscriptionAttributes()).thenReturn(testSubscriptionAttributes);
|
||||
|
||||
RegionFactoryBean factoryBean = new RegionFactoryBean() {
|
||||
@Override boolean isUserSpecifiedEvictionAttributes(final RegionAttributes regionAttributes) {
|
||||
|
||||
@Override
|
||||
boolean isUserSpecifiedEvictionAttributes(RegionAttributes regionAttributes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override void validateRegionAttributes(final RegionAttributes regionAttributes) {
|
||||
@Override
|
||||
void validateRegionAttributes(RegionAttributes regionAttributes) {
|
||||
// no-op!
|
||||
}
|
||||
};
|
||||
@@ -405,6 +430,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
verify(mockRegionFactory).setLockGrantor(eq(true));
|
||||
verify(mockRegionFactory).setMembershipAttributes(same(testMembershipAttributes));
|
||||
verify(mockRegionFactory).setMulticastEnabled(eq(false));
|
||||
verify(mockRegionFactory).setOffHeap(eq(true));
|
||||
verify(mockRegionFactory).setPartitionAttributes(eq(testPartitionAttributes));
|
||||
verify(mockRegionFactory).setPoolName(eq("swimming"));
|
||||
verify(mockRegionFactory).setRegionIdleTimeout(same(testExpirationAttributes));
|
||||
@@ -415,43 +441,47 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergeRegionAttributesWithNull() {
|
||||
|
||||
RegionFactory mockRegionFactory = createMockRegionFactory();
|
||||
|
||||
factoryBean.mergeRegionAttributes(mockRegionFactory, null);
|
||||
|
||||
verify(mockRegionFactory, never()).setCloningEnabled(false);
|
||||
verify(mockRegionFactory, never()).setConcurrencyChecksEnabled(true);
|
||||
verify(mockRegionFactory, never()).setConcurrencyLevel(2);
|
||||
verify(mockRegionFactory, never()).setCloningEnabled(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setConcurrencyChecksEnabled(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setConcurrencyLevel(anyInt());
|
||||
verify(mockRegionFactory, never()).setCustomEntryIdleTimeout(any(CustomExpiry.class));
|
||||
verify(mockRegionFactory, never()).setCustomEntryTimeToLive(any(CustomExpiry.class));
|
||||
verify(mockRegionFactory, never()).setDiskSynchronous(true);
|
||||
verify(mockRegionFactory, never()).setEnableAsyncConflation(true);
|
||||
verify(mockRegionFactory, never()).setEnableSubscriptionConflation(false);
|
||||
verify(mockRegionFactory, never()).setDiskSynchronous(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setEnableAsyncConflation(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setEnableSubscriptionConflation(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setEntryIdleTimeout(any(ExpirationAttributes.class));
|
||||
verify(mockRegionFactory, never()).setEntryTimeToLive(any(ExpirationAttributes.class));
|
||||
verify(mockRegionFactory, never()).setEvictionAttributes(any(EvictionAttributes.class));
|
||||
verify(mockRegionFactory, never()).setIgnoreJTA(false);
|
||||
verify(mockRegionFactory, never()).setIndexMaintenanceSynchronous(false);
|
||||
verify(mockRegionFactory, never()).setInitialCapacity(51);
|
||||
verify(mockRegionFactory, never()).setIgnoreJTA(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setIndexMaintenanceSynchronous(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setInitialCapacity(anyInt());
|
||||
verify(mockRegionFactory, never()).setKeyConstraint(any(Class.class));
|
||||
verify(mockRegionFactory, never()).setLoadFactor(0.75f);
|
||||
verify(mockRegionFactory, never()).setLockGrantor(true);
|
||||
verify(mockRegionFactory, never()).setLoadFactor(anyFloat());
|
||||
verify(mockRegionFactory, never()).setLockGrantor(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setMembershipAttributes(any(MembershipAttributes.class));
|
||||
verify(mockRegionFactory, never()).setMulticastEnabled(false);
|
||||
verify(mockRegionFactory, never()).setMulticastEnabled(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setOffHeap(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setPartitionAttributes(any(PartitionAttributes.class));
|
||||
verify(mockRegionFactory, never()).setPoolName(any(String.class));
|
||||
verify(mockRegionFactory, never()).setRegionIdleTimeout(any(ExpirationAttributes.class));
|
||||
verify(mockRegionFactory, never()).setRegionTimeToLive(any(ExpirationAttributes.class));
|
||||
verify(mockRegionFactory, never()).setStatisticsEnabled(true);
|
||||
verify(mockRegionFactory, never()).setStatisticsEnabled(anyBoolean());
|
||||
verify(mockRegionFactory, never()).setSubscriptionAttributes(any(SubscriptionAttributes.class));
|
||||
verify(mockRegionFactory, never()).setValueConstraint(any(Class.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialMergeRegionAttributes() {
|
||||
|
||||
ExpirationAttributes testExpirationAttributes = new ExpirationAttributes(300, ExpirationAction.LOCAL_INVALIDATE);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory<Long, String> mockRegionFactory = (RegionFactory<Long, String>) createMockRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getCloningEnabled()).thenReturn(true);
|
||||
@@ -473,6 +503,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
when(mockRegionAttributes.isLockGrantor()).thenReturn(false);
|
||||
when(mockRegionAttributes.getMembershipAttributes()).thenReturn(null);
|
||||
when(mockRegionAttributes.getMulticastEnabled()).thenReturn(true);
|
||||
when(mockRegionAttributes.getOffHeap()).thenReturn(true);
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(null);
|
||||
when(mockRegionAttributes.getPoolName()).thenReturn("swimming");
|
||||
when(mockRegionAttributes.getRegionIdleTimeout()).thenReturn(testExpirationAttributes);
|
||||
@@ -511,6 +542,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
verify(mockRegionFactory).setLockGrantor(eq(false));
|
||||
verify(mockRegionFactory).setMembershipAttributes(null);
|
||||
verify(mockRegionFactory).setMulticastEnabled(eq(true));
|
||||
verify(mockRegionFactory).setOffHeap(eq(true));
|
||||
verify(mockRegionFactory, never()).setPartitionAttributes(any(PartitionAttributes.class));
|
||||
verify(mockRegionFactory).setPoolName(eq("swimming"));
|
||||
verify(mockRegionFactory).setRegionIdleTimeout(same(testExpirationAttributes));
|
||||
@@ -521,10 +553,13 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergePartitionAttributesWithPartitionRedundantProxy() throws Exception {
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion", 512000, 15000l, 0,
|
||||
30000l, 1024000l, 51);
|
||||
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion",
|
||||
512000, 15000L, 0, 30000L,
|
||||
1024000L, 51);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory mockRegionFactory = createTestRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(testPartitionAttributes);
|
||||
@@ -534,16 +569,17 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("regionAttributes",
|
||||
TestUtils.readField("attrsFactory", mockRegionFactory));
|
||||
|
||||
PartitionAttributes actualPartitionAttributes = regionAttributes.getPartitionAttributes();
|
||||
|
||||
assertNotNull(actualPartitionAttributes);
|
||||
assertNotSame(testPartitionAttributes, actualPartitionAttributes);
|
||||
assertEquals("TestRegion", actualPartitionAttributes.getColocatedWith());
|
||||
assertEquals(0, actualPartitionAttributes.getLocalMaxMemory());
|
||||
assertEquals(15000l, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(15000L, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(1, actualPartitionAttributes.getRedundantCopies());
|
||||
assertEquals(30000l, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000l, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(30000L, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000L, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(51, actualPartitionAttributes.getTotalNumBuckets());
|
||||
|
||||
verify(mockRegionAttributes, times(2)).getPartitionAttributes();
|
||||
@@ -551,10 +587,13 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergePartitionAttributesWithPartitionRedundant() throws Exception {
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion", 512000, 15000l, 0,
|
||||
30000l, 1024000l, 51);
|
||||
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion",
|
||||
512000, 15000L, 0, 30000L,
|
||||
1024000L, 51);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory mockRegionFactory = createTestRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(testPartitionAttributes);
|
||||
@@ -564,16 +603,17 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("regionAttributes",
|
||||
TestUtils.readField("attrsFactory", mockRegionFactory));
|
||||
|
||||
PartitionAttributes actualPartitionAttributes = regionAttributes.getPartitionAttributes();
|
||||
|
||||
assertNotNull(actualPartitionAttributes);
|
||||
assertNotSame(testPartitionAttributes, actualPartitionAttributes);
|
||||
assertEquals("TestRegion", actualPartitionAttributes.getColocatedWith());
|
||||
assertEquals(512000, actualPartitionAttributes.getLocalMaxMemory());
|
||||
assertEquals(15000l, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(15000L, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(1, actualPartitionAttributes.getRedundantCopies());
|
||||
assertEquals(30000l, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000l, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(30000L, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000L, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(51, actualPartitionAttributes.getTotalNumBuckets());
|
||||
|
||||
verify(mockRegionAttributes, times(2)).getPartitionAttributes();
|
||||
@@ -581,10 +621,13 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergePartitionAttributesWithPartitionRedundantPersistentOverflow() throws Exception {
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion", 512000, 15000l, 3,
|
||||
30000l, 1024000l, 51);
|
||||
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion",
|
||||
512000, 15000L, 3, 30000L,
|
||||
1024000L, 51);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory mockRegionFactory = createTestRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(testPartitionAttributes);
|
||||
@@ -594,16 +637,17 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("regionAttributes",
|
||||
TestUtils.readField("attrsFactory", mockRegionFactory));
|
||||
|
||||
PartitionAttributes actualPartitionAttributes = regionAttributes.getPartitionAttributes();
|
||||
|
||||
assertNotNull(actualPartitionAttributes);
|
||||
assertNotSame(testPartitionAttributes, actualPartitionAttributes);
|
||||
assertEquals("TestRegion", actualPartitionAttributes.getColocatedWith());
|
||||
assertEquals(512000, actualPartitionAttributes.getLocalMaxMemory());
|
||||
assertEquals(15000l, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(15000L, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(3, actualPartitionAttributes.getRedundantCopies());
|
||||
assertEquals(30000l, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000l, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(30000L, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000L, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(51, actualPartitionAttributes.getTotalNumBuckets());
|
||||
|
||||
verify(mockRegionAttributes, times(2)).getPartitionAttributes();
|
||||
@@ -611,10 +655,13 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergePartitionAttributesWithPartitionProxy() throws Exception {
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion", 512000, 15000l, 0,
|
||||
30000l, 1024000l, 51);
|
||||
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion",
|
||||
512000, 15000L, 0, 30000L,
|
||||
1024000L, 51);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory mockRegionFactory = createTestRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(testPartitionAttributes);
|
||||
@@ -624,16 +671,17 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("regionAttributes",
|
||||
TestUtils.readField("attrsFactory", mockRegionFactory));
|
||||
|
||||
PartitionAttributes actualPartitionAttributes = regionAttributes.getPartitionAttributes();
|
||||
|
||||
assertNotNull(actualPartitionAttributes);
|
||||
assertNotSame(testPartitionAttributes, actualPartitionAttributes);
|
||||
assertEquals("TestRegion", actualPartitionAttributes.getColocatedWith());
|
||||
assertEquals(0, actualPartitionAttributes.getLocalMaxMemory());
|
||||
assertEquals(15000l, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(15000L, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(0, actualPartitionAttributes.getRedundantCopies());
|
||||
assertEquals(30000l, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000l, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(30000L, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000L, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(51, actualPartitionAttributes.getTotalNumBuckets());
|
||||
|
||||
verify(mockRegionAttributes, times(2)).getPartitionAttributes();
|
||||
@@ -641,10 +689,13 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergePartitionAttributesWithPartition() throws Exception {
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion", 512000, 15000l, 0,
|
||||
30000l, 1024000l, 51);
|
||||
|
||||
PartitionAttributes testPartitionAttributes = createPartitionAttributes("TestRegion",
|
||||
512000, 15000L, 0, 30000L,
|
||||
1024000L, 51);
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory mockRegionFactory = createTestRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(testPartitionAttributes);
|
||||
@@ -654,16 +705,17 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
RegionAttributes regionAttributes = TestUtils.readField("regionAttributes",
|
||||
TestUtils.readField("attrsFactory", mockRegionFactory));
|
||||
|
||||
PartitionAttributes actualPartitionAttributes = regionAttributes.getPartitionAttributes();
|
||||
|
||||
assertNotNull(actualPartitionAttributes);
|
||||
assertNotSame(testPartitionAttributes, actualPartitionAttributes);
|
||||
assertEquals("TestRegion", actualPartitionAttributes.getColocatedWith());
|
||||
assertEquals(512000, actualPartitionAttributes.getLocalMaxMemory());
|
||||
assertEquals(15000l, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(15000L, actualPartitionAttributes.getRecoveryDelay());
|
||||
assertEquals(0, actualPartitionAttributes.getRedundantCopies());
|
||||
assertEquals(30000l, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000l, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(30000L, actualPartitionAttributes.getStartupRecoveryDelay());
|
||||
assertEquals(1024000L, actualPartitionAttributes.getTotalMaxMemory());
|
||||
assertEquals(51, actualPartitionAttributes.getTotalNumBuckets());
|
||||
|
||||
verify(mockRegionAttributes, times(2)).getPartitionAttributes();
|
||||
@@ -671,7 +723,9 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testMergePartitionAttributes() {
|
||||
|
||||
RegionAttributes mockRegionAttributes = mock(RegionAttributes.class);
|
||||
|
||||
RegionFactory mockRegionFactory = createMockRegionFactory();
|
||||
|
||||
when(mockRegionAttributes.getPartitionAttributes()).thenReturn(null);
|
||||
@@ -1044,9 +1098,9 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
|
||||
verify(mockRegionFactory).setDataPolicy(eq(DataPolicy.PERSISTENT_REPLICATE));
|
||||
}
|
||||
|
||||
protected static class TestRegionFactory extends RegionFactory {
|
||||
static class TestRegionFactory extends RegionFactory {
|
||||
|
||||
protected TestRegionFactory() {
|
||||
TestRegionFactory() {
|
||||
super((GemFireCacheImpl) null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,27 +41,36 @@ import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CacheParser}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.Cache
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.springframework.data.gemfire.config.xml.CacheParser
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "cache-ns.xml")
|
||||
@SuppressWarnings("unused")
|
||||
public class CacheNamespaceTest{
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testNoNamedCache() throws Exception {
|
||||
assertTrue(context.containsBean("gemfireCache"));
|
||||
assertTrue(context.containsBean("gemfire-cache")); // assert alias is registered
|
||||
|
||||
Cache gemfireCache = context.getBean("gemfireCache", Cache.class);
|
||||
assertTrue(applicationContext.containsBean("gemfireCache"));
|
||||
assertTrue(applicationContext.containsBean("gemfire-cache")); // assert alias is registered
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertNotNull(gemfireCache);
|
||||
assertNotNull(gemfireCache.getDistributedSystem());
|
||||
@@ -69,7 +78,7 @@ public class CacheNamespaceTest{
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&gemfireCache", CacheFactoryBean.class);
|
||||
|
||||
assertNull(TestUtils.readField("cacheXml", cacheFactoryBean));
|
||||
|
||||
@@ -83,14 +92,15 @@ public class CacheNamespaceTest{
|
||||
|
||||
@Test
|
||||
public void testNamedCache() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-name"));
|
||||
|
||||
Cache gemfireCache = context.getBean("gemfireCache", Cache.class);
|
||||
assertTrue(applicationContext.containsBean("cache-with-name"));
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("gemfireCache", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-name", CacheFactoryBean.class);
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&cache-with-name", CacheFactoryBean.class);
|
||||
|
||||
assertNull(TestUtils.readField("cacheXml", cacheFactoryBean));
|
||||
|
||||
@@ -104,14 +114,16 @@ public class CacheNamespaceTest{
|
||||
|
||||
@Test
|
||||
public void testCacheWithXmlAndProperties() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-xml-and-props"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-xml-and-props", CacheFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("cache-with-xml-and-props"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&cache-with-xml-and-props", CacheFactoryBean.class);
|
||||
|
||||
Resource cacheXmlResource = TestUtils.readField("cacheXml", cacheFactoryBean);
|
||||
|
||||
assertEquals("gemfire-cache.xml", cacheXmlResource.getFilename());
|
||||
assertTrue(context.containsBean("gemfireProperties"));
|
||||
assertEquals(context.getBean("gemfireProperties"), TestUtils.readField("properties", cacheFactoryBean));
|
||||
assertTrue(applicationContext.containsBean("gemfireProperties"));
|
||||
assertEquals(applicationContext.getBean("gemfireProperties"), TestUtils.readField("properties", cacheFactoryBean));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxReadSerialized", cacheFactoryBean));
|
||||
assertEquals(Boolean.FALSE, TestUtils.readField("pdxIgnoreUnreadFields", cacheFactoryBean));
|
||||
assertEquals(Boolean.TRUE, TestUtils.readField("pdxPersistent", cacheFactoryBean));
|
||||
@@ -120,57 +132,79 @@ public class CacheNamespaceTest{
|
||||
|
||||
@Test
|
||||
public void testCacheWithGatewayConflictResolver() {
|
||||
Cache cache = context.getBean("cache-with-gateway-conflict-resolver", Cache.class);
|
||||
|
||||
Cache cache = applicationContext.getBean("cache-with-gateway-conflict-resolver", Cache.class);
|
||||
|
||||
assertTrue(cache.getGatewayConflictResolver() instanceof TestGatewayConflictResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectDisabled() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-auto-reconnect-disabled"));
|
||||
|
||||
Cache gemfireCache = context.getBean("cache-with-auto-reconnect-disabled", Cache.class);
|
||||
assertTrue(applicationContext.containsBean("cache-with-auto-reconnect-disabled"));
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("cache-with-auto-reconnect-disabled", Cache.class);
|
||||
|
||||
assertTrue(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-auto-reconnect-disabled", CacheFactoryBean.class);
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-auto-reconnect-disabled", CacheFactoryBean.class);
|
||||
|
||||
assertFalse(cacheFactoryBean.getEnableAutoReconnect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheWithAutoReconnectEnabled() throws Exception {
|
||||
assertTrue(context.containsBean("cache-with-auto-reconnect-enabled"));
|
||||
|
||||
Cache gemfireCache = context.getBean("cache-with-auto-reconnect-enabled", Cache.class);
|
||||
assertTrue(applicationContext.containsBean("cache-with-auto-reconnect-enabled"));
|
||||
|
||||
Cache gemfireCache = applicationContext.getBean("cache-with-auto-reconnect-enabled", Cache.class);
|
||||
|
||||
assertFalse(Boolean.parseBoolean(gemfireCache.getDistributedSystem().getProperties()
|
||||
.getProperty("disable-auto-reconnect")));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&cache-with-auto-reconnect-enabled", CacheFactoryBean.class);
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&cache-with-auto-reconnect-enabled", CacheFactoryBean.class);
|
||||
|
||||
assertTrue(cacheFactoryBean.getEnableAutoReconnect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeapTunedCache() throws Exception {
|
||||
assertTrue(context.containsBean("heap-tuned-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&heap-tuned-cache", CacheFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("heap-tuned-cache"));
|
||||
|
||||
Float criticalHeapPercentage = TestUtils.readField("criticalHeapPercentage", cacheFactoryBean);
|
||||
Float evictionHeapPercentage = TestUtils.readField("evictionHeapPercentage", cacheFactoryBean);
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
Float evictionHeapPercentage = cacheFactoryBean.getEvictionHeapPercentage();
|
||||
|
||||
assertEquals(70.0f, criticalHeapPercentage, 0.0001);
|
||||
assertEquals(60.0f, evictionHeapPercentage, 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffHeapTunedCache() throws Exception {
|
||||
|
||||
assertTrue(applicationContext.containsBean("off-heap-tuned-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = applicationContext.getBean("&off-heap-tuned-cache", CacheFactoryBean.class);
|
||||
|
||||
Float criticalOffHeapPercentage = cacheFactoryBean.getCriticalOffHeapPercentage();
|
||||
Float evictionOffHeapPercentage = cacheFactoryBean.getEvictionOffHeapPercentage();
|
||||
|
||||
assertEquals(90.0f, criticalOffHeapPercentage, 0.0001);
|
||||
assertEquals(50.0f, evictionOffHeapPercentage, 0.0001);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testNoBeanFactoryLocator() throws Exception {
|
||||
assertTrue(context.containsBean("no-bean-factory-locator-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean = context.getBean("&no-bean-factory-locator-cache", CacheFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("no-bean-factory-locator-cache"));
|
||||
|
||||
CacheFactoryBean cacheFactoryBean =
|
||||
applicationContext.getBean("&no-bean-factory-locator-cache", CacheFactoryBean.class);
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(cacheFactoryBean, "beanFactoryLocator"), is(nullValue()));
|
||||
|
||||
@@ -179,9 +213,11 @@ public class CacheNamespaceTest{
|
||||
|
||||
@Test
|
||||
public void namedClientCacheWithNoProperties() throws Exception {
|
||||
assertTrue(context.containsBean("client-cache-with-name"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = context.getBean("&client-cache-with-name", ClientCacheFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("client-cache-with-name"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
applicationContext.getBean("&client-cache-with-name", ClientCacheFactoryBean.class);
|
||||
|
||||
assertNull(TestUtils.readField("cacheXml", clientCacheFactoryBean));
|
||||
|
||||
@@ -193,9 +229,12 @@ public class CacheNamespaceTest{
|
||||
|
||||
@Test
|
||||
public void clientCacheWithXmlNoProperties() throws Exception {
|
||||
assertTrue(context.containsBean("client-cache-with-xml"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = context.getBean("&client-cache-with-xml", ClientCacheFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("client-cache-with-xml"));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean =
|
||||
applicationContext.getBean("&client-cache-with-xml", ClientCacheFactoryBean.class);
|
||||
|
||||
Resource cacheXmlResource = TestUtils.readField("cacheXml", clientCacheFactoryBean);
|
||||
|
||||
assertEquals("gemfire-client-cache.xml", cacheXmlResource.getFilename());
|
||||
@@ -207,6 +246,7 @@ public class CacheNamespaceTest{
|
||||
}
|
||||
|
||||
public static class TestGatewayConflictResolver implements GatewayConflictResolver {
|
||||
|
||||
@Override
|
||||
public void onEvent(TimestampedEntryEvent arg0, GatewayConflictHelper arg1) {
|
||||
throw new UnsupportedOperationException("Not Implemented!");
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.data.gemfire.SimpleCacheListener;
|
||||
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;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -53,19 +53,19 @@ import org.springframework.util.ObjectUtils;
|
||||
* @see org.springframework.data.gemfire.LocalRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.LocalRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations="local-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
public class LocalRegionNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testSimpleLocalRegion() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
|
||||
Region<?, ?> simple = context.getBean("simple", Region.class);
|
||||
assertTrue(applicationContext.containsBean("simple"));
|
||||
|
||||
Region<?, ?> simple = applicationContext.getBean("simple", Region.class);
|
||||
|
||||
assertNotNull("The 'simple' Region was not properly configured or initialized!", simple);
|
||||
assertEquals("simple", simple.getName());
|
||||
@@ -77,9 +77,10 @@ public class LocalRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public void testPublisherLocalRegion() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
|
||||
RegionFactoryBean publisherRegionFactoryBean = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("pub"));
|
||||
|
||||
RegionFactoryBean publisherRegionFactoryBean = applicationContext.getBean("&pub", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(publisherRegionFactoryBean);
|
||||
assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", publisherRegionFactoryBean));
|
||||
@@ -95,9 +96,10 @@ public class LocalRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexLocal() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
|
||||
RegionFactoryBean complexRegionFactoryBean = context.getBean("&complex", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("complex"));
|
||||
|
||||
RegionFactoryBean complexRegionFactoryBean = applicationContext.getBean("&complex", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(complexRegionFactoryBean);
|
||||
|
||||
@@ -105,19 +107,20 @@ public class LocalRegionNamespaceTest {
|
||||
|
||||
assertFalse(ObjectUtils.isEmpty(cacheListeners));
|
||||
assertEquals(2, cacheListeners.length);
|
||||
assertSame(context.getBean("c-listener"), cacheListeners[0]);
|
||||
assertSame(applicationContext.getBean("c-listener"), cacheListeners[0]);
|
||||
assertTrue(cacheListeners[1] instanceof SimpleCacheListener);
|
||||
assertNotSame(cacheListeners[0], cacheListeners[1]);
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
assertSame(applicationContext.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(applicationContext.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testLocalWithAttributes() throws Exception {
|
||||
assertTrue(context.containsBean("local-with-attributes"));
|
||||
|
||||
Region region = context.getBean("local-with-attributes", Region.class);
|
||||
assertTrue(applicationContext.containsBean("local-with-attributes"));
|
||||
|
||||
Region region = applicationContext.getBean("local-with-attributes", Region.class);
|
||||
|
||||
assertNotNull("The 'local-with-attributes' Region was not properly configured and initialized!", region);
|
||||
assertEquals("local-with-attributes", region.getName());
|
||||
@@ -132,27 +135,28 @@ public class LocalRegionNamespaceTest {
|
||||
assertEquals(10, localRegionAttributes.getInitialCapacity());
|
||||
assertEquals(String.class, localRegionAttributes.getKeyConstraint());
|
||||
assertEquals("0.9", String.valueOf(localRegionAttributes.getLoadFactor()));
|
||||
assertTrue(localRegionAttributes.getOffHeap());
|
||||
assertEquals(String.class, localRegionAttributes.getValueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testRegionLookup() throws Exception {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
Cache cache = applicationContext.getBean(Cache.class);
|
||||
Region existing = cache.createRegionFactory().create("existing");
|
||||
|
||||
assertTrue(context.containsBean("lookup"));
|
||||
assertTrue(applicationContext.containsBean("lookup"));
|
||||
|
||||
RegionLookupFactoryBean localRegionFactoryBean = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
RegionLookupFactoryBean localRegionFactoryBean = applicationContext.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
|
||||
assertEquals("existing", TestUtils.readField("name", localRegionFactoryBean));
|
||||
assertSame(existing, context.getBean("lookup"));
|
||||
assertSame(existing, applicationContext.getBean("lookup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testLocalPersistent() {
|
||||
Region persistentLocalRegion = context.getBean("persistent", Region.class);
|
||||
Region persistentLocalRegion = applicationContext.getBean("persistent", Region.class);
|
||||
|
||||
assertNotNull("The 'persistent' Local Region was not properly configured and initialized!", persistentLocalRegion);
|
||||
assertEquals("persistent", persistentLocalRegion.getName());
|
||||
@@ -166,9 +170,9 @@ public class LocalRegionNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testCompressedLocalRegion() {
|
||||
assertTrue(context.containsBean("Compressed"));
|
||||
assertTrue(applicationContext.containsBean("Compressed"));
|
||||
|
||||
Region<?, ?> compressed = context.getBean("Compressed", Region.class);
|
||||
Region<?, ?> compressed = applicationContext.getBean("Compressed", Region.class);
|
||||
|
||||
assertNotNull("The 'Compressed' Local Region was not properly configured and initialized!", compressed);
|
||||
assertEquals("Compressed", compressed.getName());
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.springframework.data.gemfire.SimplePartitionResolver;
|
||||
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;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -58,19 +58,20 @@ import org.springframework.util.ObjectUtils;
|
||||
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.xml.PartitionedRegionParser
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(locations = "partitioned-ns.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class PartitionedRegionNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testSimplePartitionRegion() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
|
||||
Region<?, ?> simple = context.getBean("simple", Region.class);
|
||||
assertTrue(applicationContext.containsBean("simple"));
|
||||
|
||||
Region<?, ?> simple = applicationContext.getBean("simple", Region.class);
|
||||
|
||||
assertNotNull(simple);
|
||||
assertEquals("simple", simple.getName());
|
||||
@@ -82,9 +83,10 @@ public class PartitionedRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testOptionsPartitionRegion() throws Exception {
|
||||
assertTrue(context.containsBean("options"));
|
||||
|
||||
RegionFactoryBean optionsRegionFactoryBean = context.getBean("&options", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("options"));
|
||||
|
||||
RegionFactoryBean optionsRegionFactoryBean = applicationContext.getBean("&options", RegionFactoryBean.class);
|
||||
|
||||
assertTrue(optionsRegionFactoryBean instanceof PartitionedRegionFactoryBean);
|
||||
assertEquals(null, TestUtils.readField("scope", optionsRegionFactoryBean));
|
||||
@@ -93,6 +95,7 @@ public class PartitionedRegionNamespaceTest {
|
||||
RegionAttributes optionsRegionAttributes = TestUtils.readField("attributes", optionsRegionFactoryBean);
|
||||
|
||||
assertNotNull(optionsRegionAttributes);
|
||||
assertTrue(optionsRegionAttributes.getOffHeap());
|
||||
assertTrue(optionsRegionAttributes.getStatisticsEnabled());
|
||||
|
||||
PartitionAttributes optionsRegionPartitionAttributes = optionsRegionAttributes.getPartitionAttributes();
|
||||
@@ -106,19 +109,20 @@ public class PartitionedRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexPartitionRegion() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
|
||||
RegionFactoryBean complexRegionFactoryBean = context.getBean("&complex", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("complex"));
|
||||
|
||||
RegionFactoryBean complexRegionFactoryBean = applicationContext.getBean("&complex", RegionFactoryBean.class);
|
||||
|
||||
CacheListener[] cacheListeners = TestUtils.readField("cacheListeners", complexRegionFactoryBean);
|
||||
|
||||
assertFalse(ObjectUtils.isEmpty(cacheListeners));
|
||||
assertEquals(2, cacheListeners.length);
|
||||
assertSame(cacheListeners[0], context.getBean("c-listener"));
|
||||
assertSame(cacheListeners[0], applicationContext.getBean("c-listener"));
|
||||
assertTrue(cacheListeners[1] instanceof SimpleCacheListener);
|
||||
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
assertSame(applicationContext.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(applicationContext.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
|
||||
RegionAttributes complexRegionAttributes = TestUtils.readField("attributes", complexRegionFactoryBean);
|
||||
|
||||
@@ -135,9 +139,10 @@ public class PartitionedRegionNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testCompressedPartitionRegion() {
|
||||
assertTrue(context.containsBean("compressed"));
|
||||
|
||||
Region<?, ?> compressed = context.getBean("compressed", Region.class);
|
||||
assertTrue(applicationContext.containsBean("compressed"));
|
||||
|
||||
Region<?, ?> compressed = applicationContext.getBean("compressed", Region.class);
|
||||
|
||||
assertNotNull("The 'compressed' PARTITION Region was not properly configured and initialized!", compressed);
|
||||
assertEquals("compressed", compressed.getName());
|
||||
@@ -151,7 +156,8 @@ public class PartitionedRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testFixedPartitionRegion() throws Exception {
|
||||
RegionFactoryBean fixedRegionFactoryBean = context.getBean("&fixed", RegionFactoryBean.class);
|
||||
|
||||
RegionFactoryBean fixedRegionFactoryBean = applicationContext.getBean("&fixed", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(fixedRegionFactoryBean);
|
||||
|
||||
@@ -175,9 +181,10 @@ public class PartitionedRegionNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testMultiplePartitionListeners() {
|
||||
assertTrue(context.containsBean("listeners"));
|
||||
|
||||
Region<?, ?> listeners = context.getBean("listeners", Region.class);
|
||||
assertTrue(applicationContext.containsBean("listeners"));
|
||||
|
||||
Region<?, ?> listeners = applicationContext.getBean("listeners", Region.class);
|
||||
|
||||
assertNotNull("The 'listeners' PARTITION Region was not properly configured and initialized!", listeners);
|
||||
assertEquals("listeners", listeners.getName());
|
||||
@@ -201,9 +208,10 @@ public class PartitionedRegionNamespaceTest {
|
||||
|
||||
@Test
|
||||
public void testSinglePartitionListeners() {
|
||||
assertTrue(context.containsBean("listenerRef"));
|
||||
|
||||
Region<?, ?> listeners = context.getBean("listenerRef", Region.class);
|
||||
assertTrue(applicationContext.containsBean("listenerRef"));
|
||||
|
||||
Region<?, ?> listeners = applicationContext.getBean("listenerRef", Region.class);
|
||||
|
||||
assertNotNull("The 'listenerRef' PARTITION Region was not properly configured and initialized!", listeners);
|
||||
assertEquals("listenerRef", listeners.getName());
|
||||
|
||||
@@ -61,13 +61,14 @@ import org.springframework.util.ObjectUtils;
|
||||
public class ReplicatedRegionNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void testSimpleReplicateRegion() throws Exception {
|
||||
assertTrue(context.containsBean("simple"));
|
||||
|
||||
RegionFactoryBean simpleRegionFactoryBean = context.getBean("&simple", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("simple"));
|
||||
|
||||
RegionFactoryBean simpleRegionFactoryBean = applicationContext.getBean("&simple", RegionFactoryBean.class);
|
||||
|
||||
assertEquals("simple", TestUtils.readField("beanName", simpleRegionFactoryBean));
|
||||
assertEquals(false, TestUtils.readField("close", simpleRegionFactoryBean));
|
||||
@@ -83,9 +84,10 @@ public class ReplicatedRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public void testPublishReplicateRegion() throws Exception {
|
||||
assertTrue(context.containsBean("pub"));
|
||||
|
||||
RegionFactoryBean publisherRegionFactoryBean = context.getBean("&pub", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("pub"));
|
||||
|
||||
RegionFactoryBean publisherRegionFactoryBean = applicationContext.getBean("&pub", RegionFactoryBean.class);
|
||||
|
||||
assertTrue(publisherRegionFactoryBean instanceof ReplicatedRegionFactoryBean);
|
||||
assertEquals("publisher", TestUtils.readField("name", publisherRegionFactoryBean));
|
||||
@@ -100,9 +102,10 @@ public class ReplicatedRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testComplexReplicateRegion() throws Exception {
|
||||
assertTrue(context.containsBean("complex"));
|
||||
|
||||
RegionFactoryBean complexRegionFactoryBean = context.getBean("&complex", RegionFactoryBean.class);
|
||||
assertTrue(applicationContext.containsBean("complex"));
|
||||
|
||||
RegionFactoryBean complexRegionFactoryBean = applicationContext.getBean("&complex", RegionFactoryBean.class);
|
||||
|
||||
assertNotNull(complexRegionFactoryBean);
|
||||
assertEquals("complex", TestUtils.readField("beanName", complexRegionFactoryBean));
|
||||
@@ -111,19 +114,20 @@ public class ReplicatedRegionNamespaceTest {
|
||||
|
||||
assertFalse(ObjectUtils.isEmpty(cacheListeners));
|
||||
assertEquals(2, cacheListeners.length);
|
||||
assertSame(context.getBean("c-listener"), cacheListeners[0]);
|
||||
assertSame(applicationContext.getBean("c-listener"), cacheListeners[0]);
|
||||
assertTrue(cacheListeners[1] instanceof SimpleCacheListener);
|
||||
assertNotSame(cacheListeners[0], cacheListeners[1]);
|
||||
assertSame(context.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
assertSame(applicationContext.getBean("c-loader"), TestUtils.readField("cacheLoader", complexRegionFactoryBean));
|
||||
assertSame(applicationContext.getBean("c-writer"), TestUtils.readField("cacheWriter", complexRegionFactoryBean));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testReplicatedRegionWithAttributes() throws Exception {
|
||||
assertTrue(context.containsBean("replicated-with-attributes"));
|
||||
|
||||
Region region = context.getBean("replicated-with-attributes", Region.class);
|
||||
assertTrue(applicationContext.containsBean("replicated-with-attributes"));
|
||||
|
||||
Region region = applicationContext.getBean("replicated-with-attributes", Region.class);
|
||||
|
||||
assertNotNull("The 'replicated-with-attributes' Region was not properly configured and initialized!", region);
|
||||
|
||||
@@ -142,15 +146,17 @@ public class ReplicatedRegionNamespaceTest {
|
||||
assertEquals(0.50, regionAttributes.getLoadFactor(), 0.001);
|
||||
assertTrue(regionAttributes.isLockGrantor());
|
||||
assertTrue(regionAttributes.getMulticastEnabled());
|
||||
assertTrue(regionAttributes.getOffHeap());
|
||||
assertEquals(Scope.GLOBAL, regionAttributes.getScope());
|
||||
assertEquals(String.class, regionAttributes.getValueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplicatedWithSynchronousIndexUpdates() {
|
||||
assertTrue(context.containsBean("replicated-with-synchronous-index-updates"));
|
||||
|
||||
Region region = context.getBean("replicated-with-synchronous-index-updates", Region.class);
|
||||
assertTrue(applicationContext.containsBean("replicated-with-synchronous-index-updates"));
|
||||
|
||||
Region region = applicationContext.getBean("replicated-with-synchronous-index-updates", Region.class);
|
||||
|
||||
assertNotNull(String.format("The '%1$s' Region was not properly configured and initialized!",
|
||||
"replicated-with-synchronous-index-updates"), region);
|
||||
@@ -164,23 +170,26 @@ public class ReplicatedRegionNamespaceTest {
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testRegionLookup() throws Exception {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
|
||||
Cache cache = applicationContext.getBean(Cache.class);
|
||||
|
||||
Region existing = cache.createRegionFactory().create("existing");
|
||||
|
||||
assertTrue(context.containsBean("lookup"));
|
||||
assertTrue(applicationContext.containsBean("lookup"));
|
||||
|
||||
RegionLookupFactoryBean regionLookupFactoryBean = context.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
RegionLookupFactoryBean regionLookupFactoryBean = applicationContext.getBean("&lookup", RegionLookupFactoryBean.class);
|
||||
|
||||
assertNotNull(regionLookupFactoryBean);
|
||||
assertEquals("existing", TestUtils.readField("name", regionLookupFactoryBean));
|
||||
assertSame(existing, context.getBean("lookup"));
|
||||
assertSame(existing, applicationContext.getBean("lookup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompressedReplicateRegion() {
|
||||
assertTrue(context.containsBean("Compressed"));
|
||||
|
||||
Region<?, ?> compressed = context.getBean("Compressed", Region.class);
|
||||
assertTrue(applicationContext.containsBean("Compressed"));
|
||||
|
||||
Region<?, ?> compressed = applicationContext.getBean("Compressed", Region.class);
|
||||
|
||||
assertNotNull("The 'Compressed' REPLICATE Region was not properly configured and initialized!", compressed);
|
||||
assertEquals("Compressed", compressed.getName());
|
||||
|
||||
@@ -38,9 +38,11 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
setClose(it.isClose());
|
||||
setCopyOnRead(it.getCopyOnRead());
|
||||
setCriticalHeapPercentage(it.getCriticalHeapPercentage());
|
||||
setCriticalOffHeapPercentage(it.getCriticalOffHeapPercentage());
|
||||
setDynamicRegionSupport(it.getDynamicRegionSupport());
|
||||
setEnableAutoReconnect(it.getEnableAutoReconnect());
|
||||
setEvictionHeapPercentage(it.getEvictionHeapPercentage());
|
||||
setEvictionOffHeapPercentage(it.getEvictionOffHeapPercentage());
|
||||
setGatewayConflictResolver(it.getGatewayConflictResolver());
|
||||
setJndiDataSources(it.getJndiDataSources());
|
||||
setLockLease(it.getLockLease());
|
||||
|
||||
Reference in New Issue
Block a user