DATAGEODE-12 - Introduce Spring Configurers to flexibly alter Spring Data GemFire configuration when using Annotation config.

Related JIRA: https://jira.spring.io/browse/SGF-586

Related JIRA: https://jira.spring.io/browse/SGF-604
This commit is contained in:
John Blum
2017-01-17 22:47:08 -08:00
parent 2a021f79b4
commit c22ebe6bd1
81 changed files with 5939 additions and 2426 deletions

View File

@@ -16,12 +16,10 @@
package org.springframework.data.gemfire;
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;
@@ -57,11 +55,13 @@ import org.apache.geode.cache.control.ResourceManager;
import org.apache.geode.cache.util.GatewayConflictResolver;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.Role;
import org.apache.geode.pdx.PdxSerializer;
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.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.io.Resource;
import org.springframework.data.gemfire.support.GemfireBeanFactoryLocator;
@@ -73,13 +73,27 @@ import org.springframework.data.util.ReflectionUtils;
* @author John Blum
* @see org.junit.Rule
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.mockito.junit.MockitoJUnitRunner
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.CacheFactory
* @see org.apache.geode.cache.CacheTransactionManager
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.distributed.DistributedMember
* @see org.apache.geode.distributed.DistributedSystem
* @see org.apache.geode.pdx.PdxSerializer
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.data.gemfire.CacheFactoryBean
* @since 1.7.0
*/
@RunWith(MockitoJUnitRunner.class)
public class CacheFactoryBeanTest {
@Mock
private Cache mockCache;
@Rule
public ExpectedException exception = ExpectedException.none();
@@ -89,7 +103,9 @@ public class CacheFactoryBeanTest {
final Properties gemfireProperties = new Properties();
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
@Override protected void postProcessBeforeCacheInitialization(Properties actualGemfireProperties) {
@Override
protected void postProcessBeforeCacheInitialization(Properties actualGemfireProperties) {
assertThat(actualGemfireProperties, is(sameInstance(gemfireProperties)));
postProcessBeforeCacheInitializationCalled.set(true);
}
@@ -169,7 +185,7 @@ public class CacheFactoryBeanTest {
final AtomicBoolean initCalled = new AtomicBoolean(false);
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean() {
@Override Cache init() throws Exception {
@Override Cache init() {
initCalled.set(true);
return mockCache;
}
@@ -194,6 +210,7 @@ public class CacheFactoryBeanTest {
}
@Test
@SuppressWarnings("deprecation")
public void init() throws Exception {
BeanFactory mockBeanFactory = mock(BeanFactory.class);
Cache mockCache = mock(Cache.class);
@@ -218,8 +235,8 @@ public class CacheFactoryBeanTest {
when(mockDistributedSystem.getDistributedMember()).thenReturn(mockDistributedMember);
when(mockDistributedSystem.getName()).thenReturn("MockDistributedSystem");
when(mockDistributedMember.getId()).thenReturn("MockDistributedMember");
when(mockDistributedMember.getGroups()).thenReturn(Collections.<String>emptyList());
when(mockDistributedMember.getRoles()).thenReturn(Collections.<Role>emptySet());
when(mockDistributedMember.getGroups()).thenReturn(Collections.emptyList());
when(mockDistributedMember.getRoles()).thenReturn(Collections.emptySet());
when(mockDistributedMember.getHost()).thenReturn("skullbox");
when(mockDistributedMember.getProcessId()).thenReturn(12345);
@@ -392,8 +409,7 @@ public class CacheFactoryBeanTest {
public void prepareFactoryWithUnspecifiedPdxOptions() {
CacheFactory mockCacheFactory = mock(CacheFactory.class);
assertThat((CacheFactory) new CacheFactoryBean().prepareFactory(mockCacheFactory),
is(sameInstance(mockCacheFactory)));
assertThat(new CacheFactoryBean().prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
verify(mockCacheFactory, never()).setPdxIgnoreUnreadFields(any(Boolean.class));
@@ -412,8 +428,7 @@ public class CacheFactoryBeanTest {
CacheFactory mockCacheFactory = mock(CacheFactory.class);
assertThat((CacheFactory) cacheFactoryBean.prepareFactory(mockCacheFactory),
is(sameInstance(mockCacheFactory)));
assertThat(cacheFactoryBean.prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
verify(mockCacheFactory, never()).setPdxDiskStore(any(String.class));
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
@@ -434,8 +449,7 @@ public class CacheFactoryBeanTest {
CacheFactory mockCacheFactory = mock(CacheFactory.class);
assertThat((CacheFactory) cacheFactoryBean.prepareFactory(mockCacheFactory),
is(sameInstance(mockCacheFactory)));
assertThat(cacheFactoryBean.prepareFactory(mockCacheFactory), is(sameInstance(mockCacheFactory)));
verify(mockCacheFactory, times(1)).setPdxDiskStore(eq("testPdxDiskStoreName"));
verify(mockCacheFactory, times(1)).setPdxIgnoreUnreadFields(eq(false));
@@ -444,52 +458,25 @@ public class CacheFactoryBeanTest {
verify(mockCacheFactory, times(1)).setPdxSerializer(any(PdxSerializer.class));
}
@Test
public void prepareFactoryWithInvalidTypeForPdxSerializer() {
CacheFactory mockCacheFactory = mock(CacheFactory.class);
Object pdxSerializer = new Object();
try {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
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);
}
finally {
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));
}
}
@Test
public void createCacheWithExistingCache() throws Exception {
Cache mockCache = mock(Cache.class);
CacheFactory mockCacheFactory = mock(CacheFactory.class);
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.setCache(mockCache);
Cache actualCache = cacheFactoryBean.createCache(null);
assertThat(cacheFactoryBean.getCache(), is(sameInstance(mockCache)));
Cache actualCache = cacheFactoryBean.createCache(mockCacheFactory);
assertThat(actualCache, is(sameInstance(mockCache)));
verify(mockCacheFactory, never()).create();
verifyZeroInteractions(mockCache);
}
@Test
public void createCacheWithNoExistingCache() {
Cache mockCache = mock(Cache.class);
CacheFactory mockCacheFactory = mock(CacheFactory.class);
when(mockCacheFactory.create()).thenReturn(mockCache);
@@ -510,13 +497,17 @@ public class CacheFactoryBeanTest {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.setCriticalHeapPercentage(200.0f);
cacheFactoryBean.postProcess(null);
cacheFactoryBean.postProcess(mockCache);
}
catch (IllegalArgumentException expected) {
assertEquals("'criticalHeapPercentage' (200.0) is invalid; 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)
@@ -525,19 +516,23 @@ public class CacheFactoryBeanTest {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
cacheFactoryBean.setEvictionHeapPercentage(-75.0f);
cacheFactoryBean.postProcess(null);
cacheFactoryBean.postProcess(mockCache);
}
catch (IllegalArgumentException expected) {
assertEquals("'evictionHeapPercentage' (-75.0) is invalid; 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
@SuppressWarnings("unchecked")
public void getObjectType() {
assertThat((Class<Cache>) new CacheFactoryBean().getObjectType(), is(equalTo(Cache.class)));
assertThat(new CacheFactoryBean().getObjectType(), is(equalTo(Cache.class)));
}
@Test
@@ -686,10 +681,10 @@ public class CacheFactoryBeanTest {
assertTrue(Boolean.FALSE.equals(TestUtils.readField("useBeanFactoryLocator", cacheFactoryBean)));
assertTrue(Boolean.FALSE.equals(TestUtils.readField("close", cacheFactoryBean)));
assertTrue(cacheFactoryBean.getCopyOnRead());
assertEquals(0.95f, cacheFactoryBean.getCriticalHeapPercentage().floatValue(), 0.0f);
assertEquals(0.95f, cacheFactoryBean.getCriticalHeapPercentage(), 0.0f);
assertNotNull(cacheFactoryBean.getDynamicRegionSupport());
assertTrue(cacheFactoryBean.getEnableAutoReconnect());
assertEquals(0.70f, cacheFactoryBean.getEvictionHeapPercentage().floatValue(), 0.0f);
assertEquals(0.70f, cacheFactoryBean.getEvictionHeapPercentage(), 0.0f);
assertSame(mockGatewayConflictResolver, cacheFactoryBean.getGatewayConflictResolver());
assertNotNull(cacheFactoryBean.getJndiDataSources());
assertEquals(1, cacheFactoryBean.getJndiDataSources().size());

View File

@@ -22,11 +22,11 @@ import org.junit.Before;
import org.junit.Test;
/**
* The DiskStoreFactoryBeanTest class is a test suite of test cases testing the contract and functionality of the
* DiskStoreFactoryBean class.
* Unit tests for {@link DiskStoreFactoryBean}.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.DiskStore
* @see org.springframework.data.gemfire.DiskStoreFactoryBean
* @since 1.3.4
*/
@@ -58,7 +58,7 @@ public class DiskStoreFactoryBeanTest {
}
catch (IllegalArgumentException expected) {
assertEquals(String.format("The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
factoryBean.getName(), -1), expected.getMessage());
factoryBean.resolveDiskStoreName(), -1), expected.getMessage());
throw expected;
}
}
@@ -70,7 +70,7 @@ public class DiskStoreFactoryBeanTest {
}
catch (IllegalArgumentException expected) {
assertEquals(String.format("The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
factoryBean.getName(), 101), expected.getMessage());
factoryBean.resolveDiskStoreName(), 101), expected.getMessage());
throw expected;
}
}
@@ -88,7 +88,7 @@ public class DiskStoreFactoryBeanTest {
catch (IllegalArgumentException expected) {
assertEquals(String.format(
"The DiskStore's (%1$s) compaction threshold (%2$d) must be an integer value between 0 and 100 inclusive.",
factoryBean.getName(), 200), expected.getMessage());
factoryBean.resolveDiskStoreName(), 200), expected.getMessage());
throw expected;
}
}
@@ -99,9 +99,8 @@ public class DiskStoreFactoryBeanTest {
factoryBean.afterPropertiesSet();
}
catch (IllegalStateException expected) {
assertEquals("A reference to the GemFire Cache must be set for Disk Store 'testDiskStore'.", expected.getMessage());
assertEquals("Cache is required to create DiskStore [testDiskStore]", expected.getMessage());
throw expected;
}
}
}

View File

@@ -22,10 +22,24 @@ import static org.hamcrest.CoreMatchers.isA;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
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.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doAnswer;
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.ArrayList;
import java.util.Arrays;
@@ -55,16 +69,14 @@ import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.util.ReflectionUtils;
/**
* The IndexFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the IndexFactoryBean class.
* Unit tests for {@link IndexFactoryBean}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.client.ClientCache
* @see org.apache.geode.cache.query.Index
* @see org.apache.geode.cache.query.QueryService
* @see org.springframework.data.gemfire.IndexFactoryBean
* @since 1.5.2
*/
public class IndexFactoryBeanTest {
@@ -136,10 +148,12 @@ public class IndexFactoryBeanTest {
@Test(expected = IllegalArgumentException.class)
public void afterPropertiesSetWithNullCache() throws Exception {
try {
new IndexFactoryBean().afterPropertiesSet();
IndexFactoryBean indexFactoryBean = new IndexFactoryBean();
indexFactoryBean.setName("TestIndex");
indexFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("The GemFire Cache reference must not be null!", expected.getMessage());
assertEquals("Cache is required", expected.getMessage());
throw expected;
}
}
@@ -154,6 +168,7 @@ public class IndexFactoryBeanTest {
};
indexFactoryBean.setCache(mockCache);
indexFactoryBean.setName("TestIndex");
indexFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
@@ -165,10 +180,12 @@ public class IndexFactoryBeanTest {
@Test(expected = IllegalArgumentException.class)
public void afterPropertiesSetWithUnspecifiedExpression() throws Exception {
try {
newIndexFactoryBean().afterPropertiesSet();
IndexFactoryBean indexFactoryBean = newIndexFactoryBean();
indexFactoryBean.setName("TestIndex");
indexFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("Index 'expression' is required", expected.getMessage());
assertEquals("Index expression is required", expected.getMessage());
throw expected;
}
}
@@ -177,11 +194,12 @@ public class IndexFactoryBeanTest {
public void afterPropertiesSetWithUnspecifiedFromClause() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectCause(is(nullValue(Throwable.class)));
expectedException.expectMessage("Index 'from clause' is required");
expectedException.expectMessage("Index from clause is required");
IndexFactoryBean indexFactoryBean = newIndexFactoryBean();
indexFactoryBean.setExpression("id");
indexFactoryBean.setName("TestIndex");
indexFactoryBean.afterPropertiesSet();
}
@@ -194,7 +212,7 @@ public class IndexFactoryBeanTest {
indexFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("Index 'name' is required", expected.getMessage());
assertEquals("Index name is required", expected.getMessage());
throw expected;
}
}
@@ -211,7 +229,7 @@ public class IndexFactoryBeanTest {
indexFactoryBean.afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("'imports' are not supported with a KEY Index", expected.getMessage());
assertEquals("imports are not supported with a KEY Index", expected.getMessage());
throw expected;
}
}
@@ -1076,5 +1094,4 @@ public class IndexFactoryBeanTest {
throw expected;
}
}
}

View File

@@ -169,7 +169,7 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "PARTITION");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'PARTITION' is invalid when persistent is true.", e.getMessage());
assertEquals("Data Policy [PARTITION] is invalid when persistent is true.", e.getMessage());
throw e;
}
finally {
@@ -195,7 +195,7 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, false, "PERSISTENT_PARTITION");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'PERSISTENT_PARTITION' is invalid when persistent is false.", e.getMessage());
assertEquals("Data Policy [PERSISTENT_PARTITION] is invalid when persistent is false.", e.getMessage());
throw e;
}
finally {
@@ -212,5 +212,4 @@ public class PartitionedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "PERSISTENT_PARTITION");
verify(mockRegionFactory).setDataPolicy(eq(DataPolicy.PERSISTENT_PARTITION));
}
}

View File

@@ -57,12 +57,10 @@ import org.springframework.data.gemfire.test.support.AbstractRegionFactoryBeanTe
import org.springframework.data.gemfire.util.ArrayUtils;
/**
* The RegionFactoryBeanTest class is a test suite of test cases testing the contract and functionality of the
* RegionFactoryBean class.
* Unit tests for {@link RegionFactoryBean}.
*
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.RegionFactoryBean
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.DataPolicy
* @see org.apache.geode.cache.PartitionAttributes
@@ -70,6 +68,8 @@ import org.springframework.data.gemfire.util.ArrayUtils;
* @see org.apache.geode.cache.RegionAttributes
* @see org.apache.geode.cache.RegionFactory
* @see org.apache.geode.cache.RegionShortcut
* @see org.springframework.data.gemfire.RegionFactoryBean
* @see org.springframework.data.gemfire.test.support.AbstractRegionFactoryBeanTests
*/
@SuppressWarnings("unchecked")
public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
@@ -125,7 +125,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
@Override
public void verify() {
assertNotNull(this.exception);
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false.",
assertEquals("Data Policy [PERSISTENT_REPLICATE] is invalid when persistent is false.",
exception.getMessage());
}
};
@@ -195,7 +195,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.REPLICATE);
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'REPLICATE' is invalid when persistent is true.", expected.getMessage());
assertEquals("Data Policy [REPLICATE] is invalid when persistent is true.", expected.getMessage());
throw expected;
}
}
@@ -208,7 +208,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.assertDataPolicyAndPersistentAttributesAreCompatible(DataPolicy.PERSISTENT_PARTITION);
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_PARTITION' is invalid when persistent is false.",
assertEquals("Data Policy [PERSISTENT_PARTITION] is invalid when persistent is false.",
expected.getMessage());
throw expected;
}
@@ -724,7 +724,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, true, " ");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy ' ' is invalid.", expected.getMessage());
assertEquals("Data Policy [ ] is invalid.", expected.getMessage());
throw expected;
}
finally {
@@ -743,7 +743,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy '' is invalid.", expected.getMessage());
assertEquals("Data Policy [] is invalid.", expected.getMessage());
throw expected;
}
finally {
@@ -762,7 +762,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "CSV");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'CSV' is invalid.", expected.getMessage());
assertEquals("Data Policy [CSV] is invalid.", expected.getMessage());
throw expected;
}
finally {
@@ -796,7 +796,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "EMPTY");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'EMPTY' is invalid when persistent is true.", expected.getMessage());
assertEquals("Data Policy [EMPTY] is invalid when persistent is true.", expected.getMessage());
throw expected;
}
finally {
@@ -830,7 +830,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, false, "PERSISTENT_PARTITION");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_PARTITION' is invalid when persistent is false.", expected.getMessage());
assertEquals("Data Policy [PERSISTENT_PARTITION] is invalid when persistent is false.", expected.getMessage());
throw expected;
}
finally {
@@ -852,7 +852,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
"Setting the 'persistent' attribute to TRUE and 'Data Policy' to PARTITION should have thrown an IllegalArgumentException!");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PARTITION' is invalid when persistent is true.", expected.getMessage());
assertEquals("Data Policy [PARTITION] is invalid when persistent is true.", expected.getMessage());
throw expected;
}
finally {
@@ -922,7 +922,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, false, (String) null);
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_PARTITION' is invalid when persistent is false.", expected.getMessage());
assertEquals("Data Policy [PERSISTENT_PARTITION] is invalid when persistent is false.", expected.getMessage());
throw expected;
}
finally {
@@ -943,7 +943,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
factoryBean.resolveDataPolicy(mockRegionFactory, true, (String) null);
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PARTITION' is invalid when persistent is true.", expected.getMessage());
assertEquals("Data Policy [PARTITION] is invalid when persistent is true.", expected.getMessage());
throw expected;
}
finally {
@@ -1005,7 +1005,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
fail("Setting the 'persistent' attribute to FALSE and 'Data Policy' to PERSISTENT_REPLICATE should have thrown an IllegalArgumentException!");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false.", expected.getMessage());
assertEquals("Data Policy [PERSISTENT_REPLICATE] is invalid when persistent is false.", expected.getMessage());
throw expected;
}
finally {
@@ -1026,7 +1026,7 @@ public class RegionFactoryBeanTest extends AbstractRegionFactoryBeanTests {
fail("Setting the 'persistent' attribute to TRUE and 'Data Policy' to REPLICATE should have thrown an IllegalArgumentException!");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'REPLICATE' is invalid when persistent is true.", expected.getMessage());
assertEquals("Data Policy [REPLICATE] is invalid when persistent is true.", expected.getMessage());
throw expected;
}
finally {

View File

@@ -168,7 +168,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "empty");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'EMPTY' is invalid when persistent is true.", e.getMessage());
assertEquals("Data Policy [EMPTY] is invalid when persistent is true.", e.getMessage());
throw e;
}
finally {
@@ -202,7 +202,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "REPLICATE");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'REPLICATE' is invalid when persistent is true.", e.getMessage());
assertEquals("Data Policy [REPLICATE] is invalid when persistent is true.", e.getMessage());
throw e;
}
finally {
@@ -228,7 +228,7 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, false, "PERSISTENT_REPLICATE");
}
catch (IllegalArgumentException e) {
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false.", e.getMessage());
assertEquals("Data Policy [PERSISTENT_REPLICATE] is invalid when persistent is false.", e.getMessage());
throw e;
}
finally {
@@ -245,5 +245,4 @@ public class ReplicatedRegionFactoryBeanTest {
factoryBean.resolveDataPolicy(mockRegionFactory, true, "PERSISTENT_REPLICATE");
verify(mockRegionFactory).setDataPolicy(eq(DataPolicy.PERSISTENT_REPLICATE));
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.gemfire.client;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
@@ -42,6 +41,7 @@ import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -65,15 +65,21 @@ import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.data.gemfire.util.DistributedSystemUtils;
/**
* The ClientCacheFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the SDG ClientCacheFactoryBean class.
* Unit tests for {@link ClientCacheFactoryBean}
*
* @author John Blum
* @see org.mockito.Mockito
* @see java.net.InetSocketAddress
* @see org.junit.Rule
* @see org.junit.Test
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
* @see org.mockito.Mockito
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.client.ClientCache
* @see org.apache.geode.cache.client.ClientCacheFactory
* @see org.apache.geode.cache.client.Pool
* @see org.apache.geode.distributed.DistributedSystem
* @see org.apache.geode.pdx.PdxSerializer
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
* @since 1.7.0
*/
public class ClientCacheFactoryBeanTest {
@@ -81,24 +87,25 @@ public class ClientCacheFactoryBeanTest {
@Rule
public ExpectedException exception = ExpectedException.none();
protected Properties createProperties(String key, String value) {
private Properties createProperties(String key, String value) {
return addProperty(null, key, value);
}
protected Properties addProperty(Properties properties, String key, String value) {
properties = (properties != null ? properties : new Properties());
@SuppressWarnings("all")
private Properties addProperty(Properties properties, String key, String value) {
properties = Optional.ofNullable(properties).orElseGet(Properties::new);
properties.setProperty(key, value);
return properties;
}
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
private ConnectionEndpoint newConnectionEndpoint(String host, int port) {
return new ConnectionEndpoint(host, port);
}
@Test
@SuppressWarnings("unchecked")
public void getObjectType() {
assertThat((Class<ClientCache>) new ClientCacheFactoryBean().getObjectType(), is(equalTo(ClientCache.class)));
assertThat(new ClientCacheFactoryBean().getObjectType(), is(equalTo(ClientCache.class)));
}
@Test
@@ -252,18 +259,21 @@ public class ClientCacheFactoryBeanTest {
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
@Override ClientCacheFactory initializePdx(final ClientCacheFactory clientCacheFactory) {
@Override
ClientCacheFactory initializePdx(ClientCacheFactory clientCacheFactory) {
initializePdxCalled.set(true);
return clientCacheFactory;
}
@Override ClientCacheFactory initializePool(final ClientCacheFactory clientCacheFactory) {
@Override
ClientCacheFactory initializePool(final ClientCacheFactory clientCacheFactory) {
initializePoolCalled.set(true);
return clientCacheFactory;
}
};
assertThat((ClientCacheFactory) clientCacheFactoryBean.prepareFactory(mockClientCacheFactory),
assertThat(clientCacheFactoryBean.prepareFactory(mockClientCacheFactory),
is(sameInstance(mockClientCacheFactory)));
assertThat(initializePdxCalled.get(), is(true));
assertThat(initializePoolCalled.get(), is(true));
@@ -285,7 +295,7 @@ public class ClientCacheFactoryBeanTest {
assertThat(clientCacheFactoryBean.getPdxIgnoreUnreadFields(), is(false));
assertThat(clientCacheFactoryBean.getPdxPersistent(), is(true));
assertThat(clientCacheFactoryBean.getPdxReadSerialized(), is(false));
assertThat((PdxSerializer) clientCacheFactoryBean.getPdxSerializer(), is(sameInstance(mockPdxSerializer)));
assertThat(clientCacheFactoryBean.getPdxSerializer(), is(sameInstance(mockPdxSerializer)));
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
@@ -342,51 +352,19 @@ public class ClientCacheFactoryBeanTest {
verifyZeroInteractions(mockClientCacheFactory);
}
@Test
public void initializePdxUsingIllegalTypeForPdxSerializer() {
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
try {
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
Object pdxSerializer = new Object();
clientCacheFactoryBean.setPdxSerializer(pdxSerializer);
clientCacheFactoryBean.setPdxReadSerialized(false);
clientCacheFactoryBean.setPdxPersistent(true);
clientCacheFactoryBean.setPdxIgnoreUnreadFields(false);
clientCacheFactoryBean.setPdxDiskStoreName("test");
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)));
assertThat(clientCacheFactoryBean.initializePdx(mockClientCacheFactory),
is(sameInstance(mockClientCacheFactory)));
}
finally {
verify(mockClientCacheFactory, never()).setPdxSerializer(any(PdxSerializer.class));
verify(mockClientCacheFactory, never()).setPdxDiskStore(any(String.class));
verify(mockClientCacheFactory, never()).setPdxIgnoreUnreadFields(any(Boolean.class));
verify(mockClientCacheFactory, never()).setPdxPersistent(any(Boolean.class));
verify(mockClientCacheFactory, never()).setPdxReadSerialized(any(Boolean.class));
}
}
@Test
public void initializePoolWithPool() {
Pool mockPool = mock(Pool.class);
when(mockPool.getFreeConnectionTimeout()).thenReturn(10000);
when(mockPool.getIdleTimeout()).thenReturn(120000l);
when(mockPool.getIdleTimeout()).thenReturn(120000L);
when(mockPool.getLoadConditioningInterval()).thenReturn(30000);
when(mockPool.getLocators()).thenReturn(Collections.<InetSocketAddress>emptyList());
when(mockPool.getLocators()).thenReturn(Collections.emptyList());
when(mockPool.getMaxConnections()).thenReturn(100);
when(mockPool.getMinConnections()).thenReturn(10);
when(mockPool.getMultiuserAuthentication()).thenReturn(true);
when(mockPool.getPRSingleHopEnabled()).thenReturn(true);
when(mockPool.getPingInterval()).thenReturn(15000l);
when(mockPool.getPingInterval()).thenReturn(15000L);
when(mockPool.getReadTimeout()).thenReturn(20000);
when(mockPool.getRetryAttempts()).thenReturn(1);
when(mockPool.getServerGroup()).thenReturn("TestGroup");
@@ -453,13 +431,13 @@ public class ClientCacheFactoryBeanTest {
verify(mockPool, times(1)).getSubscriptionRedundancy();
verify(mockPool, times(1)).getThreadLocalConnections();
verify(mockClientCacheFactory, times(1)).setPoolFreeConnectionTimeout(eq(10000));
verify(mockClientCacheFactory, times(1)).setPoolIdleTimeout(eq(120000l));
verify(mockClientCacheFactory, times(1)).setPoolIdleTimeout(eq(120000L));
verify(mockClientCacheFactory, times(1)).setPoolLoadConditioningInterval(eq(30000));
verify(mockClientCacheFactory, times(1)).setPoolMaxConnections(eq(100));
verify(mockClientCacheFactory, times(1)).setPoolMinConnections(eq(10));
verify(mockClientCacheFactory, times(1)).setPoolMultiuserAuthentication(eq(true));
verify(mockClientCacheFactory, times(1)).setPoolPRSingleHopEnabled(eq(true));
verify(mockClientCacheFactory, times(1)).setPoolPingInterval(eq(15000l));
verify(mockClientCacheFactory, times(1)).setPoolPingInterval(eq(15000L));
verify(mockClientCacheFactory, times(1)).setPoolReadTimeout(eq(20000));
verify(mockClientCacheFactory, times(1)).setPoolRetryAttempts(eq(1));
verify(mockClientCacheFactory, times(1)).setPoolServerGroup(eq("TestGroup"));
@@ -482,12 +460,12 @@ public class ClientCacheFactoryBeanTest {
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
clientCacheFactoryBean.setFreeConnectionTimeout(5000);
clientCacheFactoryBean.setIdleTimeout(300000l);
clientCacheFactoryBean.setIdleTimeout(300000L);
clientCacheFactoryBean.setLoadConditioningInterval(120000);
clientCacheFactoryBean.setMaxConnections(99);
clientCacheFactoryBean.setMinConnections(9);
clientCacheFactoryBean.setMultiUserAuthentication(true);
clientCacheFactoryBean.setPingInterval(15000l);
clientCacheFactoryBean.setPingInterval(15000L);
clientCacheFactoryBean.setPool(mockPool);
clientCacheFactoryBean.setPrSingleHopEnabled(true);
clientCacheFactoryBean.setReadTimeout(20000);
@@ -504,13 +482,13 @@ public class ClientCacheFactoryBeanTest {
newConnectionEndpoint("skullbox", 10334));
assertThat(clientCacheFactoryBean.getFreeConnectionTimeout(), is(equalTo(5000)));
assertThat(clientCacheFactoryBean.getIdleTimeout(), is(equalTo(300000l)));
assertThat(clientCacheFactoryBean.getIdleTimeout(), is(equalTo(300000L)));
assertThat(clientCacheFactoryBean.getLoadConditioningInterval(), is(equalTo(120000)));
assertThat(clientCacheFactoryBean.getLocators().size(), is(equalTo(2)));
assertThat(clientCacheFactoryBean.getMaxConnections(), is(equalTo(99)));
assertThat(clientCacheFactoryBean.getMinConnections(), is(equalTo(9)));
assertThat(clientCacheFactoryBean.getMultiUserAuthentication(), is(equalTo(true)));
assertThat(clientCacheFactoryBean.getPingInterval(), is(equalTo(15000l)));
assertThat(clientCacheFactoryBean.getPingInterval(), is(equalTo(15000L)));
assertThat(clientCacheFactoryBean.getPool(), is(sameInstance(mockPool)));
assertThat(clientCacheFactoryBean.getPoolName(), is(nullValue()));
assertThat(clientCacheFactoryBean.getPrSingleHopEnabled(), is(equalTo(true)));
@@ -533,12 +511,12 @@ public class ClientCacheFactoryBeanTest {
verifyZeroInteractions(mockPool);
verify(mockClientCacheFactory, times(1)).setPoolFreeConnectionTimeout(eq(5000));
verify(mockClientCacheFactory, times(1)).setPoolIdleTimeout(eq(300000l));
verify(mockClientCacheFactory, times(1)).setPoolIdleTimeout(eq(300000L));
verify(mockClientCacheFactory, times(1)).setPoolLoadConditioningInterval(eq(120000));
verify(mockClientCacheFactory, times(1)).setPoolMaxConnections(eq(99));
verify(mockClientCacheFactory, times(1)).setPoolMinConnections(eq(9));
verify(mockClientCacheFactory, times(1)).setPoolMultiuserAuthentication(eq(true));
verify(mockClientCacheFactory, times(1)).setPoolPingInterval(eq(15000l));
verify(mockClientCacheFactory, times(1)).setPoolPingInterval(eq(15000L));
verify(mockClientCacheFactory, times(1)).setPoolPRSingleHopEnabled(eq(true));
verify(mockClientCacheFactory, times(1)).setPoolReadTimeout(eq(20000));
verify(mockClientCacheFactory, times(1)).setPoolRetryAttempts(eq(2));
@@ -560,13 +538,13 @@ public class ClientCacheFactoryBeanTest {
Pool mockPool = mock(Pool.class);
when(mockPool.getFreeConnectionTimeout()).thenReturn(5000);
when(mockPool.getIdleTimeout()).thenReturn(120000l);
when(mockPool.getIdleTimeout()).thenReturn(120000L);
when(mockPool.getLoadConditioningInterval()).thenReturn(300000);
when(mockPool.getLocators()).thenReturn(Collections.<InetSocketAddress>emptyList());
when(mockPool.getLocators()).thenReturn(Collections.emptyList());
when(mockPool.getMaxConnections()).thenReturn(200);
when(mockPool.getMinConnections()).thenReturn(10);
when(mockPool.getMultiuserAuthentication()).thenReturn(false);
when(mockPool.getPingInterval()).thenReturn(15000l);
when(mockPool.getPingInterval()).thenReturn(15000L);
when(mockPool.getPRSingleHopEnabled()).thenReturn(false);
when(mockPool.getReadTimeout()).thenReturn(30000);
when(mockPool.getRetryAttempts()).thenReturn(1);
@@ -582,7 +560,7 @@ public class ClientCacheFactoryBeanTest {
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
clientCacheFactoryBean.setIdleTimeout(180000l);
clientCacheFactoryBean.setIdleTimeout(180000L);
clientCacheFactoryBean.setMaxConnections(500);
clientCacheFactoryBean.setMinConnections(50);
clientCacheFactoryBean.setMultiUserAuthentication(true);
@@ -598,7 +576,7 @@ public class ClientCacheFactoryBeanTest {
clientCacheFactoryBean.addLocators(newConnectionEndpoint("localhost", 11235));
assertThat(clientCacheFactoryBean.getFreeConnectionTimeout(), is(nullValue()));
assertThat(clientCacheFactoryBean.getIdleTimeout(), is(equalTo(180000l)));
assertThat(clientCacheFactoryBean.getIdleTimeout(), is(equalTo(180000L)));
assertThat(clientCacheFactoryBean.getLoadConditioningInterval(), is(nullValue()));
assertThat(clientCacheFactoryBean.getLocators().size(), is(equalTo(1)));
assertThat(clientCacheFactoryBean.getMaxConnections(), is(equalTo(500)));
@@ -646,12 +624,12 @@ public class ClientCacheFactoryBeanTest {
verify(mockPool, never()).getSubscriptionRedundancy();
verify(mockPool, never()).getThreadLocalConnections();
verify(mockClientCacheFactory, times(1)).setPoolFreeConnectionTimeout(eq(5000));
verify(mockClientCacheFactory, times(1)).setPoolIdleTimeout(eq(180000l));
verify(mockClientCacheFactory, times(1)).setPoolIdleTimeout(eq(180000L));
verify(mockClientCacheFactory, times(1)).setPoolLoadConditioningInterval(eq(300000));
verify(mockClientCacheFactory, times(1)).setPoolMaxConnections(eq(500));
verify(mockClientCacheFactory, times(1)).setPoolMinConnections(eq(50));
verify(mockClientCacheFactory, times(1)).setPoolMultiuserAuthentication(eq(true));
verify(mockClientCacheFactory, times(1)).setPoolPingInterval(eq(15000l));
verify(mockClientCacheFactory, times(1)).setPoolPingInterval(eq(15000L));
verify(mockClientCacheFactory, times(1)).setPoolPRSingleHopEnabled(eq(true));
verify(mockClientCacheFactory, times(1)).setPoolReadTimeout(eq(30000));
verify(mockClientCacheFactory, times(1)).setPoolRetryAttempts(eq(1));
@@ -724,7 +702,7 @@ public class ClientCacheFactoryBeanTest {
public void initializePoolWithPoolServer() {
Pool mockPool = mock(Pool.class);
when(mockPool.getLocators()).thenReturn(Collections.<InetSocketAddress>emptyList());
when(mockPool.getLocators()).thenReturn(Collections.emptyList());
when(mockPool.getServers()).thenReturn(Collections.singletonList(new InetSocketAddress("boombox", 41414)));
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
@@ -751,7 +729,7 @@ public class ClientCacheFactoryBeanTest {
Pool mockPool = mock(Pool.class);
when(mockPool.getLocators()).thenReturn(Collections.singletonList(new InetSocketAddress("skullbox", 21668)));
when(mockPool.getServers()).thenReturn(Collections.<InetSocketAddress>emptyList());
when(mockPool.getServers()).thenReturn(Collections.emptyList());
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
@@ -803,8 +781,7 @@ public class ClientCacheFactoryBeanTest {
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
assertThat((ClientCache) clientCacheFactoryBean.createCache(mockClientCacheFactory),
is(sameInstance(mockClientCache)));
assertThat(clientCacheFactoryBean.createCache(mockClientCacheFactory), is(sameInstance(mockClientCache)));
verify(mockClientCacheFactory, times(1)).create();
verifyZeroInteractions(mockClientCache);
@@ -878,7 +855,7 @@ public class ClientCacheFactoryBeanTest {
clientCacheFactoryBean.setBeanFactory(mockBeanFactory);
clientCacheFactoryBean.setPoolName("TestPool");
assertThat((ListableBeanFactory) clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getPool(), is(nullValue()));
assertThat(clientCacheFactoryBean.getPoolName(), is(equalTo("TestPool")));
assertThat(clientCacheFactoryBean.resolvePool(), is(equalTo(mockPool)));
@@ -903,7 +880,7 @@ public class ClientCacheFactoryBeanTest {
clientCacheFactoryBean.setBeanFactory(mockBeanFactory);
assertThat((ListableBeanFactory) clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getPool(), is(nullValue()));
assertThat(clientCacheFactoryBean.getPoolName(), is(nullValue()));
assertThat(clientCacheFactoryBean.resolvePool(), is(equalTo(mockPool)));
@@ -925,7 +902,7 @@ public class ClientCacheFactoryBeanTest {
clientCacheFactoryBean.setBeanFactory(mockBeanFactory);
assertThat((ListableBeanFactory) clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getPool(), is(nullValue()));
assertThat(clientCacheFactoryBean.getPoolName(), is(nullValue()));
assertThat(clientCacheFactoryBean.resolvePool(), is(nullValue()));
@@ -949,7 +926,7 @@ public class ClientCacheFactoryBeanTest {
clientCacheFactoryBean.setBeanFactory(mockBeanFactory);
clientCacheFactoryBean.setPoolName("TestPool");
assertThat((ListableBeanFactory) clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getBeanFactory(), is(equalTo(mockBeanFactory)));
assertThat(clientCacheFactoryBean.getPool(), is(nullValue()));
assertThat(clientCacheFactoryBean.getPoolName(), is(equalTo("TestPool")));
assertThat(clientCacheFactoryBean.resolvePool(), is(nullValue()));
@@ -1176,12 +1153,12 @@ public class ClientCacheFactoryBeanTest {
assertThat(clientCacheFactoryBean.getThreadLocalConnections(), is(nullValue()));
clientCacheFactoryBean.setFreeConnectionTimeout(5000);
clientCacheFactoryBean.setIdleTimeout(120000l);
clientCacheFactoryBean.setIdleTimeout(120000L);
clientCacheFactoryBean.setLoadConditioningInterval(300000);
clientCacheFactoryBean.setMaxConnections(500);
clientCacheFactoryBean.setMinConnections(50);
clientCacheFactoryBean.setMultiUserAuthentication(true);
clientCacheFactoryBean.setPingInterval(15000l);
clientCacheFactoryBean.setPingInterval(15000L);
clientCacheFactoryBean.setPrSingleHopEnabled(true);
clientCacheFactoryBean.setReadTimeout(30000);
clientCacheFactoryBean.setRetryAttempts(1);
@@ -1195,12 +1172,12 @@ public class ClientCacheFactoryBeanTest {
clientCacheFactoryBean.setThreadLocalConnections(false);
assertThat(clientCacheFactoryBean.getFreeConnectionTimeout(), is(equalTo(5000)));
assertThat(clientCacheFactoryBean.getIdleTimeout(), is(equalTo(120000l)));
assertThat(clientCacheFactoryBean.getIdleTimeout(), is(equalTo(120000L)));
assertThat(clientCacheFactoryBean.getLoadConditioningInterval(), is(equalTo(300000)));
assertThat(clientCacheFactoryBean.getMaxConnections(), is(equalTo(500)));
assertThat(clientCacheFactoryBean.getMinConnections(), is(equalTo(50)));
assertThat(clientCacheFactoryBean.getMultiUserAuthentication(), is(equalTo(true)));
assertThat(clientCacheFactoryBean.getPingInterval(), is(equalTo(15000l)));
assertThat(clientCacheFactoryBean.getPingInterval(), is(equalTo(15000L)));
assertThat(clientCacheFactoryBean.getPrSingleHopEnabled(), is(equalTo(true)));
assertThat(clientCacheFactoryBean.getReadTimeout(), is(equalTo(30000)));
assertThat(clientCacheFactoryBean.getRetryAttempts(), is(equalTo(1)));
@@ -1233,7 +1210,7 @@ public class ClientCacheFactoryBeanTest {
assertThat(clientCacheFactoryBean.getReadyForEvents(), is(false));
}
protected ClientCache mockClientCache(String durableClientId) {
private ClientCache mockClientCache(String durableClientId) {
ClientCache mockClientCache = mock(ClientCache.class);
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
@@ -1363,7 +1340,7 @@ public class ClientCacheFactoryBeanTest {
assertThat(clientCacheFactoryBean.getLocators().size(), is(equalTo(1)));
assertThat(clientCacheFactoryBean.getLocators().findOne("localhost"), is(equalTo(localhost)));
clientCacheFactoryBean.setLocators(Collections.<ConnectionEndpoint>emptyList());
clientCacheFactoryBean.setLocators(Collections.emptyList());
assertThat(clientCacheFactoryBean.getLocators(), is(notNullValue()));
assertThat(clientCacheFactoryBean.getLocators().isEmpty(), is(true));
@@ -1398,7 +1375,7 @@ public class ClientCacheFactoryBeanTest {
assertThat(clientCacheFactoryBean.getServers().size(), is(equalTo(1)));
assertThat(clientCacheFactoryBean.getServers().findOne("localhost"), is(equalTo(localhost)));
clientCacheFactoryBean.setServers(Collections.<ConnectionEndpoint>emptyList());
clientCacheFactoryBean.setServers(Collections.emptyList());
assertThat(clientCacheFactoryBean.getServers(), is(notNullValue()));
assertThat(clientCacheFactoryBean.getServers().isEmpty(), is(true));

View File

@@ -140,7 +140,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.setSnapshot(mockSnapshot);
factoryBean.setShortcut(null);
Region actualRegion = factoryBean.lookupRegion(mockClientCache, testRegionName);
Region actualRegion = factoryBean.createRegion(mockClientCache, testRegionName);
assertSame(mockRegion, actualRegion);
@@ -190,7 +190,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.setPoolName("TestPool");
factoryBean.setShortcut(null);
Region<Object, Object> actualRegion = factoryBean.lookupRegion(mockClientCache, "TestRegion");
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestRegion");
assertSame(mockRegion, actualRegion);
@@ -218,7 +218,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.setBeanFactory(mockBeanFactory);
factoryBean.setShortcut(ClientRegionShortcut.CACHING_PROXY);
Region<Object, Object> actualRegion = factoryBean.lookupRegion(mockClientCache, "TestRegion");
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestRegion");
assertSame(mockRegion, actualRegion);
@@ -246,7 +246,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.setParent(mockRegion);
factoryBean.setShortcut(ClientRegionShortcut.PROXY);
Region<Object, Object> actualRegion = factoryBean.lookupRegion(mockClientCache, "TestSubRegion");
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestSubRegion");
assertSame(mockSubRegion, actualRegion);
@@ -271,7 +271,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.setBeanFactory(mockBeanFactory);
factoryBean.setShortcut(ClientRegionShortcut.LOCAL_HEAP_LRU);
Region<Object, Object> actualRegion = factoryBean.lookupRegion(mockClientCache, "TestRegion");
Region<Object, Object> actualRegion = factoryBean.createRegion(mockClientCache, "TestRegion");
assertSame(mockRegion, actualRegion);
@@ -295,7 +295,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.setDataPolicyName("INVALID");
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'INVALID' is invalid.", expected.getMessage());
assertEquals("Data Policy [INVALID] is not valid", expected.getMessage());
throw expected;
}
finally {
@@ -440,7 +440,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.resolveClientRegionShortcut();
}
catch (IllegalArgumentException expected) {
assertEquals("Client Region Shortcut 'CACHING_PROXY' is invalid when persistent is true",
assertEquals("Client Region Shortcut [CACHING_PROXY] is not valid when persistent is true",
expected.getMessage());
throw expected;
}
@@ -467,7 +467,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.resolveClientRegionShortcut();
}
catch (IllegalArgumentException expected) {
assertEquals("Client Region Shortcut 'LOCAL_PERSISTENT' is invalid when persistent is false",
assertEquals("Client Region Shortcut [LOCAL_PERSISTENT] is not valid when persistent is false",
expected.getMessage());
throw expected;
}
@@ -514,7 +514,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.resolveClientRegionShortcut();
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'NORMAL' is invalid when persistent is true", expected.getMessage());
assertEquals("Data Policy [NORMAL] is not valid when persistent is true", expected.getMessage());
throw expected;
}
}
@@ -540,7 +540,7 @@ public class ClientRegionFactoryBeanTest {
factoryBean.resolveClientRegionShortcut();
}
catch (IllegalArgumentException expected) {
assertEquals("Data Policy 'PERSISTENT_REPLICATE' is invalid when persistent is false", expected.getMessage());
assertEquals("Data Policy [PERSISTENT_REPLICATE] is not valid when persistent is false", expected.getMessage());
throw expected;
}
}

View File

@@ -52,19 +52,15 @@ import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.data.util.ReflectionUtils;
/**
* The PoolFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the PoolFactoryBean class.
* Unit tests for {@link PoolFactoryBean}.
*
* @author John Blum
* @see org.junit.Rule
* @see org.junit.Test
* @see org.junit.rules.ExpectedException
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.client.PoolFactoryBean
* @see org.springframework.data.gemfire.support.ConnectionEndpoint
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.client.Pool
* @see org.apache.geode.cache.client.PoolFactory
* @see org.springframework.data.gemfire.client.PoolFactoryBean
* @since 1.7.0
*/
public class PoolFactoryBeanTest {
@@ -164,7 +160,7 @@ public class PoolFactoryBeanTest {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("Pool 'name' is required");
exception.expectMessage("Pool name is required");
poolFactoryBean.afterPropertiesSet();
}

View File

@@ -18,6 +18,7 @@
package org.springframework.data.gemfire.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
@@ -53,8 +54,10 @@ import org.springframework.util.MethodInvoker;
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.Spy
* @see org.mockito.junit.MockitoJUnitRunner
* @see org.springframework.data.gemfire.config.annotation.AbstractCacheConfiguration
* @since 1.9.0
@@ -174,7 +177,7 @@ public class AbstractCacheConfigurationUnitTests {
MappingPdxSerializer mockPdxSerializer = mock(MappingPdxSerializer.class);
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
doReturn(mockPdxSerializer).when(cacheConfigurationSpy).newPdxSerializer();
doReturn(mockPdxSerializer).when(cacheConfigurationSpy).newPdxSerializer(any(BeanFactory.class));
cacheConfigurationSpy.setBeanFactory(mockBeanFactory);
@@ -184,7 +187,7 @@ public class AbstractCacheConfigurationUnitTests {
verify(mockBeanFactory, times(1)).containsBean(eq("TestPdxSerializer"));
verify(mockBeanFactory, never()).getBean(anyString(), eq(PdxSerializer.class));
verify(cacheConfigurationSpy, times(1)).newPdxSerializer();
verify(cacheConfigurationSpy, times(1)).newPdxSerializer(eq(mockBeanFactory));
}
@Test

View File

@@ -0,0 +1,130 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for {@link CacheServerConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.apache.geode.cache.server.CacheServer
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.config.annotation.CacheServerConfigurer
* @see org.springframework.data.gemfire.config.annotation.EnableCacheServer
* @see org.springframework.data.gemfire.config.annotation.EnableCacheServers
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.1.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class CacheServerConfigurerIntegrationTests {
@Autowired
@Qualifier("configurerOne")
private TestCacheServerConfigurer configurerOne;
@Autowired
@Qualifier("configurerTwo")
private TestCacheServerConfigurer configurerTwo;
private void assertCacheServerConfigurerCalled(TestCacheServerConfigurer configurer,
String... cacheServerBeanNames) {
assertThat(configurer).isNotNull();
assertThat(configurer).hasSize(cacheServerBeanNames.length);
assertThat(configurer).contains(cacheServerBeanNames);
}
@Test
public void cacheServerConfigurerOneCalledSuccessfully() {
assertCacheServerConfigurerCalled(this.configurerOne,
"gemfireCacheServer", "marsServer", "saturnServer", "venusServer");
}
@Test
public void cacheServerConfigurerTwoCalledSuccessfully() {
assertCacheServerConfigurerCalled(this.configurerTwo,
"gemfireCacheServer", "marsServer", "saturnServer", "venusServer");
}
@Configuration
@CacheServerApplication
@EnableCacheServers(servers = {
@EnableCacheServer(name = "marsServer"),
@EnableCacheServer(name = "saturnServer"),
@EnableCacheServer(name = "venusServer"),
})
static class TestConfiguration {
@Bean
GemfireTestBeanPostProcessor testBeanPostProcessor() {
return new GemfireTestBeanPostProcessor();
}
@Bean
TestCacheServerConfigurer configurerOne() {
return new TestCacheServerConfigurer();
}
@Bean
TestCacheServerConfigurer configurerTwo() {
return new TestCacheServerConfigurer();
}
@Bean
Object nonRelevantBean() {
return "test";
}
}
static class TestCacheServerConfigurer implements CacheServerConfigurer, Iterable<String> {
private final Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, CacheServerFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.geode.cache.client.ClientCache;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for {@link ClientCacheConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.apache.geode.cache.client.ClientCache
* @see org.springframework.data.gemfire.client.ClientCacheFactoryBean
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
* @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer
* @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.1.0
*/
@RunWith(SpringRunner.class)
@SuppressWarnings("unused")
public class ClientCacheConfigurerIntegrationTests {
@Autowired
private ClientCache clientCache;
@Autowired
@Qualifier("testClientCacheConfigurerOne")
private TestClientCacheConfigurer configurerOne;
@Autowired
@Qualifier("testClientCacheConfigurerTwo")
private TestClientCacheConfigurer configurerTwo;
@Before
public void setup() {
assertThat(this.clientCache).isNotNull();
}
private void assertClientCacheConfigurerInvokedSuccessfully(TestClientCacheConfigurer clientCacheConfigurer,
String... beanNames) {
assertThat(clientCacheConfigurer).isNotNull();
assertThat(clientCacheConfigurer).hasSize(beanNames.length);
assertThat(clientCacheConfigurer).contains(beanNames);
}
@Test
public void clientCacheConfigurerOneCalledSuccessfully() {
assertClientCacheConfigurerInvokedSuccessfully(this.configurerOne, "gemfireCache");
}
@Test
public void clientCacheConfigurerTwoCalledSuccessfully() {
assertClientCacheConfigurerInvokedSuccessfully(this.configurerTwo, "gemfireCache");
}
@ClientCacheApplication
static class TestConfiguration {
@Bean
GemfireTestBeanPostProcessor testBeanPostProcessor() {
return new GemfireTestBeanPostProcessor();
}
@Bean
TestClientCacheConfigurer testClientCacheConfigurerOne() {
return new TestClientCacheConfigurer();
}
@Bean
TestClientCacheConfigurer testClientCacheConfigurerTwo() {
return new TestClientCacheConfigurer();
}
@Bean
String nonRelevantBean() {
return "test";
}
}
static final class TestClientCacheConfigurer implements ClientCacheConfigurer, Iterable<String> {
private Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, ClientCacheFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.DiskStoreFactoryBean;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for {@link DiskStoreConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.apache.geode.cache.DiskStore
* @see org.apache.geode.cache.DiskStoreFactory
* @see org.apache.geode.cache.GemFireCache
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.DiskStoreFactoryBean
* @see org.springframework.data.gemfire.config.annotation.DiskStoreConfiguration
* @see org.springframework.data.gemfire.config.annotation.DiskStoreConfigurer
* @see org.springframework.data.gemfire.config.annotation.EnableDiskStore
* @see org.springframework.data.gemfire.config.annotation.EnableDiskStores
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.1.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class DiskStoreConfigurerIntegrationTests {
@Autowired
@Qualifier("configurerOne")
private TestDiskStoreConfigurer configurerOne;
@Autowired
@Qualifier("configurerTwo")
private TestDiskStoreConfigurer configurerTwo;
private void assertDiskStoreConfigurerCalled(TestDiskStoreConfigurer configurer, String... beanNames) {
assertThat(configurer).isNotNull();
assertThat(configurer).hasSize(beanNames.length);
assertThat(configurer).contains(beanNames);
}
@Test
public void diskStoreConfigurerOneCalledSuccessfully() {
assertDiskStoreConfigurerCalled(this.configurerOne, "cd", "floppy", "tape");
}
@Test
public void diskStoreConfigurerTwoCalledSuccessfully() {
assertDiskStoreConfigurerCalled(this.configurerTwo, "cd", "floppy", "tape");
}
@PeerCacheApplication
@EnableDiskStores(diskStores = {
@EnableDiskStore(name = "cd"),
@EnableDiskStore(name = "floppy"),
@EnableDiskStore(name = "tape"),
})
static class TestConfiguration {
@Bean
GemfireTestBeanPostProcessor testBeanPostProcessor() {
return new GemfireTestBeanPostProcessor();
}
@Bean
TestDiskStoreConfigurer configurerOne() {
return new TestDiskStoreConfigurer();
}
@Bean
TestDiskStoreConfigurer configurerTwo() {
return new TestDiskStoreConfigurer();
}
@Bean
Object nonRelevantBean() {
return "test";
}
}
static class TestDiskStoreConfigurer implements DiskStoreConfigurer, Iterable<String> {
private final Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, DiskStoreFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -0,0 +1,211 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.lucene.LuceneIndex;
import org.apache.geode.cache.lucene.LuceneService;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.gemfire.IndexFactoryBean;
import org.springframework.data.gemfire.config.annotation.test.entities.CollocatedPartitionRegionEntity;
import org.springframework.data.gemfire.config.annotation.test.entities.NonEntity;
import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
import org.springframework.data.gemfire.mapping.annotation.LocalRegion;
import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion;
import org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
/**
* Integration tests for {@link IndexConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.lucene.LuceneIndex
* @see org.apache.geode.cache.query.Index
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see org.springframework.data.gemfire.config.annotation.IndexConfigurer
* @see org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean
* @since 1.0.0
*/
public class IndexConfigurerIntegrationTests {
private static ConfigurableApplicationContext applicationContext;
@BeforeClass
public static void setup() {
applicationContext = newApplicationContext(TestConfiguration.class);
assertThat(applicationContext).isNotNull();
assertThat(applicationContext.containsBean("CustomersFirstNameFunctionalIdx")).isTrue();
assertThat(applicationContext.containsBean("CustomersIdKeyIdx")).isTrue();
assertThat(applicationContext.containsBean("GenericRegionEntityIdKeyIdx")).isTrue();
assertThat(applicationContext.containsBean("LastNameIdx")).isTrue();
assertThat(applicationContext.containsBean("luceneIndex")).isTrue();
assertThat(applicationContext.containsBean("oqlIndex")).isTrue();
assertThat(applicationContext.containsBean("TitleLuceneIdx")).isTrue();
}
@AfterClass
public static void tearDown() {
Optional.ofNullable(applicationContext).ifPresent(ConfigurableApplicationContext::close);
}
/* (non-Javadoc) */
private static ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
applicationContext.registerShutdownHook();
return applicationContext;
}
/* (non-Javadoc) */
private void assertIndexConfigurerInvocations(TestIndexConfigurer indexConfigurer, String... indexBeanNames) {
assertThat(indexConfigurer).isNotNull();
assertThat(indexConfigurer).contains(indexBeanNames);
assertThat(indexConfigurer).hasSize(indexBeanNames.length);
}
@Test
public void indexConfigurerOneCalledSuccessfully() {
assertIndexConfigurerInvocations(
applicationContext.getBean("testIndexConfigurerOne", TestIndexConfigurer.class),
"CustomersFirstNameFunctionalIdx", "CustomersIdKeyIdx", "GenericRegionEntityIdKeyIdx",
"LastNameIdx", "TitleLuceneIdx");
}
@Test
public void indexConfigurerTwoCalledSuccessfully() {
assertIndexConfigurerInvocations(
applicationContext.getBean("testIndexConfigurerTwo", TestIndexConfigurer.class),
"CustomersFirstNameFunctionalIdx", "CustomersIdKeyIdx", "GenericRegionEntityIdKeyIdx",
"LastNameIdx", "TitleLuceneIdx");
}
@PeerCacheApplication
@EnableIndexing
@SuppressWarnings("unused")
@EnableEntityDefinedRegions(basePackageClasses = NonEntity.class,
excludeFilters = {
@ComponentScan.Filter(type = FilterType.ANNOTATION,
classes = { ClientRegion.class, LocalRegion.class, ReplicateRegion.class }),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = CollocatedPartitionRegionEntity.class)
}
)
static class TestConfiguration {
@Bean
GemfireTestBeanPostProcessor testBeanPostProcessor() {
return new GemfireTestBeanPostProcessor();
}
@Bean
BeanPostProcessor indexFactoryBeanReplacingBeanPostProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof LuceneIndexFactoryBean) {
LuceneIndexFactoryBean luceneIndexFactoryBean = (LuceneIndexFactoryBean) bean;
LuceneService mockLuceneService = mock(LuceneService.class);
LuceneIndex mockLuceneIndex = mock(LuceneIndex.class);
luceneIndexFactoryBean.setLuceneIndex(mockLuceneIndex);
luceneIndexFactoryBean.setLuceneService(mockLuceneService);
luceneIndexFactoryBean.setRegionPath("/Test");
}
return bean;
}
};
}
@Bean
LuceneIndexFactoryBean luceneIndex() {
return new LuceneIndexFactoryBean();
}
@Bean
IndexFactoryBean oqlIndex(GemFireCache cache) {
IndexFactoryBean indexFactory = new IndexFactoryBean();
indexFactory.setCache(cache);
indexFactory.setExpression("*");
indexFactory.setFrom("/Test");
return indexFactory;
}
@Bean
TestIndexConfigurer testIndexConfigurerOne() {
return new TestIndexConfigurer();
}
@Bean
TestIndexConfigurer testIndexConfigurerTwo() {
return new TestIndexConfigurer();
}
@Bean
String nonRelevantBean() {
return "test";
}
}
private static class TestIndexConfigurer implements IndexConfigurer, Iterable<String> {
private final Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, IndexFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public void configure(String beanName, LuceneIndexFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.geode.cache.Cache;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for {@link PeerCacheConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.apache.geode.cache.Cache
* @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.springframework.data.gemfire.config.annotation.PeerCacheApplication
* @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
* @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.0.0
*/
@RunWith(SpringRunner.class)
@SuppressWarnings("unused")
public class PeerCacheConfigurerIntegrationTests {
@Autowired
private Cache peerCache;
@Autowired
@Qualifier("testPeerCacheConfigurerOne")
private TestPeerCacheConfigurer configurerOne;
@Autowired
@Qualifier("testPeerCacheConfigurerTwo")
private TestPeerCacheConfigurer configurerTwo;
@Before
public void setup() {
assertThat(this.peerCache).isNotNull();
}
private void assertTestPeerCacheConfigurerCalledSuccessully(TestPeerCacheConfigurer peerCacheConfigurer,
String... beanNames) {
assertThat(peerCacheConfigurer).isNotNull();
assertThat(peerCacheConfigurer).hasSize(beanNames.length);
assertThat(peerCacheConfigurer).contains(beanNames);
}
@Test
public void peerCacheConfigurerOneCalledSuccessfully() {
assertTestPeerCacheConfigurerCalledSuccessully(this.configurerOne, "gemfireCache");
}
@Test
public void peerCacheConfigurerTwoCalledSuccessfully() {
assertTestPeerCacheConfigurerCalledSuccessully(this.configurerTwo, "gemfireCache");
}
@PeerCacheApplication
static class TestConfiguration {
@Bean
GemfireTestBeanPostProcessor testBeanPostProcessor() {
return new GemfireTestBeanPostProcessor();
}
@Bean
TestPeerCacheConfigurer testPeerCacheConfigurerOne() {
return new TestPeerCacheConfigurer();
}
@Bean
TestPeerCacheConfigurer testPeerCacheConfigurerTwo() {
return new TestPeerCacheConfigurer();
}
@Bean
String nonRelevantBean() {
return "test";
}
}
static class TestPeerCacheConfigurer implements Iterable<String>, PeerCacheConfigurer {
private Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, CacheFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.client.PoolFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests for {@link PoolConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.client.Pool
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.client.PoolFactoryBean
* @see org.springframework.data.gemfire.config.annotation.AddPoolConfiguration
* @see org.springframework.data.gemfire.config.annotation.AddPoolsConfiguration
* @see org.springframework.data.gemfire.config.annotation.PoolConfigurer
* @see org.springframework.data.gemfire.config.annotation.EnablePool
* @see org.springframework.data.gemfire.config.annotation.EnablePools
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 1.1.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class PoolConfigurerIntegrationTests {
@Autowired
@Qualifier("configurerOne")
private TestPoolConfigurer configurerOne;
@Autowired
@Qualifier("configurerTwo")
private TestPoolConfigurer configurerTwo;
protected void assertPoolConfigurerCalled(TestPoolConfigurer configurer, String... beanNames) {
assertThat(configurer).isNotNull();
assertThat(configurer).hasSize(beanNames.length);
assertThat(configurer).contains(beanNames);
}
@Test
public void poolConfigurerOneCalledSuccessfully() {
assertPoolConfigurerCalled(this.configurerOne, "poolOne", "poolTwo", "poolThree");
}
@Test
public void poolConfigurerTwoCalledSuccessfully() {
assertPoolConfigurerCalled(this.configurerTwo, "poolOne", "poolTwo", "poolThree");
}
@Configuration
@EnablePools(pools = {
@EnablePool(name = "poolOne"),
@EnablePool(name = "poolTwo"),
@EnablePool(name = "poolThree"),
})
static class TestConfiguration {
@Bean
TestPoolConfigurer configurerOne() {
return new TestPoolConfigurer();
}
@Bean
TestPoolConfigurer configurerTwo() {
return new TestPoolConfigurer();
}
@Bean
Object nonRelevantBean() {
return "test";
}
}
static class TestPoolConfigurer implements Iterable<String>, PoolConfigurer {
private final Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, PoolFactoryBean bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -0,0 +1,204 @@
/*
* Copyright 2017 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import org.apache.geode.cache.GemFireCache;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.test.entities.CollocatedPartitionRegionEntity;
import org.springframework.data.gemfire.config.annotation.test.entities.NonEntity;
import org.springframework.data.gemfire.mapping.annotation.ClientRegion;
import org.springframework.data.gemfire.mapping.annotation.LocalRegion;
import org.springframework.data.gemfire.mapping.annotation.PartitionRegion;
import org.springframework.data.gemfire.mapping.annotation.ReplicateRegion;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
/**
* Integration tests for {@link RegionConfigurer}.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.springframework.context.ConfigurableApplicationContext
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
* @see org.springframework.data.gemfire.RegionFactoryBean
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.data.gemfire.config.annotation.RegionConfigurer
* @see org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor
* @since 1.1.0
*/
public class RegionConfigurerIntegrationTests {
private ConfigurableApplicationContext applicationContext;
@After
public void tearDown() {
Optional.ofNullable(this.applicationContext).ifPresent(ConfigurableApplicationContext::close);
}
/* (non-Javadoc) */
private void assertRegionConfigurerInvocations(TestRegionConfigurer regionConfigurer, String... regionBeanNames) {
assertThat(regionConfigurer).isNotNull();
assertThat(regionConfigurer).contains(regionBeanNames);
assertThat(regionConfigurer).hasSize(regionBeanNames.length);
}
/* (non-Javadoc) */
private ConfigurableApplicationContext newApplicationContext(Class<?>... annotatedClasses) {
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(annotatedClasses);
applicationContext.registerShutdownHook();
return applicationContext;
}
@Test
public void clientRegionConfigurersCalledSuccessfully() {
this.applicationContext = newApplicationContext(ClientTestConfiguration.class);
assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("Sessions")).isTrue();
assertThat(this.applicationContext.containsBean("GenericRegionEntity")).isTrue();
assertThat(this.applicationContext.containsBean("Test")).isTrue();
assertThat(this.applicationContext.containsBean("testRegionConfigurerOne")).isTrue();
assertThat(this.applicationContext.containsBean("testRegionConfigurerTwo")).isTrue();
assertRegionConfigurerInvocations(
this.applicationContext.getBean("testRegionConfigurerOne", TestRegionConfigurer.class),
"GenericRegionEntity", "Sessions");
assertRegionConfigurerInvocations(
this.applicationContext.getBean("testRegionConfigurerTwo", TestRegionConfigurer.class),
"GenericRegionEntity", "Sessions");
}
@Test
public void peerRegionConfigurersCalledSuccessfully() {
this.applicationContext = newApplicationContext(PeerTestConfiguration.class);
assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("Customers")).isTrue();
assertThat(this.applicationContext.containsBean("GenericRegionEntity")).isTrue();
assertThat(this.applicationContext.containsBean("Test")).isTrue();
assertThat(this.applicationContext.containsBean("testRegionConfigurerOne")).isTrue();
assertThat(this.applicationContext.containsBean("testRegionConfigurerTwo")).isTrue();
assertRegionConfigurerInvocations(
this.applicationContext.getBean("testRegionConfigurerOne", TestRegionConfigurer.class),
"Customers", "GenericRegionEntity");
assertRegionConfigurerInvocations(
this.applicationContext.getBean("testRegionConfigurerTwo", TestRegionConfigurer.class),
"Customers", "GenericRegionEntity");
}
@SuppressWarnings("unused")
static class AbstractTestConfiguration {
@Bean
GemfireTestBeanPostProcessor testBeanPostProcessor() {
return new GemfireTestBeanPostProcessor();
}
@Bean
TestRegionConfigurer testRegionConfigurerOne() {
return new TestRegionConfigurer();
}
@Bean
TestRegionConfigurer testRegionConfigurerTwo() {
return new TestRegionConfigurer();
}
@Bean
String nonRelevantBean() {
return "test";
}
}
@ClientCacheApplication
@EnableEntityDefinedRegions(basePackageClasses = NonEntity.class,
excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION,
classes = { LocalRegion.class, PartitionRegion.class, ReplicateRegion.class }))
@SuppressWarnings("unused")
static class ClientTestConfiguration extends AbstractTestConfiguration {
@Bean(name = "Test")
ClientRegionFactoryBean<Object, Object> testRegion(GemFireCache gemfireCache) {
ClientRegionFactoryBean<Object, Object> testRegionFactory = new ClientRegionFactoryBean<>();
testRegionFactory.setCache(gemfireCache);
return testRegionFactory;
}
}
@PeerCacheApplication
@EnableEntityDefinedRegions(basePackageClasses = NonEntity.class,
excludeFilters = {
@ComponentScan.Filter(type = FilterType.ANNOTATION,
classes = { ClientRegion.class, LocalRegion.class, ReplicateRegion.class }),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = CollocatedPartitionRegionEntity.class)
}
)
@SuppressWarnings("unused")
static class PeerTestConfiguration extends AbstractTestConfiguration {
@Bean(name = "Test")
PartitionedRegionFactoryBean<Object, Object> testRegion(GemFireCache gemfireCache) {
PartitionedRegionFactoryBean<Object, Object> testRegionFactory = new PartitionedRegionFactoryBean<>();
testRegionFactory.setCache(gemfireCache);
return testRegionFactory;
}
}
private static class TestRegionConfigurer implements Iterable<String>, RegionConfigurer {
private final Set<String> beanNames = new HashSet<>();
@Override
public void configure(String beanName, RegionFactoryBean<?, ?> bean) {
this.beanNames.add(beanName);
}
@Override
public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {
this.beanNames.add(beanName);
}
@Override
public Iterator<String> iterator() {
return Collections.unmodifiableSet(this.beanNames).iterator();
}
}
}

View File

@@ -16,21 +16,23 @@
package org.springframework.data.gemfire.config.xml;
import static java.util.Arrays.stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
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 static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
import java.io.File;
import java.io.FilenameFilter;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.geode.cache.CacheListener;
@@ -46,6 +48,7 @@ import org.apache.geode.cache.LoaderHelper;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.geode.cache.util.CacheWriterAdapter;
import org.apache.geode.compression.Compressor;
@@ -66,12 +69,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
/**
* The ClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
* of GemFire Client Region namespace support in SDG.
* Unit tests for Spring Data GemFire's XML namespace support for client {@link Region Regions}.
*
* @author Costin Leau
* @author David Turanski
* @author John Blum
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.client.ClientCache
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.data.gemfire.config.xml.ClientRegionParser
*/
@@ -81,35 +85,29 @@ import org.springframework.util.ObjectUtils;
public class ClientRegionNamespaceTest {
@Autowired
private ApplicationContext context;
private ApplicationContext applicationContext;
@AfterClass
public static void tearDown() {
for (String name : new File(".").list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("BACKUP");
}
})) {
new File(name).delete();
}
stream(nullSafeArray(new File(".").list((dir, name) -> name.startsWith("BACKUP")), String.class))
.forEach(fileName -> new File(fileName).delete());
}
@Test
public void testBeanNames() throws Exception {
assertTrue(context.containsBean("SimpleRegion"));
assertTrue(context.containsBean("Publisher"));
assertTrue(context.containsBean("ComplexRegion"));
assertTrue(context.containsBean("PersistentRegion"));
assertTrue(context.containsBean("OverflowRegion"));
assertTrue(context.containsBean("Compressed"));
assertTrue(applicationContext.containsBean("SimpleRegion"));
assertTrue(applicationContext.containsBean("Publisher"));
assertTrue(applicationContext.containsBean("ComplexRegion"));
assertTrue(applicationContext.containsBean("PersistentRegion"));
assertTrue(applicationContext.containsBean("OverflowRegion"));
assertTrue(applicationContext.containsBean("Compressed"));
}
@Test
public void testSimpleClientRegion() throws Exception {
assertTrue(context.containsBean("simple"));
assertTrue(applicationContext.containsBean("simple"));
Region<?, ?> simple = context.getBean("simple", Region.class);
Region<?, ?> simple = applicationContext.getBean("simple", Region.class);
assertNotNull("The 'SimpleRegion' Client Region was not properly configured and initialized!", simple);
assertEquals("SimpleRegion", simple.getName());
@@ -121,9 +119,10 @@ public class ClientRegionNamespaceTest {
@Test
@SuppressWarnings("rawtypes")
public void testPublishingClientRegion() throws Exception {
assertTrue(context.containsBean("empty"));
assertTrue(applicationContext.containsBean("empty"));
ClientRegionFactoryBean emptyClientRegionFactoryBean = context.getBean("&empty", ClientRegionFactoryBean.class);
ClientRegionFactoryBean emptyClientRegionFactoryBean = applicationContext
.getBean("&empty", ClientRegionFactoryBean.class);
assertNotNull(emptyClientRegionFactoryBean);
assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", emptyClientRegionFactoryBean));
@@ -135,9 +134,10 @@ public class ClientRegionNamespaceTest {
@Test
@SuppressWarnings("rawtypes")
public void testComplexClientRegion() throws Exception {
assertTrue(context.containsBean("complex"));
assertTrue(applicationContext.containsBean("complex"));
ClientRegionFactoryBean complexClientRegionFactoryBean = context.getBean("&complex", ClientRegionFactoryBean.class);
ClientRegionFactoryBean complexClientRegionFactoryBean = applicationContext
.getBean("&complex", ClientRegionFactoryBean.class);
assertNotNull(complexClientRegionFactoryBean);
@@ -145,7 +145,7 @@ public class ClientRegionNamespaceTest {
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);
assertNotSame(cacheListeners[0], cacheListeners[1]);
@@ -161,9 +161,9 @@ public class ClientRegionNamespaceTest {
@Test
@SuppressWarnings({ "deprecation", "rawtypes" })
public void testPersistentClientRegion() throws Exception {
assertTrue(context.containsBean("persistent"));
assertTrue(applicationContext.containsBean("persistent"));
Region persistent = context.getBean("persistent", Region.class);
Region persistent = applicationContext.getBean("persistent", Region.class);
assertNotNull("The 'PersistentRegion' Region was not properly configured and initialized!", persistent);
assertEquals("PersistentRegion", persistent.getName());
@@ -179,9 +179,10 @@ public class ClientRegionNamespaceTest {
@Test
@SuppressWarnings("rawtypes")
public void testOverflowClientRegion() throws Exception {
assertTrue(context.containsBean("overflow"));
assertTrue(applicationContext.containsBean("overflow"));
ClientRegionFactoryBean overflowClientRegionFactoryBean = context.getBean("&overflow", ClientRegionFactoryBean.class);
ClientRegionFactoryBean overflowClientRegionFactoryBean = applicationContext
.getBean("&overflow", ClientRegionFactoryBean.class);
assertNotNull(overflowClientRegionFactoryBean);
assertEquals("diskStore", TestUtils.readField("diskStoreName", overflowClientRegionFactoryBean));
@@ -203,9 +204,9 @@ public class ClientRegionNamespaceTest {
@Test
public void testClientRegionWithCacheLoaderAndCacheWriter() throws Exception {
assertTrue(context.containsBean("loadWithWrite"));
assertTrue(applicationContext.containsBean("loadWithWrite"));
ClientRegionFactoryBean factory = context.getBean("&loadWithWrite", ClientRegionFactoryBean.class);
ClientRegionFactoryBean factory = applicationContext.getBean("&loadWithWrite", ClientRegionFactoryBean.class);
assertNotNull(factory);
assertEquals("LoadedFullOfWrites", TestUtils.readField("name", factory));
@@ -216,9 +217,9 @@ public class ClientRegionNamespaceTest {
@Test
public void testCompressedReplicateRegion() {
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' Client Region was not properly configured and initialized!", compressed);
assertEquals("Compressed", compressed.getName());
@@ -235,9 +236,9 @@ public class ClientRegionNamespaceTest {
@Test
@SuppressWarnings("unchecked")
public void testClientRegionWithAttributes() {
assertTrue(context.containsBean("client-with-attributes"));
assertTrue(applicationContext.containsBean("client-with-attributes"));
Region<Long, String> clientRegion = context.getBean("client-with-attributes", Region.class);
Region<Long, String> clientRegion = applicationContext.getBean("client-with-attributes", Region.class);
assertNotNull("The 'client-with-attributes' Client Region was not properly configured and initialized!", clientRegion);
assertEquals("client-with-attributes", clientRegion.getName());
@@ -258,9 +259,11 @@ public class ClientRegionNamespaceTest {
@Test
@SuppressWarnings("unchecked")
public void testClientRegionWithRegisteredInterests() throws Exception {
assertTrue(context.containsBean("client-with-interests"));
ClientRegionFactoryBean factoryBean = context.getBean("&client-with-interests", ClientRegionFactoryBean.class);
assertTrue(applicationContext.containsBean("client-with-interests"));
ClientRegionFactoryBean factoryBean =
applicationContext.getBean("&client-with-interests", ClientRegionFactoryBean.class);
assertNotNull(factoryBean);
@@ -276,10 +279,11 @@ public class ClientRegionNamespaceTest {
assertNotNull(mockClientRegion);
verify(mockClientRegion, times(1)).registerInterest(eq(".*"), eq(InterestResultPolicy.KEYS),
eq(true), eq(false));
verify(mockClientRegion, times(1)).registerInterestRegex(eq("keyPrefix.*"), eq(InterestResultPolicy.KEYS_VALUES),
eq(true), eq(false));
verify(mockClientRegion, times(1)).registerInterest(eq(".*"),
eq(InterestResultPolicy.KEYS), eq(true), eq(false));
verify(mockClientRegion, times(1)).registerInterestRegex(eq("keyPrefix.*"),
eq(InterestResultPolicy.KEYS_VALUES), eq(true), eq(false));
}
protected void assertInterest(final boolean expectedDurable, final boolean expectedReceiveValues,
@@ -300,38 +304,41 @@ public class ClientRegionNamespaceTest {
return null;
}
public static final class MockCacheFactoryBean implements FactoryBean<ClientCache>, InitializingBean {
static final class MockCacheFactoryBean implements FactoryBean<ClientCache>, InitializingBean {
protected static final AtomicReference<Region> MOCK_REGION_REF = new AtomicReference<Region>(null);
static final AtomicReference<Region> MOCK_REGION_REF = new AtomicReference<Region>(null);
private ClientCache mockClientCache;
@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {
mockClientCache = mock(ClientCache.class, ClientRegionNamespaceTest.class.getSimpleName()
.concat(".MockClientCache"));
this.mockClientCache = mock(ClientCache.class,
ClientRegionNamespaceTest.class.getSimpleName().concat(".MockClientCache"));
MOCK_REGION_REF.compareAndSet(null, mock(Region.class, ClientRegionNamespaceTest.class.getSimpleName()
.concat(".MockClientRegion")));
ClientRegionFactory mockClientRegionFactory = mock(ClientRegionFactory.class,
ClientRegionNamespaceTest.class.getSimpleName().concat("MockClientRegionFactory"));
when(mockClientCache.getRegion(anyString())).thenReturn(MOCK_REGION_REF.get());
when(this.mockClientCache.createClientRegionFactory(any(ClientRegionShortcut.class)))
.thenReturn(mockClientRegionFactory);
Region mockRegion = mock(Region.class,
ClientRegionNamespaceTest.class.getSimpleName().concat(".MockClientRegion"));
when(mockClientRegionFactory.create(anyString())).thenReturn(mockRegion);
MOCK_REGION_REF.compareAndSet(null, mockRegion);
}
@Override
public ClientCache getObject() throws Exception {
return mockClientCache;
return this.mockClientCache;
}
@Override
public Class<?> getObjectType() {
return ClientCache.class;
}
@Override
public boolean isSingleton() {
return true;
}
}
public static final class TestCacheLoader implements CacheLoader<Object, Object> {
@@ -371,6 +378,5 @@ public class ClientRegionNamespaceTest {
public String toString() {
return this.name;
}
}
}

View File

@@ -37,15 +37,18 @@ import org.springframework.data.gemfire.RegionFactoryBean;
*/
public class InvalidRegionDefinitionUsingBeansNamespaceTest {
private static final String CONFIG_LOCATION =
"org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml";
@Test(expected = IllegalArgumentException.class)
public void testInvalidDataPolicyPersistentAttributeSettings() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml");
new ClassPathXmlApplicationContext(CONFIG_LOCATION);
}
catch (BeanCreationException expected) {
assertTrue(expected.getCause() instanceof IllegalArgumentException);
assertEquals("Data Policy 'REPLICATE' is invalid when persistent is true.", expected.getCause().getMessage());
assertEquals("Data Policy [REPLICATE] is invalid when persistent is true.", expected.getCause().getMessage());
throw (IllegalArgumentException) expected.getCause();
}
}
@@ -53,5 +56,4 @@ public class InvalidRegionDefinitionUsingBeansNamespaceTest {
@SuppressWarnings("unused")
public static final class TestRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
}
}

View File

@@ -44,9 +44,9 @@ public class SubRegionWithInvalidDataPolicyTest {
"/org/springframework/data/gemfire/config/xml/subregion-with-invalid-datapolicy.xml");
}
catch (XmlBeanDefinitionStoreException expected) {
//expected.printStackTrace(System.err);
assertTrue(expected.getCause() instanceof SAXParseException);
assertTrue(expected.getCause().getMessage().contains("PERSISTENT_PARTITION"));
throw expected;
}
}
@@ -58,13 +58,12 @@ public class SubRegionWithInvalidDataPolicyTest {
"/org/springframework/data/gemfire/config/xml/subregion-with-inconsistent-datapolicy-persistent-settings.xml");
}
catch (BeanCreationException expected) {
//expected.printStackTrace(System.err);
assertTrue(expected.getMessage().contains("Error creating bean with name '/Parent/Child'"));
assertTrue(expected.getCause() instanceof IllegalArgumentException);
assertEquals("Data Policy 'REPLICATE' is invalid when persistent is true.",
assertEquals("Data Policy [REPLICATE] is invalid when persistent is true.",
expected.getCause().getMessage());
throw expected;
}
}
}

View File

@@ -84,6 +84,7 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
@BeforeClass
public static void startGemFireServer() throws Exception {
int availablePort = findAvailablePort();
gemfireServer = run(ServerProcess.class,
@@ -101,8 +102,10 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
stop(gemfireServer);
}
protected PdxInstance toPdxInstance(final Map<String, Object> pdxData) {
PdxInstanceFactory pdxInstanceFactory = gemfireClientCache.createPdxInstanceFactory(pdxData.get("@type").toString());
private PdxInstance toPdxInstance(Map<String, Object> pdxData) {
PdxInstanceFactory pdxInstanceFactory =
gemfireClientCache.createPdxInstanceFactory(pdxData.get("@type").toString());
for (Map.Entry<String, Object> entry : pdxData.entrySet()) {
pdxInstanceFactory.writeObject(entry.getKey(), entry.getValue());
@@ -112,9 +115,10 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@Test
public void testConvertedFunctionArgumentTypes() {
Class[] argumentTypes = functionExecutions.captureConvertedArgumentTypes("test", 1, Boolean.TRUE,
new Person("Jon", "Doe"), Gender.MALE);
public void convertedFunctionArgumentTypes() {
Class[] argumentTypes = functionExecutions.captureConvertedArgumentTypes("test", 1,
Boolean.TRUE, new Person("Jon", "Doe"), Gender.MALE);
assertNotNull(argumentTypes);
assertEquals(5, argumentTypes.length);
@@ -126,9 +130,10 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@Test
public void testUnconvertedFunctionArgumentTypes() {
Class[] argumentTypes = functionExecutions.captureUnconvertedArgumentTypes("test", 2, Boolean.FALSE,
new Person("Jane", "Doe"), Gender.FEMALE);
public void unconvertedFunctionArgumentTypes() {
Class[] argumentTypes = functionExecutions.captureUnconvertedArgumentTypes("test", 2,
Boolean.FALSE, new Person("Jane", "Doe"), Gender.FEMALE);
assertNotNull(argumentTypes);
assertEquals(5, argumentTypes.length);
@@ -140,13 +145,14 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@Test
public void testGetAddressFieldValue() {
public void getAddressFieldValue() {
assertEquals("Portland", functionExecutions.getAddressField(new Address(
"100 Main St.", "Portland", "OR", "97205"), "city"));
}
@Test
public void testPdxDataFieldValue() {
public void pdxDataFieldValue() {
Map<String, Object> pdxData = new HashMap<String, Object>(3);
pdxData.put("@type", "x.y.z.domain.MyApplicationDomainType");
@@ -162,6 +168,7 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
public static class ApplicationDomainFunctions {
private Class[] getArgumentTypes(final Object... arguments) {
Class[] argumentTypes = new Class[arguments.length];
int index = 0;
@@ -174,25 +181,27 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@GemfireFunction
public Class[] captureConvertedArgumentTypes(final String stringValue, final Integer integerValue,
final Boolean booleanValue, final Person person, final Gender gender) {
public Class[] captureConvertedArgumentTypes(String stringValue, Integer integerValue, Boolean booleanValue,
Person person, Gender gender) {
return getArgumentTypes(stringValue, integerValue, booleanValue, person, gender);
}
@GemfireFunction
public Class[] captureUnconvertedArgumentTypes(final String stringValue, final Integer integerValue,
final Boolean booleanValue, final Object domainObject, final Object enumValue) {
public Class[] captureUnconvertedArgumentTypes(String stringValue, Integer integerValue, Boolean booleanValue,
Object domainObject, Object enumValue) {
return getArgumentTypes(stringValue, integerValue, booleanValue, domainObject, enumValue);
}
@GemfireFunction
public String getAddressField(final PdxInstance address, final String fieldName) {
Assert.isTrue(Address.class.getName().equals(address.getClassName()));
public String getAddressField(PdxInstance address, String fieldName) {
Assert.isTrue(Address.class.getName().equals(address.getClassName()), "Address is not the correct type");
return String.valueOf(address.getField(fieldName));
}
@GemfireFunction
public Object getDataField(final PdxInstance data, final String fieldName) {
public Object getDataField(PdxInstance data, String fieldName) {
return data.getField(fieldName);
}
}
@@ -204,11 +213,12 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
private final String state; // refactor; use Enum!
private final String zipCode;
public Address(final String street, final String city, final String state, final String zipCode) {
public Address(String street, String city, String state, String zipCode) {
Assert.hasText("The Address 'street' must be specified", street);
Assert.hasText("The Address 'city' must be specified", city);
Assert.hasText("The Address 'state' must be specified", state);
Assert.hasText("The Address 'zipCode' must be specified", zipCode);
this.street = street;
this.city = city;
this.state = state;
@@ -233,6 +243,7 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
@@ -251,11 +262,14 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
@Override
public int hashCode() {
int hashValue = 17;
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getStreet());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getCity());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getState());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getZipCode());
return hashValue;
}
@@ -275,9 +289,10 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
private final String firstName;
private final String lastName;
public Person(final String firstName, final String lastName) {
public Person(String firstName, String lastName) {
Assert.hasText(firstName, "The person's first name must be specified!");
Assert.hasText(lastName, "The person's last name must be specified!");
this.firstName = firstName;
this.lastName = lastName;
}
@@ -292,6 +307,7 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
@@ -308,9 +324,12 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
@Override
public int hashCode() {
int hashValue = 17;
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName());
return hashValue;
}
@@ -324,18 +343,18 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
private final PdxSerializer[] pdxSerializers;
private ComposablePdxSerializer(final PdxSerializer[] pdxSerializers) {
private ComposablePdxSerializer(PdxSerializer[] pdxSerializers) {
this.pdxSerializers = pdxSerializers;
}
public static PdxSerializer compose(final PdxSerializer... pdxSerializers) {
public static PdxSerializer compose(PdxSerializer... pdxSerializers) {
return (pdxSerializers == null ? null : (pdxSerializers.length == 1 ? pdxSerializers[0]
: new ComposablePdxSerializer(pdxSerializers)));
}
@Override
public boolean toData(final Object obj, final PdxWriter out) {
for (PdxSerializer pdxSerializer : pdxSerializers) {
public boolean toData(Object obj, PdxWriter out) {
for (PdxSerializer pdxSerializer : this.pdxSerializers) {
if (pdxSerializer.toData(obj, out)) {
return true;
}
@@ -345,8 +364,8 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@Override
public Object fromData(final Class<?> type, final PdxReader in) {
for (PdxSerializer pdxSerializer : pdxSerializers) {
public Object fromData(Class<?> type, final PdxReader in) {
for (PdxSerializer pdxSerializer : this.pdxSerializers) {
Object obj = pdxSerializer.fromData(type, in);
if (obj != null) {
@@ -393,7 +412,8 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
public static class AddressPdxSerializer implements PdxSerializer {
@Override
public boolean toData(final Object obj, final PdxWriter out) {
public boolean toData(Object obj, PdxWriter out) {
if (obj instanceof Address) {
Address address = (Address) obj;
out.writeString("street", address.getStreet());
@@ -407,7 +427,8 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@Override
public Object fromData(final Class<?> type, final PdxReader in) {
public Object fromData(Class<?> type, PdxReader in) {
if (Address.class.isAssignableFrom(type)) {
return new Address(in.readString("street"), in.readString("city"), in.readString("state"),
in.readString("zipCode"));
@@ -419,7 +440,8 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
public static class PersonPdxSerializer implements PdxSerializer {
@Override
public boolean toData(final Object obj, final PdxWriter out) {
public boolean toData(Object obj, PdxWriter out) {
if (obj instanceof Person) {
Person person = (Person) obj;
out.writeString("firstName", person.getFirstName());
@@ -431,7 +453,7 @@ public class ClientCacheFunctionExecutionWithPdxIntegrationTest extends ClientSe
}
@Override
public Object fromData(final Class<?> type, final PdxReader in) {
public Object fromData(Class<?> type, PdxReader in) {
if (Person.class.isAssignableFrom(type)) {
return new Person(in.readString("firstName"), in.readString("lastName"));
}

View File

@@ -32,44 +32,45 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.gemfire.function.execution.GemfireOnServerFunctionTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author David Turanski
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = { TestClientCacheConfig.class })
public class FunctionExecutionClientCacheTests {
@Autowired
ApplicationContext context;
ApplicationContext applicationContext;
@Test
public void contextCreated() throws Exception {
ClientCache cache = context.getBean("gemfireCache", ClientCache.class);
Pool pool = context.getBean("gemfirePool", Pool.class);
ClientCache cache = applicationContext.getBean("gemfireCache", ClientCache.class);
Pool pool = applicationContext.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));
Region region = context.getBean("r1", Region.class);
Region region = applicationContext.getBean("r1", Region.class);
assertEquals("gemfirePool", region.getAttributes().getPoolName());
GemfireOnServerFunctionTemplate template = context.getBean(GemfireOnServerFunctionTemplate.class);
GemfireOnServerFunctionTemplate template = applicationContext.getBean(GemfireOnServerFunctionTemplate.class);
assertTrue(template.getResultCollector() instanceof MyResultCollector);
}
}
@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() {
return new MyResultCollector();
@@ -115,5 +116,4 @@ class MyResultCollector implements ResultCollector {
public Object getResult(long arg0, TimeUnit arg1) throws FunctionException, InterruptedException {
return null;
}
}

View File

@@ -23,14 +23,12 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.LocalRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
import org.springframework.data.gemfire.repository.sample.Person;
import org.springframework.data.gemfire.repository.sample.PersonRepository;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.test.MockCacheFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -39,29 +37,24 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* repository configuration).
*
* @author Oliver Gierke
* @author John Blum
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers=GemfireTestApplicationContextInitializer.class)
public class GemfireRepositoriesRegistrarIntegrationTest {
@Configuration
@PeerCacheApplication
@EnableGemfireRepositories(value = "org.springframework.data.gemfire.repository.sample",
includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
value = org.springframework.data.gemfire.repository.sample.PersonRepository.class))
static class Config {
@Bean
public GemFireCache cache() throws Exception {
public Region<Long, Person> simple(GemFireCache gemfireCache) throws Exception {
CacheFactoryBean factory = new MockCacheFactoryBean();
return factory.getObject();
}
LocalRegionFactoryBean<Long, Person> factory = new LocalRegionFactoryBean<>();
@Bean
public Region<Long, Person> simple() throws Exception {
LocalRegionFactoryBean<Long, Person> factory = new LocalRegionFactoryBean<Long, Person>();
factory.setCache(cache());
factory.setCache(gemfireCache);
factory.setName("simple");
factory.afterPropertiesSet();
@@ -75,5 +68,4 @@ public class GemfireRepositoriesRegistrarIntegrationTest {
@Test
public void bootstrapsRepositoriesCorrectly() {
}
}

View File

@@ -111,7 +111,7 @@ public class LuceneIndexFactoryBeanUnitTests {
doReturn(mockCache).when(factoryBean).resolveCache();
doReturn(mockLuceneService).when(factoryBean).resolveLuceneService();
doReturn("/Example").when(factoryBean).resolveRegionPath();
doReturn(mockLuceneIndex).when(factoryBean).createIndex(eq("ExampleIndex"), eq("/Example"));
doReturn(mockLuceneIndex).when(factoryBean).createLuceneIndex(eq("ExampleIndex"), eq("/Example"));
factoryBean.setIndexName("ExampleIndex");
@@ -122,10 +122,10 @@ public class LuceneIndexFactoryBeanUnitTests {
assertThat(factoryBean.getObject()).isEqualTo(mockLuceneIndex);
verify(factoryBean, times(1)).resolveCache();
verify(factoryBean, times(1)).resolveLuceneService();
verify(factoryBean, times(2)).resolveLuceneService();
verify(factoryBean, times(1)).resolveRegionPath();
verify(factoryBean, times(1))
.createIndex(eq("ExampleIndex"), eq("/Example"));
.createLuceneIndex(eq("ExampleIndex"), eq("/Example"));
}
@Test
@@ -138,7 +138,7 @@ public class LuceneIndexFactoryBeanUnitTests {
}
@Test
public void createIndexWithAllFields() {
public void createLuceneIndexWithAllFields() {
factoryBean.setLuceneService(mockLuceneService);
when(mockLuceneService.getIndex(eq("ExampleIndex"), eq("/Example"))).thenReturn(mockLuceneIndex);
@@ -146,7 +146,7 @@ public class LuceneIndexFactoryBeanUnitTests {
assertThat(factoryBean.getFieldAnalyzers()).isEmpty();
assertThat(factoryBean.getFields()).isEmpty();
assertThat(factoryBean.getLuceneService()).isSameAs(mockLuceneService);
assertThat(factoryBean.createIndex("ExampleIndex", "/Example")).isEqualTo(mockLuceneIndex);
assertThat(factoryBean.createLuceneIndex("ExampleIndex", "/Example")).isEqualTo(mockLuceneIndex);
verify(mockLuceneService, times(1)).createIndexFactory();
verify(mockLuceneIndexFactory, times(1))
@@ -158,7 +158,7 @@ public class LuceneIndexFactoryBeanUnitTests {
}
@Test
public void createIndexWithFieldAnalyzers() {
public void createLuceneIndexWithFieldAnalyzers() {
Map<String, Analyzer> fieldAnalyzers = Collections.singletonMap("fieldOne", mockAnalyzer);
factoryBean.setFieldAnalyzers(fieldAnalyzers);
@@ -169,7 +169,7 @@ public class LuceneIndexFactoryBeanUnitTests {
assertThat(factoryBean.getFieldAnalyzers()).isEqualTo(fieldAnalyzers);
assertThat(factoryBean.getFields()).isEmpty();
assertThat(factoryBean.getLuceneService()).isSameAs(mockLuceneService);
assertThat(factoryBean.createIndex("ExampleIndex", "/Example")).isEqualTo(mockLuceneIndex);
assertThat(factoryBean.createLuceneIndex("ExampleIndex", "/Example")).isEqualTo(mockLuceneIndex);
verify(mockLuceneService, times(1)).createIndexFactory();
verify(mockLuceneIndexFactory, times(1)).setFields(eq(fieldAnalyzers));
@@ -180,7 +180,7 @@ public class LuceneIndexFactoryBeanUnitTests {
}
@Test
public void createIndexWithTargetedFields() {
public void createLuceneIndexWithTargetedFields() {
factoryBean.setFields("fieldOne", "fieldTwo");
factoryBean.setLuceneService(mockLuceneService);
@@ -189,7 +189,7 @@ public class LuceneIndexFactoryBeanUnitTests {
assertThat(factoryBean.getFieldAnalyzers()).isEmpty();
assertThat(factoryBean.getFields()).containsAll(Arrays.asList("fieldOne", "fieldTwo"));
assertThat(factoryBean.getLuceneService()).isSameAs(mockLuceneService);
assertThat(factoryBean.createIndex("ExampleIndex", "/Example")).isEqualTo(mockLuceneIndex);
assertThat(factoryBean.createLuceneIndex("ExampleIndex", "/Example")).isEqualTo(mockLuceneIndex);
verify(mockLuceneService, times(1)).createIndexFactory();
verify(mockLuceneIndexFactory, times(1))

View File

@@ -44,11 +44,12 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
* The CacheServerFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the CacheServerFactoryBean class.
* Unit tests for {@link CacheServerFactoryBean}.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.server.CacheServer
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
* @since 1.6.0
*/
@@ -146,7 +147,7 @@ public class CacheServerFactoryBeanTest {
new CacheServerFactoryBean().afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("A GemFire Cache is required.", expected.getMessage());
assertEquals("Cache is required", expected.getMessage());
throw expected;
}
}
@@ -228,5 +229,4 @@ public class CacheServerFactoryBeanTest {
assertFalse(factoryBean.isRunning());
assertTrue(called.get());
}
}

View File

@@ -0,0 +1,168 @@
/*
* Copyright 2017 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.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.apache.commons.logging.Log;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
/**
* Unit tests for {@link AbstractFactoryBeanSupport}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.Spy
* @see org.springframework.data.gemfire.support.AbstractFactoryBeanSupport
* @since 1.0.0
*/
@RunWith(MockitoJUnitRunner.class)
public class AbstractFactoryBeanSupportUnitTests {
@Mock
private Log mockLog;
@Spy
private TestFactoryBeanSupport<?> factoryBeanSupport;
@Before
public void setup() {
when(factoryBeanSupport.getLog()).thenReturn(mockLog);
}
@Test
public void setAndGetBeanClassLoader() {
assertThat(factoryBeanSupport.getBeanClassLoader()).isNull();
ClassLoader mockClassLoader = mock(ClassLoader.class);
factoryBeanSupport.setBeanClassLoader(mockClassLoader);
assertThat(factoryBeanSupport.getBeanClassLoader()).isSameAs(mockClassLoader);
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
factoryBeanSupport.setBeanClassLoader(systemClassLoader);
assertThat(factoryBeanSupport.getBeanClassLoader()).isSameAs(systemClassLoader);
factoryBeanSupport.setBeanClassLoader(null);
assertThat(factoryBeanSupport.getBeanClassLoader()).isNull();
}
@Test
public void setAndGetBeanFactory() {
assertThat(factoryBeanSupport.getBeanFactory()).isNull();
BeanFactory mockBeanFactory = mock(BeanFactory.class);
factoryBeanSupport.setBeanFactory(mockBeanFactory);
assertThat(factoryBeanSupport.getBeanFactory()).isSameAs(mockBeanFactory);
factoryBeanSupport.setBeanFactory(null);
assertThat(factoryBeanSupport.getBeanFactory()).isNull();
}
@Test
public void setAndGetBeanName() {
assertThat(factoryBeanSupport.getBeanName()).isNullOrEmpty();
factoryBeanSupport.setBeanName("test");
assertThat(factoryBeanSupport.getBeanName()).isEqualTo("test");
factoryBeanSupport.setBeanName(null);
assertThat(factoryBeanSupport.getBeanName()).isNullOrEmpty();
}
@Test
public void isSingletonDefaultsToTrue() {
assertThat(factoryBeanSupport.isSingleton()).isTrue();
}
@Test
public void logsDebugWhenDebugIsEnabled() {
when(mockLog.isDebugEnabled()).thenReturn(true);
factoryBeanSupport.logDebug("%s log test", "debug");
verify(mockLog, times(1)).isDebugEnabled();
verify(mockLog, times(1)).debug(eq("debug log test"));
}
@Test
public void logsInfoWhenInfoIsEnabled() {
when(mockLog.isInfoEnabled()).thenReturn(true);
factoryBeanSupport.logInfo("%s log test", "info");
verify(mockLog, times(1)).isInfoEnabled();
verify(mockLog, times(1)).info(eq("info log test"));
}
@Test
public void suppressesDebugLoggingWhenDebugIsDisabled() {
when(mockLog.isDebugEnabled()).thenReturn(false);
factoryBeanSupport.logDebug(() -> "test");
verify(mockLog, times(1)).isDebugEnabled();
verify(mockLog, never()).debug(any());
}
@Test
public void suppressesInfoLoggingWhenInfoIsDisabled() {
when(mockLog.isInfoEnabled()).thenReturn(false);
factoryBeanSupport.logInfo(() -> "test");
verify(mockLog, times(1)).isInfoEnabled();
verify(mockLog, never()).info(any());
}
private static class TestFactoryBeanSupport<T> extends AbstractFactoryBeanSupport<T> {
@Override
public T getObject() throws Exception {
return null;
}
@Override
public Class<?> getObjectType() {
return Object.class;
}
}
}

View File

@@ -13,6 +13,8 @@
package org.springframework.data.gemfire.test;
import java.util.Optional;
import org.apache.geode.cache.GemFireCache;
import org.springframework.data.gemfire.CacheFactoryBean;
@@ -27,36 +29,39 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
}
public MockCacheFactoryBean(CacheFactoryBean cacheFactoryBean) {
setUseBeanFactoryLocator(false);
if (cacheFactoryBean != null) {
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());
setUseBeanFactoryLocator(cacheFactoryBean.isUseBeanFactoryLocator());
}
Optional.ofNullable(cacheFactoryBean).ifPresent(it -> {
setBeanClassLoader(it.getBeanClassLoader());
setBeanFactory(it.getBeanFactory());
setBeanName(it.getBeanName());
setCacheXml(it.getCacheXml());
setPhase(it.getPhase());
setProperties(it.getProperties());
setClose(it.isClose());
setCopyOnRead(it.getCopyOnRead());
setCriticalHeapPercentage(it.getCriticalHeapPercentage());
setDynamicRegionSupport(it.getDynamicRegionSupport());
setEnableAutoReconnect(it.getEnableAutoReconnect());
setEvictionHeapPercentage(it.getEvictionHeapPercentage());
setGatewayConflictResolver(it.getGatewayConflictResolver());
setJndiDataSources(it.getJndiDataSources());
setLockLease(it.getLockLease());
setLockTimeout(it.getLockTimeout());
setMessageSyncInterval(it.getMessageSyncInterval());
setPdxDiskStoreName(it.getPdxDiskStoreName());
setPdxIgnoreUnreadFields(it.getPdxIgnoreUnreadFields());
setPdxPersistent(it.getPdxPersistent());
setPdxReadSerialized(it.getPdxReadSerialized());
setPdxSerializer(it.getPdxSerializer());
setSearchTimeout(it.getSearchTimeout());
setTransactionListeners(it.getTransactionListeners());
setTransactionWriter(it.getTransactionWriter());
setUseBeanFactoryLocator(it.isUseBeanFactoryLocator());
});
applyPeerCacheConfigurers(cacheFactoryBean.getCompositePeerCacheConfigurer());
}
@Override
@@ -66,5 +71,4 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
stubCache.setProperties(getProperties());
return (T) stubCache;
}
}

View File

@@ -12,6 +12,8 @@
*/
package org.springframework.data.gemfire.test;
import java.util.Optional;
import org.apache.geode.cache.GemFireCache;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
@@ -22,38 +24,41 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
public MockClientCacheFactoryBean(ClientCacheFactoryBean clientCacheFactoryBean) {
setUseBeanFactoryLocator(false);
if (clientCacheFactoryBean != null) {
this.beanFactoryLocator = clientCacheFactoryBean.getBeanFactoryLocator();
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());
}
Optional.ofNullable(clientCacheFactoryBean).ifPresent(it -> {
this.beanFactoryLocator = it.getBeanFactoryLocator();
setBeanClassLoader(it.getBeanClassLoader());
setBeanFactory(it.getBeanFactory());
setBeanName(it.getBeanName());
setCacheXml(it.getCacheXml());
setCopyOnRead(it.getCopyOnRead());
setCriticalHeapPercentage(it.getCriticalHeapPercentage());
setDurableClientId(it.getDurableClientId());
setDurableClientTimeout(it.getDurableClientTimeout());
setDynamicRegionSupport(it.getDynamicRegionSupport());
setEvictionHeapPercentage(it.getEvictionHeapPercentage());
setGatewayConflictResolver(it.getGatewayConflictResolver());
setJndiDataSources(it.getJndiDataSources());
setKeepAlive(it.isKeepAlive());
setLockLease(it.getLockLease());
setLockTimeout(it.getLockTimeout());
setMessageSyncInterval(it.getMessageSyncInterval());
setPdxDiskStoreName(it.getPdxDiskStoreName());
setPdxIgnoreUnreadFields(it.getPdxIgnoreUnreadFields());
setPdxPersistent(it.getPdxPersistent());
setPdxReadSerialized(it.getPdxReadSerialized());
setPdxSerializer(it.getPdxSerializer());
setPoolName(it.getPoolName());
setProperties(it.getProperties());
setReadyForEvents(it.getReadyForEvents());
setSearchTimeout(it.getSearchTimeout());
setTransactionListeners(it.getTransactionListeners());
setTransactionWriter(it.getTransactionWriter());
});
applyClientCacheConfigurers(clientCacheFactoryBean.getCompositeClientCacheConfigurer());
}
@SuppressWarnings("unchecked")
@@ -62,6 +67,4 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
stubCache.setProperties(getProperties());
return (T) stubCache;
}
}