Skip to content

Commit 063e30c

Browse files
committed
Create initial app and ExecutorService demo.
1 parent 19ce7f1 commit 063e30c

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
}
5+
6+
apply from: "$rootDir/gradle/java.gradle"
7+
8+
description = 'Concurrent Integration Tests.'
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
implementation project(':dd-trace-api')
16+
testImplementation project(':dd-smoke-tests')
17+
18+
testImplementation platform('org.junit:junit-bom:5.10.0')
19+
testImplementation 'org.junit.jupiter:junit-jupiter'
20+
}
21+
22+
application {
23+
mainClassName = 'datadog.smoketest.concurrent.ConcurrentApp'
24+
}
25+
26+
test {
27+
useJUnitPlatform()
28+
}
29+
30+
jar {
31+
manifest {
32+
attributes(
33+
'Main-Class': 'datadog.smoketest.concurrent.ConcurrentApp'
34+
)
35+
}
36+
}
37+
38+
//tasks.withType(Test).configureEach {
39+
// dependsOn "shadowJar"
40+
//
41+
// jvmArgs "-Ddatadog.smoketest.shadowJar.path=${tasks.shadowJar.archiveFile.get()}"
42+
//}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package datadog.smoketest.concurrent;
2+
3+
public class ConcurrentApp {
4+
public static void main(String[] args) {
5+
System.out.println("=====ConcurrentApp start=====");
6+
7+
// demo ExecutorService
8+
demoExecutorService.main(args);
9+
10+
// demo ForkJoin
11+
12+
// demo custom spans
13+
14+
// demo something else?
15+
16+
System.out.println("=====ConcurrentApp finish=====");
17+
}
18+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package datadog.smoketest.concurrent;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.Callable;
6+
import java.util.concurrent.ExecutionException;
7+
import java.util.concurrent.ExecutorService;
8+
import java.util.concurrent.Executors;
9+
import java.util.concurrent.Future;
10+
import java.util.concurrent.TimeUnit;
11+
12+
// examples from https://www.baeldung.com/java-executor-service-tutorial
13+
public class demoExecutorService {
14+
public static void main(String[] args) {
15+
System.out.println("=====demoExecutorService start=====");
16+
17+
// instantiate executorService and result
18+
ExecutorService executorService = Executors.newFixedThreadPool(10);
19+
List<String> result = new ArrayList<>();
20+
21+
// create callable task
22+
Callable<String> callableTask =
23+
() -> {
24+
TimeUnit.MILLISECONDS.sleep(300);
25+
return "callableTask executed!";
26+
};
27+
28+
// invoke callable tasks three times
29+
List<Callable<String>> callableTasks = new ArrayList<>();
30+
callableTasks.add(callableTask);
31+
callableTasks.add(callableTask);
32+
callableTasks.add(callableTask);
33+
List<Future<String>> futures;
34+
try {
35+
futures = executorService.invokeAll(callableTasks);
36+
} catch (InterruptedException e) {
37+
throw new RuntimeException(e);
38+
}
39+
40+
// add futures result to 'result' var
41+
for (Future<String> future : futures) {
42+
try {
43+
result.add(future.get());
44+
} catch (InterruptedException | ExecutionException e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
49+
// shutdown executorService
50+
executorService.shutdown();
51+
try {
52+
if (!executorService.awaitTermination(800, TimeUnit.MILLISECONDS)) {
53+
executorService.shutdownNow();
54+
}
55+
} catch (InterruptedException e) {
56+
executorService.shutdownNow();
57+
}
58+
59+
// print result
60+
System.out.println("ExecutorService result: " + result);
61+
62+
System.out.println("=====demoExecutorService finish=====");
63+
}
64+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ include ':dd-smoke-tests:apm-tracing-disabled'
9696
include ':dd-smoke-tests:armeria-grpc'
9797
include ':dd-smoke-tests:backend-mock'
9898
include ':dd-smoke-tests:cli'
99+
include 'dd-smoke-tests:concurrent'
99100
include ':dd-smoke-tests:crashtracking'
100101
include ':dd-smoke-tests:custom-systemloader'
101102
include ':dd-smoke-tests:dynamic-config'
@@ -524,4 +525,3 @@ include ':dd-java-agent:benchmark'
524525
include ':dd-java-agent:benchmark-integration'
525526
include ':dd-java-agent:benchmark-integration:jetty-perftest'
526527
include ':dd-java-agent:benchmark-integration:play-perftest'
527-

0 commit comments

Comments
 (0)