Skip to content

Commit

Permalink
Update tests to test external resources file
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jun 9, 2011
1 parent 60325b6 commit 57e5406
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
public class TestNodeDispatcherService extends AbstractBaseTest {
private static final String PROJ_NAME = "TestNodeDispatcherService";
private File resourcesfile;
private File extResourcesfile;

public TestNodeDispatcherService(String name) {
super(name);
Expand All @@ -61,6 +62,7 @@ public void setUp() {
} catch (IOException e) {
throw new RuntimeException("Caught Setup exception: " + e.getMessage(), e);
}
extResourcesfile = new File("src/test/com/dtolabs/rundeck/core/common/test-nodes2.xml");

}

Expand Down Expand Up @@ -271,4 +273,107 @@ public File getNodesFile() {

}
}

/**
* Test specifying an external nodes file
*/
public void testExtResources() throws Exception {
final Framework frameworkInstance = getFrameworkInstance();
final NodeDispatcherService service = NodeDispatcherService.getInstanceForFramework(
frameworkInstance);
{ //use test-1 file
final NodeSet nodeSet = new NodeSet();
nodeSet.createInclude().setTags("priority1"); //matches single nodes in test1 file
nodeSet.setThreadCount(2);
//get node dispatcher for a context. nodeset<2 and threadcount>1 returns sequential provider
final ExecutionContext context = new ExecutionContext() {
public String getFrameworkProject() {
return PROJ_NAME;
}

public Framework getFramework() {
return frameworkInstance;
}

public String getUser() {
return "blah";
}

public NodeSet getNodeSet() {

return nodeSet;
}

public String[] getArgs() {
return new String[0];
}

public int getLoglevel() {
return 0;
}

public Map<String, Map<String, String>> getDataContext() {
return null;
}

public ExecutionListener getExecutionListener() {
return null;
}

public File getNodesFile() {
return resourcesfile;
}
};
final NodeDispatcher nodeDispatcher = service.getNodeDispatcher(context);
assertNotNull(nodeDispatcher);
assertTrue(nodeDispatcher instanceof SequentialNodeDispatcher);
}
{
final NodeSet nodeSet = new NodeSet();
nodeSet.createInclude().setTags("priority1"); //matches two nodes in external file
nodeSet.setThreadCount(2);
//get node dispatcher for a context. nodeset>1 and threadcount>1 returns parallel provider
final ExecutionContext context = new ExecutionContext() {
public String getFrameworkProject() {
return PROJ_NAME;
}

public Framework getFramework() {
return frameworkInstance;
}

public String getUser() {
return "blah";
}

public NodeSet getNodeSet() {

return nodeSet;
}

public String[] getArgs() {
return new String[0];
}

public int getLoglevel() {
return 0;
}

public Map<String, Map<String, String>> getDataContext() {
return null;
}

public ExecutionListener getExecutionListener() {
return null;
}

public File getNodesFile() {
return extResourcesfile;
}
};
final NodeDispatcher nodeDispatcher = service.getNodeDispatcher(context);
assertNotNull(nodeDispatcher);
assertTrue(nodeDispatcher instanceof ParallelNodeDispatcher);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
public class TestNodeFirstWorkflowStrategy extends AbstractBaseTest {
Framework testFramework;
String testnode;
private File extResourcesfile;
private static final String TEST_PROJECT = "TestNodeFirstWorkflowStrategy";

public TestNodeFirstWorkflowStrategy(String name) {
Expand All @@ -78,6 +79,7 @@ protected void setUp() {
} catch (IOException e) {
throw new RuntimeException("Caught Setup exception: " + e.getMessage(), e);
}
extResourcesfile = new File("src/test/com/dtolabs/rundeck/core/common/test-nodes2.xml");
}

protected void tearDown() throws Exception {
Expand Down Expand Up @@ -305,6 +307,126 @@ public boolean isSuccess() {
}
}

public void testMultipleNodesExtFile() {

{
//test jobref item
final NodeSet nodeset = new NodeSet();
nodeset.createInclude().setName(".*");
final ArrayList<ExecutionItem> commands = new ArrayList<ExecutionItem>();
final testWorkflowCmdItem item = new testWorkflowCmdItem();
item.type = "my-type";
commands.add(item);
final WorkflowImpl workflow = new WorkflowImpl(commands, 1, false,
WorkflowStrategy.STEP_FIRST);
final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
final NodeFirstWorkflowStrategy strategy = new NodeFirstWorkflowStrategy(testFramework);
final com.dtolabs.rundeck.core.execution.ExecutionContext context =
com.dtolabs.rundeck.core.execution.ExecutionContextImpl.createExecutionContextImpl(
TEST_PROJECT,
"user1",
nodeset,
null,
0,
null,
new testListener(),
testFramework,
extResourcesfile);//specify ext resources file

//setup testInterpreter for all command types
final CommandInterpreterService interpreterService = CommandInterpreterService.getInstanceForFramework(
testFramework);
testInterpreter interpreterMock = new testInterpreter();
testInterpreter failMock = new testInterpreter();
failMock.shouldThrowException = true;
interpreterService.registerInstance("my-type", interpreterMock);
interpreterService.registerInstance("exec", failMock);
interpreterService.registerInstance("script", failMock);
interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);

//set resturn result node 1
interpreterMock.resultList.add(new InterpreterResult() {
public boolean isSuccess() {
return true;
}
});
//set resturn result node 2
interpreterMock.resultList.add(new InterpreterResult() {
public boolean isSuccess() {
return true;
}
});
//set resturn result node 3
interpreterMock.resultList.add(new InterpreterResult() {
public boolean isSuccess() {
return true;
}
});

final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

assertNotNull(result);
if (!result.isSuccess() && null != result.getException()) {
result.getException().printStackTrace(System.err);
}
assertNull("threw exception: " + result.getException(), result.getException());
assertTrue(result.isSuccess());
assertEquals(3, interpreterMock.executionItemList.size());
assertEquals(3, interpreterMock.executionContextList.size());
{
final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
assertTrue("wrong class: " + executionItem1.getClass().getName(),
executionItem1 instanceof testWorkflowCmdItem);
testWorkflowCmdItem execItem = (testWorkflowCmdItem) executionItem1;
assertNotNull(execItem.getType());
assertEquals("my-type", execItem.getType());

final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
assertNull(executionContext.getArgs());
assertNull(executionContext.getDataContext());
assertEquals(0, executionContext.getLoglevel());
assertEquals("user1", executionContext.getUser());
assertEquals(new NodeSet("test1"), executionContext.getNodeSet());
}
{

final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(1);
assertTrue("wrong class: " + executionItem1.getClass().getName(),
executionItem1 instanceof testWorkflowCmdItem);
testWorkflowCmdItem execItem = (testWorkflowCmdItem) executionItem1;
assertNotNull(execItem.getType());
assertEquals("my-type", execItem.getType());

final ExecutionContext executionContext = interpreterMock.executionContextList.get(1);
assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
assertNull(executionContext.getArgs());
assertNull(executionContext.getDataContext());
assertEquals(0, executionContext.getLoglevel());
assertEquals("user1", executionContext.getUser());
assertEquals(new NodeSet("testnode2"), executionContext.getNodeSet());
}
{

final ExecutionItem executionItem1 = interpreterMock.executionItemList.get(2);
assertTrue("wrong class: " + executionItem1.getClass().getName(),
executionItem1 instanceof testWorkflowCmdItem);
testWorkflowCmdItem execItem = (testWorkflowCmdItem) executionItem1;
assertNotNull(execItem.getType());
assertEquals("my-type", execItem.getType());

final ExecutionContext executionContext = interpreterMock.executionContextList.get(2);
assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());
assertNull(executionContext.getArgs());
assertNull(executionContext.getDataContext());
assertEquals(0, executionContext.getLoglevel());
assertEquals("user1", executionContext.getUser());
assertEquals(new NodeSet("testnode3"), executionContext.getNodeSet());
}
}
}

public void testMultipleItemsAndNodes() {

{
Expand Down

0 comments on commit 57e5406

Please sign in to comment.