wang-x-xia commented on a change in pull request #3376: URL: https://github.com/apache/iceberg/pull/3376#discussion_r743405173
########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsFileIO.java ########## @@ -0,0 +1,104 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Map; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A {@link java.io.Externalizable} FileIO of ECS S3 object client. + */ +public class EcsFileIO implements FileIO, Externalizable, AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(EcsFileIO.class); Review comment: Removed! ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsFileIO.java ########## @@ -0,0 +1,104 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Map; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A {@link java.io.Externalizable} FileIO of ECS S3 object client. + */ +public class EcsFileIO implements FileIO, Externalizable, AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(EcsFileIO.class); + + /** + * Saved properties for {@link java.io.Serializable} + */ + private Map<String, String> properties; + private S3Client client; + + /** + * Blank constructor + */ + public EcsFileIO() { + } + + @Override + public void initialize(Map<String, String> inputProperties) { + this.properties = ImmutableMap.copyOf(inputProperties); + this.client = EcsClientFactory.create(inputProperties); + } + + @Override + public InputFile newInputFile(String path) { + return new EcsInputFile(client, path); + } + + @Override + public OutputFile newOutputFile(String path) { + return new EcsOutputFile(client, path); + } + + @Override + public void deleteFile(String path) { + EcsURI uri = EcsURI.create(path); + client.deleteObject(uri.getBucket(), uri.getName()); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(properties); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + @SuppressWarnings("unchecked") + Map<String, String> inputProperties = (Map<String, String>) in.readObject(); + initialize(inputProperties); + } + + @Override + public void close() { + client.destroy(); + log.info("FileIO closed"); Review comment: Removed! ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsFileIO.java ########## @@ -0,0 +1,104 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Map; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A {@link java.io.Externalizable} FileIO of ECS S3 object client. + */ +public class EcsFileIO implements FileIO, Externalizable, AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(EcsFileIO.class); + + /** + * Saved properties for {@link java.io.Serializable} + */ + private Map<String, String> properties; + private S3Client client; + + /** + * Blank constructor + */ + public EcsFileIO() { + } + + @Override + public void initialize(Map<String, String> inputProperties) { + this.properties = ImmutableMap.copyOf(inputProperties); + this.client = EcsClientFactory.create(inputProperties); + } + + @Override + public InputFile newInputFile(String path) { + return new EcsInputFile(client, path); + } + + @Override + public OutputFile newOutputFile(String path) { + return new EcsOutputFile(client, path); + } + + @Override + public void deleteFile(String path) { + EcsURI uri = EcsURI.create(path); + client.deleteObject(uri.getBucket(), uri.getName()); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(properties); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + @SuppressWarnings("unchecked") + Map<String, String> inputProperties = (Map<String, String>) in.readObject(); + initialize(inputProperties); + } + + @Override + public void close() { + client.destroy(); + log.info("FileIO closed"); + } + + @VisibleForTesting + Map<String, String> getProperties() { Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsFileIO.java ########## @@ -0,0 +1,104 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Map; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.OutputFile; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A {@link java.io.Externalizable} FileIO of ECS S3 object client. + */ +public class EcsFileIO implements FileIO, Externalizable, AutoCloseable { + + private static final Logger log = LoggerFactory.getLogger(EcsFileIO.class); + + /** + * Saved properties for {@link java.io.Serializable} + */ + private Map<String, String> properties; + private S3Client client; + + /** + * Blank constructor + */ + public EcsFileIO() { + } + + @Override + public void initialize(Map<String, String> inputProperties) { + this.properties = ImmutableMap.copyOf(inputProperties); + this.client = EcsClientFactory.create(inputProperties); + } + + @Override + public InputFile newInputFile(String path) { + return new EcsInputFile(client, path); + } + + @Override + public OutputFile newOutputFile(String path) { + return new EcsOutputFile(client, path); + } + + @Override + public void deleteFile(String path) { + EcsURI uri = EcsURI.create(path); + client.deleteObject(uri.getBucket(), uri.getName()); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + out.writeObject(properties); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + @SuppressWarnings("unchecked") + Map<String, String> inputProperties = (Map<String, String>) in.readObject(); + initialize(inputProperties); + } + + @Override + public void close() { + client.destroy(); + log.info("FileIO closed"); + } + + @VisibleForTesting + Map<String, String> getProperties() { + return properties; + } + + @VisibleForTesting + S3Client getClient() { Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsOutputFile.java ########## @@ -0,0 +1,68 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +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 EcsOutputFile implements OutputFile { + + private final S3Client client; + private final String location; + private final EcsURI uri; + + public EcsOutputFile(S3Client client, String location) { + this.client = client; + this.location = location; + this.uri = EcsURI.create(location); + } + + /** + * Check object existence and then create a {@link PositionOutputStream} + * + * @return Output stream of object + */ + @Override + public PositionOutputStream create() { + if (!toInputFile().exists()) { Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsSeekableInputStream.java ########## @@ -0,0 +1,110 @@ +/* + * 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.dell; + +import com.emc.object.Range; +import com.emc.object.s3.S3Client; +import java.io.IOException; +import java.io.InputStream; +import org.apache.iceberg.io.SeekableInputStream; + +/** + * A {@link SeekableInputStream} impl that warp {@link S3Client#readObjectStream(String, String, Range)} Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/EcsAppendOutputStreamTest.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import com.emc.object.Range; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class EcsAppendOutputStreamTest { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void generalTest() throws IOException { Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/EcsAppendOutputStreamTest.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import com.emc.object.Range; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class EcsAppendOutputStreamTest { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void generalTest() throws IOException { + String objectName = "test"; + try (EcsAppendOutputStream output = EcsAppendOutputStream.createWithBufferSize( + rule.getClient(), + new EcsURI(rule.getBucket(), objectName), + 10)) { + // write 1 byte + output.write('1'); + // write 3 bytes + output.write("123".getBytes()); + // write 7 bytes, totally 11 bytes > local buffer limit (10) + output.write("1234567".getBytes()); + // write 11 bytes, flush remain 7 bytes and new 11 bytes + output.write("12345678901".getBytes()); + } + + try (InputStream input = rule.getClient().readObjectStream(rule.getBucket(), objectName, + Range.fromOffset(0))) { + assertEquals("object content", "1" + "123" + "1234567" + "12345678901", Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/EcsAppendOutputStreamTest.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import com.emc.object.Range; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class EcsAppendOutputStreamTest { Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsURI.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import java.net.URI; +import java.util.Objects; +import java.util.Set; +import org.apache.iceberg.exceptions.ValidationException; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; + +/** + * An immutable record class of ECS location + */ +public class EcsURI { Review comment: Move to package private. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsURI.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import java.net.URI; +import java.util.Objects; +import java.util.Set; +import org.apache.iceberg.exceptions.ValidationException; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; + +/** + * An immutable record class of ECS location + */ +public class EcsURI { Review comment: Moved to package private. ########## File path: build.gradle ########## @@ -566,6 +566,23 @@ project(':iceberg-nessie') { } } +project(':iceberg-dell') { + dependencies { + implementation project(':iceberg-core') + implementation project(':iceberg-common') + implementation project(path: ':iceberg-bundled-guava', configuration: 'shadow') + implementation 'com.emc.ecs:object-client-bundle' Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsClientFactory.java ########## @@ -0,0 +1,96 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +import com.emc.object.s3.S3Config; +import com.emc.object.s3.jersey.S3JerseyClient; +import java.net.URI; +import java.util.Map; +import java.util.Optional; +import org.apache.iceberg.common.DynConstructors; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public interface EcsClientFactory { + + /** + * Create the ECS S3 Client from properties + */ + static S3Client create(Map<String, String> properties) { + return createWithFactory(properties).orElseGet(() -> createDefault(properties)); + } + + /** + * Try to create the ECS S3 client from factory method. + */ + static Optional<S3Client> createWithFactory(Map<String, String> properties) { + String factory = properties.get(EcsClientProperties.ECS_CLIENT_FACTORY); + if (factory == null || factory.isEmpty()) { + return Optional.empty(); + } + + DynConstructors.Ctor<EcsClientFactory> ctor; + try { + ctor = DynConstructors.builder(EcsClientFactory.class).impl(factory).buildChecked(); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(String.format( + "Cannot find EcsClientFactory implementation %s: %s", factory, e.getMessage()), e); + } + + EcsClientFactory clientFactory; + try { + clientFactory = ctor.newInstance(); + } catch (ClassCastException e) { + throw new IllegalArgumentException( + String.format("Cannot initialize Catalog, %s does not implement EcsClientFactory.", factory), e); Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsClientFactory.java ########## @@ -0,0 +1,96 @@ +/* + * 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.dell; + +import com.emc.object.s3.S3Client; +import com.emc.object.s3.S3Config; +import com.emc.object.s3.jersey.S3JerseyClient; +import java.net.URI; +import java.util.Map; +import java.util.Optional; +import org.apache.iceberg.common.DynConstructors; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public interface EcsClientFactory { + + /** + * Create the ECS S3 Client from properties + */ + static S3Client create(Map<String, String> properties) { + return createWithFactory(properties).orElseGet(() -> createDefault(properties)); + } + + /** + * Try to create the ECS S3 client from factory method. + */ + static Optional<S3Client> createWithFactory(Map<String, String> properties) { + String factory = properties.get(EcsClientProperties.ECS_CLIENT_FACTORY); + if (factory == null || factory.isEmpty()) { + return Optional.empty(); + } + + DynConstructors.Ctor<EcsClientFactory> ctor; + try { + ctor = DynConstructors.builder(EcsClientFactory.class).impl(factory).buildChecked(); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(String.format( + "Cannot find EcsClientFactory implementation %s: %s", factory, e.getMessage()), e); + } + + EcsClientFactory clientFactory; + try { + clientFactory = ctor.newInstance(); + } catch (ClassCastException e) { + throw new IllegalArgumentException( + String.format("Cannot initialize Catalog, %s does not implement EcsClientFactory.", factory), e); + } + + S3Client client = clientFactory.createS3Client(properties); + + if (client == null) { + throw new IllegalArgumentException(String.format( + "Invalid EcsClientFactory %s that return null client", + factory)); + } + + return Optional.of(client); + } + + /** + * Get built-in ECS S3 client. + */ + static S3Client createDefault(Map<String, String> properties) { + Preconditions.checkNotNull(properties.get(EcsClientProperties.ENDPOINT), + "Endpoint(%s) cannot be null", EcsClientProperties.ENDPOINT); Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsClientProperties.java ########## @@ -0,0 +1,48 @@ +/* + * 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.dell; + +/** + * Property constants of catalog + */ +public interface EcsClientProperties { Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsURI.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import java.net.URI; +import java.util.Objects; +import java.util.Set; +import org.apache.iceberg.exceptions.ValidationException; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; + +/** + * An immutable record class of ECS location + */ +class EcsURI { + + private static final Set<String> VALID_SCHEME = ImmutableSet.of("ecs", "s3", "s3a", "s3n"); + + static EcsURI create(String location) { + URI uri = URI.create(location); + if (!VALID_SCHEME.contains(uri.getScheme().toLowerCase())) { Review comment: Done. ########## File path: dell/src/main/java/org/apache/iceberg/dell/EcsClientProperties.java ########## @@ -0,0 +1,48 @@ +/* + * 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.dell; + +/** + * Property constants of catalog + */ +public interface EcsClientProperties { Review comment: We assume to use this class name. I think other staffs should use their own properties. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsAppendOutputStream.java ########## @@ -0,0 +1,88 @@ +/* + * 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.dell; + +import com.emc.object.Range; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class TestEcsAppendOutputStream { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testBaseObjectWrite() throws IOException { + String objectName = "test"; + try (EcsAppendOutputStream output = EcsAppendOutputStream.createWithBufferSize( + rule.getClient(), + new EcsURI(rule.getBucket(), objectName), + 10)) { + // write 1 byte + output.write('1'); + // write 3 bytes + output.write("123".getBytes()); + // write 7 bytes, totally 11 bytes > local buffer limit (10) + output.write("1234567".getBytes()); + // write 11 bytes, flush remain 7 bytes and new 11 bytes + output.write("12345678901".getBytes()); + } + + try (InputStream input = rule.getClient().readObjectStream(rule.getBucket(), objectName, + Range.fromOffset(0))) { + assertEquals("Must write all the object content", "1" + "123" + "1234567" + "12345678901", + new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8)); + } + } + + @Test + public void testRewrite() throws IOException { + String objectName = "test"; + try (EcsAppendOutputStream output = EcsAppendOutputStream.createWithBufferSize( + rule.getClient(), + new EcsURI(rule.getBucket(), objectName), + 10)) { + // write 7 bytes + output.write("7654321".getBytes()); + } + + try (EcsAppendOutputStream output = EcsAppendOutputStream.createWithBufferSize( + rule.getClient(), + new EcsURI(rule.getBucket(), objectName), + 10)) { + // write 14 bytes + output.write("1234567".getBytes()); + output.write("1234567".getBytes()); + } + + try (InputStream input = rule.getClient().readObjectStream(rule.getBucket(), objectName, + Range.fromOffset(0))) { + assertEquals("object content", "1234567" + "1234567", Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFile.java ########## @@ -0,0 +1,79 @@ +/* + * 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.dell; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +public class TestEcsFile { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testFileReadAndWrite() throws IOException { + String objectName = "test"; + String location = new EcsURI(rule.getBucket(), objectName).toString(); + EcsInputFile inputFile = new EcsInputFile(rule.getClient(), location); + EcsOutputFile outpufFile = new EcsOutputFile(rule.getClient(), location); + + // absent + assertFalse("File is absent", inputFile.exists()); + assertEquals("File length is 0 if absent", 0, inputFile.getLength()); + + // write and read + try (PositionOutputStream output = outpufFile.create()) { + output.write("1234567890".getBytes()); + } + + assertTrue("File is present", inputFile.exists()); + assertEquals("File length is 10", 10, inputFile.getLength()); + try (SeekableInputStream input = inputFile.newStream()) { + assertEquals("File content is expected", "1234567890", + new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8)); + } + + // rewrite file + try (PositionOutputStream output = outpufFile.createOrOverwrite()) { + output.write("987654321".getBytes()); + } + + assertEquals("New file length is 9", 9, inputFile.getLength()); + try (SeekableInputStream input = inputFile.newStream()) { + assertEquals("New file content is overwrite old content", "987654321", + new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8)); + } + + // write checker + assertThrows("If file exists, throw exception", AlreadyExistsException.class, outpufFile::create); Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFile.java ########## @@ -0,0 +1,79 @@ +/* + * 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.dell; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; Review comment: Remove all static imports. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFile.java ########## @@ -0,0 +1,79 @@ +/* + * 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.dell; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; Review comment: Removed all static imports. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFileIO.java ########## @@ -0,0 +1,51 @@ +/* + * 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.dell; + +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.util.SerializationUtil; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; Review comment: Removed all static imports. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFile.java ########## @@ -0,0 +1,79 @@ +/* + * 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.dell; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +public class TestEcsFile { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testFileReadAndWrite() throws IOException { Review comment: This test class separated to 2 test files. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFile.java ########## @@ -0,0 +1,79 @@ +/* + * 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.dell; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +public class TestEcsFile { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testFileReadAndWrite() throws IOException { Review comment: This test class is separated to 2 test files. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFile.java ########## @@ -0,0 +1,79 @@ +/* + * 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.dell; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.exceptions.AlreadyExistsException; +import org.apache.iceberg.io.PositionOutputStream; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +public class TestEcsFile { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testFileReadAndWrite() throws IOException { Review comment: This test class is separated into 2 test files. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFileIO.java ########## @@ -0,0 +1,51 @@ +/* + * 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.dell; + +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.util.SerializationUtil; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + +public class TestEcsFileIO { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.manualCreateBucket(); + + @Test + public void externalizable() { Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsFileIO.java ########## @@ -0,0 +1,51 @@ +/* + * 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.dell; + +import java.util.LinkedHashMap; +import java.util.Map; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.apache.iceberg.util.SerializationUtil; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; + +public class TestEcsFileIO { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.manualCreateBucket(); + + @Test + public void externalizable() { + try (EcsFileIO instance1 = new EcsFileIO()) { + Map<String, String> input = new LinkedHashMap<>(rule.getClientProperties()); Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsSeekableInputStream.java ########## @@ -0,0 +1,62 @@ +/* + * 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.dell; + +import com.emc.object.s3.request.PutObjectRequest; +import java.io.IOException; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class TestEcsSeekableInputStream { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testSeekPosRead() throws IOException { Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsSeekableInputStream.java ########## @@ -0,0 +1,62 @@ +/* + * 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.dell; + +import com.emc.object.s3.request.PutObjectRequest; +import java.io.IOException; +import org.apache.iceberg.dell.mock.EcsS3MockRule; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; Review comment: Removed all static imports. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsURI.java ########## @@ -0,0 +1,61 @@ +/* + * 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.dell; + +import org.apache.iceberg.exceptions.ValidationException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; Review comment: Removed all static imports. ########## File path: dell/src/test/java/org/apache/iceberg/dell/TestEcsURI.java ########## @@ -0,0 +1,61 @@ +/* + * 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.dell; + +import org.apache.iceberg.exceptions.ValidationException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +public class TestEcsURI { + + @Test + public void testCreate() { + assertEquals( + new EcsURI("bucket", ""), + EcsURI.create("ecs://bucket")); + assertEquals( + new EcsURI("bucket", ""), + EcsURI.create("ecs://bucket/")); + assertEquals( + new EcsURI("bucket", ""), + EcsURI.create("ecs://bucket//")); + assertEquals( + new EcsURI("bucket", "a"), + EcsURI.create("ecs://bucket//a")); + assertEquals( + new EcsURI("bucket", "a/b"), + EcsURI.create("ecs://bucket/a/b")); + assertEquals( + new EcsURI("bucket", "a//b"), + EcsURI.create("ecs://bucket/a//b")); + assertEquals( + new EcsURI("bucket", "a//b"), + EcsURI.create("ecs://bucket//a//b")); + } + + @Test + public void testInvalidLocation() { + assertThrows( Review comment: Done. ########## File path: dell/src/test/java/org/apache/iceberg/dell/mock/TestExceptionCode.java ########## @@ -0,0 +1,56 @@ +/* + * 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.dell.mock; + +import com.emc.object.Range; +import com.emc.object.s3.S3Exception; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Verify the error codes between real client and mock client. + */ +public class TestExceptionCode { + + @Rule + public EcsS3MockRule rule = EcsS3MockRule.create(); + + @Test + public void testExceptionCode() { + String object = "test"; + assertS3Exception("Append absent object", 404, "NoSuchKey", + () -> rule.getClient().appendObject(rule.getBucket(), object, "abc".getBytes())); + assertS3Exception("Get object", 404, "NoSuchKey", + () -> rule.getClient().readObjectStream(rule.getBucket(), object, Range.fromOffset(0))); + } + + public void assertS3Exception(String message, int httpCode, String errorCode, Runnable task) { + try { + task.run(); + fail(message + ", expect s3 exception"); Review comment: Done. -- 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]
