GH-2261: Fix ScatterGatherHandler.stop()

Fixes: spring-projects/spring-integration#2261

* Fix `ScatterGatherHandler.stop()` to call `GatherEndpoint.stop()` instead of `start()`

Adding unit test as per artembilan's suggestion

Replacing asterisk import with specific namespaces

Fixing formatting/codestyle errors shown by travis

Creating separate bean for new unit test

* Some simple polishing
* Merge the assertions for the fix into an existing test

**Cherry-pick to 4.3.x**
This commit is contained in:
Abdul Zaheer
2017-10-11 16:39:31 -04:00
committed by Artem Bilan
parent 00807d47e2
commit f202b25775
2 changed files with 15 additions and 3 deletions

View File

@@ -43,6 +43,8 @@ import org.springframework.util.ClassUtils;
* <a href="http://www.eaipatterns.com/BroadcastAggregate.html">Scatter-Gather</a> EIP pattern.
*
* @author Artem Bilan
* @author Abdul Zaheer
*
* @since 4.1
*/
public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler implements Lifecycle {
@@ -161,7 +163,7 @@ public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler i
@Override
public void stop() {
if (this.gatherEndpoint != null) {
this.gatherEndpoint.start();
this.gatherEndpoint.stop();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-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.
@@ -18,6 +18,7 @@ package org.springframework.integration.scattergather.config;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
@@ -30,11 +31,12 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.Lifecycle;
import org.springframework.integration.aggregator.AggregatingMessageHandler;
import org.springframework.integration.channel.FixedSubscriberChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.scattergather.ScatterGatherHandler;
import org.springframework.integration.router.RecipientListRouter;
import org.springframework.integration.scattergather.ScatterGatherHandler;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageHandler;
import org.springframework.test.context.ContextConfiguration;
@@ -42,6 +44,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Artem Bilan
* @author Abdul Zaheer
*
* @since 4.1
*/
@ContextConfiguration
@@ -73,6 +77,7 @@ public class ScatterGatherParserTests {
MessageHandler scatterGather = this.beanFactory.getBean("scatterGather2.handler", MessageHandler.class);
assertSame(this.beanFactory.getBean("gatherChannel"),
TestUtils.getPropertyValue(scatterGather, "gatherChannel"));
Lifecycle gatherEndpoint = TestUtils.getPropertyValue(scatterGather, "gatherEndpoint", Lifecycle.class);
assertNotNull(TestUtils.getPropertyValue(scatterGather, "gatherEndpoint"));
assertThat(TestUtils.getPropertyValue(scatterGather, "gatherEndpoint"), instanceOf(EventDrivenConsumer.class));
assertTrue(TestUtils.getPropertyValue(scatterGather, "gatherEndpoint.running", Boolean.class));
@@ -97,6 +102,11 @@ public class ScatterGatherParserTests {
assertThat(scatterChannel, instanceOf(FixedSubscriberChannel.class));
assertSame(scatterer, TestUtils.getPropertyValue(scatterChannel, "handler"));
assertTrue(gatherEndpoint.isRunning());
((Lifecycle) scatterGather).stop();
assertFalse(((Lifecycle) scatterGather).isRunning());
assertFalse(gatherEndpoint.isRunning());
}
}