SGF-863 - Add integration tests testing the addition of AsyncEventQueues and GatewaySenders declared as both objects and identifiers to an existing Region defined in cache.xml.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
|
||||
import org.apache.geode.cache.wan.GatewaySender;
|
||||
|
||||
@@ -24,10 +25,16 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* The AbstractPeerRegionParser class...
|
||||
* Abstract Spring XML Parser for peer {@link Region} bean definitions.
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.0.0
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueue
|
||||
* @see org.apache.geode.cache.wan.GatewaySender
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.w3c.dom.Element
|
||||
* @since 2.2.0
|
||||
*/
|
||||
public abstract class AbstractPeerRegionParser extends AbstractRegionParser {
|
||||
|
||||
|
||||
@@ -13,15 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.xml;
|
||||
|
||||
import org.apache.geode.cache.asyncqueue.AsyncEventQueue;
|
||||
import org.apache.geode.cache.wan.GatewaySender;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.LookupRegionFactoryBean;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
@@ -30,8 +31,13 @@ import org.w3c.dom.Element;
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueue
|
||||
* @see org.apache.geode.cache.wan.GatewaySender
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.springframework.data.gemfire.LookupRegionFactoryBean
|
||||
* @see AbstractRegionParser
|
||||
* @see org.springframework.data.gemfire.config.xml.AbstractRegionParser
|
||||
* @see org.w3c.dom.Element
|
||||
*/
|
||||
class LookupRegionParser extends AbstractRegionParser {
|
||||
|
||||
@@ -52,14 +58,17 @@ class LookupRegionParser extends AbstractRegionParser {
|
||||
|
||||
super.doParse(element, builder);
|
||||
|
||||
String resolvedCacheRef = ParsingUtils.resolveCacheReference(
|
||||
element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME));
|
||||
String resolvedCacheRef =
|
||||
ParsingUtils.resolveCacheReference(element.getAttribute(ParsingUtils.CACHE_REF_ATTRIBUTE_NAME));
|
||||
|
||||
builder.addPropertyReference("cache", resolvedCacheRef);
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "async-event-queue-ids");
|
||||
ParsingUtils.setPropertyValue(element, builder, "cloning-enabled");
|
||||
ParsingUtils.setPropertyValue(element, builder, "eviction-maximum");
|
||||
ParsingUtils.setPropertyValue(element, builder, "gateway-sender-ids");
|
||||
ParsingUtils.setPropertyValue(element, builder, "name");
|
||||
|
||||
ParsingUtils.parseExpiration(element, parserContext, builder);
|
||||
|
||||
parseCollectionOfCustomSubElements(element, parserContext, builder, AsyncEventQueue.class.getName(),
|
||||
@@ -71,23 +80,22 @@ class LookupRegionParser extends AbstractRegionParser {
|
||||
Element cacheListenerElement = DomUtils.getChildElementByTagName(element, "cache-listener");
|
||||
|
||||
if (cacheListenerElement != null) {
|
||||
builder.addPropertyValue("cacheListeners", ParsingUtils.parseRefOrNestedBeanDeclaration(
|
||||
cacheListenerElement, parserContext,
|
||||
builder));
|
||||
builder.addPropertyValue("cacheListeners",
|
||||
ParsingUtils.parseRefOrNestedBeanDeclaration(cacheListenerElement, parserContext, builder));
|
||||
}
|
||||
|
||||
Element cacheLoaderElement = DomUtils.getChildElementByTagName(element, "cache-loader");
|
||||
|
||||
if (cacheLoaderElement != null) {
|
||||
builder.addPropertyValue("cacheLoader", ParsingUtils.parseRefOrSingleNestedBeanDeclaration(
|
||||
cacheLoaderElement, parserContext, builder));
|
||||
builder.addPropertyValue("cacheLoader",
|
||||
ParsingUtils.parseRefOrSingleNestedBeanDeclaration(cacheLoaderElement, parserContext, builder));
|
||||
}
|
||||
|
||||
Element cacheWriterElement = DomUtils.getChildElementByTagName(element, "cache-writer");
|
||||
|
||||
if (cacheWriterElement != null) {
|
||||
builder.addPropertyValue("cacheWriter", ParsingUtils.parseRefOrSingleNestedBeanDeclaration(
|
||||
cacheWriterElement, parserContext, builder));
|
||||
builder.addPropertyValue("cacheWriter",
|
||||
ParsingUtils.parseRefOrSingleNestedBeanDeclaration(cacheWriterElement, parserContext, builder));
|
||||
}
|
||||
|
||||
if (!subRegion) {
|
||||
|
||||
@@ -975,7 +975,7 @@ The name of the region definition.]]>
|
||||
<xsd:complexType name="baseRegionType" abstract="true">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="baseReadOnlyRegionType">
|
||||
<xsd:sequence minOccurs="0" maxOccurs="1">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="cache-loader" type="beanDeclarationType" minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.apache.geode.cache.CacheLoader"><![CDATA[
|
||||
|
||||
@@ -975,7 +975,7 @@ The name of the region definition.]]>
|
||||
<xsd:complexType name="baseRegionType" abstract="true">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="baseReadOnlyRegionType">
|
||||
<xsd:sequence minOccurs="0" maxOccurs="1">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="cache-loader" type="beanDeclarationType" minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.apache.geode.cache.CacheLoader"><![CDATA[
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2018 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
|
||||
*
|
||||
* https://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.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.DataPolicy;
|
||||
import org.apache.geode.cache.Region;
|
||||
import org.apache.geode.cache.RegionAttributes;
|
||||
import org.apache.geode.cache.asyncqueue.AsyncEventListener;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractFactoryBeanSupport;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The LookupRegionWithAsyncEventQueuesAndGatewaySendersIntegrationTests class...
|
||||
*
|
||||
* @author John Blum
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
@SuppressWarnings("unused")
|
||||
public class LookupRegionWithAsyncEventQueuesAndGatewaySendersIntegrationTests {
|
||||
|
||||
@Resource(name = "Example")
|
||||
private Region<?, ?> example;
|
||||
|
||||
@Test
|
||||
public void regionWithAsyncEventQueuesAndGatewaySenderConfigurationIsCorrect() {
|
||||
|
||||
assertThat(this.example).isNotNull();
|
||||
assertThat(this.example.getName()).isEqualTo("Example");
|
||||
|
||||
RegionAttributes<?, ?> exampleAttributes = this.example.getAttributes();
|
||||
|
||||
assertThat(exampleAttributes).isNotNull();
|
||||
assertThat(exampleAttributes.getDataPolicy()).isEqualTo(DataPolicy.REPLICATE);
|
||||
|
||||
assertThat(exampleAttributes.getAsyncEventQueueIds()).containsExactlyInAnyOrder(
|
||||
"TestAsyncEventQueueZero",
|
||||
"TestAsyncEventQueueOne",
|
||||
"TestAsyncEventQueueTwo",
|
||||
"TestAsyncEventQueueThree",
|
||||
"TestAsyncEventQueueFour"
|
||||
);
|
||||
|
||||
assertThat(exampleAttributes.getGatewaySenderIds()).containsExactlyInAnyOrder(
|
||||
"TestGatewaySenderZero",
|
||||
"TestGatewaySenderOne",
|
||||
"TestGatewaySenderTwo",
|
||||
"TestGatewaySenderThree",
|
||||
"TestGatewaySenderFour"
|
||||
);
|
||||
}
|
||||
|
||||
public static final class AsyncEventListenerFactoryBean extends AbstractFactoryBeanSupport<AsyncEventListener> {
|
||||
|
||||
private final AsyncEventListener mockAsyncEventListener = mock(AsyncEventListener.class);
|
||||
|
||||
@Nullable @Override
|
||||
public AsyncEventListener getObject() {
|
||||
return this.mockAsyncEventListener;
|
||||
}
|
||||
|
||||
@Nullable @Override
|
||||
public Class<?> getObjectType() {
|
||||
|
||||
return this.mockAsyncEventListener != null
|
||||
? this.mockAsyncEventListener.getClass()
|
||||
: AsyncEventListener.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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/geode"
|
||||
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/geode http://www.springframework.org/schema/geode/spring-geode.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
||||
">
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
<util:properties id="gemfireProperties">
|
||||
<prop key="name">LookupRegionWithAsyncEventQueuesAndGatewaySendersIntegrationTests</prop>
|
||||
<prop key="log-level">error</prop>
|
||||
</util:properties>
|
||||
|
||||
<gfe:cache cache-xml-location="region-with-asynceventqueues-gatewaysenders-cache.xml"
|
||||
properties-ref="gemfireProperties"/>
|
||||
|
||||
<bean id="MockAsyncEventListener"
|
||||
class="org.springframework.data.gemfire.config.xml.LookupRegionWithAsyncEventQueuesAndGatewaySendersIntegrationTests$AsyncEventListenerFactoryBean"/>
|
||||
|
||||
|
||||
<gfe:async-event-queue id="TestAsyncEventQueueFour">
|
||||
<gfe:async-event-listener ref="MockAsyncEventListener"/>
|
||||
</gfe:async-event-queue>
|
||||
|
||||
<gfe:gateway-sender id="TestGatewaySenderFour" manual-start="true" remote-distributed-system-id="1"/>
|
||||
|
||||
<gfe:lookup-region id="Example"
|
||||
async-event-queue-ids="TestAsyncEventQueueOne, TestAsyncEventQueueTwo, TestAsyncEventQueueFour"
|
||||
gateway-sender-ids="TestGatewaySenderZero, TestGatewaySenderOne, TestGatewaySenderTwo">
|
||||
|
||||
<gfe:gateway-sender name="TestGatewaySenderThree" manual-start="true" remote-distributed-system-id="1"/>
|
||||
|
||||
<gfe:gateway-sender-ref bean="TestGatewaySenderFour"/>
|
||||
|
||||
<gfe:async-event-queue name="TestAsyncEventQueueThree">
|
||||
<gfe:async-event-listener ref="MockAsyncEventListener"/>
|
||||
</gfe:async-event-queue>
|
||||
|
||||
<gfe:async-event-queue-ref bean="TestAsyncEventQueueFour"/>
|
||||
|
||||
</gfe:lookup-region>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cache xmlns="http://geode.apache.org/schema/cache"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://geode.apache.org/schema/cache https://geode.apache.org/schema/cache/cache-1.0.xsd"
|
||||
version="1.0">
|
||||
|
||||
<region name="Example" refid="REPLICATE">
|
||||
<region-attributes async-event-queue-ids="TestAsyncEventQueueZero" gateway-sender-ids="TestGatewaySenderZero"/>
|
||||
</region>
|
||||
|
||||
</cache>
|
||||
Reference in New Issue
Block a user