-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to retry a task on timeout (#53)
* Ability to retry a task on timeout * Fix issues with control message on retry * Integration test to test basic restart scenarios
- Loading branch information
Ankit Nanglia
authored
Jul 3, 2019
1 parent
72e5c2d
commit 288775a
Showing
29 changed files
with
451 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/test/java/com/cognitree/kronos/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.cognitree.kronos; | ||
|
||
import com.cognitree.kronos.scheduler.JobService; | ||
import com.cognitree.kronos.scheduler.ServiceTest; | ||
import com.cognitree.kronos.scheduler.model.Job; | ||
import com.cognitree.kronos.scheduler.model.WorkflowTrigger; | ||
import com.cognitree.kronos.scheduler.store.StoreService; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static com.cognitree.kronos.TestUtil.scheduleWorkflow; | ||
import static com.cognitree.kronos.TestUtil.waitForJobsToTriggerAndComplete; | ||
|
||
public class ApplicationTest extends ServiceTest { | ||
|
||
@Test | ||
public void testSchedulerDown() throws Exception { | ||
final StoreService storeService = (StoreService) ServiceProvider.getService(StoreService.class.getSimpleName()); | ||
if (!storeService.isPersistent()) { | ||
return; | ||
} | ||
final WorkflowTrigger workflowTriggerOne = scheduleWorkflow(WORKFLOW_TEMPLATE_YAML); | ||
final WorkflowTrigger workflowTriggerTwo = scheduleWorkflow(WORKFLOW_TEMPLATE_YAML); | ||
SCHEDULER_APP.stop(); | ||
Thread.sleep(1000); | ||
SCHEDULER_APP.start(); | ||
|
||
waitForJobsToTriggerAndComplete(workflowTriggerOne); | ||
waitForJobsToTriggerAndComplete(workflowTriggerTwo); | ||
|
||
JobService jobService = JobService.getService(); | ||
final List<Job> workflowOneJobs = jobService.get(workflowTriggerOne.getNamespace()); | ||
Assert.assertEquals(1, workflowOneJobs.size()); | ||
Assert.assertNotNull(jobService.get(workflowOneJobs.get(0))); | ||
Assert.assertFalse(workflowOneJobs.stream().anyMatch(t -> t.getStatus() != Job.Status.SUCCESSFUL)); | ||
|
||
final List<Job> workflowTwoJobs = jobService.get(workflowTriggerTwo.getNamespace()); | ||
Assert.assertEquals(1, workflowTwoJobs.size()); | ||
Assert.assertNotNull(jobService.get(workflowTwoJobs.get(0))); | ||
} | ||
|
||
|
||
@Test | ||
public void testExecutorDown() throws Exception { | ||
final StoreService storeService = (StoreService) ServiceProvider.getService(StoreService.class.getSimpleName()); | ||
if (!storeService.isPersistent()) { | ||
return; | ||
} | ||
EXECUTOR_APP.stop(); | ||
final WorkflowTrigger workflowTriggerOne = scheduleWorkflow(WORKFLOW_TEMPLATE_YAML); | ||
final WorkflowTrigger workflowTriggerTwo = scheduleWorkflow(WORKFLOW_TEMPLATE_YAML); | ||
Thread.sleep(1000); | ||
EXECUTOR_APP.start(); | ||
|
||
waitForJobsToTriggerAndComplete(workflowTriggerOne); | ||
waitForJobsToTriggerAndComplete(workflowTriggerTwo); | ||
|
||
JobService jobService = JobService.getService(); | ||
final List<Job> workflowOneJobs = jobService.get(workflowTriggerOne.getNamespace()); | ||
Assert.assertEquals(1, workflowOneJobs.size()); | ||
Assert.assertNotNull(jobService.get(workflowOneJobs.get(0))); | ||
|
||
final List<Job> workflowTwoJobs = jobService.get(workflowTriggerTwo.getNamespace()); | ||
Assert.assertEquals(1, workflowTwoJobs.size()); | ||
Assert.assertNotNull(jobService.get(workflowTwoJobs.get(0))); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/src/test/java/com/cognitree/kronos/executor/handlers/MockRetryTaskHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 com.cognitree.kronos.executor.handlers; | ||
|
||
import com.cognitree.kronos.executor.model.TaskResult; | ||
import com.cognitree.kronos.model.Task; | ||
import com.cognitree.kronos.model.TaskId; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class MockRetryTaskHandler implements TaskHandler { | ||
private static final Logger logger = LoggerFactory.getLogger(MockRetryTaskHandler.class); | ||
|
||
private static final List<TaskId> tasks = Collections.synchronizedList(new ArrayList<>()); | ||
private boolean abort = false; | ||
private Task task; | ||
|
||
public static boolean isHandled(TaskId taskId) { | ||
return tasks.contains(taskId); | ||
} | ||
|
||
@Override | ||
public void init(Task task, ObjectNode config) { | ||
this.task = task; | ||
} | ||
|
||
@Override | ||
public TaskResult execute() { | ||
logger.info("Received request to execute task {}", task); | ||
tasks.add(task); | ||
while (!abort && task.getRetryCount() < 2) { // the task should pass on the third retry | ||
try { | ||
Thread.sleep(50); | ||
} catch (InterruptedException e) { | ||
logger.error("Thread has been interrupted"); | ||
} | ||
} | ||
return TaskResult.SUCCESS; | ||
} | ||
|
||
@Override | ||
public void abort() { | ||
abort = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.