Skip to content

Commit

Permalink
[FLINK-27428][core] Deduplicate #toDuration(Time)
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Apr 27, 2022
1 parent 6fc5f78 commit 18ed571
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1008,16 +1008,6 @@ public static <T> CompletableFuture<T> supplyAsync(
executor);
}

/**
* Converts Flink time into a {@link Duration}.
*
* @param time to convert into a Duration
* @return Duration with the length of the given time
*/
public static Duration toDuration(Time time) {
return Duration.ofMillis(time.toMilliseconds());
}

// ------------------------------------------------------------------------
// Converting futures
// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.apache.flink.runtime.webmonitor.testutils.HttpTestClient;
import org.apache.flink.runtime.webmonitor.utils.WebFrontendBootstrap;
import org.apache.flink.util.TestLogger;
import org.apache.flink.util.concurrent.FutureUtils;
import org.apache.flink.util.TimeUtils;

import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext;
import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse;
Expand Down Expand Up @@ -75,19 +75,19 @@ public void testLeaderRetrievalGateway() throws Exception {
try (HttpTestClient httpClient =
new HttpTestClient("localhost", bootstrap.getServerPort())) {
// 1. no leader gateway available --> Service unavailable
httpClient.sendGetRequest(restPath, FutureUtils.toDuration(timeout));
httpClient.sendGetRequest(restPath, TimeUtils.toDuration(timeout));

HttpTestClient.SimpleHttpResponse response =
httpClient.getNextResponse(FutureUtils.toDuration(timeout));
httpClient.getNextResponse(TimeUtils.toDuration(timeout));

Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

// 2. with leader
gatewayFuture.complete(gateway);

httpClient.sendGetRequest(restPath, FutureUtils.toDuration(timeout));
httpClient.sendGetRequest(restPath, TimeUtils.toDuration(timeout));

response = httpClient.getNextResponse(FutureUtils.toDuration(timeout));
response = httpClient.getNextResponse(TimeUtils.toDuration(timeout));

Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());
Expand Down

0 comments on commit 18ed571

Please sign in to comment.