Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6311#discussion_r202275460
  
    --- Diff: 
flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JarSubmissionITCase.java
 ---
    @@ -0,0 +1,223 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.flink.runtime.webmonitor.handlers;
    +
    +import org.apache.flink.api.common.time.Time;
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.runtime.dispatcher.DispatcherGateway;
    +import org.apache.flink.runtime.rest.handler.HandlerRequest;
    +import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
    +import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
    +import org.apache.flink.runtime.rest.messages.JobPlanInfo;
    +import org.apache.flink.runtime.testingUtils.TestingUtils;
    +import org.apache.flink.runtime.webmonitor.RestfulGateway;
    +import org.apache.flink.runtime.webmonitor.TestingDispatcherGateway;
    +import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
    +import org.apache.flink.util.ExceptionUtils;
    +
    +import org.junit.Assert;
    +import org.junit.Rule;
    +import org.junit.Test;
    +import org.junit.rules.TemporaryFolder;
    +
    +import java.net.ConnectException;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.nio.file.Paths;
    +import java.util.Collections;
    +import java.util.Map;
    +import java.util.Optional;
    +import java.util.concurrent.CompletableFuture;
    +import java.util.concurrent.Executor;
    +
    +import static org.hamcrest.Matchers.containsString;
    +
    +/**
    + * Tests the entire lifecycle of a jar submission.
    + */
    +public class JarSubmissionITCase {
    +
    +   @Rule
    +   public final TemporaryFolder temporaryFolder = new TemporaryFolder();
    +
    +   @Test
    +   public void testJarSubmission() throws Exception {
    +           final TestingDispatcherGateway restfulGateway = new 
TestingDispatcherGateway.Builder().build();
    +           final JarHandlers handlers = new 
JarHandlers(temporaryFolder.newFolder().toPath(), restfulGateway);
    +           final JarUploadHandler uploadHandler = handlers.uploadHandler;
    +           final JarListHandler listHandler = handlers.listHandler;
    +           final JarPlanHandler planHandler = handlers.planHandler;
    +           final JarRunHandler runHandler = handlers.runHandler;
    +           final JarDeleteHandler deleteHandler = handlers.deleteHandler;
    +
    +           // targetDir property is set via surefire configuration
    +           final Path originalJar = 
Paths.get(System.getProperty("targetDir")).resolve("test-program.jar");
    +           final Path jar = Files.copy(originalJar, 
temporaryFolder.getRoot().toPath().resolve("test-program.jar"));
    +
    +           final String storedJarPath = uploadJar(uploadHandler, jar, 
restfulGateway);
    +           final String storedJarName = 
Paths.get(storedJarPath).getFileName().toString();
    +
    +           final JarListInfo postUploadListResponse = 
listJars(listHandler, restfulGateway);
    +           Assert.assertEquals(1, 
postUploadListResponse.jarFileList.size());
    +           final JarListInfo.JarFileInfo listEntry = 
postUploadListResponse.jarFileList.iterator().next();
    +           Assert.assertEquals(jar.getFileName().toString(), 
listEntry.name);
    +           Assert.assertEquals(storedJarName, listEntry.id);
    +
    +           final JobPlanInfo planResponse = showPlan(planHandler, 
storedJarName, restfulGateway);
    +           // we're only interested in the core functionality so checking 
for a small detail is sufficient
    +           Assert.assertThat(planResponse.getJsonPlan(), 
containsString("TestProgram.java:29"));
    +
    +           try {
    +                   runJar(runHandler, storedJarName, restfulGateway);
    +                   Assert.fail("We assume the actual job submission to 
fail.");
    +           } catch (Exception e) {
    +                   final Optional<ConnectException> expected = 
ExceptionUtils.findThrowable(e, ConnectException.class);
    --- End diff --
    
    we can make this part a lot nicer by starting a `BlobServer´ like we do in 
the `JobSubmitHandlerTest` and setting a `submitFunction` on the 
`TestingDispatcherGateway`.
    
    Will add this later.


---

Reply via email to