kfaraz commented on code in PR #18302: URL: https://github.com/apache/druid/pull/18302#discussion_r2239050224
########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/docker/DruidContainerResource.java: ########## @@ -0,0 +1,229 @@ +/* + * 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.druid.testing.embedded.docker; + +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.testing.DruidCommand; +import org.apache.druid.testing.DruidContainer; +import org.apache.druid.testing.MountedDir; +import org.apache.druid.testing.embedded.EmbeddedDruidCluster; +import org.apache.druid.testing.embedded.TestcontainerResource; +import org.testcontainers.utility.DockerImageName; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * {@link TestcontainerResource} to run Druid services. + * Currently, only core extensions can be used out-of-the-box with these containers + * such as {@code druid-s3-extensions} or {@code postgresql-metadata-storage}, + * simply by adding them to {@code druid.extensions.loadList}. + * <p> + * {@link DruidContainers} should be used only for testing backward compatiblity + * or a Docker-specific feature. For all other testing needs, use plain old + * {@code EmbeddedDruidServer} as they are much faster, allow easy debugging and + * do not require downloading any images. + */ +public class DruidContainerResource extends TestcontainerResource<DruidContainer> +{ + /** + * Java system property to specify the name of the Docker test image. + */ + public static final String PROPERTY_TEST_IMAGE = "druid.testing.docker.image"; + + private static final Logger log = new Logger(DruidContainerResource.class); + + /** + * Forbidden server properties that may be used by EmbeddedDruidServers but + * interfere with the functioning of DruidContainer-based services. + */ + private static final Set<String> FORBIDDEN_PROPERTIES = Set.of( + "druid.extensions.modulesForEmbeddedTests", + "druid.emitter" + ); + + /** + * A static incremental ID is used instead of a random number to ensure that + * tests are more deterministic and easier to debug. + */ + private static final AtomicInteger SERVER_ID = new AtomicInteger(0); + + private final String name; + private final DruidCommand command; + private final Map<String, String> properties = new HashMap<>(); + + private DockerImageName imageName; + private EmbeddedDruidCluster cluster; + + private File containerDirectory; + + private MountedDir indexerLogsDeepStorageDirectory; + private MountedDir serviceLogsDirectory; + private MountedDir segmentDeepStorageDirectory; + + DruidContainerResource(DruidCommand command) + { + this.name = StringUtils.format( + "container_%s_%d", + command.getName(), + SERVER_ID.incrementAndGet() + ); + this.command = command; + addProperty("druid.host", EmbeddedDruidCluster.getDefaultHost()); + } + + public DruidContainerResource withImage(DockerImageName imageName) + { + this.imageName = imageName; + return this; + } + + /** + * Uses the Docker test image specified by the system property + * {@link #PROPERTY_TEST_IMAGE} for this container. + */ + public DruidContainerResource withTestImage() Review Comment: Fixed. ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/docker/DruidContainerResource.java: ########## @@ -0,0 +1,229 @@ +/* + * 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.druid.testing.embedded.docker; + +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.testing.DruidCommand; +import org.apache.druid.testing.DruidContainer; +import org.apache.druid.testing.MountedDir; +import org.apache.druid.testing.embedded.EmbeddedDruidCluster; +import org.apache.druid.testing.embedded.TestcontainerResource; +import org.testcontainers.utility.DockerImageName; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * {@link TestcontainerResource} to run Druid services. + * Currently, only core extensions can be used out-of-the-box with these containers + * such as {@code druid-s3-extensions} or {@code postgresql-metadata-storage}, + * simply by adding them to {@code druid.extensions.loadList}. + * <p> + * {@link DruidContainers} should be used only for testing backward compatiblity + * or a Docker-specific feature. For all other testing needs, use plain old + * {@code EmbeddedDruidServer} as they are much faster, allow easy debugging and + * do not require downloading any images. + */ +public class DruidContainerResource extends TestcontainerResource<DruidContainer> +{ + /** + * Java system property to specify the name of the Docker test image. + */ + public static final String PROPERTY_TEST_IMAGE = "druid.testing.docker.image"; + + private static final Logger log = new Logger(DruidContainerResource.class); + + /** + * Forbidden server properties that may be used by EmbeddedDruidServers but + * interfere with the functioning of DruidContainer-based services. + */ + private static final Set<String> FORBIDDEN_PROPERTIES = Set.of( + "druid.extensions.modulesForEmbeddedTests", + "druid.emitter" + ); + + /** + * A static incremental ID is used instead of a random number to ensure that + * tests are more deterministic and easier to debug. + */ + private static final AtomicInteger SERVER_ID = new AtomicInteger(0); + + private final String name; + private final DruidCommand command; + private final Map<String, String> properties = new HashMap<>(); + + private DockerImageName imageName; + private EmbeddedDruidCluster cluster; + + private File containerDirectory; + + private MountedDir indexerLogsDeepStorageDirectory; + private MountedDir serviceLogsDirectory; + private MountedDir segmentDeepStorageDirectory; + + DruidContainerResource(DruidCommand command) + { + this.name = StringUtils.format( + "container_%s_%d", + command.getName(), + SERVER_ID.incrementAndGet() + ); + this.command = command; + addProperty("druid.host", EmbeddedDruidCluster.getDefaultHost()); + } + + public DruidContainerResource withImage(DockerImageName imageName) Review Comment: fixed, thanks for the suggestion! -- 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]
