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
This commit is contained in:
abilan
2023-03-29 10:25:29 -04:00
parent 8f83be2a91
commit b326225df7
5 changed files with 31 additions and 60 deletions

View File

@@ -878,6 +878,11 @@ project('spring-integration-scripting') {
testRuntimeOnly 'org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable'
}
tasks.withType(JavaForkOptions) {
jvmArgs '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED',
'--add-opens', 'java.base/java.io=ALL-UNNAMED'
}
}
project('spring-integration-security') {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2022 the original author or authors.
* Copyright 2013-2023 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.
@@ -19,7 +19,6 @@ package org.springframework.integration.amqp.inbound;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -494,6 +493,7 @@ public class InboundEndpointTests {
QueueChannel out = new QueueChannel();
gateway.setRequestChannel(out);
gateway.setBindSourceMessage(true);
gateway.setReplyTimeout(0);
gateway.afterPropertiesSet();
ChannelAwareMessageListener listener = (ChannelAwareMessageListener) container.getMessageListener();
SimpleBatchingStrategy bs = new SimpleBatchingStrategy(2, 10_000, 10_000L);
@@ -784,41 +784,7 @@ public class InboundEndpointTests {
assertThat(recoveredMessages.get()).isSameAs(messages);
}
public static class Foo {
private String bar;
public Foo() {
}
public Foo(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Foo foo = (Foo) o;
return Objects.equals(bar, foo.bar);
}
@Override
public int hashCode() {
return bar != null ? bar.hashCode() : 0;
}
public record Foo(String bar) {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-2023 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.
@@ -292,6 +292,7 @@ public class TransformerTests {
.errorChannel(enricherErrorChannel())
.requestPayloadExpression("payload")
.shouldClonePayload(false)
.replyTimeout(1L)
.propertyExpression("name", "payload['name']")
.propertyFunction("date", m -> new Date())
.headerExpression("foo", "payload['name']")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -19,8 +19,7 @@ package org.springframework.integration.scripting.jsr223;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactory;
@@ -35,49 +34,50 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author David Turanski
* @author Artem Bilan
*
*/
public class Jsr223ScriptExecutingMessageProcessorTests {
ScriptExecutor executor;
@Before
public void setUp() {
executor = ScriptExecutorFactory.getScriptExecutor("jruby");
}
private static final ScriptExecutor SCRIPT_EXECUTOR = ScriptExecutorFactory.getScriptExecutor("jruby");
@Test
public void testExecuteWithVariables() {
Map<String, Object> vars = new HashMap<String, Object>();
Map<String, Object> vars = new HashMap<>();
vars.put("one", 1);
vars.put("two", "two");
vars.put("three", 3);
ScriptSource scriptSource = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
ScriptSource scriptSource =
new ResourceScriptSource(
new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor, vars);
ScriptExecutingMessageProcessor messageProcessor =
new ScriptExecutingMessageProcessor(scriptSource, SCRIPT_EXECUTOR, vars);
messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class));
Message<?> message = new GenericMessage<String>("hello");
Message<?> message = new GenericMessage<>("hello");
Object obj = messageProcessor.processMessage(message);
assertThat(obj.toString().substring(0, "hello modified".length())).isEqualTo("hello modified");
assertThat(obj.toString()).contains("hello modified 1 two 3");
}
@Test
public void testWithNoVars() {
ScriptSource scriptSource = new ResourceScriptSource(new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
ScriptSource scriptSource =
new ResourceScriptSource(
new ClassPathResource("/org/springframework/integration/scripting/jsr223/print_message.rb"));
ScriptExecutingMessageProcessor messageProcessor = new ScriptExecutingMessageProcessor(scriptSource, executor);
ScriptExecutingMessageProcessor messageProcessor =
new ScriptExecutingMessageProcessor(scriptSource, SCRIPT_EXECUTOR);
messageProcessor.setBeanFactory(Mockito.mock(BeanFactory.class));
Message<?> message = new GenericMessage<String>("hello");
Message<?> message = new GenericMessage<>("hello");
Object obj = messageProcessor.processMessage(message);
assertThat(obj.toString().substring(0, "hello modified".length())).isEqualTo("hello modified");
assertThat(obj.toString()).contains("hello modified");
}
}

View File

@@ -2,11 +2,10 @@ require "java"
java_import 'java.util.Date'
#payload and headers a global variable
if payload
payload = payload+" modified #{Date.new}"
payload = payload+" modified #{(defined? one) ? one : ''} #{(defined? two) ? two : ''} #{(defined? three) ? three : ''} #{Date.new}"
end
puts payload
if headers
headers.each {|key, value| puts "#{key} is #{value}" }
end
puts "#{$one} #{$two} #{$three}"
puts payload
payload