Skip to content

Commit

Permalink
convert spring-webflux groovy test to java (#9677)
Browse files Browse the repository at this point in the history
Co-authored-by: Jean Bisutti <jean.bisutti@gmail.com>
  • Loading branch information
123liuziming and jeanbisutti authored Oct 17, 2023
1 parent e7db2c0 commit 3b08db7
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
testInstrumentation(project(":instrumentation:reactor:reactor-3.1:javaagent"))
testInstrumentation(project(":instrumentation:reactor:reactor-netty:reactor-netty-1.0:javaagent"))

testImplementation(project(":instrumentation:spring:spring-webflux:spring-webflux-5.0:testing"))

testImplementation(project(":instrumentation:spring:spring-webflux:spring-webflux-5.3:testing"))

testLibrary("org.springframework.boot:spring-boot-starter-webflux:2.0.0.RELEASE")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.spring.webflux.v5_0.server;

import io.opentelemetry.instrumentation.spring.webflux.IpcSingleThreadNettyCustomizer;
import io.opentelemetry.instrumentation.spring.webflux.server.SingleThreadNettyCustomizer;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
import org.springframework.context.annotation.Bean;
import server.SpringWebFluxTestApplication;

/**
* Run all Webflux tests under netty event loop having only 1 thread. Some of the bugs are better
* visible in this setup because same thread is reused for different requests.
*/
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = {
SpringWebFluxTestApplication.class,
SpringThreadedSpringWebfluxTest.ForceSingleThreadedNettyAutoConfiguration.class
})
class SpringThreadedSpringWebfluxTest extends SpringWebfluxTest {

@TestConfiguration
static class ForceSingleThreadedNettyAutoConfiguration {
@Bean
NettyReactiveWebServerFactory nettyFactory() {
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
factory.addServerCustomizers(customizer());
return factory;
}
}

static NettyServerCustomizer customizer() {
if (Boolean.getBoolean("testLatestDeps")) {
return new SingleThreadNettyCustomizer();
}
return new IpcSingleThreadNettyCustomizer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id("otel.java-conventions")
}

dependencies {
implementation(project(":testing-common"))

compileOnly("org.springframework:spring-webflux:5.0.0.RELEASE")
compileOnly("org.springframework.boot:spring-boot-starter-reactor-netty:2.0.0.RELEASE")
compileOnly("org.springframework.boot:spring-boot:2.0.0.RELEASE")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.webflux;

import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
import reactor.ipc.netty.http.server.HttpServerOptions;

public class IpcSingleThreadNettyCustomizer implements NettyServerCustomizer {

@Override
public void customize(HttpServerOptions.Builder builder) {
builder.loopResources(reactor.ipc.netty.resources.LoopResources.create("my-http", 1, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ dependencies {
// latest dep tests.
compileOnly("io.projectreactor.ipc:reactor-netty:0.7.0.RELEASE")
compileOnly("io.projectreactor.netty:reactor-netty-http:1.0.7")

compileOnly("org.springframework.boot:spring-boot:2.1.0.RELEASE")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.spring.webflux.server;

import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
import reactor.netty.http.server.HttpServer;

public class SingleThreadNettyCustomizer implements NettyServerCustomizer {

@Override
public HttpServer apply(HttpServer server) {
return server.runOn(reactor.netty.resources.LoopResources.create("my-http", 1, true));
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ include(":instrumentation:spring:spring-webmvc:spring-webmvc-6.0:library")
include(":instrumentation:spring:spring-webmvc:spring-webmvc-common:javaagent")
include(":instrumentation:spring:spring-webmvc:spring-webmvc-common:testing")
include(":instrumentation:spring:spring-webflux:spring-webflux-5.0:javaagent")
include(":instrumentation:spring:spring-webflux:spring-webflux-5.0:testing")
include(":instrumentation:spring:spring-webflux:spring-webflux-5.3:testing")
include(":instrumentation:spring:spring-webflux:spring-webflux-5.3:library")
include(":instrumentation:spring:spring-ws-2.0:javaagent")
Expand Down

0 comments on commit 3b08db7

Please sign in to comment.