jtuglu1 commented on code in PR #18622: URL: https://github.com/apache/druid/pull/18622#discussion_r2431396686
########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/gcs/GcsTestUtil.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.gcs; + +import com.google.api.client.http.FileContent; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.common.base.Predicates; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.storage.google.GoogleInputDataConfig; +import org.apache.druid.storage.google.GoogleStorage; +import org.apache.druid.storage.google.GoogleUtils; +import org.apache.druid.testing.embedded.indexing.Resources; + +import java.io.File; +import java.io.IOException; + +public class GcsTestUtil +{ + private static final Logger LOG = new Logger(GcsTestUtil.class); + private final GoogleStorage googleStorageClient; + private final String bucket; + private final String pathPrefix; + + public GcsTestUtil(String storageUrl, String bucket, String pathPrefix) + { + this.bucket = bucket; + this.pathPrefix = pathPrefix; + + try (Storage storage = GoogleStorageTestModule.createStorageForTests(storageUrl)) { + storage.create(BucketInfo.of(bucket)); + this.googleStorageClient = new GoogleStorage(() -> storage); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void uploadFileToGcs(String filePath, String contentType) throws IOException + { + LOG.info("Uploading file %s at path %s in bucket %s", filePath, pathPrefix, bucket); Review Comment: nit: we use file[%s], etc. in other places – maybe be consistent here. ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexer/IndexerTest.java: ########## @@ -343,39 +337,44 @@ public void testGetLockedIntervals() throws Exception ITRetryUtil.retryUntilFalse( () -> { lockedIntervals.clear(); - lockedIntervals.putAll(indexer.getLockedIntervals(lockFilterPolicies)); + lockedIntervals.putAll(cluster.callApi().onLeaderOverlord(o -> o.findLockedIntervals(lockFilterPolicies))); return lockedIntervals.isEmpty(); }, "Verify Intervals are Locked" ); // Verify the locked intervals for this datasource - Assert.assertEquals(lockedIntervals.size(), 1); - Assert.assertEquals( + Assertions.assertEquals(lockedIntervals.size(), 1); Review Comment: nit: reverse the order of these ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexer/IndexerTest.java: ########## @@ -238,15 +236,14 @@ public void testMERGEIndexData() throws Exception @Test public void testIndexDataAwaitSegmentAvailability() throws Exception { - try ( - final Closeable ignored1 = unloader(INDEX_DATASOURCE + config.getExtraDatasourceNameSuffix()); - ) { + final String indexDatasource = dataSource; + try (final Closeable ignored1 = unloader(indexDatasource)) { final Function<String, String> transform = spec -> { try { return StringUtils.replace( spec, "%%SEGMENT_AVAIL_TIMEOUT_MILLIS%%", - jsonMapper.writeValueAsString("600000") + jsonMapper.writeValueAsString("120000") Review Comment: why this change? ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/azure/AzureTestUtil.java: ########## Review Comment: minor nit while we're here: `container::createIfNotExists` ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/gcs/GcsTestUtil.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.gcs; + +import com.google.api.client.http.FileContent; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.common.base.Predicates; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.storage.google.GoogleInputDataConfig; +import org.apache.druid.storage.google.GoogleStorage; +import org.apache.druid.storage.google.GoogleUtils; +import org.apache.druid.testing.embedded.indexing.Resources; + +import java.io.File; +import java.io.IOException; + +public class GcsTestUtil +{ + private static final Logger LOG = new Logger(GcsTestUtil.class); + private final GoogleStorage googleStorageClient; + private final String bucket; + private final String pathPrefix; + + public GcsTestUtil(String storageUrl, String bucket, String pathPrefix) + { + this.bucket = bucket; + this.pathPrefix = pathPrefix; + + try (Storage storage = GoogleStorageTestModule.createStorageForTests(storageUrl)) { + storage.create(BucketInfo.of(bucket)); + this.googleStorageClient = new GoogleStorage(() -> storage); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void uploadFileToGcs(String filePath, String contentType) throws IOException + { + LOG.info("Uploading file %s at path %s in bucket %s", filePath, pathPrefix, bucket); + File file = Resources.getFileForResource(filePath); + googleStorageClient.insert( + bucket, + pathPrefix + "/" + file.getName(), + new FileContent(contentType, file), + null + ); + } + + public void deleteFileFromGcs(String gcsObjectName) + { + LOG.info("Deleting object %s at path %s in bucket %s", gcsObjectName, pathPrefix, bucket); Review Comment: https://github.com/apache/druid/pull/18622/files#r2431396686 ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexer/AbstractIndexerTest.java: ########## @@ -0,0 +1,159 @@ +/* + * 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.indexer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import org.apache.commons.io.IOUtils; +import org.apache.druid.common.utils.IdUtils; +import org.apache.druid.indexer.TaskStatusPlus; +import org.apache.druid.java.util.common.parsers.CloseableIterator; +import org.apache.druid.query.aggregation.datasketches.hll.HllSketchModule; +import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchModule; +import org.apache.druid.query.aggregation.datasketches.theta.SketchModule; +import org.apache.druid.testing.embedded.EmbeddedBroker; +import org.apache.druid.testing.embedded.EmbeddedClusterApis; +import org.apache.druid.testing.embedded.EmbeddedCoordinator; +import org.apache.druid.testing.embedded.EmbeddedDruidCluster; +import org.apache.druid.testing.embedded.EmbeddedHistorical; +import org.apache.druid.testing.embedded.EmbeddedIndexer; +import org.apache.druid.testing.embedded.EmbeddedOverlord; +import org.apache.druid.testing.embedded.EmbeddedRouter; +import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase; +import org.junit.jupiter.api.BeforeAll; + +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * The tests that extend this class have been converted from old style integration + * tests. As such, they do not make the most effective use of the embedded test + * framework. These tests should be refactored later to rely more on constructs + * such as {@code LatchableEmitter}, {@code TaskBuilder}, {@code EmbeddedClusterApis} + * and less on {@code ITRetryUtil} and the string replacement of {@code %%args%%} + * to construct task and query payloads. + */ +public abstract class AbstractIndexerTest extends EmbeddedClusterTestBase +{ + protected static class PlaceHolders + { + protected static final String DATASOURCE = "%%DATASOURCE%%"; + protected static final String DATA_DIRECTORY = "%%DATA_DIRECTORY%%"; + } + + protected final EmbeddedCoordinator coordinator = new EmbeddedCoordinator() + .addProperty("druid.manager.segments.useIncrementalCache", "always"); + protected final EmbeddedOverlord overlord = new EmbeddedOverlord(); + protected final EmbeddedIndexer indexer = new EmbeddedIndexer() + .setServerMemory(500_000_000L) + .addProperty("druid.worker.capacity", "5") + .addProperty("druid.segment.handoff.pollDuration", "PT0.1s"); Review Comment: Is this same/slower/faster as before? ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/gcs/GcsTestUtil.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.gcs; + +import com.google.api.client.http.FileContent; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.common.base.Predicates; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.storage.google.GoogleInputDataConfig; +import org.apache.druid.storage.google.GoogleStorage; +import org.apache.druid.storage.google.GoogleUtils; +import org.apache.druid.testing.embedded.indexing.Resources; + +import java.io.File; +import java.io.IOException; + +public class GcsTestUtil +{ + private static final Logger LOG = new Logger(GcsTestUtil.class); + private final GoogleStorage googleStorageClient; + private final String bucket; + private final String pathPrefix; + + public GcsTestUtil(String storageUrl, String bucket, String pathPrefix) + { + this.bucket = bucket; + this.pathPrefix = pathPrefix; + + try (Storage storage = GoogleStorageTestModule.createStorageForTests(storageUrl)) { + storage.create(BucketInfo.of(bucket)); + this.googleStorageClient = new GoogleStorage(() -> storage); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + public void uploadFileToGcs(String filePath, String contentType) throws IOException + { + LOG.info("Uploading file %s at path %s in bucket %s", filePath, pathPrefix, bucket); + File file = Resources.getFileForResource(filePath); + googleStorageClient.insert( + bucket, + pathPrefix + "/" + file.getName(), + new FileContent(contentType, file), + null + ); + } + + public void deleteFileFromGcs(String gcsObjectName) + { + LOG.info("Deleting object %s at path %s in bucket %s", gcsObjectName, pathPrefix, bucket); + googleStorageClient.delete(bucket, pathPrefix + "/" + gcsObjectName); + } + + public void deletePrefixFolderFromGcs(String datasource) throws Exception + { + LOG.info("Deleting path %s in bucket %s", pathPrefix, bucket); Review Comment: https://github.com/apache/druid/pull/18622/files#r2431396686 -- 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]
