github-advanced-security[bot] commented on code in PR #18147:
URL: https://github.com/apache/druid/pull/18147#discussion_r2154665404


##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/simulate/KafkaSupervisorSimTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.indexing.kafka.simulate;
+
+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.indexing.kafka.KafkaIndexTaskModule;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorIOConfig;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorSpec;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorStatus;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.CloseableIterator;
+import org.apache.druid.segment.TestDataSource;
+import org.apache.druid.segment.indexing.DataSchema;
+import org.apache.druid.testing.simulate.EmbeddedCoordinator;
+import org.apache.druid.testing.simulate.EmbeddedDruidCluster;
+import org.apache.druid.testing.simulate.EmbeddedIndexer;
+import org.apache.druid.testing.simulate.EmbeddedOverlord;
+import org.apache.druid.testing.simulate.junit5.DruidSimulationTestBase;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Map;
+
+public class KafkaSupervisorSimTest extends DruidSimulationTestBase
+{
+  private EmbeddedKafkaServer kafkaServer;
+  private EmbeddedDruidCluster cluster;
+
+  @Override
+  public EmbeddedDruidCluster createCluster()
+  {
+    cluster = 
EmbeddedDruidCluster.withExtensions(List.of(KafkaIndexTaskModule.class))
+                                  .addServer(new EmbeddedCoordinator())
+                                  .addServer(EmbeddedIndexer.create())
+                                  .addServer(EmbeddedOverlord.create());
+
+    kafkaServer = new EmbeddedKafkaServer(cluster.getZookeeper(), 
cluster.getTestFolder(), Map.of());
+    cluster.addResource(kafkaServer);
+
+    return cluster;
+  }
+
+  @Test
+  public void test_runKafkaTask() throws Exception
+  {
+    // Set up a topic
+    final String topic = TestDataSource.WIKI;
+    kafkaServer.createTopicWithPartitions(topic, 2);
+
+    // Produce some records to the topic
+    final List<ProducerRecord<byte[], byte[]>> records = List.of(
+        new ProducerRecord<>(topic, 0, StringUtils.toUtf8("key1"), 
StringUtils.toUtf8("value1")),
+        new ProducerRecord<>(topic, 1, StringUtils.toUtf8("key2"), 
StringUtils.toUtf8("value2"))
+    );
+    kafkaServer.produceRecordsToTopic(records);
+
+    // Submit and start a supervisor
+    final KafkaSupervisorSpec kafkaSupervisorSpec = new KafkaSupervisorSpec(
+        null,
+        null,
+        DataSchema.builder()
+                  .withDataSource(TestDataSource.WIKI)
+                  .withTimestamp(new TimestampSpec("time", null, null))
+                  .withDimensions(DimensionsSpec.EMPTY)
+                  .build(),
+        null,
+        new KafkaSupervisorIOConfig(
+            topic,
+            null,
+            new CsvInputFormat(List.of("col1"), null, null, false, 0, false),
+            null, null, null,
+            kafkaServer.consumerProperties(),
+            null, null, null, null, null,
+            true,
+            null, null, null, null, null, null, null,
+            false
+        ),
+        Map.of(),
+        false,
+        null, null, null, null, null, null, null, null, null
+    );
+
+    final Map<String, String> startSupervisorResult = getResult(
+        cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec)
+    );

Review Comment:
   ## Unread local variable
   
   Variable 'Map<String,String> startSupervisorResult' is never read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9244)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/simulate/KafkaSupervisorSimTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.indexing.kafka.simulate;
+
+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.indexing.kafka.KafkaIndexTaskModule;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorIOConfig;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorSpec;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorStatus;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.CloseableIterator;
+import org.apache.druid.segment.TestDataSource;
+import org.apache.druid.segment.indexing.DataSchema;
+import org.apache.druid.testing.simulate.EmbeddedCoordinator;
+import org.apache.druid.testing.simulate.EmbeddedDruidCluster;
+import org.apache.druid.testing.simulate.EmbeddedIndexer;
+import org.apache.druid.testing.simulate.EmbeddedOverlord;
+import org.apache.druid.testing.simulate.junit5.DruidSimulationTestBase;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Map;
+
+public class KafkaSupervisorSimTest extends DruidSimulationTestBase
+{
+  private EmbeddedKafkaServer kafkaServer;
+  private EmbeddedDruidCluster cluster;
+
+  @Override
+  public EmbeddedDruidCluster createCluster()
+  {
+    cluster = 
EmbeddedDruidCluster.withExtensions(List.of(KafkaIndexTaskModule.class))
+                                  .addServer(new EmbeddedCoordinator())
+                                  .addServer(EmbeddedIndexer.create())
+                                  .addServer(EmbeddedOverlord.create());
+
+    kafkaServer = new EmbeddedKafkaServer(cluster.getZookeeper(), 
cluster.getTestFolder(), Map.of());
+    cluster.addResource(kafkaServer);
+
+    return cluster;
+  }
+
+  @Test
+  public void test_runKafkaTask() throws Exception
+  {
+    // Set up a topic
+    final String topic = TestDataSource.WIKI;
+    kafkaServer.createTopicWithPartitions(topic, 2);
+
+    // Produce some records to the topic
+    final List<ProducerRecord<byte[], byte[]>> records = List.of(
+        new ProducerRecord<>(topic, 0, StringUtils.toUtf8("key1"), 
StringUtils.toUtf8("value1")),
+        new ProducerRecord<>(topic, 1, StringUtils.toUtf8("key2"), 
StringUtils.toUtf8("value2"))
+    );
+    kafkaServer.produceRecordsToTopic(records);
+
+    // Submit and start a supervisor
+    final KafkaSupervisorSpec kafkaSupervisorSpec = new KafkaSupervisorSpec(
+        null,
+        null,
+        DataSchema.builder()
+                  .withDataSource(TestDataSource.WIKI)
+                  .withTimestamp(new TimestampSpec("time", null, null))
+                  .withDimensions(DimensionsSpec.EMPTY)
+                  .build(),
+        null,
+        new KafkaSupervisorIOConfig(
+            topic,
+            null,
+            new CsvInputFormat(List.of("col1"), null, null, false, 0, false),
+            null, null, null,
+            kafkaServer.consumerProperties(),
+            null, null, null, null, null,
+            true,
+            null, null, null, null, null, null, null,
+            false
+        ),
+        Map.of(),
+        false,
+        null, null, null, null, null, null, null, null, null
+    );
+
+    final Map<String, String> startSupervisorResult = getResult(
+        cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec)
+    );
+
+    CloseableIterator<SupervisorStatus> supervisorStatuses = getResult(
+        cluster.leaderOverlord().supervisorStatuses()
+    );

Review Comment:
   ## Unread local variable
   
   Variable 'CloseableIterator<SupervisorStatus> supervisorStatuses' is never 
read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9245)



##########
quidem-ut/src/test/java/org/apache/druid/indexing/IndexTaskSimTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.indexing;
+
+import org.apache.druid.client.indexing.TaskStatusResponse;
+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.InlineInputSource;
+import org.apache.druid.data.input.impl.TimestampSpec;
+import org.apache.druid.indexer.TaskState;
+import org.apache.druid.indexing.common.task.IndexTask;
+import org.apache.druid.indexing.common.task.Task;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.guava.Comparators;
+import org.apache.druid.query.http.ClientSqlQuery;
+import org.apache.druid.segment.TestDataSource;
+import org.apache.druid.segment.indexing.DataSchema;
+import org.apache.druid.testing.simulate.EmbeddedBroker;
+import org.apache.druid.testing.simulate.EmbeddedCoordinator;
+import org.apache.druid.testing.simulate.EmbeddedDruidCluster;
+import org.apache.druid.testing.simulate.EmbeddedHistorical;
+import org.apache.druid.testing.simulate.EmbeddedIndexer;
+import org.apache.druid.testing.simulate.EmbeddedOverlord;
+import org.apache.druid.testing.simulate.junit5.DruidSimulationTestBase;
+import org.apache.druid.timeline.DataSegment;
+import org.joda.time.DateTime;
+import org.joda.time.Interval;
+import org.joda.time.Period;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * Simulation tests for batch {@link IndexTask} using inline datasources.
+ */
+public class IndexTaskSimTest extends DruidSimulationTestBase
+{
+  private final EmbeddedOverlord overlord = EmbeddedOverlord.create();
+
+  @Override
+  public EmbeddedDruidCluster createCluster()
+  {
+    return EmbeddedDruidCluster.create()
+                               .addServer(new EmbeddedCoordinator())
+                               
.addServer(EmbeddedIndexer.withProps(Map.of("druid.worker.capacity", "25")))
+                               .addServer(overlord)
+                               .addServer(new EmbeddedHistorical())
+                               .addServer(new EmbeddedBroker());
+  }
+
+  @Test
+  @Timeout(60)
+  public void test_run10Tasks_concurrently()
+  {
+    runTasksConcurrently(10);
+  }
+
+  @Test
+  @Timeout(60)
+  public void test_run50Tasks_oneByOne()
+  {
+    for (int i = 0; i < 25; ++i) {
+      runTasksConcurrently(1);
+    }
+  }
+
+  @Test
+  @Timeout(60)
+  public void test_run25Tasks_concurrently()
+  {
+    runTasksConcurrently(25);
+  }
+
+  @Test
+  @Timeout(60)
+  public void test_run100Tasks_concurrently()
+  {
+    runTasksConcurrently(100);
+  }
+
+  @Test
+  @Timeout(60)
+  public void test_runIndexTask_forInlineDatasource()
+  {
+    final String txnData10Days
+        = "time,item,value"
+          + "\n2025-06-01,shirt,105"
+          + "\n2025-06-02,trousers,210"
+          + "\n2025-06-03,jeans,150"
+          + "\n2025-06-04,t-shirt,53"
+          + "\n2025-06-05,microwave,1099"
+          + "\n2025-06-06,spoon,11"
+          + "\n2025-06-07,television,1100"
+          + "\n2025-06-08,plant pots,75"
+          + "\n2025-06-09,shirt,99"
+          + "\n2025-06-10,toys,101";
+
+    final Task task = createIndexTaskForInlineData(TestDataSource.WIKI, 
txnData10Days);
+    final String taskId = task.getId();
+
+    getResult(overlord.client().runTask(taskId, task));
+    verifyTaskHasSucceeded(taskId);
+
+    // Verify that the task created 10 DAY-granularity segments
+    final List<DataSegment> segments = new ArrayList<>(
+        
overlord.segmentsMetadataStorage().retrieveAllUsedSegments(TestDataSource.WIKI, 
null)
+    );
+    segments.sort(
+        (o1, o2) -> Comparators.intervalsByStartThenEnd()
+                               .compare(o1.getInterval(), o2.getInterval())
+    );
+
+    Assertions.assertEquals(10, segments.size());
+    DateTime start = DateTimes.of("2025-06-01");
+    for (DataSegment segment : segments) {
+      Assertions.assertEquals(TestDataSource.WIKI, segment.getDataSource());
+      Assertions.assertEquals(new Interval(start, Period.days(1)), 
segment.getInterval());
+      start = start.plusDays(1);
+    }
+
+    final Object result = getResult(
+        cluster.anyBroker().submitSqlQuery(
+            new ClientSqlQuery("SELECT * FROM sys.segments", null, true, true, 
true, Map.of(), List.of())
+        )
+    );

Review Comment:
   ## Unread local variable
   
   Variable 'Object result' is never read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9247)



##########
extensions-core/kafka-indexing-service/src/test/java/org/apache/druid/indexing/kafka/simulate/KafkaSupervisorSimTest.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.indexing.kafka.simulate;
+
+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.indexing.kafka.KafkaIndexTaskModule;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorIOConfig;
+import org.apache.druid.indexing.kafka.supervisor.KafkaSupervisorSpec;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorStatus;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.parsers.CloseableIterator;
+import org.apache.druid.segment.TestDataSource;
+import org.apache.druid.segment.indexing.DataSchema;
+import org.apache.druid.testing.simulate.EmbeddedCoordinator;
+import org.apache.druid.testing.simulate.EmbeddedDruidCluster;
+import org.apache.druid.testing.simulate.EmbeddedIndexer;
+import org.apache.druid.testing.simulate.EmbeddedOverlord;
+import org.apache.druid.testing.simulate.junit5.DruidSimulationTestBase;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Map;
+
+public class KafkaSupervisorSimTest extends DruidSimulationTestBase
+{
+  private EmbeddedKafkaServer kafkaServer;
+  private EmbeddedDruidCluster cluster;
+
+  @Override
+  public EmbeddedDruidCluster createCluster()
+  {
+    cluster = 
EmbeddedDruidCluster.withExtensions(List.of(KafkaIndexTaskModule.class))
+                                  .addServer(new EmbeddedCoordinator())
+                                  .addServer(EmbeddedIndexer.create())
+                                  .addServer(EmbeddedOverlord.create());
+
+    kafkaServer = new EmbeddedKafkaServer(cluster.getZookeeper(), 
cluster.getTestFolder(), Map.of());
+    cluster.addResource(kafkaServer);
+
+    return cluster;
+  }
+
+  @Test
+  public void test_runKafkaTask() throws Exception
+  {
+    // Set up a topic
+    final String topic = TestDataSource.WIKI;
+    kafkaServer.createTopicWithPartitions(topic, 2);
+
+    // Produce some records to the topic
+    final List<ProducerRecord<byte[], byte[]>> records = List.of(
+        new ProducerRecord<>(topic, 0, StringUtils.toUtf8("key1"), 
StringUtils.toUtf8("value1")),
+        new ProducerRecord<>(topic, 1, StringUtils.toUtf8("key2"), 
StringUtils.toUtf8("value2"))
+    );
+    kafkaServer.produceRecordsToTopic(records);
+
+    // Submit and start a supervisor
+    final KafkaSupervisorSpec kafkaSupervisorSpec = new KafkaSupervisorSpec(
+        null,
+        null,
+        DataSchema.builder()
+                  .withDataSource(TestDataSource.WIKI)
+                  .withTimestamp(new TimestampSpec("time", null, null))
+                  .withDimensions(DimensionsSpec.EMPTY)
+                  .build(),
+        null,
+        new KafkaSupervisorIOConfig(
+            topic,
+            null,
+            new CsvInputFormat(List.of("col1"), null, null, false, 0, false),
+            null, null, null,
+            kafkaServer.consumerProperties(),
+            null, null, null, null, null,
+            true,
+            null, null, null, null, null, null, null,
+            false
+        ),
+        Map.of(),
+        false,
+        null, null, null, null, null, null, null, null, null
+    );
+
+    final Map<String, String> startSupervisorResult = getResult(
+        cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec)
+    );
+
+    CloseableIterator<SupervisorStatus> supervisorStatuses = getResult(
+        cluster.leaderOverlord().supervisorStatuses()
+    );
+
+    // Get the task ID
+    // Let that task finish
+    // Verify that there are some segments
+
+    // Suspend supervisor
+    final Map<String, String> suspendSupervisorResult = getResult(
+        
cluster.leaderOverlord().postSupervisor(kafkaSupervisorSpec.createSuspendedSpec())
+    );

Review Comment:
   ## Unread local variable
   
   Variable 'Map<String,String> suspendSupervisorResult' is never read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9246)



-- 
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]

Reply via email to