flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zentol <...@git.apache.org>
Subject [GitHub] flink pull request #6178: [FLINK-9599][rest] Implement generic mechanism to ...
Date Wed, 20 Jun 2018 08:05:01 GMT
Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6178#discussion_r196681937
  
    --- Diff: flink-runtime/src/test/java/org/apache/flink/runtime/rest/FileUploadHandlerTest.java
---
    @@ -0,0 +1,471 @@
    +/*
    + * 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.rest;
    +
    +import org.apache.flink.api.common.time.Time;
    +import org.apache.flink.api.java.tuple.Tuple2;
    +import org.apache.flink.configuration.ConfigConstants;
    +import org.apache.flink.configuration.Configuration;
    +import org.apache.flink.configuration.RestOptions;
    +import org.apache.flink.configuration.WebOptions;
    +import org.apache.flink.runtime.rest.handler.AbstractRestHandler;
    +import org.apache.flink.runtime.rest.handler.FileUploads;
    +import org.apache.flink.runtime.rest.handler.HandlerRequest;
    +import org.apache.flink.runtime.rest.handler.RestHandlerException;
    +import org.apache.flink.runtime.rest.handler.RestHandlerSpecification;
    +import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
    +import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
    +import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
    +import org.apache.flink.runtime.rest.messages.MessageHeaders;
    +import org.apache.flink.runtime.rest.messages.RequestBody;
    +import org.apache.flink.runtime.rest.util.RestMapperUtils;
    +import org.apache.flink.runtime.rpc.RpcUtils;
    +import org.apache.flink.runtime.webmonitor.RestfulGateway;
    +import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
    +import org.apache.flink.util.Preconditions;
    +
    +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
    +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
    +import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
    +import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler;
    +import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
    +
    +import okhttp3.MediaType;
    +import okhttp3.MultipartBody;
    +import okhttp3.OkHttpClient;
    +import okhttp3.Request;
    +import okhttp3.Response;
    +import org.junit.AfterClass;
    +import org.junit.BeforeClass;
    +import org.junit.ClassRule;
    +import org.junit.Test;
    +import org.junit.rules.TemporaryFolder;
    +
    +import javax.annotation.Nonnull;
    +
    +import java.io.File;
    +import java.io.IOException;
    +import java.io.StringWriter;
    +import java.nio.file.Files;
    +import java.nio.file.Path;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.Random;
    +import java.util.concurrent.CompletableFuture;
    +
    +import static java.util.Objects.requireNonNull;
    +import static org.junit.Assert.assertArrayEquals;
    +import static org.junit.Assert.assertEquals;
    +import static org.mockito.Matchers.any;
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.when;
    +
    +/**
    + * Tests for the {@link FileUploadHandler}. Ensures that multipart http messages containing
files and/or json are properly
    + * handled.
    + */
    +public class FileUploadHandlerTest {
    +
    +	private static final ObjectMapper OBJECT_MAPPER = RestMapperUtils.getStrictObjectMapper();
    +	private static final Random RANDOM = new Random();
    +
    +	@ClassRule
    +	public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
    +
    +	private static RestServerEndpoint serverEndpoint;
    +	private static String serverAddress;
    +
    +	private static MultipartMixedHandler mixedHandler;
    +	private static MultipartJsonHandler jsonHandler;
    +	private static MultipartFileHandler fileHandler;
    +	private static File file1;
    +	private static File file2;
    +
    +	@BeforeClass
    +	public static void setup() throws Exception {
    +		Configuration config = new Configuration();
    +		config.setInteger(RestOptions.PORT, 0);
    +		config.setString(RestOptions.ADDRESS, "localhost");
    +		config.setString(WebOptions.UPLOAD_DIR, TEMPORARY_FOLDER.newFolder().getCanonicalPath());
    +
    +		RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);
    +
    +		final String restAddress = "http://localhost:1234";
    +		RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);
    --- End diff --
    
    neat.


---

Mime
View raw message