jon-wei commented on a change in pull request #9576: Add Integration Test for 
functionality of kinesis ingestion
URL: https://github.com/apache/druid/pull/9576#discussion_r401339376
 
 

 ##########
 File path: 
integration-tests/src/test/java/org/apache/druid/tests/indexer/ITKinesisIndexingServiceTest.java
 ##########
 @@ -0,0 +1,443 @@
+/*
+ * 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.tests.indexer;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Inject;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorStateManager;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.testing.guice.DruidTestModuleFactory;
+import org.apache.druid.testing.utils.DruidClusterAdminClient;
+import org.apache.druid.testing.utils.ITRetryUtil;
+import org.apache.druid.testing.utils.KinesisAdminClient;
+import org.apache.druid.testing.utils.KinesisEventWriter;
+import org.apache.druid.testing.utils.WikipediaStreamEventStreamGenerator;
+import org.apache.druid.tests.TestNGGroup;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Guice;
+import org.testng.annotations.Test;
+
+import java.io.Closeable;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.Function;
+
+@Test(groups = TestNGGroup.KINESIS_INDEX)
+@Guice(moduleFactory = DruidTestModuleFactory.class)
+public class ITKinesisIndexingServiceTest extends AbstractITBatchIndexTest
+{
+  private static final Logger LOG = new Logger(AbstractKafkaIndexerTest.class);
+  private static final int KINESIS_SHARD_COUNT = 2;
+  private static final String STREAM_EXPIRE_TAG = "druid-ci-expire-after";
+  private static final long WAIT_TIME_MILLIS = 3 * 60 * 1000L;
+  private static final DateTime FIRST_EVENT_TIME = DateTimes.of(1994, 4, 29, 
1, 0);
+  private static final String INDEXER_FILE_LEGACY_PARSER = 
"/indexer/stream_supervisor_spec_legacy_parser.json";
+  private static final String INDEXER_FILE_INPUT_FORMAT = 
"/indexer/stream_supervisor_spec_input_format.json";
+  private static final String QUERIES_FILE = 
"/indexer/stream_index_queries.json";
+  // format for the querying interval
+  private static final DateTimeFormatter INTERVAL_FMT = 
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:'00Z'");
+  // format for the expected timestamp in a query response
+  private static final DateTimeFormatter TIMESTAMP_FMT = 
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'.000Z'");
+  private static final int EVENTS_PER_SECOND = 6;
+  private static final long CYCLE_PADDING_MS = 100;
+  private static final int TOTAL_NUMBER_OF_SECOND = 10;
+
+  @Inject
+  private DruidClusterAdminClient druidClusterAdminClient;
+
+  private String streamName;
+  private String fullDatasourceName;
+  private KinesisAdminClient kinesisAdminClient;
+  private KinesisEventWriter kinesisEventWriter;
+  private WikipediaStreamEventStreamGenerator wikipediaStreamEventGenerator;
+  private Function<String, String> kinesisIngestionPropsTransform;
+  private Function<String, String> kinesisQueryPropsTransform;
+  private String supervisorId;
+  private int secondsToGenerateRemaining;
+
+  @BeforeClass
+  public void beforeClass() throws Exception
+  {
+    kinesisAdminClient = new KinesisAdminClient(config.getStreamEndpoint());
+    kinesisEventWriter = new KinesisEventWriter(config.getStreamEndpoint(), 
false);
+    wikipediaStreamEventGenerator = new 
WikipediaStreamEventStreamGenerator(EVENTS_PER_SECOND, CYCLE_PADDING_MS);
+  }
+
+  @AfterClass
+  public void tearDown()
+  {
+    wikipediaStreamEventGenerator.shutdown();
+    kinesisEventWriter.shutdown();
+  }
+
+  @BeforeMethod
+  public void before()
+  {
+    streamName = "kinesis_index_test_" + UUID.randomUUID();
+    String datasource = "kinesis_indexing_service_test_" + UUID.randomUUID();
+    Map<String, String> tags = ImmutableMap.of(STREAM_EXPIRE_TAG, 
Long.toString(DateTimes.nowUtc().plusMinutes(30).getMillis()));
+    kinesisAdminClient.createStream(streamName, KINESIS_SHARD_COUNT, tags);
+    ITRetryUtil.retryUntil(
+        () -> kinesisAdminClient.isStreamActive(streamName),
+        true,
+        10000,
+        30,
+        "Wait for stream active"
+    );
+    secondsToGenerateRemaining = TOTAL_NUMBER_OF_SECOND;
+    fullDatasourceName = datasource + config.getExtraDatasourceNameSuffix();
+    kinesisIngestionPropsTransform = spec -> {
+      try {
+        spec = StringUtils.replace(
+            spec,
+            "%%DATASOURCE%%",
+            fullDatasourceName
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%STREAM_TYPE%%",
+            "kinesis"
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TOPIC_KEY%%",
+            "stream"
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TOPIC_VALUE%%",
+            streamName
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%USE_EARLIEST_KEY%%",
+            "useEarliestSequenceNumber"
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%STREAM_PROPERTIES_KEY%%",
+            "endpoint"
+        );
+        return StringUtils.replace(
+            spec,
+            "%%STREAM_PROPERTIES_VALUE%%",
+            jsonMapper.writeValueAsString(config.getStreamEndpoint())
+        );
+      }
+      catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+    };
+    kinesisQueryPropsTransform = spec -> {
+      try {
+        spec = StringUtils.replace(
+            spec,
+            "%%DATASOURCE%%",
+            fullDatasourceName
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMEBOUNDARY_RESPONSE_TIMESTAMP%%",
+            TIMESTAMP_FMT.print(FIRST_EVENT_TIME)
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMEBOUNDARY_RESPONSE_MAXTIME%%",
+            
TIMESTAMP_FMT.print(FIRST_EVENT_TIME.plusSeconds(TOTAL_NUMBER_OF_SECOND - 1))
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMEBOUNDARY_RESPONSE_MINTIME%%",
+            TIMESTAMP_FMT.print(FIRST_EVENT_TIME)
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMESERIES_QUERY_START%%",
+            INTERVAL_FMT.print(FIRST_EVENT_TIME)
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMESERIES_QUERY_END%%",
+            
INTERVAL_FMT.print(FIRST_EVENT_TIME.plusSeconds(TOTAL_NUMBER_OF_SECOND - 
1).plusMinutes(2))
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMESERIES_RESPONSE_TIMESTAMP%%",
+            TIMESTAMP_FMT.print(FIRST_EVENT_TIME)
+        );
+        spec = StringUtils.replace(
+            spec,
+            "%%TIMESERIES_ADDED%%",
+            Long.toString(getSumOfEventSequence(EVENTS_PER_SECOND) * 
TOTAL_NUMBER_OF_SECOND)
+        );
+        return StringUtils.replace(
+            spec,
+            "%%TIMESERIES_NUMEVENTS%%",
+            Integer.toString(EVENTS_PER_SECOND * TOTAL_NUMBER_OF_SECOND)
+        );
+      }
+      catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+    };
+  }
+
+  @AfterMethod
+  public void teardown()
+  {
+    try {
+      kinesisEventWriter.flush();
+      indexer.shutdownSupervisor(supervisorId);
+      unloader(fullDatasourceName);
+      kinesisAdminClient.deleteStream(streamName);
+    }
+    catch (Exception e) {
+      // Best effort cleanup
+    }
+  }
+
+  @Test
+  public void testKineseIndexDataWithLegacyParserStableState() throws Exception
 
 Review comment:
   In the test names, `Kinese` -> `Kinesis` here and elsewhere

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to