Copilot commented on code in PR #10966:
URL: https://github.com/apache/ozone/pull/10966#discussion_r3735732851


##########
hadoop-ozone/ozone-testcontainers/src/test/java/org/apache/ozone/testcontainers/TestOzoneContainer.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.ozone.testcontainers;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import java.net.URI;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.DockerClientFactory;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.core.ResponseBytes;
+import software.amazon.awssdk.core.sync.RequestBody;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.GetObjectResponse;
+
+/**
+ * Smoke test: start single-node Ozone in a container and exercise the S3
+ * Gateway with the AWS SDK v2 (create bucket / put / get). Skipped when no
+ * Docker daemon is available (for example on a unit-only CI runner).
+ */
+class TestOzoneContainer {
+
+  @Test
+  void putGetThroughS3Gateway() {
+    assumeTrue(DockerClientFactory.instance().isDockerAvailable(),
+        "Docker is not available");
+    try (OzoneContainer ozone = new OzoneContainer()) {
+      ozone.start();
+
+      S3Client s3 = S3Client.builder()
+          .endpointOverride(URI.create(ozone.getS3Endpoint()))
+          .credentialsProvider(StaticCredentialsProvider.create(
+              AwsBasicCredentials.create(ozone.getAccessKey(), 
ozone.getSecretKey())))
+          .region(Region.of(ozone.getRegion()))
+          .forcePathStyle(true)
+          .build();
+
+      String bucket = "test-bucket";
+      String key = "hello.txt";
+      String body = "hello ozone";
+
+      // The container is ready (out of safe mode) after start(), so no retry.
+      s3.createBucket(b -> b.bucket(bucket));
+      s3.putObject(b -> b.bucket(bucket).key(key), 
RequestBody.fromString(body));
+
+      ResponseBytes<GetObjectResponse> got =
+          s3.getObjectAsBytes(b -> b.bucket(bucket).key(key));
+
+      assertEquals(body, got.asUtf8String());
+      assertTrue(s3.listBuckets().buckets().stream()
+          .anyMatch(b -> b.name().equals(bucket)));
+    }

Review Comment:
   `S3Client` implements `AutoCloseable` but is never closed here, which can 
leak HTTP resources/threads and make the test JVM hang after completion. Wrap 
the client in a try-with-resources block (or call `close()` explicitly).



##########
hadoop-ozone/ozone-testcontainers/pom.xml:
##########
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.ozone</groupId>
+    <artifactId>ozone</artifactId>
+    <version>2.3.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>ozone-testcontainers</artifactId>
+  <version>2.3.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>Apache Ozone Testcontainers</name>
+  <description>Testcontainers module to run a single-node Ozone with S3 
Gateway in integration tests</description>
+
+  <properties>
+    <aws-java-sdk2.version>2.49.3</aws-java-sdk2.version>
+    <maven.javadoc.skip>true</maven.javadoc.skip>
+    <testcontainers.version>1.20.4</testcontainers.version>
+  </properties>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.testcontainers</groupId>
+        <artifactId>testcontainers-bom</artifactId>
+        <version>${testcontainers.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+      <dependency>
+        <groupId>software.amazon.awssdk</groupId>
+        <artifactId>bom</artifactId>
+        <version>${aws-java-sdk2.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.testcontainers</groupId>
+      <artifactId>testcontainers</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>

Review Comment:
   This module inherits a SLF4J binding from the parent POM (`slf4j-reload4j` 
in test scope). Adding `slf4j-simple` introduces multiple SLF4J providers on 
the test classpath, which typically produces warnings and can lead to 
inconsistent logging behavior. Remove `slf4j-simple` here.
   
   This issue also appears on line 69 of the same file.



##########
hadoop-hdds/docs/content/tools/Testcontainers.md:
##########
@@ -0,0 +1,76 @@
+---
+title: "Testcontainers"
+summary: Start a single-node Ozone with S3 Gateway from JVM integration tests 
using Testcontainers.
+---
+<!---
+  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.
+-->
+
+The `ozone-testcontainers` module lets JVM integration tests start a 
single-node
+Ozone with an S3 Gateway inside a Docker container, the same way tests use the
+MinIO or LocalStack [Testcontainers](https://testcontainers.com/) modules. It
+wraps the all-in-one Ozone image, which runs SCM, OM, a datanode and the S3
+Gateway in one container.
+
+Requires a running Docker daemon. The smoke test is skipped automatically when
+Docker is not available.
+
+## Dependency
+
+```xml
+<dependency>
+  <groupId>org.apache.ozone</groupId>
+  <artifactId>ozone-testcontainers</artifactId>
+  <scope>test</scope>
+</dependency>
+```
+
+## Usage
+
+```java
+try (OzoneContainer ozone = new OzoneContainer()) {
+  ozone.start();
+
+  S3Client s3 = S3Client.builder()
+      .endpointOverride(URI.create(ozone.getS3Endpoint()))
+      .credentialsProvider(StaticCredentialsProvider.create(
+          AwsBasicCredentials.create(ozone.getAccessKey(), 
ozone.getSecretKey())))
+      .region(Region.of(ozone.getRegion()))
+      .forcePathStyle(true)
+      .build();
+
+  s3.createBucket(b -> b.bucket("my-bucket"));
+  // ... put / get / list objects
+}

Review Comment:
   The usage snippet creates an `S3Client` but does not close it. Since 
`S3Client` is `AutoCloseable`, recommending try-with-resources avoids leaking 
HTTP resources/threads in consumers’ integration tests.



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