|
![]() |
In this part we will not explain how to write a simple test, for this see Your first Test section.
In first step, we will test a ProActive Group creation with 3 Agents, and after this creation we will test the Agents migration by a group communication.
Create a new class who extends testsuite.test.ProActiveFunctionalTest, it is an abstract class.
See this template code :
import org.objectweb.proactive.core.node.Node;
import testsuite.test.ProActiveFunctionalTest;
import java.io.Serializable;
public class TestGroupCreation extends ProActiveFunctionalTest
implements Serializable {
public TestGroupCreation() {
super(null, "Group Creation",
"Create a Group of active object in specify node.");
}
public TestGroupCreation(Node node) {
super(node, "Group Creation",
"Create a Group of active object in specify node.");
}
public void action() throws Exception {
}
public boolean postConditions() throws Exception {
}
public boolean preConditions() throws Exception {
}
public void initTest() throws Exception {
// nothing to do
}
public void endTest() throws Exception {
// nothing to do
}
}
Next we will simply test in preconditions if the node exists (different of null) :
public boolean preConditions() throws Exception {
return getNode() != null;
}
Now we will implement the action method to create a ProActive Group with 3 Agent (see the Agent code at the end of this document) :
import org.objectweb.proactive.core.group.Group;
import org.objectweb.proactive.core.group.ProActiveGroup;
public class TestGroupCreation extends ProActiveFunctionalTest
implements Serializable {
private Agent group = null;
// ...
public void action() throws Exception {
createGroupAgent();
}
private void createGroupAgent() throws Exception {
Object[][] params = {
{ "Agent0" },
{ "Agent1" },
{ "Agent2" }
};
Node node = getNode();
Node[] nodes = { node };
group = (Agent) ProActiveGroup.newGroup(Agent.class.getName(), params,
nodes);
}
// ...
}
Remarks : We use an external method to create the group is for the simple reason of we use this code after in another method.
Remarks : We don't explain the Agent code because it is a ProActive example.
For the postconditions we will test if the group containts 3 elements and they are in the good node :
public boolean postConditions() throws Exception {
if (group == null) {
return false;
} else {
Group agentGroup = ProActiveGroup.getGroup(group);
if (agentGroup.size() != 3) {
return false;
} else {
Agent agent0 = (Agent) agentGroup.get(0);
Agent agent1 = (Agent) agentGroup.get(1);
Agent agent2 = (Agent) agentGroup.get(2);
String nodeURL = getNode().getNodeInformation().getURL()
.toUpperCase();
return (agent0.getNodeName().compareTo(nodeURL) == 0) &&
(agent1.getNodeName().compareTo(nodeURL) == 0) &&
(agent2.getNodeName().compareTo(nodeURL) == 0);
}
}
}
This class is now readi for a standalone use.
Now, we will add a new action method who return a ProActive Group :
public Agent action(Object o) throws Exception {
createGroupAgent();
return this.group;
}
This method return an Agent (who is the group) and have one argument : o. This argument will not use , we must to put this argument is for have a different method signature from action().
Our test for group creation is now ready.
All the code is the same of the precedant class unexcepted for the actions methods and for the method to create group of course.
In this test we can't run this method in a standalone test, but for other maybe you can. It is just for this test.
public void action() throws Exception {
throw new Exception("This test doesn't work in standalone mode");
}
The result of the precedent test is an Agent, so the argument will be an Agent. This test have no result but we must to return an Object here it is null because the API use the reflection mechanism of Java.
public Object action(Agent group) throws Exception {
this.group = group;
this.group.moveTo(getNode().getNodeInformation().getURL());
return null;
}
Create a simple ProActiveFuncTestManager with a main :
import testsuite.manager.ProActiveFuncTestManager;
public class Manager extends ProActiveFuncTestManager {
public Manager(String name, String description) {
super(name, description);
}
public static void main(String[] args) {
Manager manager = new Manager("Migration Tests",
"Create a group and migrate its objects.");
}
}
Create a new Group (testsuite.group.Group) in our main :
import testsuite.group.Group;
// ...
Group group = new Group("Group Migration",
"Migration on an active group objects.");
// ...
Create and add the 2 precends tests in the group :
// ...
TestGroupCreation creation = new TestGroupCreation(manager.getLocalVMNode());
group.add(creation);
TestGroupMigration migration = new TestGroupMigration(manager.getRemoteVMNode());
group.add(migration);
// ...
Specify the ancestor test of migration is creation :
// ...
FunctionalTest[] params = { creation };
migration.setTests(params);
// ...
You can see in the configuration file part how to do this by a configuration file.
Warning : Don't forget to write a prop file with the name of the remote host.
Add the group and launch the test :
// ...
manager.add(group);
manager.execute(group, migration, true);
// ...
Warning : when you use a ProActiveManager you must to had System.exit(0) at the end of the main method. If don't do that, the manager can't properly.
8/26/03 12:40:47.407 [MESSAGE] Local hostname : amda.inria.fr
8/26/03 12:40:47.408 [MESSAGE] Remote hostname : owenii
8/26/03 12:40:47.498 [MESSAGE] Starting with interlinked Tests ...
8/26/03 12:40:47.498 [MESSAGE] Init Manager with success
8/26/03 12:40:48.547 [RESULT] Group Creation : Test run with success [SUCCESS]
8/26/03 12:40:50.149 [RESULT] Group Migration : Test run with success [SUCCESS]
8/26/03 12:40:50.149 [RESULT] Group : Group Migration Runs : 2 Errors : 0 [SUCCESS]
8/26/03 12:40:50.243 [MESSAGE] ... Finish
Manager.prop |
---|
|
Manager.java |
---|
|
TestGroupMigration.java |
---|
|
TestGroupCreation.java |
---|
|