@@ -46,16 +46,33 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
*/
|
||||
class ActuatorBindingsTest {
|
||||
|
||||
private static ClassLoader createClassLoader(String[] additionalClasspathDirectories) throws IOException {
|
||||
URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ? new URL[0]
|
||||
: new URL[additionalClasspathDirectories.length];
|
||||
if (!ObjectUtils.isEmpty(additionalClasspathDirectories)) {
|
||||
for (int i = 0; i < additionalClasspathDirectories.length; i++) {
|
||||
urls[i] = new URL(new ClassPathResource(additionalClasspathDirectories[i])
|
||||
.getURL().toString() + "/");
|
||||
}
|
||||
}
|
||||
return new URLClassLoader(urls,
|
||||
ActuatorBindingsTest.class.getClassLoader());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Even though this test performs some simple assertions, the main purpose for it is to validate that
|
||||
* it does not result in recursive exception described in https://github.com/spring-cloud/spring-cloud-stream/issues/2253
|
||||
*/
|
||||
@Test
|
||||
void actuatorDoesNotCauseInfiniteRecursion() {
|
||||
void actuatorDoesNotCauseInfiniteRecursion() throws Exception {
|
||||
ClassLoader classLoader = createClassLoader(new String[] { "binder1" });
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestChannelBinderConfiguration.getCompleteConfiguration(Bindings.class))
|
||||
.resourceLoader(new DefaultResourceLoader(classLoader))
|
||||
.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false",
|
||||
"--spring.cloud.function.definition=consume",
|
||||
"--spring.cloud.stream.bindings.consume-in-0.binder=integration1",
|
||||
"--spring.jackson.visibility.field=ANY" // see https://github.com/spring-cloud/spring-cloud-stream/issues/2253
|
||||
// we need the above just to verify that such action does not
|
||||
// interfere with instance of ObjectMapper inside of BindingsLifecycleController
|
||||
@@ -69,18 +86,6 @@ class ActuatorBindingsTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static ClassLoader createClassLoader(String[] additionalClasspathDirectories) throws IOException {
|
||||
URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ? new URL[0]
|
||||
: new URL[additionalClasspathDirectories.length];
|
||||
if (!ObjectUtils.isEmpty(additionalClasspathDirectories)) {
|
||||
for (int i = 0; i < additionalClasspathDirectories.length; i++) {
|
||||
urls[i] = new URL(new ClassPathResource(additionalClasspathDirectories[i])
|
||||
.getURL().toString() + "/");
|
||||
}
|
||||
}
|
||||
return new URLClassLoader(urls,
|
||||
ActuatorBindingsTest.class.getClassLoader());
|
||||
}
|
||||
|
||||
// Following three tests are verifying the behavior for
|
||||
// https://github.com/spring-cloud/spring-cloud-stream/commit/3abf06345ad1ed57dea161b35503eba107feb04a
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.cloud.stream.function.edgecases;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -25,7 +28,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* This test validates that the issue https://github.com/spring-cloud/spring-cloud-stream/issues/1801
|
||||
@@ -36,15 +42,29 @@ import org.springframework.messaging.Message;
|
||||
*/
|
||||
class GH1801Test {
|
||||
|
||||
private static ClassLoader createClassLoader(String[] additionalClasspathDirectories) throws IOException {
|
||||
URL[] urls = ObjectUtils.isEmpty(additionalClasspathDirectories) ? new URL[0]
|
||||
: new URL[additionalClasspathDirectories.length];
|
||||
if (!ObjectUtils.isEmpty(additionalClasspathDirectories)) {
|
||||
for (int i = 0; i < additionalClasspathDirectories.length; i++) {
|
||||
urls[i] = new URL(new ClassPathResource(additionalClasspathDirectories[i]).getURL().toString() + "/");
|
||||
}
|
||||
}
|
||||
return new URLClassLoader(urls, GH1801Test.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyNoNPEWhenFactoryMethodNull() {
|
||||
SampleBootApplication.main("--spring.cloud.stream.defaultBinder=integration");
|
||||
void verifyNoNPEWhenFactoryMethodNull() throws Exception {
|
||||
SampleBootApplication.main("--spring.cloud.stream.defaultBinder=integration1");
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
public static class SampleBootApplication {
|
||||
public static void main(String... args) {
|
||||
new SpringApplicationBuilder(SampleBootApplication.class).web(WebApplicationType.NONE).run(args);
|
||||
public static void main(String... args) throws Exception {
|
||||
ClassLoader classLoader = createClassLoader(new String[] { "binder1" });
|
||||
new SpringApplicationBuilder(SampleBootApplication.class)
|
||||
.resourceLoader(new DefaultResourceLoader(classLoader))
|
||||
.web(WebApplicationType.NONE).run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
integration1:\
|
||||
org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration
|
||||
integration2:\
|
||||
org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
integration:\
|
||||
org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration
|
||||
Reference in New Issue
Block a user