chihsuan commented on code in PR #10966: URL: https://github.com/apache/ozone/pull/10966#discussion_r4770924025
########## 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: Could we use TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX=ghcr.io/ in CI instead of OZONE_IMAGE? Ryuk is still pulled from Docker Hub. The prefix moves both images to ghcr.io, so the test can just use apache/ozone. ########## 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: Could we add a log4j.properties under src/test/resources, like the s3gateway module has? Without it, the container logs are lost when startup fails. -- 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]
