Skip to content

Commit a0968f0

Browse files
committed
Add System.exit() test
1 parent e052cca commit a0968f0

File tree

9 files changed

+103
-0
lines changed

9 files changed

+103
-0
lines changed

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ include ':test:smoke:testApps:JMS'
8181
include ':test:smoke:testApps:Kafka'
8282
include ':test:smoke:testApps:SpringCloudStream'
8383
include ':test:smoke:testApps:Micrometer'
84+
include ':test:smoke:testApps:SystemExit'
8485
include ':test:smoke:testApps:VerifyShading'
8586
include ':test:smoke:testApps:VerifyJava7'
8687

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id 'java'
3+
id 'org.springframework.boot' version '2.1.7.RELEASE'
4+
}
5+
6+
sourceCompatibility = 1.8
7+
targetCompatibility = 1.8
8+
compileSmokeTestJava.sourceCompatibility = 1.8
9+
compileSmokeTestJava.targetCompatibility = 1.8
10+
11+
ext.testAppArtifactDir = jar.destinationDirectory
12+
ext.testAppArtifactFilename = jar.archiveFileName.get()
13+
14+
dependencies {
15+
compileOnly aiAgentJar // this is just to force building the agent first
16+
17+
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.7.RELEASE'
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.microsoft.ajl.simple;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringBootApp {
8+
9+
public static void main(String[] args) {
10+
11+
SpringApplication.run(SpringBootApp.class, args);
12+
}
13+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.microsoft.ajl.simple;
2+
3+
import java.util.concurrent.Executors;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
11+
12+
@RestController
13+
public class TestController {
14+
15+
private static final Logger logger = LoggerFactory.getLogger(TestController.class);
16+
17+
@GetMapping("/")
18+
public String root() {
19+
return "OK";
20+
}
21+
22+
@GetMapping("/delayedSystemExit")
23+
public String delayedSystemExit() {
24+
// need a small delay to ensure response has been sent
25+
Executors.newScheduledThreadPool(1)
26+
.schedule(() -> {
27+
logger.error("this is an error right before shutdown");
28+
System.exit(0);
29+
}, 200, MILLISECONDS);
30+
return "OK!";
31+
}
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.microsoft.applicationinsights.smoketest;
2+
3+
import java.util.List;
4+
5+
import com.microsoft.applicationinsights.internal.schemav2.MessageData;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.*;
9+
10+
@UseAgent
11+
public class SpringBootAutoTest extends AiSmokeTest {
12+
13+
@Test
14+
@TargetUri("/delayedSystemExit")
15+
public void doDelayedSystemExitTest() throws Exception {
16+
mockedIngestion.waitForItems("RequestData", 1);
17+
mockedIngestion.waitForItems("MessageData", 1);
18+
19+
List<MessageData> messageData = mockedIngestion.getTelemetryDataByType("MessageData");
20+
21+
assertEquals(1, messageData.size());
22+
assertEquals("this is an error right before shutdown", messageData.get(0).getMessage());
23+
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`jre.excludes.txt` is needed because Spring Boot 2 does not support Java 7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
javase
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
azul/zulu-openjdk:7
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE configuration>
3+
<configuration>
4+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
7+
</encoder>
8+
</appender>
9+
<root level="warn">
10+
<appender-ref ref="CONSOLE" />
11+
</root>
12+
</configuration>

0 commit comments

Comments
 (0)