From 2a3354ada9c3fc59b8c7c9a34f84fcb073b1832a Mon Sep 17 00:00:00 2001 From: John Blum Date: Thu, 31 Oct 2019 13:33:46 -0700 Subject: [PATCH] Add additional assertions and a ClientHttpRequestInterceptor bean to test the avoidance of possible interference caused by the Interceptor during the client to server cluster configuration metadata push provided in SDG. See https://jira.spring.io/browse/DATAGEODE-243 for more details. --- ...ionWithAuthenticationIntegrationTests.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java index df387481..4845aaee 100644 --- a/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java +++ b/spring-geode-autoconfigure/src/test/java/org/springframework/geode/boot/autoconfigure/cluster/ClusterConfigurationWithAuthenticationIntegrationTests.java @@ -19,9 +19,12 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; +import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -51,6 +54,10 @@ import org.springframework.data.gemfire.config.annotation.EnableLogging; import org.springframework.data.gemfire.config.annotation.EnableManager; import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport; import org.springframework.geode.security.TestSecurityManager; +import org.springframework.http.HttpMethod; +import org.springframework.http.client.ClientHttpRequest; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.test.context.junit4.SpringRunner; import example.app.books.model.Book; @@ -81,6 +88,9 @@ import example.app.books.model.ISBN; @SuppressWarnings("unused") public class ClusterConfigurationWithAuthenticationIntegrationTests extends ForkingClientServerIntegrationTestsSupport { + private static final AtomicBoolean REDIRECTING_CLIENT_HTTP_REQUEST_INTERCEPTOR_INVOKED = + new AtomicBoolean(false); + private static final String GEMFIRE_LOG_LEVEL = "off"; @BeforeClass @@ -97,6 +107,11 @@ public class ClusterConfigurationWithAuthenticationIntegrationTests extends Fork assertThat(this.booksTemplate).isNotNull(); } + @After + public void tearDown() { + assertThat(REDIRECTING_CLIENT_HTTP_REQUEST_INTERCEPTOR_INVOKED.get()).isFalse(); + } + @Test public void clusterConfigurationAndRegionDataAccessOperationsAreSuccessful() { @@ -117,7 +132,34 @@ public class ClusterConfigurationWithAuthenticationIntegrationTests extends Fork @EnableLogging(logLevel = GEMFIRE_LOG_LEVEL) @EnableEntityDefinedRegions(basePackageClasses = Book.class) @EnableClusterConfiguration(useHttp = true) - static class GeodeClientConfiguration { } + static class GeodeClientConfiguration { + + // NOTE: This ClientHttpRequestInterceptor bean should no longer be picked up by SDG's Cluster Configuration + // infrastructure as of SD Moore-SR1 + @Bean + ClientHttpRequestInterceptor testRedirectingClientHttpRequestInterceptor() { + + return (request, body, execution) -> { + + REDIRECTING_CLIENT_HTTP_REQUEST_INTERCEPTOR_INVOKED.set(true); + + String urlPattern = "%1$s://%2$s:%3$d%4$s"; + + URI originalUri = request.getURI(); + URI redirectedUri = URI.create(String.format(urlPattern, originalUri.getScheme(), "nonExistingHost", + originalUri.getPort(), originalUri.getPath())); + + HttpMethod httpMethod = request.getMethod(); + + httpMethod = httpMethod != null ? httpMethod : HttpMethod.GET; + + ClientHttpRequest newRequest = + new SimpleClientHttpRequestFactory().createRequest(redirectedUri, httpMethod); + + return execution.execute(newRequest, body); + }; + } + } @SpringBootApplication @ComponentScan(excludeFilters =