openinx commented on a change in pull request #3498: URL: https://github.com/apache/iceberg/pull/3498#discussion_r746221663
########## File path: aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSOutputFile.java ########## @@ -0,0 +1,163 @@ +/* + * 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.iceberg.aliyun.oss; + +import com.aliyun.oss.OSS; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; +import org.apache.iceberg.AssertHelpers; +import org.apache.iceberg.aliyun.AliyunProperties; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Assert; +import org.junit.Test; + +public class TestOSSOutputFile extends AliyunOSSTestBase { + + private final OSS ossClient = ossClient().get(); + private final Random random = ThreadLocalRandom.current(); + private final AliyunProperties aliyunProperties = new AliyunProperties(); + + @Test + public void testWriteFile() throws IOException { + OSSURI uri = randomURI(); + int dataSize = 1024 * 10; + byte[] data = randomData(dataSize); + + InputStream is = new ByteArrayInputStream(data); + OutputFile out = OSSOutputFile.fromLocation(ossClient, uri.location(), aliyunProperties); + try (OutputStream os = out.create()) { + ByteStreams.copy(is, os); + } + + Assert.assertTrue("OSS file should exist", ossClient.doesObjectExist(uri.bucket(), uri.key())); + Assert.assertEquals("Object length should match", ossDataLength(uri), dataSize); + + byte[] actual = new byte[dataSize]; + ByteStreams.readFully(ossDataContent(uri), actual); Review comment: Maybe we can just return the byte array from `ossDataContent` and close it inside the `ossDataContent`. ########## File path: aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSInputFile.java ########## @@ -60,7 +60,8 @@ public void testReadFile() throws Exception { public void testOSSInputFile() { OSSURI uri = randomURI(); AssertHelpers.assertThrows("File length should not be negative", ValidationException.class, - "Invalid file length", () -> new OSSInputFile(ossClient().get(), uri, -1)); + "Invalid file length", + () -> new OSSInputFile(ossClient().get(), uri, -1)); Review comment: Nit: Pls revert this unrelated change. ########## File path: aliyun/src/main/java/org/apache/iceberg/aliyun/oss/OSSOutputFile.java ########## @@ -0,0 +1,57 @@ +/* + * 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.iceberg.aliyun.oss; + +import com.aliyun.oss.OSS; +import org.apache.iceberg.aliyun.AliyunProperties; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.io.PositionOutputStream; + +public class OSSOutputFile extends BaseOSSFile implements OutputFile { Review comment: This class don't need to be exposed as `public` because we are only exposed as the abstracted `OutputFile` in iceberg project. ########## File path: aliyun/src/test/java/org/apache/iceberg/aliyun/oss/TestOSSOutputFile.java ########## @@ -0,0 +1,163 @@ +/* + * 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.iceberg.aliyun.oss; + +import com.aliyun.oss.OSS; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; +import org.apache.iceberg.AssertHelpers; +import org.apache.iceberg.aliyun.AliyunProperties; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Assert; +import org.junit.Test; + +public class TestOSSOutputFile extends AliyunOSSTestBase { + + private final OSS ossClient = ossClient().get(); + private final Random random = ThreadLocalRandom.current(); + private final AliyunProperties aliyunProperties = new AliyunProperties(); + + @Test + public void testWriteFile() throws IOException { + OSSURI uri = randomURI(); + int dataSize = 1024 * 10; + byte[] data = randomData(dataSize); + + InputStream is = new ByteArrayInputStream(data); + OutputFile out = OSSOutputFile.fromLocation(ossClient, uri.location(), aliyunProperties); + try (OutputStream os = out.create()) { + ByteStreams.copy(is, os); + } + + Assert.assertTrue("OSS file should exist", ossClient.doesObjectExist(uri.bucket(), uri.key())); + Assert.assertEquals("Object length should match", ossDataLength(uri), dataSize); + + byte[] actual = new byte[dataSize]; + ByteStreams.readFully(ossDataContent(uri), actual); Review comment: Looks like we are forgetting to close the input stream from http connection, right ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
