INT-3104:Add auto-start attribute to Gemfire Adapters

JIRA: https://jira.spring.io/browse/INT-3104

Add phase and remove unnecessary auto-starup

INT-3104: Remove reduntant code and format

Polishing and fixing parser tests
This commit is contained in:
David Liu
2014-07-25 12:56:18 +03:00
committed by Artem Bilan
parent eff1c7b7d8
commit aaf88ecc7c
13 changed files with 286 additions and 139 deletions

View File

@@ -0,0 +1,41 @@
<?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:gfe="http://www.springframework.org/schema/gemfire"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire
http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd
http://www.springframework.org/schema/gemfire
http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
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/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder properties-ref="props" />
<util:properties id="props">
<prop key="durable">true</prop>
</util:properties>
<bean id="queryListenerContainer" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer"/>
</bean>
<int-gfe:cq-inbound-channel-adapter id="withDurable"
cq-listener-container="queryListenerContainer" query="select * from /test"
channel="outputChannel1" durable="${durable}" auto-startup="false" phase="2"/>
<int:channel id="outputChannel1">
<int:queue/>
</int:channel>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2014 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
@@ -13,31 +13,56 @@
package org.springframework.integration.gemfire.config.xml;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.w3c.dom.Element;
import static org.junit.Assert.assertEquals;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.integration.gemfire.inbound.ContinuousQueryMessageProducer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dan Oxlade
* @author Liujiong
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class GemfireCqInboundChannelAdapterParserTests {
private GemfireCqInboundChannelAdapterParser underTest = new GemfireCqInboundChannelAdapterParser();
private GemfireCqInboundChannelAdapterParser underTest = new GemfireCqInboundChannelAdapterParser();
@Test(expected = BeanDefinitionParsingException.class)
public void cqListenerContainerIsARequiredAttribute() throws Exception {
String xml = "<cq-inbound-channel-adapter query=\"some-query\"/>";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.doParse(element, createFakeParserContext(), null);
}
@Autowired
@Qualifier("withDurable")
ContinuousQueryMessageProducer adapter;
@Test(expected = BeanDefinitionParsingException.class)
public void queryIsARequiredAttribute() throws Exception {
String xml = "<cq-inbound-channel-adapter cq-listener-container=\"some-reference\" />";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.doParse(element, createFakeParserContext(), null);
}
@Test(expected = BeanDefinitionParsingException.class)
public void cqListenerContainerIsARequiredAttribute() throws Exception {
String xml = "<cq-inbound-channel-adapter query=\"some-query\"/>";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.doParse(element, createFakeParserContext(), null);
}
@Test(expected = BeanDefinitionParsingException.class)
public void queryIsARequiredAttribute() throws Exception {
String xml = "<cq-inbound-channel-adapter cq-listener-container=\"some-reference\" />";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.doParse(element, createFakeParserContext(), null);
}
@Test
public void testPhase() {
assertEquals(2, adapter.getPhase());
}
@Test
public void testAutoStartup() {
assertEquals(false, adapter.isAutoStartup());
}
}

View File

@@ -0,0 +1,24 @@
<?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:gfe="http://www.springframework.org/schema/gemfire"
xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire
http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd
http://www.springframework.org/schema/gemfire
http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<gfe:cache id="gemfire-cache-2"/>
<gfe:replicated-region id="region1" cache-ref="gemfire-cache-2"/>
<int-gfe:inbound-channel-adapter id="channel1"
region="region1"
cache-events="CREATED"
expression="newValue"
auto-startup="false"
phase="2"/>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2014 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
@@ -13,24 +13,49 @@
package org.springframework.integration.gemfire.config.xml;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.w3c.dom.Element;
import static org.junit.Assert.assertEquals;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.integration.gemfire.inbound.CacheListeningMessageProducer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dan Oxlade
* @author Liujiong
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class GemfireInboundChannelAdapterParserTests {
private GemfireInboundChannelAdapterParser underTest = new GemfireInboundChannelAdapterParser();
private GemfireInboundChannelAdapterParser underTest = new GemfireInboundChannelAdapterParser();
@Test(expected = BeanDefinitionParsingException.class)
public void regionIsARequiredAttribute() throws Exception {
String xml = "<inbound-channel-adapter />";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.doParse(element, createFakeParserContext(), null);
}
@Autowired
@Qualifier("channel1.adapter")
CacheListeningMessageProducer adapter1;
@Test(expected = BeanDefinitionParsingException.class)
public void regionIsARequiredAttribute() throws Exception {
String xml = "<inbound-channel-adapter />";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.doParse(element, createFakeParserContext(), null);
}
@Test
public void testPhase() {
assertEquals(2, adapter1.getPhase());
}
@Test
public void testAutoStart() {
assertEquals(false, adapter1.isAutoStartup());
}
}

View File

@@ -1,21 +1,24 @@
<?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:int-gfe="http://www.springframework.org/schema/integration/gemfire"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire
http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:channel id="input" />
<int:channel id="input"/>
<int-gfe:outbound-channel-adapter region="region" channel="input">
<int-gfe:outbound-channel-adapter id="adapter" region="region" channel="input" auto-startup="false" phase="2">
<int-gfe:request-handler-advice-chain>
<bean class="org.springframework.integration.gemfire.config.xml.GemfireOutboundChannelAdapterParserTests$FooAdvice" />
<bean class="org.springframework.integration.gemfire.config.xml.GemfireOutboundChannelAdapterParserTests$FooAdvice"/>
</int-gfe:request-handler-advice-chain>
</int-gfe:outbound-channel-adapter>
<bean id="region" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.gemstone.gemfire.cache.Region" />
<constructor-arg value="com.gemstone.gemfire.cache.Region"/>
</bean>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2014 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
@@ -18,24 +18,40 @@ import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.config.ConsumerEndpointFactoryBean;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.messaging.support.GenericMessage;
import org.w3c.dom.Element;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dan Oxlade
* @author Liujiong
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class GemfireOutboundChannelAdapterParserTests {
private GemfireOutboundChannelAdapterParser underTest = new GemfireOutboundChannelAdapterParser();
private volatile static int adviceCalled;
@Autowired
@Qualifier("adapter")
ConsumerEndpointFactoryBean adapter1;
@Autowired
ApplicationContext ctx;
@Test(expected = BeanDefinitionParsingException.class)
public void regionIsARequiredAttribute() throws Exception {
String xml = "<outbound-channel-adapter />";
@@ -45,12 +61,22 @@ public class GemfireOutboundChannelAdapterParserTests {
@Test
public void withAdvice() {
ApplicationContext ctx = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-context.xml", this.getClass());
adapter1.start();
MessageChannel channel = ctx.getBean("input", MessageChannel.class);
channel.send(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
}
@Test
public void testPhase() {
assertEquals(2, adapter1.getPhase());
}
@Test
public void testAutoStart() {
assertEquals(false, adapter1.isAutoStartup());
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {
@Override

View File

@@ -1,25 +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:gfe="http://www.springframework.org/schema/gemfire"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:int-gfe="http://www.springframework.org/schema/integration/gemfire"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire
http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire.xsd
http://www.springframework.org/schema/gemfire
http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<gfe:cache id="gemfire-cache-2"/>
<gfe:replicated-region id="region1" cache-ref="gemfire-cache-2"/>
<gfe:replicated-region id="region2" cache-ref="gemfire-cache-2"/>
<gfe:replicated-region id="region3" cache-ref="gemfire-cache-2"/>
<int-gfe:inbound-channel-adapter id="channel1" region="region1" cache-events="CREATED" expression="newValue"/>
<int-gfe:inbound-channel-adapter id="channel2" region="region2"/>
<int-gfe:inbound-channel-adapter id="channel3" region="region3" error-channel="errorChannel"/>
</beans>