kfaraz commented on code in PR #18265: URL: https://github.com/apache/druid/pull/18265#discussion_r2214722647
########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/docker/IngestionDockerTest.java: ########## @@ -0,0 +1,292 @@ +/* + * 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 com.google.common.collect.ImmutableList; +import org.apache.druid.common.utils.IdUtils; +import org.apache.druid.data.input.impl.CsvInputFormat; +import org.apache.druid.data.input.impl.DimensionsSpec; +import org.apache.druid.data.input.impl.TimestampSpec; +import org.apache.druid.indexer.TaskState; +import org.apache.druid.indexer.TaskStatusPlus; +import org.apache.druid.indexing.kafka.KafkaIndexTaskModule; +import org.apache.druid.indexing.kafka.simulate.KafkaResource; +import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorIOConfig; +import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorSpec; +import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorTuningConfig; +import org.apache.druid.indexing.overlord.Segments; +import org.apache.druid.indexing.overlord.supervisor.SupervisorStatus; +import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.parsers.CloseableIterator; +import org.apache.druid.query.DruidMetrics; +import org.apache.druid.segment.indexing.DataSchema; +import org.apache.druid.testing.embedded.EmbeddedBroker; +import org.apache.druid.testing.embedded.EmbeddedClusterApis; +import org.apache.druid.testing.embedded.EmbeddedDruidCluster; +import org.apache.druid.testing.embedded.EmbeddedOverlord; +import org.apache.druid.testing.embedded.EmbeddedRouter; +import org.apache.druid.testing.embedded.derby.EmbeddedDerbyMetadataResource; +import org.apache.druid.testing.embedded.indexing.Resources; +import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase; +import org.apache.druid.testing.embedded.minio.MinIOStorageResource; +import org.apache.druid.timeline.DataSegment; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.joda.time.DateTime; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +/** + * Runs some basic ingestion tests using {@link DruidContainers}. + */ +public class IngestionDockerTest extends EmbeddedClusterTestBase +{ + // Druid Docker containers + protected final DruidContainerResource overlordLeader = DruidContainers.newOverlord().withTestImage(); + protected final DruidContainerResource coordinator = DruidContainers.newCoordinator().withTestImage(); + protected final DruidContainerResource historical = DruidContainers.newHistorical().withTestImage(); + protected final DruidContainerResource broker1 = DruidContainers.newBroker().withTestImage(); + protected final DruidContainerResource middleManager = DruidContainers + .newMiddleManager() + .withTestImage() + .addProperty("druid.segment.handoff.pollDuration", "PT0.1s"); + + // Follower EmbeddedOverlord to watch segment publish events + private final EmbeddedOverlord overlordFollower = new EmbeddedOverlord() + .addProperty("druid.plaintextPort", "7090") + .addProperty("druid.manager.segments.useIncrementalCache", "always") + .addProperty("druid.manager.segments.pollDuration", "PT0.1s"); + + // Additional EmbeddedBroker to wait for segments to become queryable + private final EmbeddedBroker broker2 = new EmbeddedBroker() + .addProperty("druid.plaintextPort", "7082"); + + private final KafkaResource kafkaServer = new KafkaResource(); + + @Override + public EmbeddedDruidCluster createCluster() + { + final EmbeddedDruidCluster cluster = EmbeddedDruidCluster.withZookeeper(); + + return cluster + .useDruidContainers() + .useLatchableEmitter() + // Needed for overlordFollower to recognize the KafkaSupervisor type + .addExtension(KafkaIndexTaskModule.class) + .addResource(new EmbeddedDerbyMetadataResource()) + .addResource(new MinIOStorageResource()) + .addResource(kafkaServer) + .addCommonProperty( + "druid.extensions.loadList", + "[\"druid-s3-extensions\", \"druid-kafka-indexing-service\", \"druid-multi-stage-query\"]" + ) + .addResource(coordinator) + .addResource(overlordLeader) + .addResource(middleManager) + .addResource(historical) + .addResource(broker1) + .addServer(overlordFollower) + .addServer(broker2) + .addServer(new EmbeddedRouter()); + } + + @Test + public void test_runIndexTask_andKillData() + { + + } + + @Test + public void test_runIndexParallelTask_andCompactData() + { + + } + + @Test + public void test_runMsqTask_andQueryData() + { + + } + + @Test + public void test_runIndexTask() + { + final String taskId = IdUtils.getRandomId(); + final Object task = createIndexTaskForInlineData( + taskId, + StringUtils.replace(Resources.CSV_DATA_10_DAYS, "\n", "\\n") + ); + + cluster.callApi().onLeaderOverlord(o -> o.runTask(taskId, task)); + waitForCachedUsedSegmentCount(10); + verifyUsedSegmentCount(10); + } + + private Object createIndexTaskForInlineData(String taskId, String inlineDataCsv) + { + return EmbeddedClusterApis.createTaskFromPayload( + taskId, + StringUtils.format(Resources.INDEX_TASK_PAYLOAD_WITH_INLINE_DATA, inlineDataCsv, dataSource) + ); + } + + @Test + public void test_runKafkaSupervisor() + { + final String topic = dataSource; + kafkaServer.createTopicWithPartitions(topic, 2); + + kafkaServer.produceRecordsToTopic( + generateRecordsForTopic(topic, 10, DateTimes.of("2025-06-01")) + ); + + // Submit and start a supervisor + final String supervisorId = dataSource; + final KafkaSupervisorSpec kafkaSupervisorSpec = createKafkaSupervisor(supervisorId, topic); + + final Map<String, String> startSupervisorResult = cluster.callApi().onLeaderOverlord( + o -> o.postSupervisor(kafkaSupervisorSpec) + ); + Assertions.assertEquals(Map.of("id", supervisorId), startSupervisorResult); + + // Wait for the broker to discover the realtime segments + broker2.latchableEmitter().waitForEvent( Review Comment: The difference is very slight but I preferred the second syntax: ``` waitForEvent(EventMatcher.matchesStuff(...)) ``` and ``` waitForEvent(event -> event.matchesStuff()) ``` -- 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: commits-unsubscr...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org