-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert spring-webflux groovy test to java (#9677)
Co-authored-by: Jean Bisutti <jean.bisutti@gmail.com>
- Loading branch information
1 parent
e7db2c0
commit 3b08db7
Showing
8 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
...bflux/spring-webflux-5.0/javaagent/src/test/groovy/SingleThreadedSpringWebfluxTest.groovy
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
...javaagent/instrumentation/spring/webflux/v5_0/server/SpringThreadedSpringWebfluxTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
instrumentation/spring/spring-webflux/spring-webflux-5.0/testing/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
17 changes: 17 additions & 0 deletions
17
.../java/io/opentelemetry/instrumentation/spring/webflux/IpcSingleThreadNettyCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...a/io/opentelemetry/instrumentation/spring/webflux/server/SingleThreadNettyCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters