kfaraz commented on code in PR #18235:
URL: https://github.com/apache/druid/pull/18235#discussion_r2206188388
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedMSQRealtimeQueryTest.java:
##########
@@ -138,54 +133,46 @@ public EmbeddedDruidCluster createCluster()
.addCommonProperty("druid.monitoring.emissionPeriod", "PT0.1s")
.addCommonProperty("druid.msq.dart.enabled", "true")
.useLatchableEmitter()
- .addResource(kafka)
.addServer(coordinator)
.addServer(overlord)
- .addServer(indexer)
- .addServer(broker)
- .addServer(historical)
.addServer(router);
}
+ @BeforeAll
+ @Override
+ protected void setup() throws Exception
+ {
+ super.setup();
+
+ // Initialize lookups
+ cluster.callApi().onLeaderCoordinator(
+ c -> c.updateAllLookups(Map.of())
+ );
+
+ final String lookupPayload = StringUtils.format(
+ BULK_UPDATE_LOOKUP_PAYLOAD,
+ LOOKUP_TABLE
+ );
+ cluster.callApi().onLeaderCoordinator(
+ c ->
c.updateAllLookups(EmbeddedClusterApis.deserializeJsonToMap(lookupPayload))
+ );
+
+ // Initialize the broker/data-servers later so that lookups are loaded on
startup.
+ cluster.addServer(broker)
+ .addServer(indexer)
+ .addServer(historical);
+ broker.start();
+ indexer.start();
+ historical.start();
+ }
+
@BeforeEach
void setUpEach()
{
msqApis = new EmbeddedMSQApis(cluster, overlord);
- topic = dataSource = EmbeddedClusterApis.createTestDatasourceName();
-
- // Create Kafka topic.
- kafka.createTopicWithPartitions(topic, 2);
-
- // Submit a supervisor.
- final KafkaSupervisorSpec kafkaSupervisorSpec = createKafkaSupervisor();
- final Map<String, String> startSupervisorResult =
- cluster.callApi().onLeaderOverlord(o ->
o.postSupervisor(kafkaSupervisorSpec));
- Assertions.assertEquals(Map.of("id", dataSource), startSupervisorResult);
-
- // Send data to Kafka.
- final QueryableIndexCursorFactory wikiCursorFactory =
- new QueryableIndexCursorFactory(TestIndex.getMMappedWikipediaIndex());
- final RowSignature wikiSignature = wikiCursorFactory.getRowSignature();
- kafka.produceRecordsToTopic(
- FrameTestUtil.readRowsFromCursorFactory(wikiCursorFactory)
- .map(row -> {
- final Map<String, Object> rowMap = new
LinkedHashMap<>();
- for (int i = 0; i < row.size(); i++) {
- rowMap.put(wikiSignature.getColumnName(i),
row.get(i));
- }
- try {
- return new ProducerRecord<>(
- topic,
- ByteArrays.EMPTY_ARRAY,
- TestHelper.JSON_MAPPER.writeValueAsBytes(rowMap)
- );
- }
- catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- })
- .toList()
- );
+ dataSource = EmbeddedClusterApis.createTestDatasourceName();
Review Comment:
I am not sure if this step is really needed, since the `dataSource` field is
anyway randomly assigned before each test.
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedMSQApis.java:
##########
@@ -110,6 +110,19 @@ public MSQTaskReportPayload runTaskSql(String sql,
Object... args)
);
}
+ return taskStatus;
+ }
+
+ /**
+ * Submits the given SQL query to any of the brokers (using {@code
BrokerClient})
+ * of the cluster. Waits for it to complete, then returns the query report.
+ *
+ * @return The result of the SQL as a single CSV string.
+ */
+ public MSQTaskReportPayload runTaskSql(String sql, Object... args)
Review Comment:
Nit: to distinguish this method with the other one `submitTaskSql` better.
```suggestion
public MSQTaskReportPayload runTaskSqlAndGetReport(String sql, Object...
args)
```
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/EmbeddedMSQRealtimeQueryTest.java:
##########
@@ -138,54 +133,46 @@ public EmbeddedDruidCluster createCluster()
.addCommonProperty("druid.monitoring.emissionPeriod", "PT0.1s")
.addCommonProperty("druid.msq.dart.enabled", "true")
.useLatchableEmitter()
- .addResource(kafka)
.addServer(coordinator)
.addServer(overlord)
- .addServer(indexer)
- .addServer(broker)
- .addServer(historical)
.addServer(router);
}
+ @BeforeAll
+ @Override
Review Comment:
You need not do both. Either `@Override` the `setup` method or use the
`@BeforeAll` annotation on a fresh method, whichever you prefer.
##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/msq/BaseRealtimeQueryTest.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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.msq;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import it.unimi.dsi.fastutil.bytes.ByteArrays;
+import org.apache.druid.data.input.impl.DimensionsSpec;
+import org.apache.druid.data.input.impl.JsonInputFormat;
+import org.apache.druid.data.input.impl.TimestampSpec;
+import org.apache.druid.frame.testutil.FrameTestUtil;
+import org.apache.druid.indexer.TaskStatusPlus;
+import org.apache.druid.indexer.granularity.UniformGranularitySpec;
+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.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.parsers.CloseableIterator;
+import org.apache.druid.segment.QueryableIndex;
+import org.apache.druid.segment.QueryableIndexCursorFactory;
+import org.apache.druid.segment.TestHelper;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.segment.indexing.DataSchema;
+import org.apache.druid.testing.embedded.EmbeddedClusterApis;
+import org.apache.druid.testing.embedded.EmbeddedDruidCluster;
+import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.joda.time.Period;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Base test for Kafka related embedded test.
+ */
+public class BaseRealtimeQueryTest extends EmbeddedClusterTestBase
+{
+ private static final Period TASK_DURATION = Period.hours(1);
+ private static final int TASK_COUNT = 2;
+
+ protected KafkaResource kafka;
+ protected String topic;
+
+ @Override
+ protected EmbeddedDruidCluster createCluster()
+ {
+ kafka = new KafkaResource();
+ return EmbeddedDruidCluster
+ .withEmbeddedDerbyAndZookeeper()
+ .addExtension(KafkaIndexTaskModule.class)
+ .addResource(kafka);
+ }
+
+ @BeforeEach
+ void setUp()
Review Comment:
```suggestion
void setupCreateKafkaTopic()
```
--
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]