rich7420 commented on code in PR #10966: URL: https://github.com/apache/ozone/pull/10966#discussion_r4816860254
########## hadoop-ozone/ozone-testcontainers/src/main/java/org/apache/ozone/testcontainers/OzoneContainer.java: ########## @@ -0,0 +1,78 @@ +/* + * 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 java.time.Duration; +import org.apache.hadoop.hdds.annotation.InterfaceStability; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.wait.strategy.WaitAllStrategy; +import org.testcontainers.utility.DockerImageName; + +/** + * Testcontainers wrapper for a single-node Ozone with S3 Gateway, so JVM + * integration tests can start Ozone the way they use the MinIO or LocalStack + * modules. Wraps the all-in-one quickstart image, + * which runs SCM, OM, datanode, S3 Gateway, Recon and HttpFS in one container + * and exposes S3G on 9878. + * + * <p>Credentials: in non-secure mode S3G does not verify request signatures, so any secret / region is + * accepted. The access key is still passed to OM as the Ozone user name, so it decides the owner of the + * buckets and keys a test creates. {@link #getAccessKey()} / {@link #getSecretKey()} / {@link #getRegion()} + * provide a consistent set for the caller to sign requests with. + * + * <p>Readiness: the container waits for the S3 Gateway port, then retries {@code ozone admin safemode wait} + * until SCM leaves safe mode. The startup timeout defaults to four minutes and can be changed with + * {@link #withStartupTimeout(Duration)}. + */ [email protected] +public class OzoneContainer extends GenericContainer<OzoneContainer> { + + public static final int S3G_PORT = 9878; + + private static final String ACCESS_KEY = "testuser"; + private static final String SECRET_KEY = "testsecret"; + private static final String REGION = "us-east-1"; + + public OzoneContainer(DockerImageName image) { + super(image); + withExposedPorts(S3G_PORT); + waitingFor(new WaitAllStrategy() + .withStrategy(Wait.forListeningPort()) Review Comment: Added `OzoneWaitStrategy`. Tests can skip its port check, and on timeout the error shows the last `safemode wait` output. Both `TestOzoneWaitStrategy` cases run without Docker and fail if the safemode wait is removed. ########## hadoop-ozone/ozone-testcontainers/src/test/java/org/apache/ozone/testcontainers/TestOzoneContainer.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.Assumptions.assumeTrue; + +import java.net.URI; +import org.junit.jupiter.api.Test; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.utility.DockerImageName; +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; + +/** S3 smoke test, which is skipped when Docker is unavailable. */ +class TestOzoneContainer { + + @Test + void putGetThroughS3Gateway() { + assumeTrue(DockerClientFactory.instance().isDockerAvailable(), + "Docker is not available"); + try (OzoneContainer ozone = new OzoneContainer(smokeTestImage())) { + // Nothing in the image listens on this port, so it must not hold up readiness. + ozone.addExposedPort(9999); + ozone.start(); Review Comment: Added, based on the s3gateway one. Testcontainers' own logs show up in the test output now. ########## hadoop-ozone/ozone-testcontainers/src/test/java/org/apache/ozone/testcontainers/TestOzoneContainer.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.Assumptions.assumeTrue; + +import java.net.URI; +import org.junit.jupiter.api.Test; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.utility.DockerImageName; +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; + +/** S3 smoke test, which is skipped when Docker is unavailable. */ +class TestOzoneContainer { + + @Test + void putGetThroughS3Gateway() { + assumeTrue(DockerClientFactory.instance().isDockerAvailable(), + "Docker is not available"); + try (OzoneContainer ozone = new OzoneContainer(smokeTestImage())) { + // Nothing in the image listens on this port, so it must not hold up readiness. + ozone.addExposedPort(9999); + ozone.start(); + + try (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) + .overrideConfiguration(c -> c.retryStrategy(b -> b.maxAttempts(1))) + .build()) { + + String bucket = "test-bucket"; + String key = "hello.txt"; + String body = "hello ozone"; + + 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()); + } + } + } + + /** CI sets {@code OZONE_IMAGE} to the ghcr.io mirror to avoid Docker Hub rate limits. */ Review Comment: Done. CI sets `TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=ghcr.io/` now and the test just uses `apache/ozone`. I ran it locally with the prefix, and both Ryuk and Ozone came from ghcr.io. Could you take another look? -- 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]
