Skip to content

Commit

Permalink
Add new tests to Dag (#1763)
Browse files Browse the repository at this point in the history
Test that killing a dag in certain state such as killing won't have
any effect.

With this change, the DAG class has 100% code coverage.

Also make ImmutableSet in the Status enum more strongly typed.
  • Loading branch information
HappyRay committed May 22, 2018
1 parent c25fb03 commit 5803674
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 5 additions & 3 deletions azkaban-exec-server/src/main/java/azkaban/dag/Status.java
Expand Up @@ -32,22 +32,24 @@ enum Status {
KILLED; // explicitly killed by a user

// The states that will not transition to other states
private static final ImmutableSet TERMINAL_STATES = ImmutableSet.of(DISABLED, SUCCESS, FAILURE,
static final ImmutableSet<Status> TERMINAL_STATES = ImmutableSet.of(DISABLED, SUCCESS, FAILURE,
CANCELED, KILLED);

boolean isTerminal() {
return TERMINAL_STATES.contains(this);
}

// The states that are considered as success effectively
private static final ImmutableSet EFFECTIVE_SUCCESS_STATES = ImmutableSet.of(DISABLED, SUCCESS);
private static final ImmutableSet<Status> EFFECTIVE_SUCCESS_STATES = ImmutableSet.of(DISABLED,
SUCCESS);

boolean isSuccessEffectively() {
return EFFECTIVE_SUCCESS_STATES.contains(this);
}

// The states that are possible before a node ever starts to run or be killed or canceled
private static final ImmutableSet PRE_RUN_STATES = ImmutableSet.of(DISABLED, READY, BLOCKED);
private static final ImmutableSet<Status> PRE_RUN_STATES = ImmutableSet
.of(DISABLED, READY, BLOCKED);

boolean isPreRunState() {
return PRE_RUN_STATES.contains(this);
Expand Down
30 changes: 29 additions & 1 deletion azkaban-exec-server/src/test/java/azkaban/dag/DagTest.java
Expand Up @@ -17,7 +17,10 @@
package azkaban.dag;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import org.junit.Test;

Expand All @@ -28,7 +31,8 @@
*/
public class DagTest {

private final Dag testFlow = new Dag("fa", mock(DagProcessor.class));
private final DagProcessor mockDagProcessor = mock(DagProcessor.class);
private final Dag testFlow = new Dag("fa", this.mockDagProcessor);

@Test
public void dag_finish_with_only_disabled_nodes() {
Expand All @@ -49,6 +53,30 @@ public void running_nodes_can_be_killed() {
assertThat(this.testFlow.getStatus()).isEqualTo(Status.KILLING);
}

@Test
public void kill_node_in_terminal_state_should_have_no_effect() {
for (final Status status : Status.TERMINAL_STATES) {
kill_dag_in_this_state_should_have_no_effect(status);
}
}

@Test
public void kill_node_in_killing_state_should_have_no_effect() {
kill_dag_in_this_state_should_have_no_effect(Status.KILLING);
}

private void kill_dag_in_this_state_should_have_no_effect(final Status status) {
// given
this.testFlow.setStatus(status);

// when
this.testFlow.kill();

// then
assertThat(this.testFlow.getStatus()).isEqualTo(status);
verify(this.mockDagProcessor, never()).changeStatus(any(), any());
}

/**
* Tests ready nodes are canceled when the dag is killed.
*/
Expand Down

0 comments on commit 5803674

Please sign in to comment.