SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.
Removed the XSD enumeration restriction on the 'type' attribute of the 'index' element definition inside the SDG XML namespace (XSD) allowing the use of property placeholders to specify the Index types on GemFire Cache Region Indexes.
This commit is contained in:
@@ -33,13 +33,9 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -50,11 +46,7 @@ import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.CacheClosedException;
|
||||
import com.gemstone.gemfire.cache.CacheFactory;
|
||||
import com.gemstone.gemfire.cache.DynamicRegionFactory;
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.GemFireCache;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.TransactionListener;
|
||||
import com.gemstone.gemfire.cache.TransactionWriter;
|
||||
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
|
||||
@@ -917,22 +909,6 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
|
||||
return lazyInitialize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
private void initBeanFactory() {
|
||||
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
|
||||
ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) getBeanFactory();
|
||||
|
||||
beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class);
|
||||
beanFactory.registerCustomEditor(EvictionPolicyType.class, EvictionPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexMaintenancePolicyType.class, IndexMaintenancePolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected void postProcessPropertiesBeforeInitialization(Properties gemfireProperties) {
|
||||
if (GemfireUtils.isGemfireVersion8OrAbove()) {
|
||||
@@ -949,7 +925,6 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
initBeanFactory();
|
||||
postProcessPropertiesBeforeInitialization(getProperties());
|
||||
|
||||
if (!isLazyInitialize()) {
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -27,57 +24,27 @@ import org.springframework.util.StringUtils;
|
||||
* that converts a given String value into a proper IndexType.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.beans.PropertyEditorSupport
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
* @see org.springframework.data.gemfire.IndexType
|
||||
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
|
||||
* @since 1.5.2
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class IndexTypeConverter extends PropertyEditorSupport implements Converter<String, IndexType> {
|
||||
public class IndexTypeConverter extends AbstractPropertyEditorConverterSupport<IndexType> {
|
||||
|
||||
/**
|
||||
* Asserts that the given String value was successfully converted into a IndexType.
|
||||
* Converts the given String value into an appropriate IndexType.
|
||||
*
|
||||
* @param value the String value to convert into an appropriate IndexType.
|
||||
* @param indexType the converted IndexType.
|
||||
* @return the IndexType is non-null.
|
||||
* @throws java.lang.IllegalArgumentException if the IndexType argument was null, indicating that
|
||||
* the given String value could not be converted into an appropriate IndexType.
|
||||
* @see org.springframework.data.gemfire.IndexType
|
||||
*/
|
||||
private IndexType assertConverted(final String value, final IndexType indexType) {
|
||||
Assert.notNull(indexType, String.format("Failed to convert String (%1$s) into an IndexType!", value));
|
||||
return indexType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given String value into an appropriate IndexType
|
||||
*
|
||||
* @param value the String to convert into a corresponding IndexType enumerated value.
|
||||
* @return an IndexType converted from the given String value.
|
||||
* @param value the String to convert into an appropriate IndexType enumerated value.
|
||||
* @return an IndexType converted from the given String.
|
||||
* @throws java.lang.IllegalArgumentException if the given String could not be converted into
|
||||
* an appropriate IndexType enumerated value.
|
||||
* @see #assertConverted(String, IndexType)
|
||||
* @see #assertConverted(String, Object, Class)
|
||||
* @see org.springframework.data.gemfire.IndexType#valueOfIgnoreCase(String)
|
||||
* @see org.springframework.util.StringUtils#trimWhitespace(String)
|
||||
*/
|
||||
@Override
|
||||
public IndexType convert(final String value) {
|
||||
return assertConverted(value, IndexType.valueOfIgnoreCase(StringUtils.trimWhitespace(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this PropertyEditor as a IndexType enumerated value converted from the given String text.
|
||||
*
|
||||
* @param text the String to convert into a corresponding IndexType enumerated value.
|
||||
* @throws java.lang.IllegalArgumentException if the given String could not be converted into
|
||||
* an appropriate IndexType enumerated value.
|
||||
* @see #convert(String)
|
||||
* @see #setValue(Object)
|
||||
*/
|
||||
@Override
|
||||
public void setAsText(final String text) throws IllegalArgumentException {
|
||||
setValue(convert(text));
|
||||
return assertConverted(value, IndexType.valueOfIgnoreCase(StringUtils.trimWhitespace(value)), IndexType.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ class CacheParser extends AbstractSimpleBeanDefinitionParser {
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, builder);
|
||||
|
||||
registerCustomGemFireBeanFactoryPostProcessors(parserContext);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "cache-xml-location", "cacheXml");
|
||||
ParsingUtils.setPropertyReference(element, builder, "properties-ref", "properties");
|
||||
ParsingUtils.setPropertyValue(element, builder, "lazy-init","lazyInitialize");
|
||||
@@ -111,6 +113,11 @@ class CacheParser extends AbstractSimpleBeanDefinitionParser {
|
||||
parseJndiBindings(element, builder);
|
||||
}
|
||||
|
||||
private void registerCustomGemFireBeanFactoryPostProcessors(final ParserContext parserContext) {
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(BeanDefinitionBuilder.genericBeanDefinition(
|
||||
CustomEditorRegistrationBeanFactoryPostProcessor.class).getBeanDefinition(), parserContext.getRegistry());
|
||||
}
|
||||
|
||||
private void parsePdxDiskStore(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyValue(element, builder, "pdx-disk-store", "pdxDiskStoreName");
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.EvictionActionConverter;
|
||||
import org.springframework.data.gemfire.EvictionPolicyConverter;
|
||||
import org.springframework.data.gemfire.EvictionPolicyType;
|
||||
import org.springframework.data.gemfire.ExpirationActionConverter;
|
||||
import org.springframework.data.gemfire.IndexMaintenancePolicyConverter;
|
||||
import org.springframework.data.gemfire.IndexMaintenancePolicyType;
|
||||
import org.springframework.data.gemfire.IndexType;
|
||||
import org.springframework.data.gemfire.IndexTypeConverter;
|
||||
import org.springframework.data.gemfire.InterestPolicyConverter;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The CustomEditorRegistrationBeanFactoryPostProcessor class is a Spring BeanFactoryPostProcessor used to register
|
||||
* custom GemFire JavaBeans PropertyEditors and Spring Converters that are used to perform type conversions between
|
||||
* String-based configuration meta-data and actual GemFire or SDG defined enumerated types.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CustomEditorRegistrationBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
beanFactory.registerCustomEditor(EvictionAction.class, EvictionActionConverter.class);
|
||||
beanFactory.registerCustomEditor(EvictionPolicyType.class, EvictionPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(ExpirationAction.class, ExpirationActionConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexMaintenancePolicyType.class, IndexMaintenancePolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,9 +23,14 @@ import org.springframework.data.gemfire.IndexFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for <index;gt; definitions.
|
||||
* Namespace parser for <index;gt; bean definitions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class IndexParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@@ -33,17 +38,15 @@ class IndexParser extends AbstractSimpleBeanDefinitionParser {
|
||||
return IndexFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return (!"cache-ref".equals(attributeName) && super.isEligibleAttribute(attributeName));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
ParsingUtils.setPropertyReference(element, builder, "cache-ref", "cache");
|
||||
super.doParse(element, parserContext, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
if ("cache-ref".equals(attributeName)) {
|
||||
return false;
|
||||
}
|
||||
return super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2321,14 +2321,12 @@ The name of the index bean definition. If property 'name' is not set, it will be
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="type" use="optional">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="HASH" />
|
||||
<xsd:enumeration value="PRIMARY_KEY" />
|
||||
<xsd:enumeration value="FUNCTIONAL" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
<xsd:attribute name="type" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The type of index: FUNCTIONAL, HASH, PRIMARY_KEY.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="name" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
@@ -2346,16 +2344,14 @@ Corresponds to the regionPath parameter in createIndex methods.
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="imports" type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="override" type="xsd:string" use="optional"
|
||||
default="true">
|
||||
<xsd:attribute name="override" type="xsd:string" use="optional" default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether the index is created even if there is an index with the same name (default) or not.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" use="optional"
|
||||
default="gemfireCache">
|
||||
<xsd:attribute name="cache-ref" type="xsd:string" use="optional" default="gemfireCache">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The name of the bean defining the GemFire cache (by default 'gemfireCache').
|
||||
|
||||
@@ -55,7 +55,7 @@ public class IndexTypeConverterTest {
|
||||
converter.convert("function");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Failed to convert String (function) into an IndexType!", expected.getMessage());
|
||||
assertEquals("(function) is not a valid IndexType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class IndexTypeConverterTest {
|
||||
converter.setAsText("invalid");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Failed to convert String (invalid) into an IndexType!", expected.getMessage());
|
||||
assertEquals("(invalid) is not a valid IndexType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.EvictionActionConverter;
|
||||
import org.springframework.data.gemfire.EvictionPolicyConverter;
|
||||
import org.springframework.data.gemfire.EvictionPolicyType;
|
||||
import org.springframework.data.gemfire.ExpirationActionConverter;
|
||||
import org.springframework.data.gemfire.IndexMaintenancePolicyConverter;
|
||||
import org.springframework.data.gemfire.IndexMaintenancePolicyType;
|
||||
import org.springframework.data.gemfire.IndexType;
|
||||
import org.springframework.data.gemfire.IndexTypeConverter;
|
||||
import org.springframework.data.gemfire.InterestPolicyConverter;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The CustomEditorRegistrationBeanFactoryPostProcessorTest class...
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.config.CustomEditorRegistrationBeanFactoryPostProcessor
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class CustomEditorRegistrationBeanFactoryPostProcessorTest {
|
||||
|
||||
@Test
|
||||
public void testCustomEditorRegistration() {
|
||||
ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class,
|
||||
"testCustomEditorRegistration.MockBeanFactory");
|
||||
|
||||
new CustomEditorRegistrationBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
|
||||
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class),
|
||||
eq(EvictionActionConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class),
|
||||
eq(EvictionPolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ExpirationAction.class),
|
||||
eq(ExpirationActionConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexMaintenancePolicyType.class),
|
||||
eq(IndexMaintenancePolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexType.class),
|
||||
eq(IndexTypeConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestPolicy.class),
|
||||
eq(InterestPolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestResultPolicy.class),
|
||||
eq(InterestResultPolicyConverter.class));
|
||||
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class),
|
||||
eq(SubscriptionEvictionPolicyConverter.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,61 +18,70 @@ package org.springframework.data.gemfire.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.query.Index;
|
||||
|
||||
/**
|
||||
* The IndexNamespaceTest is a test suite of test cases testing the functionality of GemFire Index creation using
|
||||
* the Spring Data GemFire XML namespace (XSD).
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.IndexFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.IndexParser
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@ContextConfiguration(locations="index-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
@ContextConfiguration(locations="index-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class IndexNamespaceTest {
|
||||
|
||||
private final String name = "test-index";
|
||||
private static final String TEST_REGION_NAME = "TestIndexRegion";
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
private Cache cache;
|
||||
|
||||
@Resource(name = "simple")
|
||||
private Index simple;
|
||||
|
||||
@Resource(name = "complex")
|
||||
private Index complex;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Cache cache = (Cache) context.getBean("gemfireCache");
|
||||
|
||||
if (cache.getRegion(name) == null) {
|
||||
cache.createRegionFactory().create("test-index");
|
||||
if (cache.getRegion(TEST_REGION_NAME) == null) {
|
||||
cache.createRegionFactory().create(TEST_REGION_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicIndex() throws Exception {
|
||||
Index idx = (Index) context.getBean("simple");
|
||||
|
||||
assertEquals("/test-index", idx.getFromClause());
|
||||
assertEquals("status", idx.getIndexedExpression());
|
||||
assertEquals("simple", idx.getName());
|
||||
assertEquals(name, idx.getRegion().getName());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, idx.getType());
|
||||
assertEquals("simple", simple.getName());
|
||||
assertEquals("status", simple.getIndexedExpression());
|
||||
assertEquals(Region.SEPARATOR + TEST_REGION_NAME, simple.getFromClause());
|
||||
assertEquals(TEST_REGION_NAME, simple.getRegion().getName());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, simple.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexIndex() throws Exception {
|
||||
Index idx = (Index) context.getBean("complex");
|
||||
|
||||
assertEquals("/test-index tsi", idx.getFromClause());
|
||||
assertEquals("tsi.name", idx.getIndexedExpression());
|
||||
assertEquals("complex-index", idx.getName());
|
||||
assertEquals(name, idx.getRegion().getName());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, idx.getType());
|
||||
assertEquals("complex-index", complex.getName());
|
||||
assertEquals("tsi.name", complex.getIndexedExpression());
|
||||
assertEquals(Region.SEPARATOR + TEST_REGION_NAME + " tsi", complex.getFromClause());
|
||||
assertEquals(TEST_REGION_NAME, complex.getRegion().getName());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, complex.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
" default-lazy-init="true">
|
||||
|
||||
<util:properties id="indexConfiguration">
|
||||
<prop key="index.complex.type">HASH</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="indexConfiguration"/>
|
||||
|
||||
<!-- all beans are lazy to allow the same config to be used between multiple tests -->
|
||||
<!-- as there can be only one cache per VM -->
|
||||
|
||||
@@ -20,8 +28,9 @@
|
||||
|
||||
<gfe:cache properties-ref="gemfireProperties"/>
|
||||
|
||||
<gfe:index id="simple" expression="status" from="/test-index" type="FUNCTIONAL"/>
|
||||
<gfe:index id="simple" expression="status" from="/TestIndexRegion" type="functional"/>
|
||||
|
||||
<gfe:index id="complex" name="complex-index" expression="tsi.name" from="/test-index tsi" type="HASH" imports="import java.util"/>
|
||||
<gfe:index id="complex" name="complex-index" expression="tsi.name" from="/TestIndexRegion tsi"
|
||||
imports="import java.util" type="${index.complex.type}"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user