alirezazamani commented on a change in pull request #1169: URL: https://github.com/apache/helix/pull/1169#discussion_r461167311
########## File path: helix-core/src/test/java/org/apache/helix/task/TestDynamicTaskLoading.java ########## @@ -0,0 +1,123 @@ +package org.apache.helix.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 java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.helix.HelixManager; +import org.apache.helix.HelixManagerFactory; +import org.apache.helix.InstanceType; +import org.apache.helix.TestHelper; +import org.apache.helix.common.ZkTestBase; +import org.apache.helix.examples.MasterSlaveStateModelFactory; +import org.apache.helix.integration.manager.ClusterControllerManager; +import org.apache.helix.integration.manager.MockParticipantManager; +import org.apache.helix.integration.task.MockTask; +import org.apache.helix.participant.StateMachineEngine; +import org.apache.helix.participant.statemachine.StateModel; +import org.apache.helix.participant.statemachine.StateModelFactory; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.zookeeper.CreateMode; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class TestDynamicTaskLoading extends ZkTestBase { + HelixManager _manager; + MockParticipantManager _participant; + ClusterControllerManager _controller; + String _clusterName; + + @BeforeClass + public void beforeClass() throws Exception { + super.beforeClass(); + _clusterName = CLUSTER_PREFIX + "_" + getShortClassName(); + _gSetupTool.addCluster(_clusterName, true); + + _manager = HelixManagerFactory.getZKHelixManager(_clusterName, "Admin", + InstanceType.ADMINISTRATOR, ZK_ADDR); + _manager.connect(); + + String instanceName = "localhost_12913"; + _gSetupTool.addInstanceToCluster(_clusterName, instanceName); + _participant = new MockParticipantManager(ZK_ADDR, _clusterName, instanceName); + StateModelFactory<StateModel> stateModelFactory = new MasterSlaveStateModelFactory(instanceName, 0); + StateMachineEngine stateMach = _participant.getStateMachineEngine(); + stateMach.registerStateModelFactory("MasterSlave", stateModelFactory); + Map<String, TaskFactory> taskFactoryReg = new HashMap<>(); + _participant.getStateMachineEngine().registerStateModelFactory(TaskConstants.STATE_MODEL_NAME, + new TaskStateModelFactory(_participant, taskFactoryReg)); + _participant.syncStart(); + + _controller = new ClusterControllerManager(ZK_ADDR, _clusterName, null); + _controller.syncStart(); + + // Add task definition information as a ZNRecord. + ZNRecord configZnRecord = new ZNRecord(_participant.getInstanceName()); + configZnRecord.setSimpleField("JAR_FILE", "src/test/resources/Reindex.jar"); + configZnRecord.setSimpleField("VERSION", "1.0.0"); + List<String> taskClasses = new ArrayList<String>(); + taskClasses.add("com.mycompany.mocktask.MockTask"); + configZnRecord.setListField("TASK_CLASSES", taskClasses); + configZnRecord.setSimpleField("TASKFACTORY", "com.mycompany.mocktask.MockTaskFactory"); + String path = String.format("/%s/%s", _clusterName, "TASK_DEFINITION"); + _participant.getZkClient().create(path, configZnRecord, CreateMode.PERSISTENT); + } + + @Test + public void testDynamicTaskLoading() throws Exception { + String workflowName = TestHelper.getTestMethodName(); + TaskDriver driver = new TaskDriver(_manager); + JobConfig.Builder job = new JobConfig.Builder(); + job.setJobCommandConfigMap(Collections.singletonMap(MockTask.JOB_DELAY, "100")); + Workflow.Builder workflow = new Workflow.Builder(workflowName); + job.setWorkflow(workflowName); + TaskConfig taskConfig = + new TaskConfig(MockTask.TASK_COMMAND, new HashMap<String, String>(), null, null); + job.addTaskConfigMap(Collections.singletonMap(taskConfig.getId(), taskConfig)); + job.setJobId(TaskUtil.getNamespacedJobName(workflowName, "JOB")); + workflow.addJob("JOB", job); + driver.start(workflow.build()); + + Thread.sleep(2000); Review comment: Thanks for the PR. Good job ;-) Is there any way to make sure the functionality of this PR? Do we need to have some sort of assert/statement to make sure it works? ---------------------------------------------------------------- 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: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
