Skip to content

Commit b326225

Browse files
committed
Fix tests for replyTimeout
Some tests deliberately don't expect a reply, but they still block on a gateway's `sendAndReceive()` * Improve `Jsr223ScriptExecutingMessageProcessorTests` to verify that script variables work
1 parent 8f83be2 commit b326225

File tree

5 files changed

+31
-60
lines changed

5 files changed

+31
-60
lines changed

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,11 @@ project('spring-integration-scripting') {
878878

879879
testRuntimeOnly 'org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable'
880880
}
881+
882+
tasks.withType(JavaForkOptions) {
883+
jvmArgs '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED',
884+
'--add-opens', 'java.base/java.io=ALL-UNNAMED'
885+
}
881886
}
882887

883888
project('spring-integration-security') {

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/inbound/InboundEndpointTests.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2013-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Map;
22-
import java.util.Objects;
2322
import java.util.concurrent.CountDownLatch;
2423
import java.util.concurrent.TimeUnit;
2524
import java.util.concurrent.atomic.AtomicReference;
@@ -494,6 +493,7 @@ public void testBatchGateway() throws Exception {
494493
QueueChannel out = new QueueChannel();
495494
gateway.setRequestChannel(out);
496495
gateway.setBindSourceMessage(true);
496+
gateway.setReplyTimeout(0);
497497
gateway.afterPropertiesSet();
498498
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
499499
SimpleBatchingStrategy bs = new SimpleBatchingStrategy(2, 10_000, 10_000L);
@@ -784,41 +784,7 @@ public void testRetryWithMessageRecovererOnMessageAdapterConsumerBatch() throws
784784
assertThat(recoveredMessages.get()).isSameAs(messages);
785785
}
786786

787-
public static class Foo {
788-
789-
private String bar;
790-
791-
public Foo() {
792-
}
793-
794-
public Foo(String bar) {
795-
this.bar = bar;
796-
}
797-
798-
public String getBar() {
799-
return bar;
800-
}
801-
802-
@Override
803-
public boolean equals(Object o) {
804-
if (this == o) {
805-
return true;
806-
}
807-
if (o == null || getClass() != o.getClass()) {
808-
return false;
809-
}
810-
811-
Foo foo = (Foo) o;
812-
813-
return Objects.equals(bar, foo.bar);
814-
815-
}
816-
817-
@Override
818-
public int hashCode() {
819-
return bar != null ? bar.hashCode() : 0;
820-
}
821-
787+
public record Foo(String bar) {
822788
}
823789

824790
}

spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2022 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -292,6 +292,7 @@ public IntegrationFlow enricherFlow() {
292292
.errorChannel(enricherErrorChannel())
293293
.requestPayloadExpression("payload")
294294
.shouldClonePayload(false)
295+
.replyTimeout(1L)
295296
.propertyExpression("name", "payload['name']")
296297
.propertyFunction("date", m -> new Date())
297298
.headerExpression("foo", "payload['name']")
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,8 +19,7 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
import org.junit.Before;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2423
import org.mockito.Mockito;
2524

2625
import org.springframework.beans.factory.BeanFactory;
@@ -35,49 +34,50 @@
3534

3635
/**
3736
* @author David Turanski
37+
* @author Artem Bilan
3838
*
3939
*/
4040
public class Jsr223ScriptExecutingMessageProcessorTests {
4141

42-
ScriptExecutor executor;
43-
44-
@Before
45-
public void setUp() {
46-
executor = ScriptExecutorFactory.getScriptExecutor("jruby");
47-
}
42+
private static final ScriptExecutor SCRIPT_EXECUTOR = ScriptExecutorFactory.getScriptExecutor("jruby");
4843

4944
@Test
5045
public void testExecuteWithVariables() {
51-
Map<String, Object> vars = new HashMap<String, Object>();
46+
Map<String, Object> vars = new HashMap<>();
5247
vars.put("one", 1);
5348
vars.put("two", "two");
5449
vars.put("three", 3);
5550

56-
ScriptSource scriptSource = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
51+
ScriptSource scriptSource =
52+
new ResourceScriptSource(
53+
new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
5754

58-
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor, vars);
55+
ScriptExecutingMessageProcessor messageProcessor =
56+
new ScriptExecutingMessageProcessor(scriptSource, SCRIPT_EXECUTOR, vars);
5957
messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class));
6058

61-
Message<?> message = new GenericMessage<String>("hello");
59+
Message<?> message = new GenericMessage<>("hello");
6260

6361
Object obj = messageProcessor.processMessage(message);
6462

65-
assertThat(obj.toString().substring(0, "hello modified".length())).isEqualTo("hello modified");
63+
assertThat(obj.toString()).contains("hello modified 1 two 3");
6664
}
6765

6866
@Test
6967
public void testWithNoVars() {
70-
ScriptSource scriptSource = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
68+
ScriptSource scriptSource =
69+
new ResourceScriptSource(
70+
new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
7171

72-
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor);
72+
ScriptExecutingMessageProcessor messageProcessor =
73+
new ScriptExecutingMessageProcessor(scriptSource, SCRIPT_EXECUTOR);
7374
messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class));
7475

75-
Message<?> message = new GenericMessage<String>("hello");
76+
Message<?> message = new GenericMessage<>("hello");
7677

7778
Object obj = messageProcessor.processMessage(message);
7879

79-
assertThat(obj.toString().substring(0, "hello modified".length())).isEqualTo("hello modified");
80+
assertThat(obj.toString()).contains("hello modified");
8081
}
8182

8283
}
83-

spring-integration-scripting/src/test/java/org/springframework/integration/scripting/jsr223/print_message.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
java_import 'java.util.Date'
33
#payload and headers a global variable
44
if payload
5-
payload = payload+" modified #{Date.new}"
5+
payload = payload+" modified #{(defined? one) ? one : ''} #{(defined? two) ? two : ''} #{(defined? three) ? three : ''} #{Date.new}"
66
end
7-
puts payload
87
if headers
98
headers.each {|key, value| puts "#{key} is #{value}" }
109
end
11-
puts "#{$one} #{$two} #{$three}"
10+
puts payload
1211
payload

0 commit comments

Comments
 (0)