Merge pull request #23 from lyndonadams/SGF-160

Sgf 160
This commit is contained in:
David Turanski
2013-03-13 05:04:42 -07:00
10 changed files with 2594 additions and 2370 deletions

View File

@@ -64,6 +64,11 @@ def customizePom(pom, gradleProject) {
name = 'Oliver Gierke'
email = 'ogierke@vmware.com'
}
developer {
id = 'ladams'
name = 'Lyndon Adams'
email = 'ladams@vmware.com'
}
}
}
}

View File

@@ -119,6 +119,7 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser {
}
ParsingUtils.parseExpiration(parserContext, element, attrBuilder);
ParsingUtils.parseSubscription(parserContext, element, attrBuilder);
ParsingUtils.parseEviction(parserContext, element, attrBuilder);
ParsingUtils.parseMembershipAttributes(parserContext, element, attrBuilder);

View File

@@ -48,6 +48,7 @@ import com.gemstone.gemfire.cache.Scope;
*
* @author Costin Leau
* @author David Turanski
* @author Lyndon Adams
*/
abstract class ParsingUtils {
@@ -256,6 +257,36 @@ abstract class ParsingUtils {
attrBuilder.addPropertyValue("evictionAttributes", evictionDefBuilder.getBeanDefinition());
return true;
}
/**
* Parses the subscription sub-element. Populates the given attribute factory
* with the proper attributes.
*
* @author Lyndon Adams
* @param parserContext
* @param element
* @param attrBuilder
* @return true if parsing actually occured, false otherwise
*/
static boolean parseSubscription(ParserContext parserContext, Element element, BeanDefinitionBuilder attrBuilder) {
Element subscriptionElement = DomUtils.getChildElementByTagName(element, "subscription");
if (subscriptionElement == null)
return false;
BeanDefinitionBuilder subscriptionDefBuilder = BeanDefinitionBuilder
.genericBeanDefinition(SubscriptionAttributesFactoryBean.class);
// do manual conversion since the enum is not public
String attr = subscriptionElement.getAttribute("type");
if (StringUtils.hasText(attr)) {
subscriptionDefBuilder.addPropertyValue("type", SubscriptionType.valueOf(attr.toUpperCase()));
}
attrBuilder.addPropertyValue("subscriptionAttributes", subscriptionDefBuilder.getBeanDefinition());
return true;
}
static void parseTransportFilters(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
Element transportFilterElement = DomUtils.getChildElementByTagName(element, "transport-filter");

View File

@@ -0,0 +1,102 @@
/*
* 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 org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.SubscriptionAttributes;
/**
* Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans.
*
* @author Lyndon Adams
* @since 12 March 2013
*/
public class SubscriptionAttributesFactoryBean implements FactoryBean<SubscriptionAttributes>, InitializingBean {
SubscriptionAttributes subscriptionAttri;
InterestPolicy policy;
SubscriptionType type = SubscriptionType.ALL;
/* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
if( policy == null ){
policy = InterestPolicy.DEFAULT;
}
subscriptionAttri = createAttributes();
}
private SubscriptionAttributes createAttributes(){
switch( type ){
case ALL :
policy = InterestPolicy.ALL;
break;
case CACHE_CONTENT :
policy = InterestPolicy.CACHE_CONTENT;
break;
default :
policy = InterestPolicy.DEFAULT;
}
return new SubscriptionAttributes( policy );
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
@Override
public SubscriptionAttributes getObject() throws Exception {
return subscriptionAttri;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
public Class<?> getObjectType() {
return ( subscriptionAttri != null ) ? subscriptionAttri.getClass() : SubscriptionAttributes.class;
}
/* (non-Javadoc)
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
*/
@Override
public boolean isSingleton() {
return true;
}
public InterestPolicy getPolicy() {
return policy;
}
public SubscriptionType getType() {
return type;
}
public void setPolicy(InterestPolicy policy) {
this.policy = policy;
}
public void setType(SubscriptionType type) {
this.type = type;
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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;
/**
* Simple enumeration for the various GemFire subscription types.
*
* @author Lyndon Adams
*
*/
enum SubscriptionType {
ALL, CACHE_CONTENT;
}

View File

@@ -0,0 +1,80 @@
/*
* 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.*;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.SubscriptionAttributes;
/**
* Test to ensure subscription policy can be applied to server regions.
*
* @author Lyndon Adams
* @since 13 March 2013
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/org/springframework/data/gemfire/config/subscription-ns.xml")
public class CacheSubscriptionTest{
@Autowired ApplicationContext context;
@SuppressWarnings("rawtypes")
@Test
public void testRRSubscriptionAllPolicy() throws Exception {
assertTrue(context.containsBean("replicALL"));
RegionFactoryBean fb = context.getBean("&replicALL", RegionFactoryBean.class);
RegionAttributes attrs = TestUtils.readField("attributes", fb);
SubscriptionAttributes sa = attrs.getSubscriptionAttributes();
assertEquals(InterestPolicy.ALL, sa.getInterestPolicy() );
}
@SuppressWarnings("rawtypes")
@Test
public void testPRSubscriptionCacheContentPolicy() throws Exception {
assertTrue(context.containsBean("partCACHE_CONTENT"));
RegionFactoryBean fb = context.getBean("&partCACHE_CONTENT", RegionFactoryBean.class);
RegionAttributes attrs = TestUtils.readField("attributes", fb);
SubscriptionAttributes sa = attrs.getSubscriptionAttributes();
assertEquals(InterestPolicy.CACHE_CONTENT, sa.getInterestPolicy() );
}
@SuppressWarnings("rawtypes")
@Test
public void testPRSubscriptionDefaultPolicy() throws Exception {
assertTrue(context.containsBean("partDEFAULT"));
RegionFactoryBean fb = context.getBean("&partDEFAULT", RegionFactoryBean.class);
RegionAttributes attrs = TestUtils.readField("attributes", fb);
SubscriptionAttributes sa = attrs.getSubscriptionAttributes();
assertEquals(InterestPolicy.ALL, sa.getInterestPolicy() );
}
}

View File

@@ -12,4 +12,5 @@
<property name="cache" ref="gemfireCache"/>
<property name="dataPolicy" value="REPLICATE_PERSISTENT"/>
</bean>
</beans>

View File

@@ -9,5 +9,5 @@
<gfe:client-region data-policy="NORMAL" name="ChallengeQuestions" id="challengeQuestionsRegion"/>
<gfe:pool>
<gfe:locator host="localhost" port="1234"/>
</gfe:pool>
</gfe:pool>
</beans>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
default-lazy-init="true"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd">
<gfe:cache/>
<gfe:replicated-region id="replicALL">
<gfe:subscription type="ALL"/>
</gfe:replicated-region>
<gfe:partitioned-region id="partCACHE_CONTENT">
<gfe:subscription type="CACHE_CONTENT"/>
<gfe:eviction threshold="70"/>
</gfe:partitioned-region>
<gfe:partitioned-region id="partDEFAULT">
<gfe:subscription/>
</gfe:partitioned-region>
</beans>