Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion smoke-tests/apps/AzureFunctions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ plugins {
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12")
implementation("org.springframework:spring-webmvc:5.3.39")
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import com.microsoft.azure.functions.worker.handler.FunctionEnvironmentReloadRequestHandler;
import java.lang.reflect.Field;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
public class SpringBootApp {

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

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

// Set up Azure Functions environment
setEnv("AzureWebJobsStorage", "dummy");
setEnv(
"APPLICATIONINSIGHTS_CONNECTION_STRING",
Expand All @@ -27,7 +34,23 @@ public static void main(String[] args) throws Exception {

new FunctionEnvironmentReloadRequestHandler().execute();

SpringApplication.run(SpringBootApp.class, args);
// Start embedded Tomcat with Spring MVC
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getConnector();
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));

AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.setServletContext(context.getServletContext());
appContext.register(SpringBootApp.class);
appContext.refresh();

DispatcherServlet dispatcher = new DispatcherServlet(appContext);
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
context.addServletMappingDecoded("/*", "dispatcher");

tomcat.start();
tomcat.getServer().await();
Comment on lines +37 to +53
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a good bit of duplication of this block of code among these tests

I think that's ok since these are "standalone applications under test"

}

public static void setEnv(String name, String value) throws Exception {
Expand Down
2 changes: 0 additions & 2 deletions smoke-tests/apps/JettyNativeHandler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ plugins {
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter:2.5.12")

// jetty 10 is compiled against Java 11
implementation("org.eclipse.jetty:jetty-server:9.4.49.v20220914")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class JettyNativeHandlerApp {

public static void main(String[] args) throws Exception {
Expand Down
4 changes: 3 additions & 1 deletion smoke-tests/apps/RuntimeAttach/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ plugins {
dependencies {
implementation(project(":agent:runtime-attach"))

implementation("org.springframework.boot:spring-boot-starter-web:2.2.0.RELEASE")
implementation("org.springframework:spring-webmvc:5.3.39")
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,39 @@
package com.microsoft.applicationinsights.smoketestapp;

import com.microsoft.applicationinsights.attach.ApplicationInsights;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication
public class SpringBootApp extends SpringBootServletInitializer {
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
public class SpringBootApp {

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
// Attach Application Insights agent at runtime
ApplicationInsights.attach();
SpringApplication.run(SpringBootApp.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
return applicationBuilder.sources(SpringBootApp.class);
// Start embedded Tomcat with Spring MVC
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getConnector();
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));

AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.setServletContext(context.getServletContext());
appContext.register(SpringBootApp.class);
appContext.refresh();

DispatcherServlet dispatcher = new DispatcherServlet(appContext);
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
context.addServletMappingDecoded("/*", "dispatcher");

tomcat.start();
tomcat.getServer().await();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ dependencies {
implementation(project(":agent:runtime-attach"))
implementation(project(":classic-sdk:core"))

implementation("org.springframework.boot:spring-boot-starter-web:2.2.0.RELEASE")
implementation("org.springframework:spring-webmvc:5.3.39")
implementation("org.apache.tomcat.embed:tomcat-embed-core:9.0.98")
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,47 @@

import com.microsoft.applicationinsights.attach.ApplicationInsights;
import com.microsoft.applicationinsights.connectionstring.ConnectionString;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication
public class SpringBootApp extends SpringBootServletInitializer {
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
public class SpringBootApp {

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

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
return applicationBuilder.sources(SpringBootApp.class);
// Start embedded Tomcat with Spring MVC
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getConnector();
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));

AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.setServletContext(context.getServletContext());
appContext.register(SpringBootApp.class);
appContext.refresh();

DispatcherServlet dispatcher = new DispatcherServlet(appContext);
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
context.addServletMappingDecoded("/*", "dispatcher");

tomcat.start();
tomcat.getServer().await();
}
}
8 changes: 7 additions & 1 deletion smoke-tests/apps/SystemExit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ plugins {
}

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

implementation("io.opentelemetry:opentelemetry-api:1.12.0")

implementation("org.slf4j:slf4j-api:1.7.36")
implementation("ch.qos.logback:logback-classic:1.2.12")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,36 @@

package com.microsoft.applicationinsights.smoketestapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
public class SpringBootApp {

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
// Start embedded Tomcat with Spring MVC
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getConnector();
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));

SpringApplication.run(SpringBootApp.class, args);
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.setServletContext(context.getServletContext());
appContext.register(SpringBootApp.class);
appContext.refresh();

DispatcherServlet dispatcher = new DispatcherServlet(appContext);
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
context.addServletMappingDecoded("/*", "dispatcher");

tomcat.start();
tomcat.getServer().await();
}
}
4 changes: 3 additions & 1 deletion smoke-tests/apps/gRPC/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ protobuf {
}

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

implementation("io.grpc:grpc-core:$grpcVersion")
implementation("io.grpc:grpc-netty:$grpcVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,40 @@
package com.microsoft.applicationinsights.smoketestapp;

import io.grpc.ServerBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@SpringBootApplication
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.microsoft.applicationinsights.smoketestapp")
public class SpringBootApp {

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

// Start gRPC server on port 10203
ServerBuilder.forPort(10203).addService(new HelloworldImpl()).build().start();

SpringApplication.run(SpringBootApp.class, args);
// Start embedded Tomcat with Spring MVC
Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.getConnector();
Context context = tomcat.addContext("", System.getProperty("java.io.tmpdir"));

AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.setServletContext(context.getServletContext());
appContext.register(SpringBootApp.class);
appContext.refresh();

DispatcherServlet dispatcher = new DispatcherServlet(appContext);
Tomcat.addServlet(context, "dispatcher", dispatcher).setLoadOnStartup(1);
context.addServletMappingDecoded("/*", "dispatcher");

tomcat.start();
tomcat.getServer().await();
}
}