use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.
the class SelectionWithSeveralScriptsTest2 method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nodeSourceName = "SelectionWithSeveralScriptsTest2";
resourceManager.createNodeSource(nodeSourceName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), new Object[] { "ALL", "ALL" }, NODES_NOT_RECOVERABLE).getBooleanValue();
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nodeSourceName);
String node1Name = "node-sel2-1";
String node2Name = "node-sel2-2";
// ---------------------------------------------------
// create a first node with one VM property
// ---------------------------------------------------
HashMap<String, String> vmProp1 = new HashMap<>();
String vmPropKey1 = "myProperty1";
String vmPropValue1 = "myValue1";
vmProp1.put(vmPropKey1, vmPropValue1);
TestNode node1 = rmHelper.createNode(node1Name, vmProp1);
testNodes.add(node1);
String node1URL = node1.getNode().getNodeInformation().getURL();
resourceManager.addNode(node1URL, nodeSourceName);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// --------------------------------------------------
// create a second node with two VM properties
// ---------------------------------------------------
HashMap<String, String> vmTwoProperties = new HashMap<>();
vmTwoProperties.put(vmPropKey1, vmPropValue1);
String vmPropKey2 = "myProperty2";
String vmPropValue2 = "myValue2";
vmTwoProperties.put(vmPropKey2, vmPropValue2);
TestNode node2 = rmHelper.createNode(node2Name, vmTwoProperties);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL, nodeSourceName);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the node to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// create the static selection script object that check vm prop1
SelectionScript sScript1 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey1, vmPropValue1 }, true);
// create the static selection script object prop2
SelectionScript sScript2 = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey2, vmPropValue2 }, false);
log("Test 1");
ArrayList<SelectionScript> scriptsList = new ArrayList<>();
scriptsList.add(sScript1);
scriptsList.add(sScript2);
NodeSet nodes = resourceManager.getAtMostNodes(1, scriptsList, null);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(node2URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(nodes);
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.FREE, evt.getNodeState());
assertEquals(2, resourceManager.getState().getFreeNodesNumber());
}
use of functionaltests.utils.TestNode in project scheduling by ow2-proactive.
the class StaticSelectionScriptTest method action.
@Test
public void action() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
int nodeNumber = rmHelper.createNodeSource("StaticSelectionScriptTest");
String node1Name = "node1";
String node2Name = "node2";
HashMap<String, String> vmProperties = new HashMap<>();
String vmPropKey = "myProperty";
String vmPropValue = "myValue";
vmProperties.put(vmPropKey, vmPropValue);
TestNode node1 = rmHelper.createNode(node1Name, vmProperties);
testNodes.add(node1);
String node1URL = node1.getNode().getNodeInformation().getURL();
resourceManager.addNode(node1URL);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
// create the static selection script object
SelectionScript sScript = new SelectionScript(new File(vmPropSelectionScriptpath.toURI()), new String[] { vmPropKey, vmPropValue }, false);
log("Test 1");
NodeSet nodes = resourceManager.getAtMostNodes(1, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNode(nodes.get(0));
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 2");
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(1, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
assertEquals(node1URL, nodes.get(0).getNodeInformation().getURL());
// wait for node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNode(nodes.get(0));
// wait for node free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 3");
// add a second with JVM env var
TestNode node2 = rmHelper.createNode(node2Name, vmProperties);
testNodes.add(node2);
String node2URL = node2.getNode().getNodeInformation().getURL();
resourceManager.addNode(node2URL);
// wait node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node2URL);
// wait for the nodes to be in free state
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(2, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
// wait for node busy event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
assertEquals(NodeState.BUSY, evt.getNodeState());
resourceManager.releaseNodes(nodes);
// wait for nodes free event
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(NodeState.FREE, evt.getNodeState());
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node2URL);
Assert.assertEquals(NodeState.FREE, evt.getNodeState());
log("Test 4");
resourceManager.removeNode(node1URL, true);
resourceManager.removeNode(node2URL, true);
// wait for node removed event
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node1URL);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, node2URL);
nodes = resourceManager.getAtMostNodes(3, sScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 5");
// create the bad static selection script object
SelectionScript badScript = new SelectionScript(new File(badSelectionScriptpath.toURI()), new String[] {}, false);
nodes = resourceManager.getAtMostNodes(3, badScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
log("Test 6");
// create the static selection script object that doesn't define 'selected'
SelectionScript noSelectedScript = new SelectionScript(new File(withoutSelectedSelectionScriptpath.toURI()), new String[] {}, false);
nodes = resourceManager.getAtMostNodes(3, noSelectedScript);
// wait node selection
PAFuture.waitFor(nodes);
assertEquals(0, nodes.size());
assertEquals(nodeNumber, resourceManager.getState().getFreeNodesNumber());
}
Aggregations