nastra commented on code in PR #14333:
URL: https://github.com/apache/iceberg/pull/14333#discussion_r2567574240


##########
gcp/src/integration/java/org/apache/iceberg/gcp/gcs/IntegrationTestGcsFileIO.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.gcp.gcs;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import com.google.cloud.NoCredentials;
+import com.google.cloud.storage.Blob;
+import com.google.cloud.storage.BlobId;
+import com.google.cloud.storage.BlobInfo;
+import com.google.cloud.storage.BucketInfo;
+import com.google.cloud.storage.Storage;
+import com.google.cloud.storage.StorageOptions;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Duration;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import org.apache.iceberg.io.FileInfo;
+import org.apache.iceberg.io.IOUtil;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+
+@Testcontainers
+public class IntegrationTestGcsFileIO {
+
+  private static final String BUCKET = "test-bucket";
+  private static final String PROJECT_ID = "test-project";
+  private static final int GCS_EMULATOR_PORT = 4443;
+  private final Random random = new Random(1);
+
+  @Container
+  private static final GenericContainer<?> GCS_EMULATOR =
+      new GenericContainer<>("fsouza/fake-gcs-server:latest")
+          .withExposedPorts(GCS_EMULATOR_PORT)
+          .withCreateContainerCmdModifier(
+              cmd ->
+                  cmd.withHostConfig(
+                      new com.github.dockerjava.api.model.HostConfig()
+                          .withPortBindings(
+                              new com.github.dockerjava.api.model.PortBinding(
+                                  
com.github.dockerjava.api.model.Ports.Binding.bindPort(
+                                      GCS_EMULATOR_PORT),
+                                  new 
com.github.dockerjava.api.model.ExposedPort(
+                                      GCS_EMULATOR_PORT)))))
+          .withCommand(
+              "-scheme",
+              "http",
+              "-external-url",
+              String.format("http://localhost:%d";, GCS_EMULATOR_PORT))
+          .waitingFor(
+              new HttpWaitStrategy()
+                  .forPort(GCS_EMULATOR_PORT)
+                  .forPath("/storage/v1/b")
+                  .forStatusCode(200)
+                  .withStartupTimeout(Duration.ofMinutes(2)));
+
+  private GCSFileIO fileIO;
+  private static Storage storage;
+
+  @BeforeAll
+  public static void beforeClass() {
+    GCS_EMULATOR.start();
+    String endpoint = String.format("http://localhost:%d";, GCS_EMULATOR_PORT);
+    StorageOptions options =
+        StorageOptions.newBuilder()
+            .setProjectId(PROJECT_ID)
+            .setHost(endpoint)
+            .setCredentials(NoCredentials.getInstance())
+            .build();
+    storage = options.getService();
+    storage.create(BucketInfo.of(BUCKET));
+  }
+
+  @AfterAll
+  public static void afterClass() {
+    if (storage != null) {
+      storage.delete(BUCKET);
+    }
+    GCS_EMULATOR.stop();
+  }
+
+  @BeforeEach
+  public void before() {
+    fileIO = new GCSFileIO(() -> storage);
+    fileIO.initialize(ImmutableMap.of());
+    for (Blob blob : storage.list(BUCKET).iterateAll()) {
+      storage.delete(blob.getBlobId());
+    }
+  }
+
+  @AfterEach
+  public void after() {
+    for (Blob blob : storage.list(BUCKET).iterateAll()) {
+      storage.delete(blob.getBlobId());
+    }
+  }
+
+  @Test
+  public void testNewInputFileGcsAnalyticsCoreDisabled() throws IOException {
+    String location = String.format("gs://%s/path/to/file.txt", BUCKET);
+    byte[] expected = new byte[1024 * 1024];
+    random.nextBytes(expected);
+    
storage.create(BlobInfo.newBuilder(BlobId.fromGsUtilUri(location)).build(), 
expected);
+    InputFile in = fileIO.newInputFile(location);
+    byte[] actual = new byte[1024 * 1024];
+
+    try (InputStream is = in.newStream()) {
+      IOUtil.readFully(is, actual, 0, expected.length);
+    }
+
+    assertThat(actual).isEqualTo(expected);
+  }
+
+  @Test
+  public void testNewInputFileGcsAnalyticsCoreEnabled() throws IOException {
+    String location = String.format("gs://%s/path/to/file.txt", BUCKET);
+    byte[] expected = new byte[1024 * 1024];
+    random.nextBytes(expected);
+    
storage.create(BlobInfo.newBuilder(BlobId.fromGsUtilUri(location)).build(), 
expected);
+    fileIO.initialize(
+        ImmutableMap.of(
+            "gcs.analytics-core.enabled", "true",

Review Comment:
   we should be able to use the constant defined in `GCPProperties`



-- 
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]

Reply via email to