GH-3367: Separate timeouts in BarrierMH

Fixes https://github.com/spring-projects/spring-integration/issues/3367

Introduce a `requestTimeout` and `triggerTimeout` for `BarrierMessageHandler`
For instance, if an HTTP request sends a message to the barrier,
it should time out after 1min if no trigger message is received.
If the trigger message then arrives late and the HTTP request is no longer waiting,
it shouldn't wait for 1min before discarding the request but do so immediately.
This commit is contained in:
Michel Jung
2020-08-21 16:15:11 +02:00
committed by Artem Bilan
parent 3fb6567a1f
commit 6780bbd5c8
7 changed files with 113 additions and 47 deletions

View File

@@ -11,7 +11,8 @@
<int:barrier id="barrier1" input-channel="in" output-channel="out" correlation-strategy-expression="'foo'"
requires-reply="true" discard-channel="discards"
timeout="10000">
timeout="10000"
trigger-timeout="5000">
<int:poller fixed-delay="100" />
</int:barrier>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* Copyright 2015-2020 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,8 +18,7 @@ package org.springframework.integration.config.xml;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.aggregator.BarrierMessageHandler;
@@ -35,16 +34,16 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.2
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class BarrierParserTests {
@@ -71,8 +70,8 @@ public class BarrierParserTests {
@Test
public void parserTestsWithMessage() {
this.in.send(new GenericMessage<String>("foo"));
this.release.send(new GenericMessage<String>("bar"));
this.in.send(new GenericMessage<>("foo"));
this.release.send(new GenericMessage<>("bar"));
Message<?> received = out.receive(10000);
assertThat(received).isNotNull();
this.barrier1.stop();
@@ -82,7 +81,8 @@ public class BarrierParserTests {
public void parserFieldPopulationTests() {
BarrierMessageHandler handler = TestUtils.getPropertyValue(this.barrier1, "handler",
BarrierMessageHandler.class);
assertThat(TestUtils.getPropertyValue(handler, "timeout")).isEqualTo(10000L);
assertThat(TestUtils.getPropertyValue(handler, "requestTimeout")).isEqualTo(10000L);
assertThat(TestUtils.getPropertyValue(handler, "triggerTimeout")).isEqualTo(5000L);
assertThat(TestUtils.getPropertyValue(handler, "requiresReply", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(this.barrier2, "handler.correlationStrategy"))
.isInstanceOf(HeaderAttributeCorrelationStrategy.class);