You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2019/09/25 23:12:34 UTC

[GitHub] [samza] PawasChhokra commented on a change in pull request #1155: SAMZA-2322: Integrate startpoints with ZK Standalone integration tests.

PawasChhokra commented on a change in pull request #1155: SAMZA-2322: Integrate startpoints with ZK Standalone integration tests.
URL: https://github.com/apache/samza/pull/1155#discussion_r328375870
 
 

 ##########
 File path: samza-test/src/test/java/org/apache/samza/test/startpoint/StartpointTestHarness.java
 ##########
 @@ -0,0 +1,383 @@
+/*
+ * 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.samza.test.startpoint;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.TreeMap;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import org.apache.kafka.clients.admin.NewTopic;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.samza.Partition;
+import org.apache.samza.SamzaException;
+import org.apache.samza.config.ApplicationConfig;
+import org.apache.samza.config.Config;
+import org.apache.samza.config.JobConfig;
+import org.apache.samza.config.JobCoordinatorConfig;
+import org.apache.samza.config.MapConfig;
+import org.apache.samza.config.TaskConfig;
+import org.apache.samza.config.ZkConfig;
+import org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore;
+import org.apache.samza.runtime.ApplicationRunner;
+import org.apache.samza.runtime.ApplicationRunners;
+import org.apache.samza.startpoint.Startpoint;
+import org.apache.samza.startpoint.StartpointManager;
+import org.apache.samza.startpoint.StartpointOldest;
+import org.apache.samza.startpoint.StartpointSpecific;
+import org.apache.samza.startpoint.StartpointTimestamp;
+import org.apache.samza.startpoint.StartpointUpcoming;
+import org.apache.samza.system.IncomingMessageEnvelope;
+import org.apache.samza.system.SystemAdmin;
+import org.apache.samza.system.SystemAdmins;
+import org.apache.samza.system.SystemStream;
+import org.apache.samza.system.SystemStreamPartition;
+import org.apache.samza.task.TaskCallback;
+import org.apache.samza.test.StandaloneTestUtils;
+import org.apache.samza.test.harness.IntegrationTestHarness;
+import org.apache.samza.test.processor.SharedContextFactories;
+import org.apache.samza.test.processor.TestTaskApplication;
+import org.apache.samza.test.util.TestKafkaEvent;
+import org.apache.samza.util.CoordinatorStreamUtil;
+import org.apache.samza.util.NoOpMetricsRegistry;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+
+public class StartpointTestHarness extends IntegrationTestHarness {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(StartpointTestHarness.class);
+
+  private static final int NUM_KAFKA_EVENTS = 300;
+  private static final int ZK_TEST_PARTITION_COUNT = 5;
+  private static final String TEST_SYSTEM = "TestSystemName";
+  private static final String TEST_SSP_GROUPER_FACTORY = "org.apache.samza.container.grouper.stream.GroupByPartitionFactory";
+  private static final String TEST_TASK_GROUPER_FACTORY = "org.apache.samza.container.grouper.task.GroupByContainerIdsFactory";
+  private static final String TEST_JOB_COORDINATOR_FACTORY = "org.apache.samza.zk.ZkJobCoordinatorFactory";
+  private static final String TEST_SYSTEM_FACTORY = "org.apache.samza.system.kafka.KafkaSystemFactory";
+  private static final String TASK_SHUTDOWN_MS = "10000";
+  private static final String JOB_DEBOUNCE_TIME_MS = "10000";
+  private static final String BARRIER_TIMEOUT_MS = "10000";
+  private static final String[] PROCESSOR_IDS = new String[] {"0000000000", "0000000001", "0000000002", "0000000003"};
+
+  private String inputKafkaTopic1;
+  private String inputKafkaTopic2;
+  private String inputKafkaTopic3;
+  private String inputKafkaTopic4;
+  private String outputKafkaTopic;
+  private ApplicationConfig applicationConfig1;
+  private ApplicationConfig applicationConfig2;
+  private ApplicationConfig applicationConfig3;
+  private ApplicationConfig applicationConfig4;
+  private String testStreamAppName;
+  private String testStreamAppId;
+
+  @Rule
+  public Timeout testTimeOutInMillis = new Timeout(150000, TimeUnit.MILLISECONDS);
+
+  @Rule
+  public final ExpectedException expectedException = ExpectedException.none();
+
+  @Override
+  public void setUp() {
+    super.setUp();
+    String uniqueTestId = UUID.randomUUID().toString();
+    testStreamAppName = String.format("test-app-name-%s", uniqueTestId);
+    testStreamAppId = String.format("test-app-id-%s", uniqueTestId);
+    inputKafkaTopic1 = String.format("test-input-topic1-%s", uniqueTestId);
+    inputKafkaTopic2 = String.format("test-input-topic2-%s", uniqueTestId);
+    inputKafkaTopic3 = String.format("test-input-topic3-%s", uniqueTestId);
+    inputKafkaTopic4 = String.format("test-input-topic4-%s", uniqueTestId);
+    outputKafkaTopic = String.format("test-output-topic-%s", uniqueTestId);
+
+    // Set up stream application config map with the given testStreamAppName, testStreamAppId and test kafka system
+    // TODO: processorId should typically come up from a processorID generator as processor.id will be deprecated in 0.14.0+
+    Map<String, String> configMap =
+        buildStreamApplicationConfigMap(testStreamAppName, testStreamAppId);
+    configMap.put(JobConfig.PROCESSOR_ID, PROCESSOR_IDS[0]);
+    applicationConfig1 = new ApplicationConfig(new MapConfig(configMap));
+    configMap.put(JobConfig.PROCESSOR_ID, PROCESSOR_IDS[1]);
+    applicationConfig2 = new ApplicationConfig(new MapConfig(configMap));
+    configMap.put(JobConfig.PROCESSOR_ID, PROCESSOR_IDS[2]);
+    applicationConfig3 = new ApplicationConfig(new MapConfig(configMap));
+    configMap.put(JobConfig.PROCESSOR_ID, PROCESSOR_IDS[3]);
+    applicationConfig4 = new ApplicationConfig(new MapConfig(configMap));
+
+    ImmutableMap<String, Integer> topicToPartitionCount = ImmutableMap.<String, Integer>builder()
+        .put(inputKafkaTopic1, ZK_TEST_PARTITION_COUNT)
+        .put(inputKafkaTopic2, ZK_TEST_PARTITION_COUNT)
+        .put(inputKafkaTopic3, ZK_TEST_PARTITION_COUNT)
+        .put(inputKafkaTopic4, ZK_TEST_PARTITION_COUNT)
+        .put(outputKafkaTopic, ZK_TEST_PARTITION_COUNT)
+        .build();
+
+    List<NewTopic> newTopics =
+        topicToPartitionCount.keySet()
+            .stream()
+            .map(topic -> new NewTopic(topic, topicToPartitionCount.get(topic), (short) 1))
+            .collect(Collectors.toList());
+
+    assertTrue("Encountered errors during test setup. Failed to create topics.", createTopics(newTopics));
+  }
+
+  @Override
+  public void tearDown() {
+    deleteTopics(
+        ImmutableList.of(inputKafkaTopic1, inputKafkaTopic2, inputKafkaTopic3, inputKafkaTopic4, outputKafkaTopic));
+    SharedContextFactories.clearAll();
+    super.tearDown();
+  }
+
+  @Test
+  public void testStartpoints() throws InterruptedException {
 
 Review comment:
   Can you break this method down into multiple functions: like one for startpoint specific, one for startpoint timestamp, etc. The code in its current state is too lengthy and not legible.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services