Fix QueueChannelSpec.priority hook

* Since we already have `PriorityChannelSpec` that isn't
`QueueChannelSpec` responsibility to worry about `priority` option.
More over it has been done wrongly and `MessageGroupQueue.setPriority()`
has been called unconditionally by the provided `ChannelMessageStore` type

* Fix `PriorityChannelSpec` logic as well:
- set `this.messageGroupQueue.setPriority(true);` to check the state of
the provided `PriorityCapableChannelMessageStore`
- fix assert condition in the `doGet()`

* And simple compiled SpEL test-case for the JDK Proxy
This commit is contained in:
Artem Bilan
2017-11-13 16:39:07 -05:00
parent a2d0ea5997
commit 8c89d0ef98
3 changed files with 46 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -53,19 +53,22 @@ public class PriorityChannelSpec extends MessageChannelSpec<PriorityChannelSpec,
public PriorityChannelSpec messageStore(PriorityCapableChannelMessageStore messageGroupStore, Object groupId) {
this.messageGroupQueue = new MessageGroupQueue(messageGroupStore, groupId);
this.messageGroupQueue.setPriority(true);
return this;
}
@Override
protected PriorityChannel doGet() {
Assert.state(this.comparator != null && this.messageGroupQueue != null,
Assert.state(!(this.comparator != null && this.messageGroupQueue != null),
"Only one of 'comparator' or 'messageGroupStore' can be specified.");
if (this.messageGroupQueue != null) {
this.channel = new PriorityChannel(this.messageGroupQueue);
}
else {
this.channel = new PriorityChannel(this.capacity, this.comparator);
}
return super.doGet();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -22,7 +22,6 @@ import java.util.concurrent.locks.Lock;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.store.ChannelMessageStore;
import org.springframework.integration.store.MessageGroupQueue;
import org.springframework.integration.store.PriorityCapableChannelMessageStore;
import org.springframework.messaging.Message;
/**
@@ -113,9 +112,6 @@ public class QueueChannelSpec extends MessageChannelSpec<QueueChannelSpec, Queue
this.queue = new MessageGroupQueue(this.messageGroupStore, this.groupId);
}
((MessageGroupQueue) this.queue).setPriority(
this.messageGroupStore instanceof PriorityCapableChannelMessageStore);
return super.doGet();
}

View File

@@ -55,9 +55,12 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.SpelCompilerMode;
import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.expression.spel.SpelParserConfiguration;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.UseSpelInvoker;
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
@@ -882,6 +885,43 @@ public class MethodInvokingMessageProcessorTests {
assertThat(bean.foo.bar, equalTo("bar"));
}
@Test
public void testCompiledSpELForProxy() {
Foo foo = new FooImpl();
foo = (Foo) new ProxyFactory(foo).getProxy();
SpelExpressionParser expressionParser =
new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null));
Expression expression = expressionParser.parseExpression("#target.handle(#root)");
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.setVariable("target", foo);
expression.getValue(evaluationContext, "foo", String.class); // Twice to make a compiler to work
String result = expression.getValue(evaluationContext, "foo", String.class);
assertEquals("FOO", result);
}
public interface Foo {
String handle(String payload);
}
public class FooImpl implements Foo {
@Override
public String handle(String payload) {
return payload.toUpperCase();
}
}
private DirectFieldAccessor compileImmediate(MethodInvokingMessageProcessor processor) {
// Update the parser configuration compiler mode
SpelParserConfiguration config = TestUtils.getPropertyValue(processor,