Skip to content

Commit b0970af

Browse files
committed
Implement Phase 2: Preserve Java 8 coverage via embedded Tomcat
Convert remaining smoke tests from Spring Boot to embedded Tomcat + Spring MVC to preserve Java 8 test coverage: - JettyNativeHandler: Remove unused Spring Boot dependency - gRPC: Replace Spring Boot with embedded Tomcat + Spring MVC + gRPC server - RuntimeAttach: Preserve ApplicationInsights.attach() call - RuntimeAttachWithDelayedConnectionString: Preserve ConnectionString.configure() - SystemExit: Preserve System.exit() test logic (added SLF4J for logging) - AzureFunctions: Preserve Azure Functions worker simulation All tests now use Java 8-compatible dependencies: - spring-webmvc:5.3.39 - tomcat-embed-core:9.0.98 - javax.servlet-api:4.0.1 This avoids Spring Boot 3.x's Java 17 launcher requirement entirely while maintaining full Java 8 test coverage.
1 parent cbafd8d commit b0970af

12 files changed

Lines changed: 162 additions & 47 deletions

File tree

smoke-tests/apps/AzureFunctions/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ plugins {
33
}
44

55
dependencies {
6-
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12")
6+
implementation("org.springframework:spring-webmvc:5.3.39")
7+
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
8+
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
79
}

smoke-tests/apps/AzureFunctions/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@
66
import com.microsoft.azure.functions.worker.handler.FunctionEnvironmentReloadRequestHandler;
77
import java.lang.reflect.Field;
88
import java.util.Map;
9-
import org.springframework.boot.SpringApplication;
10-
import org.springframework.boot.autoconfigure.SpringBootApplication;
9+
import org.apache.catalina.Context;
10+
import org.apache.catalina.startup.Tomcat;
11+
import org.springframework.context.annotation.ComponentScan;
12+
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
14+
import org.springframework.web.servlet.DispatcherServlet;
15+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
1116

12-
@SpringBootApplication
17+
@Configuration
18+
@EnableWebMvc
19+
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
1320
public class SpringBootApp {
1421

1522
private static final String FAKE_BREEZE_INGESTION_ENDPOINT =
1623
"http://host.testcontainers.internal:6060/";
1724

1825
public static void main(String[] args) throws Exception {
19-
26+
// Set up Azure Functions environment
2027
setEnv("AzureWebJobsStorage", "dummy");
2128
setEnv(
2229
"APPLICATIONINSIGHTS_CONNECTION_STRING",
@@ -27,7 +34,23 @@ public static void main(String[] args) throws Exception {
2734

2835
new FunctionEnvironmentReloadRequestHandler().execute();
2936

30-
SpringApplication.run(SpringBootApp.class, args);
37+
// Start embedded Tomcat with Spring MVC
38+
Tomcat tomcat = new Tomcat();
39+
tomcat.setPort(8080);
40+
tomcat.getConnector();
41+
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
42+
43+
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
44+
appContext.setServletContext(context.getServletContext());
45+
appContext.register(SpringBootApp.class);
46+
appContext.refresh();
47+
48+
DispatcherServlet dispatcher = new DispatcherServlet(appContext);
49+
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
50+
context.addServletMappingDecoded("/*", "dispatcher");
51+
52+
tomcat.start();
53+
tomcat.getServer().await();
3154
}
3255

3356
public static void setEnv(String name, String value) throws Exception {

smoke-tests/apps/JettyNativeHandler/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ plugins {
33
}
44

55
dependencies {
6-
implementation("org.springframework.boot:spring-boot-starter:2.5.12")
7-
86
// jetty 10 is compiled against Java 11
97
implementation("org.eclipse.jetty:jetty-server:9.4.49.v20220914")
108
}

smoke-tests/apps/JettyNativeHandler/src/main/java/com/microsoft/applicationinsights/smoketestapp/JettyNativeHandlerApp.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import org.eclipse.jetty.server.Request;
1010
import org.eclipse.jetty.server.Server;
1111
import org.eclipse.jetty.server.handler.AbstractHandler;
12-
import org.springframework.boot.autoconfigure.SpringBootApplication;
1312

14-
@SpringBootApplication
1513
public class JettyNativeHandlerApp {
1614

1715
public static void main(String[] args) throws Exception {

smoke-tests/apps/RuntimeAttach/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ plugins {
55
dependencies {
66
implementation(project(":agent:runtime-attach"))
77

8-
implementation("org.springframework.boot:spring-boot-starter-web:2.2.0.RELEASE")
8+
implementation("org.springframework:spring-webmvc:5.3.39")
9+
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
10+
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
911
}

smoke-tests/apps/RuntimeAttach/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,39 @@
44
package com.microsoft.applicationinsights.smoketestapp;
55

66
import com.microsoft.applicationinsights.attach.ApplicationInsights;
7-
import org.springframework.boot.SpringApplication;
8-
import org.springframework.boot.autoconfigure.SpringBootApplication;
9-
import org.springframework.boot.builder.SpringApplicationBuilder;
10-
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
7+
import org.apache.catalina.Context;
8+
import org.apache.catalina.startup.Tomcat;
9+
import org.springframework.context.annotation.ComponentScan;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
12+
import org.springframework.web.servlet.DispatcherServlet;
13+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
1114

12-
@SpringBootApplication
13-
public class SpringBootApp extends SpringBootServletInitializer {
15+
@Configuration
16+
@EnableWebMvc
17+
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
18+
public class SpringBootApp {
1419

15-
public static void main(String[] args) {
20+
public static void main(String[] args) throws Exception {
21+
// Attach Application Insights agent at runtime
1622
ApplicationInsights.attach();
17-
SpringApplication.run(SpringBootApp.class, args);
18-
}
1923

20-
@Override
21-
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
22-
return applicationBuilder.sources(SpringBootApp.class);
24+
// Start embedded Tomcat with Spring MVC
25+
Tomcat tomcat = new Tomcat();
26+
tomcat.setPort(8080);
27+
tomcat.getConnector();
28+
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
29+
30+
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
31+
appContext.setServletContext(context.getServletContext());
32+
appContext.register(SpringBootApp.class);
33+
appContext.refresh();
34+
35+
DispatcherServlet dispatcher = new DispatcherServlet(appContext);
36+
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
37+
context.addServletMappingDecoded("/*", "dispatcher");
38+
39+
tomcat.start();
40+
tomcat.getServer().await();
2341
}
2442
}

smoke-tests/apps/RuntimeAttachWithDelayedConnectionString/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ dependencies {
66
implementation(project(":agent:runtime-attach"))
77
implementation(project(":classic-sdk:core"))
88

9-
implementation("org.springframework.boot:spring-boot-starter-web:2.2.0.RELEASE")
9+
implementation("org.springframework:spring-webmvc:5.3.39")
10+
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
11+
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
1012
}

smoke-tests/apps/RuntimeAttachWithDelayedConnectionString/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,47 @@
55

66
import com.microsoft.applicationinsights.attach.ApplicationInsights;
77
import com.microsoft.applicationinsights.connectionstring.ConnectionString;
8-
import org.springframework.boot.SpringApplication;
9-
import org.springframework.boot.autoconfigure.SpringBootApplication;
10-
import org.springframework.boot.builder.SpringApplicationBuilder;
11-
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
8+
import org.apache.catalina.Context;
9+
import org.apache.catalina.startup.Tomcat;
10+
import org.springframework.context.annotation.ComponentScan;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
13+
import org.springframework.web.servlet.DispatcherServlet;
14+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
1215

13-
@SpringBootApplication
14-
public class SpringBootApp extends SpringBootServletInitializer {
16+
@Configuration
17+
@EnableWebMvc
18+
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
19+
public class SpringBootApp {
1520

1621
private static final String FAKE_INGESTION_ENDPOINT = "http://host.testcontainers.internal:6060/";
1722

18-
public static void main(String[] args) {
23+
public static void main(String[] args) throws Exception {
24+
// Attach Application Insights agent at runtime
1925
ApplicationInsights.attach();
26+
// Configure connection string after attach
2027
ConnectionString.configure(
2128
"InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint="
2229
+ FAKE_INGESTION_ENDPOINT
2330
+ ";LiveEndpoint="
2431
+ FAKE_INGESTION_ENDPOINT);
25-
SpringApplication.run(SpringBootApp.class, args);
26-
}
2732

28-
@Override
29-
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
30-
return applicationBuilder.sources(SpringBootApp.class);
33+
// Start embedded Tomcat with Spring MVC
34+
Tomcat tomcat = new Tomcat();
35+
tomcat.setPort(8080);
36+
tomcat.getConnector();
37+
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
38+
39+
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
40+
appContext.setServletContext(context.getServletContext());
41+
appContext.register(SpringBootApp.class);
42+
appContext.refresh();
43+
44+
DispatcherServlet dispatcher = new DispatcherServlet(appContext);
45+
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
46+
context.addServletMappingDecoded("/*", "dispatcher");
47+
48+
tomcat.start();
49+
tomcat.getServer().await();
3150
}
3251
}

smoke-tests/apps/SystemExit/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ plugins {
33
}
44

55
dependencies {
6-
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12")
6+
implementation("org.springframework:spring-webmvc:5.3.39")
7+
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
8+
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
9+
710
implementation("io.opentelemetry:opentelemetry-api:1.12.0")
11+
12+
implementation("org.slf4j:slf4j-api:1.7.36")
813
}

smoke-tests/apps/SystemExit/src/main/java/com/microsoft/applicationinsights/smoketestapp/SpringBootApp.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,36 @@
33

44
package com.microsoft.applicationinsights.smoketestapp;
55

6-
import org.springframework.boot.SpringApplication;
7-
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.apache.catalina.Context;
7+
import org.apache.catalina.startup.Tomcat;
8+
import org.springframework.context.annotation.ComponentScan;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
11+
import org.springframework.web.servlet.DispatcherServlet;
12+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
813

9-
@SpringBootApplication
14+
@Configuration
15+
@EnableWebMvc
16+
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
1017
public class SpringBootApp {
1118

12-
public static void main(String[] args) {
19+
public static void main(String[] args) throws Exception {
20+
// Start embedded Tomcat with Spring MVC
21+
Tomcat tomcat = new Tomcat();
22+
tomcat.setPort(8080);
23+
tomcat.getConnector();
24+
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
1325

14-
SpringApplication.run(SpringBootApp.class, args);
26+
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
27+
appContext.setServletContext(context.getServletContext());
28+
appContext.register(SpringBootApp.class);
29+
appContext.refresh();
30+
31+
DispatcherServlet dispatcher = new DispatcherServlet(appContext);
32+
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
33+
context.addServletMappingDecoded("/*", "dispatcher");
34+
35+
tomcat.start();
36+
tomcat.getServer().await();
1537
}
1638
}

0 commit comments

Comments
 (0)