Shekharrajak commented on code in PR #19311: URL: https://github.com/apache/druid/pull/19311#discussion_r3259806882
########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/ShareGroupIndexTaskJsonSubmitIT.java: ########## @@ -0,0 +1,244 @@ +/* + * 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.indexing; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Throwables; +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.granularity.UniformGranularitySpec; +import org.apache.druid.indexing.kafka.KafkaIndexTaskModule; +import org.apache.druid.indexing.kafka.KafkaIndexTaskTuningConfig; +import org.apache.druid.indexing.kafka.ShareGroupIndexTask; +import org.apache.druid.indexing.kafka.ShareGroupIndexTaskIOConfig; +import org.apache.druid.jackson.DefaultObjectMapper; +import org.apache.druid.java.util.common.granularity.Granularities; +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.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.junit5.EmbeddedClusterTestBase; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** Verifies that ShareGroupIndexTask can be submitted via raw JSON through the Overlord HTTP API. */ +public class ShareGroupIndexTaskJsonSubmitIT extends EmbeddedClusterTestBase +{ + private static final long SHARE_CONSUMER_READY_DELAY_MS = 3_000L; + private static final String COL_TIMESTAMP = "__time"; + private static final String COL_ITEM = "item"; + private static final String COL_VALUE = "value"; + + private final EmbeddedCoordinator coordinator = new EmbeddedCoordinator(); + private final EmbeddedOverlord overlord = new EmbeddedOverlord(); + private final EmbeddedIndexer indexer = new EmbeddedIndexer(); + private final EmbeddedHistorical historical = new EmbeddedHistorical(); + private final EmbeddedBroker broker = new EmbeddedBroker(); + + private ShareGroupKafkaResource kafkaServer; + private final ObjectMapper mapper = new DefaultObjectMapper(); + + @Override + public EmbeddedDruidCluster createCluster() + { + kafkaServer = new ShareGroupKafkaResource(); + final EmbeddedDruidCluster cluster = EmbeddedDruidCluster.withEmbeddedDerbyAndZookeeper(); + indexer.addProperty("druid.segment.handoff.pollDuration", "PT0.1s"); + cluster.addExtension(KafkaIndexTaskModule.class) + .addResource(kafkaServer) + .useLatchableEmitter() + .useDefaultTimeoutForLatchableEmitter(30) + .addCommonProperty("druid.monitoring.emissionPeriod", "PT0.1s") + .addServer(coordinator) + .addServer(overlord) + .addServer(indexer) + .addServer(historical) + .addServer(broker); + return cluster; + } + + @Test + public void test_jsonSubmit_csvFormat_ingestsData() throws Exception + { + final String topic = dataSource + "_topic"; + kafkaServer.createTopicWithPartitions(topic, 2); + kafkaServer.setShareGroupAutoOffsetReset("json-submit-group", "earliest"); + + final ShareGroupIndexTask task = buildTask(topic, "json-submit-group"); + final JsonNode taskJson = mapper.readTree(mapper.writeValueAsString(task)); + cluster.callApi().onLeaderOverlord(o -> o.runTask(task.getId(), taskJson)); + + Thread.sleep(SHARE_CONSUMER_READY_DELAY_MS); + + final int numRecords = 8; + kafkaServer.publishRecordsToTopic(topic, generateRecords(numRecords)); + + indexer.latchableEmitter().waitForEventAggregate( + event -> event.hasMetricName("ingest/events/processed") + .hasDimension(DruidMetrics.DATASOURCE, dataSource), + agg -> agg.hasSumAtLeast(numRecords) + ); + cluster.callApi().waitForAllSegmentsToBeAvailable(dataSource, coordinator, broker); + + final long deadlineMs = System.currentTimeMillis() + 30_000L; + while (System.currentTimeMillis() < deadlineMs) { + try { + cluster.callApi().verifySqlQuery("SELECT COUNT(*) FROM %s", dataSource, String.valueOf(numRecords)); + break; + } + catch (AssertionError ignored) { + Thread.sleep(500); + } + } + + cluster.callApi().onLeaderOverlord(o -> o.cancelTask(task.getId())); + cluster.callApi().waitForTaskToFinish(task.getId(), overlord.latchableEmitter()); + } + + @Test + public void test_jsonSubmit_roundTripsPayload() throws Exception + { + final String topic = dataSource + "_roundtrip_topic"; + kafkaServer.createTopicWithPartitions(topic, 1); + kafkaServer.setShareGroupAutoOffsetReset("roundtrip-group", "earliest"); + + final ShareGroupIndexTask task = buildTask(topic, "roundtrip-group"); + final JsonNode taskJson = mapper.readTree(mapper.writeValueAsString(task)); + cluster.callApi().onLeaderOverlord(o -> o.runTask(task.getId(), taskJson)); + + Thread.sleep(SHARE_CONSUMER_READY_DELAY_MS); + + final org.apache.druid.client.indexing.TaskPayloadResponse payloadResponse = + cluster.callApi().onLeaderOverlord(o -> o.taskPayload(task.getId())); + Assertions.assertEquals(task.getId(), payloadResponse.getTask()); + + final JsonNode payloadJson = mapper.valueToTree(payloadResponse.getPayload()); + Assertions.assertEquals("share_group_index", payloadJson.path("type").asText()); Review Comment: https://github.com/apache/druid/pull/19311/changes/872d6f3b93031491ed35811765e0291bcbf98bd6#diff-c24dbac31b9f7e4062cd05cd6260d05c23c1c49b1c15ab8df3f9813efd806cb6 ########## embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/ShareGroupIndexTaskJsonSubmitIT.java: ########## @@ -0,0 +1,244 @@ +/* + * 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.indexing; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Throwables; +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.granularity.UniformGranularitySpec; +import org.apache.druid.indexing.kafka.KafkaIndexTaskModule; +import org.apache.druid.indexing.kafka.KafkaIndexTaskTuningConfig; +import org.apache.druid.indexing.kafka.ShareGroupIndexTask; +import org.apache.druid.indexing.kafka.ShareGroupIndexTaskIOConfig; +import org.apache.druid.jackson.DefaultObjectMapper; +import org.apache.druid.java.util.common.granularity.Granularities; +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.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.junit5.EmbeddedClusterTestBase; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** Verifies that ShareGroupIndexTask can be submitted via raw JSON through the Overlord HTTP API. */ +public class ShareGroupIndexTaskJsonSubmitIT extends EmbeddedClusterTestBase +{ + private static final long SHARE_CONSUMER_READY_DELAY_MS = 3_000L; + private static final String COL_TIMESTAMP = "__time"; + private static final String COL_ITEM = "item"; + private static final String COL_VALUE = "value"; + + private final EmbeddedCoordinator coordinator = new EmbeddedCoordinator(); + private final EmbeddedOverlord overlord = new EmbeddedOverlord(); + private final EmbeddedIndexer indexer = new EmbeddedIndexer(); + private final EmbeddedHistorical historical = new EmbeddedHistorical(); + private final EmbeddedBroker broker = new EmbeddedBroker(); + + private ShareGroupKafkaResource kafkaServer; + private final ObjectMapper mapper = new DefaultObjectMapper(); + + @Override + public EmbeddedDruidCluster createCluster() + { + kafkaServer = new ShareGroupKafkaResource(); + final EmbeddedDruidCluster cluster = EmbeddedDruidCluster.withEmbeddedDerbyAndZookeeper(); + indexer.addProperty("druid.segment.handoff.pollDuration", "PT0.1s"); + cluster.addExtension(KafkaIndexTaskModule.class) + .addResource(kafkaServer) + .useLatchableEmitter() + .useDefaultTimeoutForLatchableEmitter(30) + .addCommonProperty("druid.monitoring.emissionPeriod", "PT0.1s") + .addServer(coordinator) + .addServer(overlord) + .addServer(indexer) + .addServer(historical) + .addServer(broker); + return cluster; + } + + @Test + public void test_jsonSubmit_csvFormat_ingestsData() throws Exception + { + final String topic = dataSource + "_topic"; + kafkaServer.createTopicWithPartitions(topic, 2); + kafkaServer.setShareGroupAutoOffsetReset("json-submit-group", "earliest"); + + final ShareGroupIndexTask task = buildTask(topic, "json-submit-group"); + final JsonNode taskJson = mapper.readTree(mapper.writeValueAsString(task)); + cluster.callApi().onLeaderOverlord(o -> o.runTask(task.getId(), taskJson)); + + Thread.sleep(SHARE_CONSUMER_READY_DELAY_MS); + + final int numRecords = 8; + kafkaServer.publishRecordsToTopic(topic, generateRecords(numRecords)); + + indexer.latchableEmitter().waitForEventAggregate( + event -> event.hasMetricName("ingest/events/processed") + .hasDimension(DruidMetrics.DATASOURCE, dataSource), + agg -> agg.hasSumAtLeast(numRecords) + ); + cluster.callApi().waitForAllSegmentsToBeAvailable(dataSource, coordinator, broker); + + final long deadlineMs = System.currentTimeMillis() + 30_000L; Review Comment: https://github.com/apache/druid/pull/19311/changes/872d6f3b93031491ed35811765e0291bcbf98bd6#diff-c24dbac31b9f7e4062cd05cd6260d05c23c1c49b1c15ab8df3f9813efd806cb6 -- 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]
