File tree 2 files changed +42
-0
lines changed
src/test/java17/datadog/common/socket
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1
1
apply from : " $rootDir /gradle/java.gradle"
2
2
apply plugin : " idea"
3
3
4
+ ext {
5
+ minJavaVersionForTests = JavaVersion . VERSION_17
6
+ }
7
+
4
8
sourceSets {
5
9
main_java17 {
6
10
java. srcDirs " ${ project.projectDir} /src/main/java17"
Original file line number Diff line number Diff line change
1
+ package datadog .common .socket ;
2
+
3
+ import static org .junit .jupiter .api .Assertions .assertTimeoutPreemptively ;
4
+
5
+ import java .io .IOException ;
6
+ import java .nio .file .Files ;
7
+ import java .nio .file .Path ;
8
+ import java .time .Duration ;
9
+ import org .junit .jupiter .api .Assertions ;
10
+ import org .junit .jupiter .api .Test ;
11
+
12
+ public class TunnelingJdkSocketTest {
13
+
14
+ @ Test
15
+ public void testTimeout () throws Exception {
16
+ Assertions .assertEquals (1 + 1 , 3 ); // should fail
17
+
18
+ // create test path
19
+ Path socketPath = Files .createTempFile ("testSocket" , null );
20
+ // create client socket
21
+ TunnelingJdkSocket clientSocket = createClient (socketPath );
22
+
23
+ // attempt to read from empty socket (read should block indefinitely)
24
+ assertTimeoutPreemptively (Duration .ofSeconds (5 ), () -> clientSocket .getInputStream ().read ());
25
+
26
+ // clean up
27
+ clientSocket .close ();
28
+ Files .deleteIfExists (socketPath );
29
+ }
30
+
31
+ private TunnelingJdkSocket createClient (Path socketPath ) throws IOException {
32
+ // create client socket
33
+ TunnelingJdkSocket clientSocket = new TunnelingJdkSocket (socketPath );
34
+ // set timeout to one second
35
+ clientSocket .setSoTimeout (1000 );
36
+ return clientSocket ;
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments