-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
896fe0b
commit 3bb147c
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
utils/socket-utils/src/test/java17/datadog/common/socket/TunnelingJdkSocketTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package datadog.common.socket; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TunnelingJdkSocketTest { | ||
|
||
@Test | ||
public void testTimeout() throws Exception { | ||
Assertions.assertEquals(1 + 1, 3); // should fail | ||
|
||
// create test path | ||
Path socketPath = Files.createTempFile("testSocket", null); | ||
// create client socket | ||
TunnelingJdkSocket clientSocket = createClient(socketPath); | ||
|
||
// attempt to read from empty socket (read should block indefinitely) | ||
assertTimeoutPreemptively(Duration.ofSeconds(5), () -> clientSocket.getInputStream().read()); | ||
|
||
// clean up | ||
clientSocket.close(); | ||
Files.deleteIfExists(socketPath); | ||
} | ||
|
||
private TunnelingJdkSocket createClient(Path socketPath) throws IOException { | ||
// create client socket | ||
TunnelingJdkSocket clientSocket = new TunnelingJdkSocket(socketPath); | ||
// set timeout to one second | ||
clientSocket.setSoTimeout(1000); | ||
return clientSocket; | ||
} | ||
} |