Move SF dependencies to the latest BUILD-SNAPSHOT (#2921)
* Move SF dependencies to the latest BUILD-SNAPSHOT To avoid class loader issues it is better to align Spring Data dependencies with SF version we use explicitly. This way we don't have a `ClassLoader` issue when a newly introduced `TransactionManager` might not be visible from the previous versions * Fix code style warnings in the `TransactionSynchronizationFactoryBean` * Use `JavaUtils` in the `TransactionSynchronizationFactoryBean` to decrease code complexity * * Fix CQ Gemfire tests for upgrades compatibility
This commit is contained in:
committed by
Gary Russell
parent
0d6faa2e34
commit
444cd1e8df
12
build.gradle
12
build.gradle
@@ -136,12 +136,12 @@ subprojects { subproject ->
|
||||
rsocketVersion = '0.12.2-RC3-SNAPSHOT'
|
||||
servletApiVersion = '4.0.1'
|
||||
smackVersion = '4.3.3'
|
||||
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.2.0.M1'
|
||||
springDataJpaVersion = '2.2.0.M3'
|
||||
springDataMongoVersion = '2.2.0.M3'
|
||||
springDataRedisVersion = '2.2.0.M3'
|
||||
springGemfireVersion = '2.2.0.M3'
|
||||
springSecurityVersion = '5.2.0.M2'
|
||||
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.2.0.BUILD-SNAPSHOT'
|
||||
springDataJpaVersion = '2.2.0.BUILD-SNAPSHOT'
|
||||
springDataMongoVersion = '2.2.0.BUILD-SNAPSHOT'
|
||||
springDataRedisVersion = '2.2.0.BUILD-SNAPSHOT'
|
||||
springGemfireVersion = '2.2.0.BUILD-SNAPSHOT'
|
||||
springSecurityVersion = '5.2.0.BUILD-SNAPSHOT'
|
||||
springRetryVersion = '1.2.4.RELEASE'
|
||||
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.2.0.BUILD-SNAPSHOT'
|
||||
springWsVersion = '3.0.7.RELEASE'
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.util.JavaUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.core.BeanFactoryMessageChannelDestinationResolver;
|
||||
import org.springframework.messaging.core.DestinationResolver;
|
||||
@@ -36,6 +37,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class TransactionSynchronizationFactoryBean implements FactoryBean<DefaultTransactionSynchronizationFactory>,
|
||||
@@ -169,39 +171,29 @@ public class TransactionSynchronizationFactoryBean implements FactoryBean<Defaul
|
||||
if (this.channelResolver == null) {
|
||||
this.channelResolver = new BeanFactoryMessageChannelDestinationResolver(this.beanFactory);
|
||||
}
|
||||
ExpressionEvaluatingTransactionSynchronizationProcessor processor =
|
||||
new ExpressionEvaluatingTransactionSynchronizationProcessor();
|
||||
|
||||
if (StringUtils.hasText(this.beforeCommitExpression)) {
|
||||
processor.setBeforeCommitExpression(this.PARSER.parseExpression(this.beforeCommitExpression));
|
||||
}
|
||||
if (StringUtils.hasText(this.afterCommitExpression)) {
|
||||
processor.setAfterCommitExpression(this.PARSER.parseExpression(this.afterCommitExpression));
|
||||
}
|
||||
if (StringUtils.hasText(this.afterRollbackExpression)) {
|
||||
processor.setAfterRollbackExpression(this.PARSER.parseExpression(this.afterRollbackExpression));
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.beforeCommitChannelName)) {
|
||||
this.beforeCommitChannel = this.channelResolver.resolveDestination(this.beforeCommitChannelName);
|
||||
}
|
||||
if (this.beforeCommitChannel != null) {
|
||||
processor.setBeforeCommitChannel(this.beforeCommitChannel);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.afterCommitChannelName)) {
|
||||
this.afterCommitChannel = this.channelResolver.resolveDestination(this.afterCommitChannelName);
|
||||
}
|
||||
if (this.afterCommitChannel != null) {
|
||||
processor.setAfterCommitChannel(this.afterCommitChannel);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(this.afterRollbackChannelName)) {
|
||||
this.afterRollbackChannel = this.channelResolver.resolveDestination(this.afterRollbackChannelName);
|
||||
}
|
||||
if (this.afterRollbackChannel != null) {
|
||||
processor.setAfterRollbackChannel(this.afterRollbackChannel);
|
||||
}
|
||||
|
||||
ExpressionEvaluatingTransactionSynchronizationProcessor processor =
|
||||
new ExpressionEvaluatingTransactionSynchronizationProcessor();
|
||||
|
||||
JavaUtils.INSTANCE
|
||||
.acceptIfHasText(this.beforeCommitExpression, (expression) ->
|
||||
processor.setBeforeCommitExpression(PARSER.parseExpression(expression)))
|
||||
.acceptIfHasText(this.afterCommitExpression, (expression) ->
|
||||
processor.setAfterCommitExpression(PARSER.parseExpression(expression)))
|
||||
.acceptIfHasText(this.afterRollbackExpression, (expression) ->
|
||||
processor.setAfterRollbackExpression(PARSER.parseExpression(expression)))
|
||||
.acceptIfNotNull(this.beforeCommitChannel, processor::setBeforeCommitChannel)
|
||||
.acceptIfNotNull(this.afterCommitChannel, processor::setAfterCommitChannel)
|
||||
.acceptIfNotNull(this.afterRollbackChannel, processor::setAfterRollbackChannel);
|
||||
|
||||
if (this.beanFactory instanceof AutowireCapableBeanFactory) {
|
||||
((AutowireCapableBeanFactory) this.beanFactory).initializeBean(processor,
|
||||
|
||||
@@ -22,9 +22,9 @@ import static org.mockito.Mockito.mock;
|
||||
import org.apache.geode.cache.Operation;
|
||||
import org.apache.geode.cache.query.CqEvent;
|
||||
import org.apache.geode.cache.query.CqQuery;
|
||||
import org.apache.geode.cache.query.internal.cq.ServerCQImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.apache.geode.cache.query.cq.internal.ServerCQImpl;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.data.gemfire.listener.ContinuousQueryListenerContainer;
|
||||
@@ -37,73 +37,63 @@ import org.springframework.messaging.MessagingException;
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ContinuousQueryMessageProducerTests {
|
||||
|
||||
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
ContinuousQueryListenerContainer queryListenerContainer;
|
||||
private ContinuousQueryMessageProducer cqMessageProducer;
|
||||
|
||||
ContinuousQueryMessageProducer cqMessageProducer;
|
||||
private CqMessageHandler handler;
|
||||
|
||||
CqMessageHandler handler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
queryListenerContainer = mock(ContinuousQueryListenerContainer.class);
|
||||
cqMessageProducer = new ContinuousQueryMessageProducer(queryListenerContainer, "foo");
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
ContinuousQueryListenerContainer queryListenerContainer = mock(ContinuousQueryListenerContainer.class);
|
||||
this.cqMessageProducer = new ContinuousQueryMessageProducer(queryListenerContainer, "foo");
|
||||
DirectChannel outputChannel = new DirectChannel();
|
||||
cqMessageProducer.setOutputChannel(outputChannel);
|
||||
cqMessageProducer.setBeanFactory(mock(BeanFactory.class));
|
||||
handler = new CqMessageHandler();
|
||||
outputChannel.subscribe(handler);
|
||||
this.cqMessageProducer.setOutputChannel(outputChannel);
|
||||
this.cqMessageProducer.setBeanFactory(mock(BeanFactory.class));
|
||||
this.handler = new CqMessageHandler();
|
||||
outputChannel.subscribe(this.handler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageProduced() {
|
||||
void testMessageProduced() {
|
||||
CqEvent cqEvent = event(Operation.CREATE, "hello");
|
||||
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
|
||||
assertThat(handler.count).isEqualTo(1);
|
||||
assertThat(handler.payload).isEqualTo(cqEvent);
|
||||
this.cqMessageProducer.onEvent(cqEvent);
|
||||
assertThat(this.handler.count).isEqualTo(1);
|
||||
assertThat(this.handler.payload).isEqualTo(cqEvent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageNotProducedForUnsupportedEventType() {
|
||||
void testMessageNotProducedForUnsupportedEventType() {
|
||||
CqEvent cqEvent = event(Operation.DESTROY, "hello");
|
||||
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
|
||||
assertThat(handler.count).isEqualTo(0);
|
||||
this.cqMessageProducer.onEvent(cqEvent);
|
||||
assertThat(this.handler.count).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageProducedForAddedEventType() {
|
||||
|
||||
void testMessageProducedForAddedEventType() {
|
||||
CqEvent cqEvent = event(Operation.DESTROY, null);
|
||||
|
||||
cqMessageProducer.setSupportedEventTypes(CqEventType.DESTROYED);
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
|
||||
assertThat(handler.count).isEqualTo(1);
|
||||
assertThat(handler.payload).isEqualTo(cqEvent);
|
||||
this.cqMessageProducer.setSupportedEventTypes(CqEventType.DESTROYED);
|
||||
this.cqMessageProducer.onEvent(cqEvent);
|
||||
assertThat(this.handler.count).isEqualTo(1);
|
||||
assertThat(this.handler.payload).isEqualTo(cqEvent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPayloadExpression() {
|
||||
void testPayloadExpression() {
|
||||
CqEvent cqEvent = event(Operation.CREATE, "hello");
|
||||
cqMessageProducer.setPayloadExpression(PARSER.parseExpression("newValue.toUpperCase() + ', WORLD'"));
|
||||
cqMessageProducer.afterPropertiesSet();
|
||||
|
||||
cqMessageProducer.onEvent(cqEvent);
|
||||
assertThat(handler.count).isEqualTo(1);
|
||||
assertThat(handler.payload).isEqualTo("HELLO, WORLD");
|
||||
this.cqMessageProducer.setPayloadExpression(PARSER.parseExpression("newValue.toUpperCase() + ', WORLD'"));
|
||||
this.cqMessageProducer.afterPropertiesSet();
|
||||
this.cqMessageProducer.onEvent(cqEvent);
|
||||
assertThat(this.handler.count).isEqualTo(1);
|
||||
assertThat(this.handler.payload).isEqualTo("HELLO, WORLD");
|
||||
}
|
||||
|
||||
CqEvent event(final Operation operation, final Object value) {
|
||||
|
||||
return new CqEvent() {
|
||||
|
||||
final CqQuery cq = new ServerCQImpl();
|
||||
@@ -119,15 +109,15 @@ public class ContinuousQueryMessageProducerTests {
|
||||
}
|
||||
|
||||
public CqQuery getCq() {
|
||||
return cq;
|
||||
return this.cq;
|
||||
}
|
||||
|
||||
public byte[] getDeltaValue() {
|
||||
return ba;
|
||||
return this.ba;
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public Object getNewValue() {
|
||||
@@ -139,7 +129,7 @@ public class ContinuousQueryMessageProducerTests {
|
||||
}
|
||||
|
||||
public Throwable getThrowable() {
|
||||
return ex;
|
||||
return this.ex;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -147,13 +137,13 @@ public class ContinuousQueryMessageProducerTests {
|
||||
|
||||
private static class CqMessageHandler implements MessageHandler {
|
||||
|
||||
public int count;
|
||||
int count;
|
||||
|
||||
public Object payload;
|
||||
Object payload;
|
||||
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
count++;
|
||||
payload = message.getPayload();
|
||||
this.count++;
|
||||
this.payload = message.getPayload();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user