Created
April 18, 2019 14:30
-
-
Save Fokko/2852f2738e0e4c9bef4d255111df423c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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.fs.gcs.common; | |
import com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem; | |
import org.apache.flink.configuration.GlobalConfiguration; | |
import org.apache.flink.runtime.util.HadoopUtils; | |
import org.apache.hadoop.fs.FSDataOutputStream; | |
import org.apache.hadoop.fs.Path; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.io.IOException; | |
import java.net.URI; | |
/** | |
* HadoopFileSystem extension for a {@link GcsConcatTest}. | |
*/ | |
public class GcsConcatTest { | |
private static final String bucket_name = "fokko-yolo"; | |
private static final String path = String.format("gs://%s/", bucket_name); | |
private org.apache.hadoop.fs.FileSystem ghfs; | |
@Before | |
public void beforeTest() throws IOException { | |
ghfs = new GoogleHadoopFileSystem(); | |
final org.apache.hadoop.conf.Configuration conf = HadoopUtils.getHadoopConfiguration(GlobalConfiguration.loadConfiguration()); | |
ghfs.initialize(URI.create(path), conf); | |
} | |
@Test | |
public void ConcatFiles() throws IOException { | |
int parts = 5; | |
Path[] paths = new Path[parts]; | |
for (int i = 0; i < parts; i++) { | |
Path p = new Path(path + String.format("file-%s.txt", i)); | |
try (FSDataOutputStream fs = ghfs.create(p)) { | |
fs.write(String.format("Hello world %s", i).getBytes()); | |
} | |
paths[i] = p; | |
} | |
ghfs.concat( | |
new Path(path + "file.txt"), | |
paths | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment