INT-3485: Remove final from AE.stop(Runnable)
JIRA: https://jira.spring.io/browse/INT-3485 Delegate to doStop() instead of overriding stop() directly Delegated call to doStop() rather than stop(), added author tag and added unit test for custom doStop(runnable) Polishing
This commit is contained in:
@@ -17,10 +17,14 @@
|
||||
package org.springframework.integration.endpoint;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
@@ -37,6 +41,7 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Kris Jacyna
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public class MessageProducerSupportTests {
|
||||
@@ -114,6 +119,22 @@ public class MessageProducerSupportTests {
|
||||
assertEquals(message, exception.getFailedMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customDoStop() {
|
||||
final CustomEndpoint endpoint = new CustomEndpoint();
|
||||
assertEquals(0, endpoint.getCount());
|
||||
assertTrue(endpoint.isStopped());
|
||||
endpoint.start();
|
||||
assertFalse(endpoint.isStopped());
|
||||
endpoint.stop(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Do nothing
|
||||
}
|
||||
});
|
||||
assertEquals(1, endpoint.getCount());
|
||||
assertTrue(endpoint.isStopped());
|
||||
}
|
||||
|
||||
private static class SuccessfulErrorService {
|
||||
|
||||
@@ -125,4 +146,35 @@ public class MessageProducerSupportTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomEndpoint extends AbstractEndpoint {
|
||||
|
||||
private final AtomicInteger count = new AtomicInteger(0);
|
||||
private final AtomicBoolean stopped = new AtomicBoolean(true);
|
||||
|
||||
public int getCount() {
|
||||
return this.count.get();
|
||||
}
|
||||
|
||||
public boolean isStopped() {
|
||||
return this.stopped.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop(final Runnable callback) {
|
||||
this.count.incrementAndGet();
|
||||
super.doStop(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
this.stopped.set(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() {
|
||||
this.stopped.set(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user