INT-3665: Remove Deprecations and Resolve Issues

https://jira.spring.io/browse/INT-3665

Fixes according Travis report

Introduce `...ExpressionString(String)` setter

Some further fixes and polishing

Address PR comments
This commit is contained in:
Artem Bilan
2015-08-13 16:10:36 -04:00
committed by Gary Russell
parent 84fdd98428
commit cf528c0b5d
81 changed files with 529 additions and 1168 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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
@@ -10,6 +10,7 @@
* 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.integration.gemfire.config.xml;
import org.w3c.dom.Element;
@@ -25,6 +26,7 @@ import org.springframework.integration.gemfire.inbound.ContinuousQueryMessagePro
* @author David Turanski
* @author Dan Oxlade
* @author Gary Russell
* @author Artem Bilan
* @since 2.1
*
*/
@@ -43,8 +45,6 @@ public class GemfireCqInboundChannelAdapterParser extends AbstractChannelAdapter
private static final String QUERY_ATTRIBUTE = "query";
private static final String PAYLOAD_EXPRESSION_PROPERTY = "payloadExpression";
private static final String EXPRESSION_ATTRIBUTE = "expression";
private static final String SUPPORTED_EVENT_TYPES_PROPERTY = "supportedEventTypes";
@@ -53,11 +53,11 @@ public class GemfireCqInboundChannelAdapterParser extends AbstractChannelAdapter
@Override
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
BeanDefinitionBuilder continuousQueryMesageProducer =
BeanDefinitionBuilder continuousQueryMessageProducer =
BeanDefinitionBuilder.genericBeanDefinition(ContinuousQueryMessageProducer.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element,
EXPRESSION_ATTRIBUTE, PAYLOAD_EXPRESSION_PROPERTY);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element,
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMessageProducer, element,
EXPRESSION_ATTRIBUTE, "payloadExpressionString");
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMessageProducer, element,
QUERY_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY);
if (!element.hasAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE)) {
@@ -69,16 +69,16 @@ public class GemfireCqInboundChannelAdapterParser extends AbstractChannelAdapter
parserContext.getReaderContext().error("'" + QUERY_ATTRIBUTE + "' attribute is required.", element);
}
continuousQueryMesageProducer.addConstructorArgReference(element.getAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE));
continuousQueryMesageProducer.addConstructorArgValue(element.getAttribute(QUERY_ATTRIBUTE));
continuousQueryMessageProducer.addConstructorArgReference(element.getAttribute(QUERY_LISTENER_CONTAINER_ATTRIBUTE));
continuousQueryMessageProducer.addConstructorArgValue(element.getAttribute(QUERY_ATTRIBUTE));
continuousQueryMesageProducer.addPropertyReference(OUTPUT_CHANNEL_PROPERTY, channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(continuousQueryMesageProducer, element,
continuousQueryMessageProducer.addPropertyReference(OUTPUT_CHANNEL_PROPERTY, channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(continuousQueryMessageProducer, element,
ERROR_CHANNEL_ATTRIBUTE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, QUERY_NAME_ATTRIBUTE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMesageProducer, element, DURABLE_ATTRIBUTE);
return continuousQueryMesageProducer.getBeanDefinition();
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMessageProducer, element, QUERY_NAME_ATTRIBUTE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(continuousQueryMessageProducer, element, DURABLE_ATTRIBUTE);
return continuousQueryMessageProducer.getBeanDefinition();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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
@@ -25,6 +25,7 @@ import org.springframework.integration.gemfire.inbound.CacheListeningMessageProd
/**
* @author David Turanski
* @author Gary Russell
* @author Artem Bilan
* @since 2.1
*/
public class GemfireInboundChannelAdapterParser extends AbstractChannelAdapterParser {
@@ -35,8 +36,6 @@ public class GemfireInboundChannelAdapterParser extends AbstractChannelAdapterPa
private static final String REGION_ATTRIBUTE = "region";
private static final String PAYLOAD_EXPRESSION_PROPERTY = "payloadExpression";
private static final String EXPRESSION_ATTRIBUTE = "expression";
private static final String SUPPORTED_EVENT_TYPES_PROPERTY = "supportedEventTypes";
@@ -48,7 +47,7 @@ public class GemfireInboundChannelAdapterParser extends AbstractChannelAdapterPa
BeanDefinitionBuilder listeningMessageProducer =
BeanDefinitionBuilder.genericBeanDefinition(CacheListeningMessageProducer.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(listeningMessageProducer, element,
EXPRESSION_ATTRIBUTE, PAYLOAD_EXPRESSION_PROPERTY);
EXPRESSION_ATTRIBUTE, "payloadExpressionString");
IntegrationNamespaceUtils.setValueIfAttributeDefined(listeningMessageProducer, element,
CACHE_EVENTS_ATTRIBUTE, SUPPORTED_EVENT_TYPES_PROPERTY);

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.Message;
@@ -36,12 +37,14 @@ import com.gemstone.gemfire.cache.Region;
/**
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @since 2.1
*/
public class CacheListeningMessageProducerTests {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
@Test
@SuppressWarnings("deprecation")
public void receiveNewValuePayloadForCreateEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
Cache cache = cacheFactoryBean.getObject();
@@ -55,7 +58,7 @@ public class CacheListeningMessageProducerTests {
Region<String, String> region = regionFactoryBean.getObject();
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setPayloadExpression("key + '=' + newValue");
producer.setPayloadExpression(PARSER.parseExpression("key + '=' + newValue"));
producer.setOutputChannel(channel);
producer.setBeanFactory(mock(BeanFactory.class));
producer.afterPropertiesSet();
@@ -68,7 +71,6 @@ public class CacheListeningMessageProducerTests {
}
@Test
@SuppressWarnings("deprecation")
public void receiveNewValuePayloadForUpdateEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
Cache cache = cacheFactoryBean.getObject();
@@ -82,7 +84,7 @@ public class CacheListeningMessageProducerTests {
Region<String, String> region = regionFactoryBean.getObject();
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setPayloadExpression("newValue");
producer.setPayloadExpression(PARSER.parseExpression("newValue"));
producer.setOutputChannel(channel);
producer.setBeanFactory(mock(BeanFactory.class));
producer.afterPropertiesSet();
@@ -99,7 +101,6 @@ public class CacheListeningMessageProducerTests {
}
@Test
@SuppressWarnings("deprecation")
public void receiveOldValuePayloadForDestroyEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
Cache cache = cacheFactoryBean.getObject();
@@ -114,7 +115,7 @@ public class CacheListeningMessageProducerTests {
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setSupportedEventTypes(EventType.DESTROYED);
producer.setPayloadExpression("oldValue");
producer.setPayloadExpression(PARSER.parseExpression("oldValue"));
producer.setOutputChannel(channel);
producer.setBeanFactory(mock(BeanFactory.class));
producer.afterPropertiesSet();
@@ -129,7 +130,6 @@ public class CacheListeningMessageProducerTests {
}
@Test
@SuppressWarnings("deprecation")
public void receiveOldValuePayloadForInvalidateEvent() throws Exception {
CacheFactoryBean cacheFactoryBean = new CacheFactoryBean();
Cache cache = cacheFactoryBean.getObject();
@@ -144,7 +144,7 @@ public class CacheListeningMessageProducerTests {
QueueChannel channel = new QueueChannel();
CacheListeningMessageProducer producer = new CacheListeningMessageProducer(region);
producer.setSupportedEventTypes(EventType.INVALIDATED);
producer.setPayloadExpression("key + ' was ' + oldValue");
producer.setPayloadExpression(PARSER.parseExpression("key + ' was ' + oldValue"));
producer.setOutputChannel(channel);
producer.setBeanFactory(mock(BeanFactory.class));
producer.afterPropertiesSet();
@@ -164,4 +164,5 @@ public class CacheListeningMessageProducerTests {
attributesFactoryBean.afterPropertiesSet();
regionFactoryBean.setAttributes(attributesFactoryBean.getObject());
}
}

View File

@@ -16,16 +16,17 @@ package org.springframework.integration.gemfire.inbound;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.junit.Before;
import org.junit.Test;
import com.gemstone.gemfire.cache.Operation;
import com.gemstone.gemfire.cache.query.CqEvent;
import com.gemstone.gemfire.cache.query.CqQuery;
@@ -38,6 +39,8 @@ import com.gemstone.gemfire.cache.query.internal.CqQueryImpl;
*/
public class ContinuousQueryMessageProducerTests {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
ContinuousQueryListenerContainer queryListenerContainer;
ContinuousQueryMessageProducer cqMessageProducer;
@@ -87,10 +90,9 @@ public class ContinuousQueryMessageProducerTests {
}
@Test
@SuppressWarnings("deprecation")
public void testPayloadExpression() {
CqEvent cqEvent = event(Operation.CREATE, "hello");
cqMessageProducer.setPayloadExpression("newValue.toUpperCase() + ', WORLD'");
cqMessageProducer.setPayloadExpression(PARSER.parseExpression("newValue.toUpperCase() + ', WORLD'"));
cqMessageProducer.afterPropertiesSet();
cqMessageProducer.onEvent(cqEvent);
@@ -100,7 +102,7 @@ public class ContinuousQueryMessageProducerTests {
CqEvent event(final Operation operation, final Object value) {
CqEvent event = new CqEvent() {
return new CqEvent() {
final CqQuery cq = new CqQueryImpl();
@@ -139,8 +141,6 @@ public class ContinuousQueryMessageProducerTests {
}
};
return event;
}
private static class CqMessageHandler implements MessageHandler {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2015 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
@@ -24,6 +24,7 @@ import org.springframework.messaging.MessagingException;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -36,7 +37,9 @@ import com.gemstone.gemfire.internal.cache.DistributedRegion;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext
public class GemfireInboundChannelAdapterTests {
@Autowired
SubscribableChannel channel1;
@@ -58,8 +61,6 @@ public class GemfireInboundChannelAdapterTests {
@Autowired
DistributedRegion region3;
@Test
public void testGemfireInboundChannelAdapterWithExpression() {
@@ -96,23 +97,27 @@ public class GemfireInboundChannelAdapterTests {
region3.put("payload", "payload");
assertEquals(1, errorHandler.count);
}
static class ErrorHandler implements MessageHandler {
public int count = 0;
public void handleMessage(Message<?> message) throws MessagingException {
assertTrue(message instanceof ErrorMessage);
count++;
}
}
static class EventHandler implements MessageHandler {
public Object event = null;
public void handleMessage(Message<?> message) throws MessagingException {
event = message.getPayload();
}
}
}