narendly commented on a change in pull request #410: Fix the execution delay for the jobs (409) URL: https://github.com/apache/helix/pull/410#discussion_r315043805
########## File path: helix-core/src/test/java/org/apache/helix/integration/task/TestExecutionDelay.java ########## @@ -0,0 +1,124 @@ +package org.apache.helix.integration.task; + +/* + * 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. + */ + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import java.util.List; +import org.apache.helix.HelixAdmin; +import org.apache.helix.HelixDataAccessor; +import org.apache.helix.HelixException; +import org.apache.helix.PropertyKey; +import org.apache.helix.PropertyPathBuilder; +import org.apache.helix.TestHelper; +import org.apache.helix.task.JobConfig; +import org.apache.helix.task.JobContext; +import org.apache.helix.task.JobQueue; +import org.apache.helix.task.TaskConstants; +import org.apache.helix.task.TaskState; +import org.apache.helix.task.TaskUtil; +import org.apache.helix.task.Workflow; +import org.apache.helix.task.WorkflowContext; +import org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Test To check if the Execution Delay is respected. + */ +public class TestExecutionDelay extends TaskTestBase { + + @BeforeClass + public void beforeClass() throws Exception { + super.beforeClass(); + } + + @Test + public void testExecutionDelay() throws Exception { + // Execution Delay is set to be a large number. Hence, the workflow should not be completed + // soon. + final long executionDelay = 100000000000L; + String workflowName = TestHelper.getTestMethodName(); + Workflow.Builder builder = new Workflow.Builder(workflowName); + + // Workflow DAG Schematic: + // JOB0 + // /\ + // / \ + // / \ + // JOB1 JOB2 + + JobConfig.Builder jobBuilder = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG) + .setMaxAttemptsPerTask(1).setWorkflow(workflowName) + .setJobCommandConfigMap(ImmutableMap.of(MockTask.JOB_DELAY, "1000")); + + JobConfig.Builder jobBuilder2 = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG) + .setMaxAttemptsPerTask(1).setWorkflow(workflowName) + .setJobCommandConfigMap(ImmutableMap.of(MockTask.JOB_DELAY, "1000")); + + JobConfig.Builder jobBuilder3 = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG) + .setMaxAttemptsPerTask(1).setWorkflow(workflowName) + .setJobCommandConfigMap(ImmutableMap.of(MockTask.JOB_DELAY, "1000")); + + builder.addParentChildDependency("JOB0", "JOB1"); + builder.addParentChildDependency("JOB0", "JOB2"); + builder.addJob("JOB0", jobBuilder.setExecutionDelay(executionDelay)); + builder.addJob("JOB1", jobBuilder2); + builder.addJob("JOB2", jobBuilder3); + + // Since the execution delay is set as a long time, it is expected to reach time out. + // If the workflow completed without any exception, it means that ExecutionDelay has not been + // respected. + _driver.start(builder.build()); + + // Verify workflow Context is created. + // Wait until Workflow Context is created. + boolean resultWorkflow = TestHelper.verify(() -> { + WorkflowContext wCtx1 = _driver.getWorkflowContext(workflowName); + return (wCtx1 != null); + }, 60 * 1000); + Assert.assertTrue(resultWorkflow); + + // Verify StartTime is set for the Job. + // Wait until startTime is set. + boolean resultStartTime = TestHelper.verify(() -> { + WorkflowContext wCtx1 = _driver.getWorkflowContext(workflowName); + long startTime = -1; + try { + startTime = wCtx1.getJobStartTime(TaskUtil.getNamespacedJobName(workflowName, "JOB0")); + } catch (Exception e) { + // pass + } + return (startTime != -1); Review comment: parentheses not needed. ---------------------------------------------------------------- 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: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org