Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Braden Steffaniak
Matthew Alonso
Nathan Brown
Randall Hauch
Zach Anderson
Zach Anderson
Rothanak So
55 changes: 50 additions & 5 deletions strongback-tests/src/org/strongback/command/CommandGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

package org.strongback.command;

import static org.fest.assertions.Assertions.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.strongback.Logger;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import org.junit.Before;
import org.junit.Test;
import org.strongback.Logger;
import static org.fest.assertions.Assertions.assertThat;

public class CommandGroupTest {
private Scheduler scheduler;
Expand Down Expand Up @@ -332,6 +332,51 @@ public OtherDiagramFromBoard() {
}
}

@Test
public void shouldExecuteComposedNamedCommandGroups() {
scheduler.submit(new OuterCommandGroup());

assertThat(list).isEmpty();

// First step should come from the OuterCommandGroup
scheduler.execute(0);
assertThat(list).isEqualTo(listOf("C0 init", "C0 exe", "C0 fin" ));
list.clear();

// Second step should come from NestedCommandGroup
scheduler.execute(0);
assertThat(list).isEqualTo(listOf("C1 init", "C1 exe", "C1 fin" ));
list.clear();

// Third step should come from NestedCommandGroup
scheduler.execute(0);
assertThat(list).isEqualTo(listOf("C2 init", "C2 exe", "C2 fin" ));
list.clear();

// Fourth step should resume the OuterCommandGroup sequence
scheduler.execute(0);
assertThat(list).isEqualTo(listOf("C3 init", "C3 exe", "C3 fin" ));
list.clear();

// Fifth step is empty, nothing executed
scheduler.execute(0);
assertThat(list).isEmpty();
}

private final class OuterCommandGroup extends CommandGroup {
@SuppressWarnings("synthetic-access")
public OuterCommandGroup() {
sequentially(c[0], new InnerNamedCommandGroup(), c[3]);
}

private final class InnerNamedCommandGroup extends CommandGroup {
@SuppressWarnings("synthetic-access")
public InnerNamedCommandGroup() {
sequentially(c[1], c[2]);
}
}
}

private static final class TestCommand extends Command {
private static int commandID = 0;

Expand Down Expand Up @@ -454,4 +499,4 @@ public String toString() {
return "R" + number;
}
}
}
}
10 changes: 3 additions & 7 deletions strongback/src/org/strongback/command/CommandGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static enum Type {
SEQUENTIAL, PARRALLEL, FORK;
}

private Command root;
private CommandGroup root;
private final Command[] commands;
private final Type type;

Expand All @@ -151,15 +151,11 @@ private CommandGroup(Command[] commands, Type type) {
}

Type getType() {
return type;
return root != null ? root.type : type;
}

Command[] getCommands() {
return commands;
}

Command getRoot() {
return root;
return root != null ? root.getCommands() : commands;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions strongback/src/org/strongback/command/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public void killAll() {
*/
public void submit(Command command) {
if (command != null) {
if (command instanceof CommandGroup) {
command = ((CommandGroup) command).getRoot();
}
CommandRunner runner = buildRunner(command, null);
commands.add(runner);
}
Expand Down