Search in sources :

Example 1 with RouteResult

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));
}
Also used : Path(java.nio.file.Path) HttpRequest(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultFullHttpRequest(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) ChannelHandlerContext(org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext) AttributeKey(org.apache.flink.shaded.netty4.io.netty.util.AttributeKey) CompletableFuture(java.util.concurrent.CompletableFuture) RouteResult(org.apache.flink.runtime.rest.handler.router.RouteResult) RoutedRequest(org.apache.flink.runtime.rest.handler.router.RoutedRequest) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) RestfulGateway(org.apache.flink.runtime.webmonitor.RestfulGateway) TestingRestfulGateway(org.apache.flink.runtime.webmonitor.TestingRestfulGateway) Test(org.junit.Test)

Aggregations

Path (java.nio.file.Path)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 RouteResult (org.apache.flink.runtime.rest.handler.router.RouteResult)1 RoutedRequest (org.apache.flink.runtime.rest.handler.router.RoutedRequest)1 RestfulGateway (org.apache.flink.runtime.webmonitor.RestfulGateway)1 TestingRestfulGateway (org.apache.flink.runtime.webmonitor.TestingRestfulGateway)1 Channel (org.apache.flink.shaded.netty4.io.netty.channel.Channel)1 ChannelHandlerContext (org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext)1 DefaultFullHttpRequest (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest)1 HttpRequest (org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest)1 AttributeKey (org.apache.flink.shaded.netty4.io.netty.util.AttributeKey)1 Test (org.junit.Test)1