mosche commented on a change in pull request #16168: URL: https://github.com/apache/beam/pull/16168#discussion_r766727670
########## File path: sdks/java/io/amazon-web-services/src/test/java/org/apache/beam/sdk/io/aws/ITEnvironment.java ########## @@ -0,0 +1,125 @@ +/* + * 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.beam.sdk.io.aws; + +import static org.apache.beam.sdk.testing.TestPipeline.testingPipelineOptions; + +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration; +import java.util.function.Consumer; +import org.apache.beam.sdk.io.aws.options.AwsOptions; +import org.apache.beam.sdk.options.Default; +import org.apache.beam.sdk.options.Description; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.testing.TestPipelineOptions; +import org.junit.rules.ExternalResource; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.containers.localstack.LocalStackContainer.Service; +import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.utility.DockerImageName; + +public class ITEnvironment<T extends ITEnvironment.ITOptions> extends ExternalResource { + private static final String LOCALSTACK = "localstack/localstack"; + private static final String LOCALSTACK_VERSION = "0.12.18"; + + public interface ITOptions extends AwsOptions, TestPipelineOptions { + @Description("Number of rows to write and read by the test") + @Default.Integer(1000) + Integer getNumberOfRows(); + + void setNumberOfRows(Integer count); + + @Description("Flag if to use localstack, enabled by default.") + @Default.Boolean(true) + Boolean getUseLocalstack(); + + void setUseLocalstack(Boolean useLocalstack); + + @Description("Localstack log level, e.g. trace, debug, info") + String getLocalstackLogLevel(); + + void setLocalstackLogLevel(String level); + } + + private final Service service; + private final T options; + private final LocalStackContainer localstack; + + public ITEnvironment(Service service, Class<T> optionsClass) { + this(service, optionsClass, o -> {}); + } + + public ITEnvironment(Service service, Class<T> optionsClass, Consumer<T> optionsMutator) { + this.service = service; + localstack = + new LocalStackContainer(DockerImageName.parse(LOCALSTACK).withTag(LOCALSTACK_VERSION)) + .withServices(service) + .withStartupAttempts(3); + + PipelineOptionsFactory.register(optionsClass); + options = testingPipelineOptions().as(optionsClass); + optionsMutator.accept(options); + + if (options.getLocalstackLogLevel() != null) { + localstack + .withEnv("LS_LOG", options.getLocalstackLogLevel()) + .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(service.name()))); + } + } + + public TestPipeline testPipeline() { 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]
