Fixes bug SGF-225 involving GemFire SubRegion bean definition inconsistencies when data-policy is specified along with SGF-242 that involves the use of membership-attributes configuration on a GemFire Region.
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.DataPolicy;
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.LossAction;
|
||||
import com.gemstone.gemfire.cache.MembershipAttributes;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.ResumptionAction;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
|
||||
/**
|
||||
* The SubRegionIntegrationTest class is a test suite of test cases testing the functionality of SubRegions in GemFire
|
||||
* configured with Spring Data GemFire's XML namespace configuration meta-data. This test class tests a complex
|
||||
* SubRegion configuration in order to ensure functional completeness.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since 1.4.0
|
||||
* @since 7.0.1 (GemFire)
|
||||
*/
|
||||
@ContextConfiguration("complex-subregion.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SubRegionIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private Cache cache;
|
||||
|
||||
@Resource(name = "Customers")
|
||||
private Region customers;
|
||||
|
||||
@Resource(name = "/Customers/Accounts")
|
||||
private Region accounts;
|
||||
|
||||
@Test
|
||||
public void testGemFireAccountsSubRegionCreation() {
|
||||
assertNotNull("The GemFire Cache was not properly initialized!", cache);
|
||||
|
||||
Region customers = cache.getRegion("Customers");
|
||||
|
||||
assertNotNull(customers);
|
||||
assertEquals("Customers", customers.getName());
|
||||
assertEquals("/Customers", customers.getFullPath());
|
||||
|
||||
Region accounts = customers.getSubregion("Accounts");
|
||||
|
||||
assertNotNull(accounts);
|
||||
assertEquals("Accounts", accounts.getName());
|
||||
assertEquals("/Customers/Accounts", accounts.getFullPath());
|
||||
|
||||
Region cacheAccounts = cache.getRegion("/Customers/Accounts");
|
||||
|
||||
assertSame(accounts, cacheAccounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpringSubRegionConfiguration() {
|
||||
assertNotNull("The /Customers/Accounts SubRegion was not properly initialized!", accounts);
|
||||
assertEquals("Accounts", accounts.getName());
|
||||
assertEquals("/Customers/Accounts", accounts.getFullPath());
|
||||
|
||||
RegionAttributes regionAttributes = accounts.getAttributes();
|
||||
|
||||
assertNotNull(regionAttributes);
|
||||
assertEquals(DataPolicy.PERSISTENT_REPLICATE, regionAttributes.getDataPolicy());
|
||||
assertEquals(20, regionAttributes.getConcurrencyLevel());
|
||||
assertTrue(regionAttributes.isDiskSynchronous());
|
||||
assertTrue(regionAttributes.getIgnoreJTA());
|
||||
assertFalse(regionAttributes.getIndexMaintenanceSynchronous());
|
||||
assertEquals(1000, regionAttributes.getInitialCapacity());
|
||||
assertEquals(Long.class, regionAttributes.getKeyConstraint());
|
||||
assertEquals(Scope.DISTRIBUTED_ACK, regionAttributes.getScope());
|
||||
assertTrue(regionAttributes.getStatisticsEnabled());
|
||||
assertEquals(String.class, regionAttributes.getValueConstraint());
|
||||
assertNotNull(regionAttributes.getCacheListeners());
|
||||
assertEquals(1, regionAttributes.getCacheListeners().length);
|
||||
assertTrue(regionAttributes.getCacheListeners()[0] instanceof SimpleCacheListener);
|
||||
assertTrue(regionAttributes.getCacheLoader() instanceof SimpleCacheLoader);
|
||||
assertTrue(regionAttributes.getCacheWriter() instanceof SimpleCacheWriter);
|
||||
|
||||
EvictionAttributes evictionAttributes = regionAttributes.getEvictionAttributes();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, evictionAttributes.getAction());
|
||||
assertEquals(10000, evictionAttributes.getMaximum());
|
||||
|
||||
MembershipAttributes membershipAttributes = regionAttributes.getMembershipAttributes();
|
||||
|
||||
assertNotNull(membershipAttributes);
|
||||
assertNotNull(membershipAttributes.getRequiredRoles());
|
||||
assertEquals(1, membershipAttributes.getRequiredRoles().size());
|
||||
assertTrue(membershipAttributes.getRequiredRoles().iterator().next().getName().equalsIgnoreCase("TEST"));
|
||||
assertEquals(LossAction.LIMITED_ACCESS, membershipAttributes.getLossAction());
|
||||
assertEquals(ResumptionAction.REINITIALIZE, membershipAttributes.getResumptionAction());
|
||||
|
||||
SubscriptionAttributes subscriptionAttributes = regionAttributes.getSubscriptionAttributes();
|
||||
|
||||
assertNotNull(subscriptionAttributes);
|
||||
assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -28,7 +27,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* bean definition with both data-policy and shortcut specified.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Assert
|
||||
* @see org.junit.Test
|
||||
* @since 1.3.3
|
||||
*/
|
||||
public class ClientRegionUsingDataPolicyAndShortcutTest {
|
||||
|
||||
@@ -24,24 +24,31 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.SubRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.AttributesFactory;
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheLoader;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
|
||||
/**
|
||||
* The SubRegionNamespaceTest class is a test suite of test cases testing the contract and functionality of
|
||||
* Region/SubRegion creation in a GemFire Cache.
|
||||
* <p/>
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration(locations = "subregion-ns.xml", initializers = GemfireTestApplicationContextInitializer.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="subregion-ns.xml",
|
||||
initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SubRegionNamespaceTest {
|
||||
|
||||
@Autowired
|
||||
@@ -51,6 +58,7 @@ public class SubRegionNamespaceTest {
|
||||
@Test
|
||||
public void testNestedRegionsCreated() {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
|
||||
assertNotNull(cache.getRegion("parent"));
|
||||
assertNotNull(cache.getRegion("/parent/child"));
|
||||
assertNotNull(cache.getRegion("/parent/child/grandchild"));
|
||||
@@ -59,35 +67,31 @@ public class SubRegionNamespaceTest {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testNestedReplicatedRegions() {
|
||||
Region parent = null;
|
||||
parent = context.getBean("parent", Region.class);
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
Region parent = context.getBean("parent", Region.class);
|
||||
Region child = context.getBean("/parent/child", Region.class);
|
||||
Region grandchild = context.getBean("/parent/child/grandchild", Region.class);
|
||||
|
||||
assertNotNull(child);
|
||||
assertEquals("/parent/child", child.getFullPath());
|
||||
assertSame(child, parent.getSubregion("child"));
|
||||
|
||||
assertNotNull(grandchild);
|
||||
assertEquals("/parent/child/grandchild", grandchild.getFullPath());
|
||||
assertSame(grandchild, child.getSubregion("grandchild"));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testMixedNestedRegions() {
|
||||
Cache cache = context.getBean(Cache.class);
|
||||
|
||||
Region parent = context.getBean("replicatedParent", Region.class);
|
||||
|
||||
Region child = context.getBean("/replicatedParent/replicatedChild", Region.class);
|
||||
Region grandchild = context.getBean("/replicatedParent/replicatedChild/partitionedGrandchild", Region.class);
|
||||
|
||||
assertNotNull(child);
|
||||
assertEquals("/replicatedParent/replicatedChild", child.getFullPath());
|
||||
|
||||
assertEquals(child, parent.getSubregion("replicatedChild"));
|
||||
assertNotNull(grandchild);
|
||||
assertEquals("/replicatedParent/replicatedChild/partitionedGrandchild", grandchild.getFullPath());
|
||||
assertSame(grandchild, child.getSubregion("partitionedGrandchild"));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -100,25 +104,29 @@ public class SubRegionNamespaceTest {
|
||||
assertEquals("/parentWithSiblings/child2", child2.getFullPath());
|
||||
assertSame(child1, parent.getSubregion("child1"));
|
||||
assertSame(child2, parent.getSubregion("child2"));
|
||||
|
||||
Region grandchild1 = context.getBean("/parentWithSiblings/child1/grandChild11", Region.class);
|
||||
assertEquals("/parentWithSiblings/child1/grandChild11", grandchild1.getFullPath());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
@Test
|
||||
public void testComplexNestedRegions() throws Exception {
|
||||
Region parent = context.getBean("complexNested", Region.class);
|
||||
Region child1 = context.getBean("/complexNested/child1", Region.class);
|
||||
Region child2 = context.getBean("/complexNested/child2", Region.class);
|
||||
Region grandchild1 = context.getBean("/complexNested/child1/grandChild11", Region.class);
|
||||
Region grandchild11 = context.getBean("/complexNested/child1/grandChild11", Region.class);
|
||||
|
||||
SubRegionFactoryBean grandchild1fb = context.getBean("&/complexNested/child1/grandChild11",
|
||||
SubRegionFactoryBean.class);
|
||||
assertNotNull(grandchild1fb);
|
||||
RegionAttributes attr = grandchild1fb.create();
|
||||
assertNotNull(attr);
|
||||
CacheLoader cl = attr.getCacheLoader();
|
||||
assertNotNull(cl);
|
||||
ReplicatedRegionFactoryBean grandchild11FactoryBean = context.getBean("&/complexNested/child1/grandChild11",
|
||||
ReplicatedRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(grandchild11FactoryBean);
|
||||
|
||||
CacheLoader expectedCacheLoader = TestUtils.readField("cacheLoader", grandchild11FactoryBean);
|
||||
|
||||
assertNotNull(expectedCacheLoader);
|
||||
|
||||
CacheLoader actualCacheLoader = grandchild11.getAttributes().getCacheLoader();
|
||||
|
||||
assertSame(expectedCacheLoader, actualCacheLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* The SubRegionWithInvalidDataPolicyTest class is a test suite of test cases testing the data-policy and persistent
|
||||
* attributes settings are consistent for GemFire SubRegion bean definitions.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @since GemFire 7.0.1
|
||||
* @since Spring Data GemFire 1.4.0
|
||||
*/
|
||||
public class SubRegionWithInvalidDataPolicyTest {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testSubRegionBeanDefinitionWithInconsistentDataPolicy() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/subregion-with-invalid-datapolicy.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 'PERSISTENT_PARTITION' is not supported in Replicated Regions.",
|
||||
expected.getCause().getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testSubRegionBeanDefinitionWithInvalidDataPolicyPersistentSettings() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/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.",
|
||||
expected.getCause().getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,19 +42,19 @@ import com.gemstone.gemfire.cache.RegionService;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
import com.gemstone.gemfire.cache.query.QueryService;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
*/
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MockRegionFactory<K,V> {
|
||||
|
||||
|
||||
private static QueryService queryService = mock(QueryService.class);
|
||||
private static RegionService regionService = mock(RegionService.class);
|
||||
|
||||
|
||||
private AttributesFactory<K,V> attributesFactory;
|
||||
|
||||
|
||||
private final StubCache cache;
|
||||
|
||||
public MockRegionFactory(StubCache cache) {
|
||||
@@ -64,50 +64,55 @@ public class MockRegionFactory<K,V> {
|
||||
public RegionFactory<K, V> createMockRegionFactory() {
|
||||
return createMockRegionFactory(null);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public RegionFactory<K, V> createMockRegionFactory(RegionAttributes<K,V> attributes) {
|
||||
attributesFactory = attributes == null?
|
||||
new AttributesFactory<K,V>() :
|
||||
new AttributesFactory<K,V>(attributes) ;
|
||||
//Workaround for GemFire bug
|
||||
if(attributes !=null) {
|
||||
attributesFactory.setLockGrantor(attributes.isLockGrantor());
|
||||
}
|
||||
|
||||
final RegionFactory<K, V> regionFactory = mock(RegionFactory.class);
|
||||
|
||||
when(regionFactory.create(anyString())).thenAnswer(new Answer<Region>() {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public RegionFactory<K, V> createMockRegionFactory(RegionAttributes<K,V> attributes) {
|
||||
attributesFactory = (attributes != null ? new AttributesFactory<K,V>(attributes)
|
||||
: new AttributesFactory<K,V>());
|
||||
|
||||
//Workaround for GemFire bug
|
||||
if (attributes !=null) {
|
||||
attributesFactory.setLockGrantor(attributes.isLockGrantor());
|
||||
}
|
||||
|
||||
final RegionFactory<K, V> regionFactory = mock(RegionFactory.class);
|
||||
|
||||
when(regionFactory.create(anyString())).thenAnswer(new Answer<Region>() {
|
||||
@Override
|
||||
public Region answer(InvocationOnMock invocation) throws Throwable {
|
||||
String name = (String)invocation.getArguments()[0];
|
||||
String name = (String) invocation.getArguments()[0];
|
||||
Region region = mockRegion(name);
|
||||
cache.allRegions().put(name, region);
|
||||
return region;
|
||||
}});
|
||||
|
||||
|
||||
when(regionFactory.createSubregion(any(Region.class),anyString())).thenAnswer(new Answer<Region>() {
|
||||
}
|
||||
});
|
||||
|
||||
when(regionFactory.createSubregion(any(Region.class),anyString())).thenAnswer(new Answer<Region>() {
|
||||
@Override
|
||||
public Region answer(InvocationOnMock invocation) throws Throwable {
|
||||
Region parent = (Region)invocation.getArguments()[0];
|
||||
String name = (String)invocation.getArguments()[1];
|
||||
|
||||
String parentName = null;
|
||||
Region parent = (Region) invocation.getArguments()[0];
|
||||
String name = (String) invocation.getArguments()[1];
|
||||
String parentRegionName = null;
|
||||
|
||||
for (String key: cache.allRegions().keySet()) {
|
||||
if (cache.allRegions().get(key).equals(parent)) {
|
||||
parentName = key;
|
||||
parentRegionName = key;
|
||||
}
|
||||
}
|
||||
String regionName = parentName.startsWith("/") ? parentName+"/"+name : "/"+parentName+"/"+ name;
|
||||
Region subRegion = mockRegion(regionName);
|
||||
cache.allRegions().put(regionName, subRegion);
|
||||
|
||||
assert parentRegionName != null : "The parent Region name was null!";
|
||||
|
||||
String subRegionName = (parentRegionName.startsWith("/") ? parentRegionName+"/"+name
|
||||
: "/"+parentRegionName+"/"+ name);
|
||||
|
||||
Region subRegion = mockRegion(subRegionName);
|
||||
|
||||
cache.allRegions().put(subRegionName, subRegion);
|
||||
|
||||
return subRegion;
|
||||
}});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
when(regionFactory.setCacheLoader(any(CacheLoader.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -116,7 +121,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setCacheWriter(any(CacheWriter.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -125,8 +130,8 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
when(regionFactory.addAsyncEventQueueId(anyString())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -135,7 +140,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.addCacheListener(any(CacheListener.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -144,7 +149,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEvictionAttributes(any(EvictionAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -153,7 +158,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEntryIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -171,7 +176,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEntryTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -189,7 +194,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setRegionIdleTimeout(any(ExpirationAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -198,7 +203,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setRegionTimeToLive(any(ExpirationAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -207,7 +212,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setScope(any(Scope.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -216,7 +221,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setDataPolicy(any(DataPolicy.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -225,7 +230,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEarlyAck(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -234,7 +239,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setMulticastEnabled(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -243,7 +248,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setPoolName(anyString())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -252,7 +257,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEnableGateway(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -261,7 +266,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEnableAsyncConflation(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -270,7 +275,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setEnableSubscriptionConflation(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -279,7 +284,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setKeyConstraint(any(Class.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -288,7 +293,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setValueConstraint(any(Class.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -297,7 +302,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setInitialCapacity(anyInt())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -307,7 +312,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setLoadFactor(anyInt())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -316,7 +321,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setConcurrencyLevel(anyInt())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -325,7 +330,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setConcurrencyChecksEnabled(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -334,7 +339,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setDiskWriteAttributes(any(DiskWriteAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -343,7 +348,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setDiskStoreName(anyString())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -352,7 +357,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setDiskSynchronous(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -361,7 +366,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setDiskDirs(any(File[].class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -370,7 +375,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setDiskDirsAndSizes(any(File[].class),any(int[].class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -380,7 +385,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setPartitionAttributes(any(PartitionAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -389,7 +394,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setMembershipAttributes(any(MembershipAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -398,7 +403,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setIndexMaintenanceSynchronous(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -407,7 +412,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setStatisticsEnabled(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -416,7 +421,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setIgnoreJTA(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -425,7 +430,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setLockGrantor(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -435,7 +440,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setSubscriptionAttributes(any(SubscriptionAttributes.class))).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -444,7 +449,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setGatewayHubId(anyString())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -453,7 +458,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.setCloningEnabled(anyBoolean())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -462,7 +467,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.addGatewaySenderId(anyString())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -471,7 +476,7 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
when(regionFactory.addAsyncEventQueueId(anyString())).thenAnswer(new Answer<RegionFactory>(){
|
||||
@Override
|
||||
public RegionFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
@@ -480,82 +485,80 @@ public class MockRegionFactory<K,V> {
|
||||
return regionFactory;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
return regionFactory;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
RegionFactory createRegionFactory() {
|
||||
return createMockRegionFactory();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public Region mockRegion(String name) {
|
||||
RegionService regionService = mockRegionService();
|
||||
Region region = mock(Region.class);
|
||||
when(region.getRegionService()).thenReturn(regionService);
|
||||
|
||||
when(region.getAttributes()).thenAnswer(new Answer<RegionAttributes>() {
|
||||
|
||||
when(region.getRegionService()).thenReturn(regionService);
|
||||
|
||||
when(region.getAttributes()).thenAnswer(new Answer<RegionAttributes>() {
|
||||
@Override
|
||||
public RegionAttributes answer(InvocationOnMock invocation) throws Throwable {
|
||||
|
||||
RegionAttributes attributes = attributesFactory.create();
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
});
|
||||
when(region.getName()).thenReturn(name);
|
||||
|
||||
when(region.getSubregion(anyString())).thenAnswer(new Answer<Region>() {
|
||||
|
||||
when(region.getFullPath()).thenReturn(name);
|
||||
when(region.getName()).thenReturn(name);
|
||||
|
||||
when(region.getSubregion(anyString())).thenAnswer(new Answer<Region>() {
|
||||
@Override
|
||||
public Region answer(InvocationOnMock invocation) throws Throwable {
|
||||
Region parent = (Region) invocation.getMock();
|
||||
|
||||
String parentRegionName = parent.getName();
|
||||
String subRegionName = (String) invocation.getArguments()[0];
|
||||
String subRegionPath = (parentRegionName.startsWith("/") ? parentRegionName+"/"+subRegionName
|
||||
: "/"+parentRegionName+"/"+subRegionName);
|
||||
|
||||
Region region = cache.getRegion(subRegionPath);
|
||||
|
||||
return region;
|
||||
}
|
||||
});
|
||||
|
||||
when(region.createSubregion(anyString(), any(RegionAttributes.class))).thenAnswer(new Answer<Region>() {
|
||||
@Override
|
||||
public Region answer(InvocationOnMock invocation) throws Throwable {
|
||||
String name = (String) invocation.getArguments()[0];
|
||||
Region parent = (Region)invocation.getMock();
|
||||
String parentName = parent.getName();
|
||||
String regionName = parentName.startsWith("/") ? parentName+"/"+ name :
|
||||
"/"+parentName+"/"+ name;
|
||||
RegionAttributes attributes = (RegionAttributes) invocation.getArguments()[1];
|
||||
|
||||
Region region = cache.getRegion(regionName);
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
when(region.createSubregion(anyString(),any(RegionAttributes.class))).thenAnswer(new Answer<Region>() {
|
||||
|
||||
@Override
|
||||
public Region answer(InvocationOnMock invocation) throws Throwable {
|
||||
String name = (String)invocation.getArguments()[0];
|
||||
RegionAttributes attributes = (RegionAttributes)invocation.getArguments()[1];
|
||||
|
||||
Region parent = (Region)invocation.getMock();
|
||||
Region parent = (Region) invocation.getMock();
|
||||
String parentName = parent.getName();
|
||||
String regionName = parentName.startsWith("/") ? parentName+"/"+name : "/"+parentName+"/"+ name;
|
||||
|
||||
|
||||
Region subRegion = new MockRegionFactory(cache).createMockRegionFactory(attributes).create(regionName);
|
||||
when(subRegion.getFullPath()).thenReturn(regionName);
|
||||
|
||||
|
||||
cache.allRegions().put(regionName, subRegion);
|
||||
|
||||
return subRegion;
|
||||
}});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
|
||||
public static RegionService mockRegionService() {
|
||||
|
||||
when(regionService.getQueryService()).thenReturn(queryService);
|
||||
return regionService;
|
||||
}
|
||||
|
||||
|
||||
public static QueryService mockQueryService() {
|
||||
return queryService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user