Skip to content

Commit

Permalink
Add wildfly ejb test
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Dec 10, 2024
1 parent 25ff224 commit cc0bfe9
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 18 deletions.
11 changes: 7 additions & 4 deletions dd-smoke-tests/wildfly/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ext {
serverName = 'wildfly'
serverModule = 'servlet'
//serverModule = 'servlet'
serverModule = 'wildfly'
serverVersion = '15.0.0.Final'
serverExtension = 'zip'
}
Expand All @@ -9,7 +10,9 @@ repositories {
ivy {
url 'https://download.jboss.org/'
patternLayout {
artifact '/[organisation]/[revision]/[module]/[organisation]-[module]-[revision].[ext]'
// artifact '/[organisation]/[revision]/[module]/[organisation]-[module]-[revision].[ext]'
// we download the full EE profile and not the servlet minimal one
artifact '/[organisation]/[revision]/[organisation]-[revision].[ext]'
metadataSources {
artifact()
}
Expand Down Expand Up @@ -80,12 +83,12 @@ spotless {
}
}

def wildflyDir="${buildDir}/${serverName}-${serverModule}-${serverVersion}"
def wildflyDir="${buildDir}/${serverName}-${serverVersion}"

tasks.register("unzip", Copy) {
dependsOn tasks.earBuild
mustRunAfter tasks.compileTestGroovy
def zipFileNamePrefix = "servlet"
def zipFileNamePrefix = "wildfly"
def zipPath = project.configurations.serverFile.find {
it.name.startsWith(zipFileNamePrefix)
}
Expand Down
1 change: 1 addition & 0 deletions dd-smoke-tests/wildfly/spring-ear/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore all project specific gradle directories/files
.gradle
.idea
gradle
build
gradlew
Expand Down
2 changes: 2 additions & 0 deletions dd-smoke-tests/wildfly/spring-ear/war/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ repositories {

dependencies {
compileOnly 'org.springframework:spring-webmvc:5.3.0'
compileOnly group: 'javax', name: 'javaee-api', version: '8.0.1'
implementation group: 'com.datadoghq', name: 'dd-trace-api', version: '1.43.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example;

import java.util.concurrent.atomic.AtomicBoolean;

public class Common {
// for the sake of this example it avoids boilerplate ton inject an ejb into a spring context
public static final AtomicBoolean ENABLED = new AtomicBoolean(false);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.ejb;

import static com.example.Common.ENABLED;

import datadog.trace.api.Trace;
import javax.ejb.Schedule;
import javax.ejb.Stateless;

@Stateless
public class ScheduledEjb {

@Schedule(second = "*/1", minute = "*", hour = "*")
public void runIt() {
if (ENABLED.getAndSet(false)) {
generateSomeTrace();
}
}

@Trace
private void generateSomeTrace() {
// empty
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.example.hello;

import static com.example.Common.ENABLED;

import java.util.concurrent.CompletableFuture;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -10,4 +14,21 @@ public class HelloController {
public String hello() {
return "hello world";
}

@RequestMapping("/enableScheduling")
public CompletableFuture<ResponseEntity<Void>> enableScheduling() {
ENABLED.set(true);
return CompletableFuture.supplyAsync(
() -> {
while (!ENABLED.get()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
return ResponseEntity.ok().build();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Marker file indicating CDI should be enabled -->
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
bean-discovery-mode="all">
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<async-supported>true</async-supported>
<load-on-startup>1</load-on-startup>
</servlet>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package datadog.smoketest

import datadog.trace.agent.test.utils.OkHttpUtils
import datadog.trace.agent.test.utils.PortUtils
import datadog.trace.test.util.Flaky
import okhttp3.Request
import spock.lang.Shared
import spock.util.concurrent.PollingConditions

import java.util.concurrent.atomic.AtomicInteger

@Flaky
class WildflySmokeTest extends AbstractServerSmokeTest {

@Shared
Expand All @@ -24,12 +26,42 @@ class WildflySmokeTest extends AbstractServerSmokeTest {
*defaultJavaProperties,
"-Djboss.http.port=${httpPort}",
"-Djboss.https.port=${httpsPort}",
"-Djboss.management.http.port=${managementPort}"
"-Djboss.management.http.port=${managementPort}",
"-Ddd.trace.experimental.jee.split-by-deployment=true",
"-Ddd.writer.type=MultiWriter:TraceStructureWriter:${output.getAbsolutePath()}:includeService,DDAgentWriter",
]
processBuilder.environment().put("JAVA_OPTS", javaOpts.collect({ it.replace(' ', '\\ ')}).join(' '))
processBuilder.environment().put("JAVA_OPTS", javaOpts.collect({ it.replace(' ', '\\ ') }).join(' '))
return processBuilder
}

@Override
File createTemporaryFile() {
def ret = File.createTempFile("trace-structure-docs", "out")
ret
}

@Override
def inferServiceName() {
// do not set DD_SERVICE
false
}

@Override
protected boolean isAcceptable(int processIndex, Map<String, AtomicInteger> traceCounts) {
def hasServletRequestTraces = traceCounts.find { it.getKey() == "[war:servlet.request[war:spring.handler]]" }?.getValue()?.get() == 201
def hasScheduledEjbTrace = traceCounts.find { it.getKey() == "[war:trace.annotation]" }?.getValue()?.get() == 1
assert hasScheduledEjbTrace && hasServletRequestTraces: "Encountered traces: " + traceCounts
return true
}


def setupSpec() {
//wait for the deployment
new PollingConditions(timeout: 300, delay: 2).eventually {
assert OkHttpUtils.client().newCall(new Request.Builder().url("http://localhost:$httpPort/war/hello").build()).execute().code() == 200
}
}

def cleanupSpec() {
ProcessBuilder processBuilder = new ProcessBuilder(
"${wildflyDirectory}/bin/jboss-cli.sh",
Expand All @@ -41,9 +73,9 @@ class WildflySmokeTest extends AbstractServerSmokeTest {
process.waitFor()
}

def "default home page #n th time"() {
def "spring controller #n th time"() {
setup:
String url = "http://localhost:$httpPort/"
String url = "http://localhost:$httpPort/war/hello"
def request = new Request.Builder().url(url).get().build()

when:
Expand All @@ -52,26 +84,21 @@ class WildflySmokeTest extends AbstractServerSmokeTest {
then:
def responseBodyStr = response.body().string()
responseBodyStr != null
responseBodyStr.contains("Your WildFly instance is running.")
response.body().contentType().toString().contains("text/html")
responseBodyStr.contentEquals("hello world")
response.code() == 200

where:
n << (1..200)
}

def "spring context loaded successfully"() {
def "scheduled ejb has right service name"() {
setup:
String url = "http://localhost:$httpPort/war/hello"
String url = "http://localhost:$httpPort/war/enableScheduling"
def request = new Request.Builder().url(url).get().build()

when:
def response = client.newCall(request).execute()

then:
def responseBodyStr = response.body().string()
responseBodyStr != null
responseBodyStr.contentEquals("hello world")
response.code() == 200
}
}

0 comments on commit cc0bfe9

Please sign in to comment.