use of org.apache.flink.runtime.rest.handler.router.RouteResult in project flink by apache.
the class AbstractHandlerTest method testFileCleanup.
@Test
public void testFileCleanup() throws Exception {
final Path dir = temporaryFolder.newFolder().toPath();
final Path file = dir.resolve("file");
Files.createFile(file);
RestfulGateway mockRestfulGateway = new TestingRestfulGateway.Builder().build();
final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () -> CompletableFuture.completedFuture(mockRestfulGateway);
CompletableFuture<Void> requestProcessingCompleteFuture = new CompletableFuture<>();
TestHandler handler = new TestHandler(requestProcessingCompleteFuture, mockGatewayRetriever);
RouteResult<?> routeResult = new RouteResult<>("", "", Collections.emptyMap(), Collections.emptyMap(), "");
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, TestHandler.TestHeaders.INSTANCE.getTargetRestEndpointURL(), Unpooled.wrappedBuffer(new byte[0]));
RoutedRequest<?> routerRequest = new RoutedRequest<>(routeResult, request);
Attribute<FileUploads> attribute = new SimpleAttribute();
attribute.set(new FileUploads(dir));
Channel channel = mock(Channel.class);
when(channel.attr(any(AttributeKey.class))).thenReturn(attribute);
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
when(context.channel()).thenReturn(channel);
handler.respondAsLeader(context, routerRequest, mockRestfulGateway);
// the (asynchronous) request processing is not yet complete so the files should still exist
Assert.assertTrue(Files.exists(file));
requestProcessingCompleteFuture.complete(null);
Assert.assertFalse(Files.exists(file));
}
Aggregations