INT-3479 Improve ServiceActivatingHandler.toString
JIRA: https://jira.spring.io/browse/INT-3479 - Remove null `beanName` in `AbstractStandardMessageHandlerFactoryBean` - Change `ServiceActivatingHandler.toString()` - Fix aggregator test timing
This commit is contained in:
committed by
Artem Bilan
parent
d2da16145b
commit
4382a5796e
@@ -49,8 +49,6 @@ abstract class AbstractStandardMessageHandlerFactoryBean extends AbstractSimpleM
|
||||
|
||||
private volatile Expression expression;
|
||||
|
||||
private volatile String beanName;
|
||||
|
||||
public void setTargetObject(Object targetObject) {
|
||||
this.targetObject = targetObject;
|
||||
}
|
||||
@@ -87,7 +85,7 @@ abstract class AbstractStandardMessageHandlerFactoryBean extends AbstractSimpleM
|
||||
}
|
||||
else if (targetIsDirectReplyProducingHandler) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Wiring handler (" + beanName + ") directly into endpoint");
|
||||
logger.debug("Wiring handler (" + targetObject + ") directly into endpoint");
|
||||
}
|
||||
this.checkReuse(actualHandler);
|
||||
this.postProcessReplyProducer(actualHandler);
|
||||
|
||||
@@ -74,13 +74,14 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
throw new MessageHandlingException(message, "failure occurred in Service Activator '" + this + "'", e);
|
||||
throw new MessageHandlingException(message, "failure occurred in '" + this + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ServiceActivator for [" + this.processor + "]";
|
||||
return "ServiceActivator for [" + this.processor + "]"
|
||||
+ (this.getComponentName() == null ? "" : " (" + this.getComponentName() + ")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class AggregatorIntegrationTests {
|
||||
|
||||
// The last message in the sequence - normal release by provided 'ReleaseStrategy'
|
||||
this.groupTimeoutExpressionAggregatorInput.send(new GenericMessage<Integer>(6, stubHeaders(6, 6, 1)));
|
||||
receive = this.output.receive(0);
|
||||
receive = this.output.receive(500);
|
||||
assertNotNull(receive);
|
||||
assertEquals(1, ((Collection<?>) receive.getPayload()).size());
|
||||
assertNull(this.discard.receive(0));
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<int:service-activator id="myService" input-channel="input" expression="1 / 0">
|
||||
<int:request-handler-advice-chain>
|
||||
<bean class="org.springframework.integration.handler.advice.RequestHandlerCircuitBreakerAdvice">
|
||||
<property name="threshold" value="1" />
|
||||
</bean>
|
||||
</int:request-handler-advice-chain>
|
||||
</int:service-activator>
|
||||
|
||||
</beans>
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.integration.handler.advice;
|
||||
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -46,6 +47,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -54,6 +56,7 @@ import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.MessageSelector;
|
||||
import org.springframework.integration.endpoint.PollingConsumer;
|
||||
@@ -64,6 +67,7 @@ import org.springframework.integration.message.AdviceMessage;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
@@ -76,6 +80,9 @@ import org.springframework.retry.RetryState;
|
||||
import org.springframework.retry.policy.SimpleRetryPolicy;
|
||||
import org.springframework.retry.support.DefaultRetryState;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
@@ -83,8 +90,33 @@ import org.springframework.util.ErrorHandler;
|
||||
* @author Artem Bilan
|
||||
* @since 2.2
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class AdvisedMessageHandlerTests {
|
||||
|
||||
@Autowired
|
||||
private MessageChannel input;
|
||||
|
||||
@Test
|
||||
public void circuitBreakerExceptionText() {
|
||||
GenericMessage<String> message = new GenericMessage<String>("foo");
|
||||
try {
|
||||
input.send(message);
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertThat(e.getCause(), Matchers.instanceOf(ArithmeticException.class));
|
||||
}
|
||||
try {
|
||||
input.send(message);
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertThat(e.getMessage(), endsWith("(myService)]"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successFailureAdvice() {
|
||||
final AtomicBoolean doFail = new AtomicBoolean();
|
||||
@@ -252,6 +284,7 @@ public class AdvisedMessageHandlerTests {
|
||||
PollableChannel successChannel = new QueueChannel();
|
||||
PollableChannel failureChannel = new QueueChannel();
|
||||
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
|
||||
advice.setBeanFactory(mock(BeanFactory.class));
|
||||
advice.setSuccessChannel(successChannel);
|
||||
advice.setFailureChannel(failureChannel);
|
||||
advice.setOnSuccessExpression("1/0");
|
||||
@@ -812,6 +845,7 @@ public class AdvisedMessageHandlerTests {
|
||||
QueueChannel errors = new QueueChannel();
|
||||
|
||||
ExpressionEvaluatingRequestHandlerAdvice expressionAdvice = new ExpressionEvaluatingRequestHandlerAdvice();
|
||||
expressionAdvice.setBeanFactory(mock(BeanFactory.class));
|
||||
expressionAdvice.setOnFailureExpression("'foo'");
|
||||
expressionAdvice.setFailureChannel(errors);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user