From 45ae01976035b7278b6281f2cd09802370fac3dc Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Wed, 5 Apr 2023 12:14:23 +0200 Subject: [PATCH 1/6] Added spring 6 webflux tests, added accidentally removed spring 5 test --- .../apm-spring-webflux-plugin/pom.xml | 7 +++ .../Spring6HeaderGetterTest.java | 26 +++++++++++ .../apm-spring-webflux-spring5/pom.xml | 15 ++++++- .../springwebflux/SpringWeb5UtilsTest.java | 43 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/SpringWeb5UtilsTest.java diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml index ecdcd8b004..f94330e5bd 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml @@ -47,6 +47,13 @@ ${version.reactor} test + + co.elastic.apm + apm-spring-webflux-spring5 + ${project.version} + test + test-jar + diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java new file mode 100644 index 0000000000..3c8947f49e --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebflux; + +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; + +@EnabledForJreRange(min = JRE.JAVA_17) +public class Spring6HeaderGetterTest extends HeaderGetterTest { +} diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml index 7438336d4e..55b0c6d972 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml @@ -94,5 +94,18 @@ - + + + + maven-jar-plugin + + + + test-jar + + + + + + diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/SpringWeb5UtilsTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/SpringWeb5UtilsTest.java new file mode 100644 index 0000000000..f0fb189b42 --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/SpringWeb5UtilsTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebflux; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpResponse; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +class SpringWeb5UtilsTest { + + @Test + void testGetStatusCode() throws Exception { + ServerHttpResponse mockResponse = mock(ServerHttpResponse.class); + doReturn(HttpStatus.IM_USED).when(mockResponse).getStatusCode(); + assertThat(SpringWebVersionUtils.getStatusCode(mockResponse)).isEqualTo(226); + } + + @Test + void testWrongResponseType() { + assertThatThrownBy(() -> SpringWebVersionUtils.getStatusCode(new Object())).isInstanceOf(ClassCastException.class); + } +} From 5480c5657ac8d045e59eebce9ed86d186ac139c8 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Thu, 6 Apr 2023 13:09:25 +0200 Subject: [PATCH 2/6] Dependency cleanup --- .../apm-spring-webflux-plugin/pom.xml | 14 +++++--- .../apm-spring-webflux-spring5/pom.xml | 35 ++++--------------- apm-agent-plugins/apm-spring-webflux/pom.xml | 27 ++++++++++++++ 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml index f94330e5bd..9ca43226cc 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml @@ -21,9 +21,9 @@ - org.springframework - spring-framework-bom - 6.0.1 + org.springframework.boot + spring-boot-dependencies + 3.0.5 pom import @@ -36,6 +36,13 @@ apm-spring-webflux-spring5 ${project.version} + + + ${project.groupId} + apm-spring-webflux-testapp + ${project.version} + test + org.springframework spring-web @@ -44,7 +51,6 @@ io.projectreactor reactor-test - ${version.reactor} test diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml index 55b0c6d972..b2a05b960b 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml @@ -31,6 +31,12 @@ + + ${project.groupId} + apm-httpserver-core + ${project.version} + + org.springframework spring-web @@ -50,35 +56,6 @@ test - - ${project.groupId} - apm-httpserver-core - ${project.version} - - - - - co.elastic.apm - apm-reactor-plugin - ${project.version} - test - - - - co.elastic.apm - apm-reactor-plugin - ${project.version} - test - test-jar - - - - - co.elastic.apm - apm-servlet-plugin - ${project.version} - test - org.springframework diff --git a/apm-agent-plugins/apm-spring-webflux/pom.xml b/apm-agent-plugins/apm-spring-webflux/pom.xml index a825a65add..43b1d916b5 100644 --- a/apm-agent-plugins/apm-spring-webflux/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/pom.xml @@ -33,4 +33,31 @@ apm-spring-webflux-testapp apm-spring-webflux-spring5 + + + + + + co.elastic.apm + apm-reactor-plugin + ${project.version} + test + + + + co.elastic.apm + apm-reactor-plugin + ${project.version} + test + test-jar + + + + + co.elastic.apm + apm-servlet-plugin + ${project.version} + test + + From 5c60dd57162f90cc9a45a1c3afae6273b7f83291 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Thu, 6 Apr 2023 13:31:00 +0200 Subject: [PATCH 3/6] Added webflux spring 6 tests --- .../apm/agent/testutils}/Java17OnlyTest.java | 2 +- .../Spring6HeaderGetterTest.java | 11 ++++++- ...ng6ServerAnnotatedInstrumentationTest.java | 31 +++++++++++++++++++ ...g6ServerFunctionalInstrumentationTest.java | 31 +++++++++++++++++++ .../Spring6ServletContainerTest.java | 26 ++++++++++++++++ ...ng6WebSocketServerInstrumentationTest.java | 26 ++++++++++++++++ .../testapp/GreetingHandler.java | 2 +- .../testapp/GreetingWebClient.java | 2 +- ...ng6TransactionNameInstrumentationTest.java | 1 + ...strumentationWithExceptionHandlerTest.java | 2 +- ...trumentationWithExceptionResolverTest.java | 2 +- ...erInstrumentationWithGlobalAdviceTest.java | 2 +- ...tationWithResponseStatusExceptionTest.java | 2 +- .../template/Spring6FreeMarkerViewTest.java | 2 +- .../template/Spring6GroovyTemplateTest.java | 2 +- .../template/Spring6Jackson2JsonViewTest.java | 2 +- .../template/Spring6JspViewTest.java | 2 +- .../template/Spring6ThymeleafTest.java | 2 +- 18 files changed, 137 insertions(+), 13 deletions(-) rename {apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc => apm-agent-core/src/test/java/co/elastic/apm/agent/testutils}/Java17OnlyTest.java (98%) create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6WebSocketServerInstrumentationTest.java diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Java17OnlyTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/Java17OnlyTest.java similarity index 98% rename from apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Java17OnlyTest.java rename to apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/Java17OnlyTest.java index b55168b1ef..f681030f00 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Java17OnlyTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/Java17OnlyTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.springwebmvc; +package co.elastic.apm.agent.testutils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java index 3c8947f49e..ab65a7d8eb 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6HeaderGetterTest.java @@ -18,9 +18,18 @@ */ package co.elastic.apm.agent.springwebflux; +import co.elastic.apm.agent.testutils.Java17OnlyTest; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; @EnabledForJreRange(min = JRE.JAVA_17) -public class Spring6HeaderGetterTest extends HeaderGetterTest { +public class Spring6HeaderGetterTest extends Java17OnlyTest { + + public Spring6HeaderGetterTest() { + super(Impl.class); + } + + public static class Impl extends HeaderGetterTest { + + } } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java new file mode 100644 index 0000000000..8da6f44805 --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java @@ -0,0 +1,31 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebflux; + +import co.elastic.apm.agent.testutils.Java17OnlyTest; + +public class Spring6ServerAnnotatedInstrumentationTest extends Java17OnlyTest { + + public Spring6ServerAnnotatedInstrumentationTest() { + super(Spring6ServerFunctionalInstrumentationTest.Impl.class); + } + + public static class Impl extends ServerAnnotatedInstrumentationTest { + } +} diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java new file mode 100644 index 0000000000..c593194b20 --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerFunctionalInstrumentationTest.java @@ -0,0 +1,31 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebflux; + +import co.elastic.apm.agent.testutils.Java17OnlyTest; + +public class Spring6ServerFunctionalInstrumentationTest extends Java17OnlyTest { + + public Spring6ServerFunctionalInstrumentationTest() { + super(Impl.class); + } + + public static class Impl extends ServerFunctionalInstrumentationTest { + } +} diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java new file mode 100644 index 0000000000..a62c7a2e4b --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServletContainerTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebflux; + +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; + +@EnabledForJreRange(min = JRE.JAVA_17) +public class Spring6ServletContainerTest extends ServletContainerTest { +} diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6WebSocketServerInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6WebSocketServerInstrumentationTest.java new file mode 100644 index 0000000000..db43911d06 --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6WebSocketServerInstrumentationTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebflux; + +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; + +@EnabledForJreRange(min = JRE.JAVA_17) +public class Spring6WebSocketServerInstrumentationTest extends WebSocketServerInstrumentationTest { +} diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java index a35bb9cc64..4222b836fd 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java @@ -37,7 +37,7 @@ @Component public class GreetingHandler { - public static final Scheduler CHILDREN_SCHEDULER = Schedulers.newElastic("children"); + public static final Scheduler CHILDREN_SCHEDULER = Schedulers.newBoundedElastic(16, 128, "children"); public Mono helloMessage(@Nullable String name) { return Mono.just(String.format("Hello, %s!", Optional.ofNullable(name).orElse("Spring"))); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingWebClient.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingWebClient.java index 236f91212a..49778ccbe8 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingWebClient.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingWebClient.java @@ -77,7 +77,7 @@ public GreetingWebClient(String host, int port, boolean useFunctionalEndpoint, b this.useFunctionalEndpoint = useFunctionalEndpoint; this.headers = new HttpHeaders(); this.cookies = new HttpHeaders(); - this.clientScheduler = Schedulers.newElastic("webflux-client"); + this.clientScheduler = Schedulers.newBoundedElastic(16, 128, "webflux-client"); this.wsClient = new ReactorNettyWebSocketClient(); this.logEnabled = logEnabled; } diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Spring6TransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Spring6TransactionNameInstrumentationTest.java index e8831be9b4..91f5e09511 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Spring6TransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/Spring6TransactionNameInstrumentationTest.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc; +import co.elastic.apm.agent.testutils.Java17OnlyTest; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionHandlerTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionHandlerTest.java index ee1c5e3bdc..2d6f8a0c35 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionHandlerTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionHandlerTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.exception; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6ExceptionHandlerInstrumentationWithExceptionHandlerTest extends Java17OnlyTest { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionResolverTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionResolverTest.java index a2743c3db9..f56cf5e5aa 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionResolverTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithExceptionResolverTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.springwebmvc.exception; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; import co.elastic.apm.agent.springwebmvc.exception.testapp.exception_resolver.AbstractRestResponseStatusExceptionResolver; +import co.elastic.apm.agent.testutils.Java17OnlyTest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.stereotype.Component; diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithGlobalAdviceTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithGlobalAdviceTest.java index f6e7e9b9fb..5567009a6a 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithGlobalAdviceTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithGlobalAdviceTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.exception; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6ExceptionHandlerInstrumentationWithGlobalAdviceTest extends Java17OnlyTest { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithResponseStatusExceptionTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithResponseStatusExceptionTest.java index 27318db4ec..0d80948661 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithResponseStatusExceptionTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring6ExceptionHandlerInstrumentationWithResponseStatusExceptionTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.exception; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6ExceptionHandlerInstrumentationWithResponseStatusExceptionTest extends Java17OnlyTest { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6FreeMarkerViewTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6FreeMarkerViewTest.java index 37ba6d8ae9..a2abab803e 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6FreeMarkerViewTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6FreeMarkerViewTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.template; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6FreeMarkerViewTest extends Java17OnlyTest { public Spring6FreeMarkerViewTest() { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6GroovyTemplateTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6GroovyTemplateTest.java index 9bdb50850b..168a69210e 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6GroovyTemplateTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6GroovyTemplateTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.template; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6GroovyTemplateTest extends Java17OnlyTest { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6Jackson2JsonViewTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6Jackson2JsonViewTest.java index 1dd1b71ee6..93c17d29d6 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6Jackson2JsonViewTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6Jackson2JsonViewTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.template; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6Jackson2JsonViewTest extends Java17OnlyTest { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6JspViewTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6JspViewTest.java index 45464208e1..ff0eaff4dd 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6JspViewTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6JspViewTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.template; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; public class Spring6JspViewTest extends Java17OnlyTest { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6ThymeleafTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6ThymeleafTest.java index 3e5d520816..9d4ee15482 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6ThymeleafTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/src/test/java/co/elastic/apm/agent/springwebmvc/template/Spring6ThymeleafTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebmvc.template; -import co.elastic.apm.agent.springwebmvc.Java17OnlyTest; +import co.elastic.apm.agent.testutils.Java17OnlyTest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; From 94ee23b58aff43ee1402bc4ce737a761798fc74c Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Tue, 11 Apr 2023 15:34:31 +0200 Subject: [PATCH 4/6] Stash webclient pom updates --- .../apm-spring-webclient-plugin/pom.xml | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml index a2dc73bb75..721e0588b9 100755 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml @@ -20,6 +20,18 @@ true + + + + org.springframework.boot + spring-boot-dependencies + 2.7.10 + pom + import + + + + co.elastic.apm @@ -29,13 +41,11 @@ org.springframework spring-web - ${version.spring} provided org.springframework spring-webflux - ${version.spring} provided @@ -51,27 +61,29 @@ io.projectreactor.netty reactor-netty-http - 1.0.7 + test + + + io.netty + netty-resolver-dns-native-macos + osx-aarch_64 test org.eclipse.jetty jetty-reactive-httpclient - 1.1.11 test org.apache.httpcomponents.client5 httpclient5 - 5.1.3 test org.apache.httpcomponents.core5 httpcore5-reactive - 5.1.3 test From 06b94d091934fd8ad9363305e8d8d4a01464ee86 Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Wed, 12 Apr 2023 14:14:41 +0200 Subject: [PATCH 5/6] Further dependency cleanup, upgraded webclient tests --- .../apm-spring-webclient-plugin/pom.xml | 25 ++++- .../WebClientInstrumentationIT.java | 86 +++++++++++++++ .../WebClientInstrumentationTest.java | 103 ++++++++++-------- .../apm-spring-webflux-plugin/pom.xml | 19 +++- .../apm-spring-webflux-spring5/pom.xml | 23 +++- .../apm-spring-webflux-testapp/pom.xml | 41 +------ apm-agent-plugins/apm-spring-webflux/pom.xml | 28 +---- 7 files changed, 212 insertions(+), 113 deletions(-) create mode 100644 apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationIT.java diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml index 721e0588b9..ec8773806d 100755 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml @@ -25,7 +25,7 @@ org.springframework.boot spring-boot-dependencies - 2.7.10 + ${version.spring-boot-3} pom import @@ -42,6 +42,18 @@ org.springframework spring-web provided + + + + org.springframework + spring-jcl + + org.springframework @@ -86,6 +98,17 @@ httpcore5-reactive test + + org.apache.ivy + ivy + test + + + commons-logging + commons-logging + 1.2 + test + diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationIT.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationIT.java new file mode 100644 index 0000000000..2a2fd670f1 --- /dev/null +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationIT.java @@ -0,0 +1,86 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.springwebclient; + +import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; +import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.netty.http.client.HttpClient; + +import java.util.Arrays; +import java.util.List; + +public class WebClientInstrumentationIT { + + + @ParameterizedTest + @ValueSource(strings = {"5.3.26"}) + public void testNetty(String springVersion) throws Exception { + List dependencies = Arrays.asList( + "org.springframework:spring-web:" + springVersion, + "org.springframework:spring-webflux:" + springVersion, + "org.springframework:spring-core:" + springVersion, + "org.springframework:spring-beans:" + springVersion + ); + JUnit4TestClassWithDependencyRunner runner = new JUnit4TestClassWithDependencyRunner(dependencies, WebClientInstrumentationIT.class.getName() + "$TestImpl", WebClientInstrumentationIT.class.getName()); + runner.run(); + } + + /** + * We don't test with all variations of {@link WebClientInstrumentationTest} + * but just with netty for integration test. + */ + public static class TestImpl extends AbstractHttpClientInstrumentationTest { + + private final WebClient webClient; + + + public TestImpl() { + HttpClient httpClient = HttpClient.create() + // followRedirect(boolean) only enables redirect for 30[1278], not 303 + .followRedirect((req, res) -> res.status().code() == 303); + + // crete netty reactor client + webClient = WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(httpClient)) + .build(); + } + + @Override + public boolean isRequireCheckErrorWhenCircularRedirect() { + // circular redirect does not trigger an error to capture with netty + return false; + } + + @Override + public boolean isTestHttpCallWithUserInfoEnabled() { + // user info URI does not work with netty + return false; + } + + + @Override + protected void performGet(String path) throws Exception { + webClient.get().uri(path).exchangeToMono(response -> response.bodyToMono(String.class)).block(); + } + } +} diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationTest.java index eae3e9b497..006f673732 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/test/java/co/elastic/apm/agent/springwebclient/WebClientInstrumentationTest.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.springwebclient; +import co.elastic.apm.agent.common.JvmRuntimeInfo; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -30,13 +31,16 @@ @RunWith(Parameterized.class) public class WebClientInstrumentationTest extends AbstractHttpClientInstrumentationTest { - private final WebClient webClient; + /** + * Can't directly reference WebClient because it is compiled with java 17. + */ + private final Object webClient; private final RequestStrategy strategy; private final boolean isNetty; - public WebClientInstrumentationTest(String clientIgnored, WebClient webClient, RequestStrategy strategy, boolean isNetty) { + public WebClientInstrumentationTest(String clientIgnored, Object webClient, RequestStrategy strategy, boolean isNetty) { this.webClient = webClient; this.strategy = strategy; this.isNetty = isNetty; @@ -44,20 +48,24 @@ public WebClientInstrumentationTest(String clientIgnored, WebClient webClient, R @Parameterized.Parameters(name = "client = {0}, request strategy = {2}") public static Object[][] testParams() { - return new Object[][]{ - {"jetty", jettyClient(), RequestStrategy.EXCHANGE, false}, - {"jetty", jettyClient(), RequestStrategy.EXCHANGE_TO_FLUX, false}, - {"jetty", jettyClient(), RequestStrategy.EXCHANGE_TO_MONO, false}, - {"jetty", jettyClient(), RequestStrategy.RETRIEVE, false}, - {"netty", nettyClient(), RequestStrategy.EXCHANGE, true}, - {"netty", nettyClient(), RequestStrategy.EXCHANGE_TO_FLUX, true}, - {"netty", nettyClient(), RequestStrategy.EXCHANGE_TO_MONO, true}, - {"netty", nettyClient(), RequestStrategy.RETRIEVE, true}, - {"hc5", reactiveHttpClient5(), RequestStrategy.EXCHANGE, false}, - {"hc5", reactiveHttpClient5(), RequestStrategy.EXCHANGE_TO_FLUX, false}, - {"hc5", reactiveHttpClient5(), RequestStrategy.EXCHANGE_TO_MONO, false}, - {"hc5", reactiveHttpClient5(), RequestStrategy.RETRIEVE, false} - }; + if (JvmRuntimeInfo.ofCurrentVM().getMajorVersion() >= 17) { + return new Object[][]{ + {"jetty", Clients.jettyClient(), RequestStrategy.EXCHANGE, false}, + {"jetty", Clients.jettyClient(), RequestStrategy.EXCHANGE_TO_FLUX, false}, + {"jetty", Clients.jettyClient(), RequestStrategy.EXCHANGE_TO_MONO, false}, + {"jetty", Clients.jettyClient(), RequestStrategy.RETRIEVE, false}, + {"netty", Clients.nettyClient(), RequestStrategy.EXCHANGE, true}, + {"netty", Clients.nettyClient(), RequestStrategy.EXCHANGE_TO_FLUX, true}, + {"netty", Clients.nettyClient(), RequestStrategy.EXCHANGE_TO_MONO, true}, + {"netty", Clients.nettyClient(), RequestStrategy.RETRIEVE, true}, + {"hc5", Clients.reactiveHttpClient5(), RequestStrategy.EXCHANGE, false}, + {"hc5", Clients.reactiveHttpClient5(), RequestStrategy.EXCHANGE_TO_FLUX, false}, + {"hc5", Clients.reactiveHttpClient5(), RequestStrategy.EXCHANGE_TO_MONO, false}, + {"hc5", Clients.reactiveHttpClient5(), RequestStrategy.RETRIEVE, false} + }; + } else { + return new Object[0][0]; + } } @Override @@ -86,55 +94,58 @@ protected enum RequestStrategy { EXCHANGE { @Override @SuppressWarnings("deprecation") - void execute(WebClient client, String uri) { - client.get().uri(uri).exchange() // deprecated API + void execute(Object client, String uri) { + ((WebClient) client).get().uri(uri).exchange() // deprecated API .block(); } }, EXCHANGE_TO_FLUX { @Override - void execute(WebClient client, String uri) { - client.get().uri(uri).exchangeToFlux(response -> response.bodyToFlux(String.class)).blockLast(); + void execute(Object client, String uri) { + ((WebClient) client).get().uri(uri).exchangeToFlux(response -> response.bodyToFlux(String.class)).blockLast(); } }, EXCHANGE_TO_MONO { // TODO @Override - void execute(WebClient client, String uri) { - client.get().uri(uri).exchangeToMono(response -> response.bodyToMono(String.class)).block(); + void execute(Object client, String uri) { + ((WebClient) client).get().uri(uri).exchangeToMono(response -> response.bodyToMono(String.class)).block(); } }, RETRIEVE { @Override - void execute(WebClient client, String uri) { - client.get().uri(uri).retrieve().bodyToMono(String.class).block(); + void execute(Object client, String uri) { + ((WebClient) client).get().uri(uri).retrieve().bodyToMono(String.class).block(); } }; - abstract void execute(WebClient client, String uri); - } - - private static WebClient jettyClient() { - return WebClient.builder() - .clientConnector(new JettyClientHttpConnector()) - .build(); - } - - private static WebClient nettyClient() { - HttpClient httpClient = HttpClient.create() - // followRedirect(boolean) only enables redirect for 30[1278], not 303 - .followRedirect((req, res) -> res.status().code() == 303); - - // crete netty reactor client - return WebClient.builder() - .clientConnector(new ReactorClientHttpConnector(httpClient)) - .build(); + abstract void execute(Object client, String uri); } - public static WebClient reactiveHttpClient5() { - return WebClient.builder() - .clientConnector(new HttpComponentsClientHttpConnector()) - .build(); + public static class Clients { + + private static Object jettyClient() { + return WebClient.builder() + .clientConnector(new JettyClientHttpConnector()) + .build(); + } + + private static Object nettyClient() { + HttpClient httpClient = HttpClient.create() + // followRedirect(boolean) only enables redirect for 30[1278], not 303 + .followRedirect((req, res) -> res.status().code() == 303); + + // crete netty reactor client + return WebClient.builder() + .clientConnector(new ReactorClientHttpConnector(httpClient)) + .build(); + } + + public static Object reactiveHttpClient5() { + return WebClient.builder() + .clientConnector(new HttpComponentsClientHttpConnector()) + .build(); + } } } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml index 9ca43226cc..ae520890ea 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml @@ -23,7 +23,7 @@ org.springframework.boot spring-boot-dependencies - 3.0.5 + ${version.spring-boot-3} pom import @@ -38,6 +38,7 @@ + ${project.groupId} apm-spring-webflux-testapp ${project.version} @@ -60,6 +61,22 @@ test test-jar + + + + co.elastic.apm + apm-reactor-plugin + ${project.version} + test + + + + co.elastic.apm + apm-reactor-plugin + ${project.version} + test + test-jar + diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml index b2a05b960b..cb89142a9a 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml @@ -21,9 +21,9 @@ - org.springframework - spring-framework-bom - 5.3.25 + org.springframework.boot + spring-boot-dependencies + ${version.spring-boot-2} pom import @@ -57,6 +57,22 @@ + + + co.elastic.apm + apm-reactor-plugin + ${project.version} + test + + + + co.elastic.apm + apm-reactor-plugin + ${project.version} + test + test-jar + + org.springframework spring-test @@ -66,7 +82,6 @@ io.projectreactor reactor-test - ${version.reactor} test diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml index c43b22d389..2b6413c945 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml @@ -29,14 +29,7 @@ org.springframework.boot spring-boot-dependencies - ${version.spring-boot} - pom - import - - - com.fasterxml.jackson - jackson-bom - ${version.jackson} + ${version.spring-boot-2} pom import @@ -76,48 +69,24 @@ com.fasterxml.jackson.core jackson-databind - compile + + + org.slf4j + slf4j-simple org.springframework.boot spring-boot-starter-test test - - - - org.junit.jupiter - junit-jupiter - - - org.junit.vintage - junit-vintage-engine - - io.projectreactor reactor-test - ${version.reactor} - test - - - - - org.junit.platform - junit-platform-commons - 1.7.0 test - - org.slf4j - slf4j-simple - ${version.slf4j} - - diff --git a/apm-agent-plugins/apm-spring-webflux/pom.xml b/apm-agent-plugins/apm-spring-webflux/pom.xml index 43b1d916b5..921c0d727b 100644 --- a/apm-agent-plugins/apm-spring-webflux/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/pom.xml @@ -16,15 +16,9 @@ ${project.basedir}/../.. - - 2.5.3 - - - 5.3.10 - 3.4.18 - - - 2.12.4 + + 2.7.10 + 3.0.5 @@ -36,22 +30,6 @@ - - - co.elastic.apm - apm-reactor-plugin - ${project.version} - test - - - - co.elastic.apm - apm-reactor-plugin - ${project.version} - test - test-jar - - co.elastic.apm From 562796ff91e1a68f00b5cd8286fd8a69aed81c2e Mon Sep 17 00:00:00 2001 From: Jonas Kunz Date: Tue, 18 Apr 2023 10:36:44 +0200 Subject: [PATCH 6/6] Fix test copy paste error --- .../Spring6ServerAnnotatedInstrumentationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java index 8da6f44805..b30ca5b06f 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/test/java/co/elastic/apm/agent/springwebflux/Spring6ServerAnnotatedInstrumentationTest.java @@ -23,7 +23,7 @@ public class Spring6ServerAnnotatedInstrumentationTest extends Java17OnlyTest { public Spring6ServerAnnotatedInstrumentationTest() { - super(Spring6ServerFunctionalInstrumentationTest.Impl.class); + super(Impl.class); } public static class Impl extends ServerAnnotatedInstrumentationTest {