-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix task mighe be dispatched even if it has been killed
- Loading branch information
1 parent
3fda980
commit 22a2b0e
Showing
3 changed files
with
110 additions
and
9 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
96 changes: 96 additions & 0 deletions
96
...pache/dolphinscheduler/server/master/runner/GlobalTaskDispatchWaitingQueueLooperTest.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,96 @@ | ||
/* | ||
* 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.dolphinscheduler.server.master.runner; | ||
|
||
import static org.mockito.Mockito.doNothing; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; | ||
import org.apache.dolphinscheduler.dao.entity.TaskInstance; | ||
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext; | ||
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; | ||
import org.apache.dolphinscheduler.server.master.runner.dispatcher.TaskDispatchFactory; | ||
import org.apache.dolphinscheduler.server.master.runner.dispatcher.TaskDispatcher; | ||
import org.apache.dolphinscheduler.server.master.runner.operator.TaskExecuteRunnableOperatorManager; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.mockito.junit.jupiter.MockitoSettings; | ||
import org.mockito.quality.Strictness; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
class GlobalTaskDispatchWaitingQueueLooperTest { | ||
|
||
@InjectMocks | ||
private GlobalTaskDispatchWaitingQueueLooper globalTaskDispatchWaitingQueueLooper; | ||
|
||
@Mock | ||
private GlobalTaskDispatchWaitingQueue globalTaskDispatchWaitingQueue; | ||
|
||
@Mock | ||
private TaskDispatchFactory taskDispatchFactory; | ||
|
||
@Test | ||
void testTaskExecutionRunnableStatusIsNotSubmitted() throws Exception { | ||
ProcessInstance processInstance = new ProcessInstance(); | ||
TaskInstance taskInstance = new TaskInstance(); | ||
taskInstance.setState(TaskExecutionStatus.KILL); | ||
TaskExecutionContext taskExecutionContext = new TaskExecutionContext(); | ||
TaskExecuteRunnableOperatorManager taskExecuteRunnableOperatorManager = | ||
new TaskExecuteRunnableOperatorManager(); | ||
DefaultTaskExecuteRunnable defaultTaskExecuteRunnable = new DefaultTaskExecuteRunnable(processInstance, | ||
taskInstance, taskExecutionContext, taskExecuteRunnableOperatorManager); | ||
|
||
when(globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable()).thenReturn(defaultTaskExecuteRunnable); | ||
globalTaskDispatchWaitingQueueLooper.start(); | ||
Thread.sleep(1000); | ||
verify(taskDispatchFactory, Mockito.never()).getTaskDispatcher(taskInstance); | ||
globalTaskDispatchWaitingQueueLooper.close(); | ||
} | ||
|
||
@Test | ||
void testTaskExecutionRunnableStatusIsSubmitted() throws Exception { | ||
ProcessInstance processInstance = new ProcessInstance(); | ||
TaskInstance taskInstance = new TaskInstance(); | ||
taskInstance.setState(TaskExecutionStatus.SUBMITTED_SUCCESS); | ||
TaskExecutionContext taskExecutionContext = new TaskExecutionContext(); | ||
TaskExecuteRunnableOperatorManager taskExecuteRunnableOperatorManager = | ||
new TaskExecuteRunnableOperatorManager(); | ||
DefaultTaskExecuteRunnable defaultTaskExecuteRunnable = new DefaultTaskExecuteRunnable(processInstance, | ||
taskInstance, taskExecutionContext, taskExecuteRunnableOperatorManager); | ||
|
||
TaskDispatcher taskDispatcher = mock(TaskDispatcher.class); | ||
when(taskDispatchFactory.getTaskDispatcher(taskInstance)).thenReturn(taskDispatcher); | ||
doNothing().when(taskDispatcher).dispatchTask(Mockito.any()); | ||
|
||
when(globalTaskDispatchWaitingQueue.takeTaskExecuteRunnable()).thenReturn(defaultTaskExecuteRunnable); | ||
globalTaskDispatchWaitingQueueLooper.start(); | ||
Thread.sleep(1000); | ||
verify(taskDispatchFactory, Mockito.atLeastOnce()).getTaskDispatcher(Mockito.any(TaskInstance.class)); | ||
verify(taskDispatcher, Mockito.atLeastOnce()).dispatchTask(Mockito.any(TaskExecuteRunnable.class)); | ||
globalTaskDispatchWaitingQueueLooper.close(); | ||
|
||
} | ||
} |