JingGe commented on code in PR #23955:
URL: https://github.com/apache/flink/pull/23955#discussion_r1431057649
##########
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/operators/collect/CollectSinkFunctionTest.java:
##########
@@ -129,18 +129,19 @@ void testInvalidVersion() throws Exception {
@Test
void testConfiguredPortIsUsed() throws Exception {
- int bindingPort = 50500;
- functionWrapper
- .getRuntimeContext()
- .getTaskManagerRuntimeInfo()
- .getConfiguration()
- .setInteger(TaskManagerOptions.COLLECT_PORT, bindingPort);
- functionWrapper.openFunction();
- assertThatThrownBy(() -> new ServerSocket(bindingPort))
- .satisfies(
- FlinkAssertions.anyCauseMatches(
- BindException.class, "Address already in use
(Bind failed)"));
- functionWrapper.closeFunctionNormally();
+ try (ServerSocket socket = new ServerSocket(0)) {
+ functionWrapper
+ .getRuntimeContext()
+ .getTaskManagerRuntimeInfo()
+ .getConfiguration()
+ .setInteger(TaskManagerOptions.COLLECT_PORT,
socket.getLocalPort());
+ assertThatThrownBy(() -> functionWrapper.openFunction())
+ .satisfies(
+ FlinkAssertions.anyCauseMatches(
+ BindException.class, "Address already in
use (Bind failed)"));
+ } finally {
+ functionWrapper.closeWrapper();
Review Comment:
Afaik, `functionWrapper.closeWrapper()` will be called in the `@AfterEach`
method. Another question is that why you didn't call
`functionWrapper.closeFunctionNormally()` like all other test methods did?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]