back to index     prev     next  

3. How to create a Test Suite with interlinked Tests

In this part we will not explain how to write a simple test, for this see Your first Test section.

Description of our Test

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.

Root Test : ProActive Group Creation

A simply ProActiveTest

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.

Action method for interlinked mode

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.

An independant Test : A Group migration

All the code is the same of the precedant class unexcepted for the actions methods and for the method to create group of course.

The default action method

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 action method for interlinked tests

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;
}

Run your tests

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.

An example of results for this test with verbatim option


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

All the code

Manager.prop
 
RemoteHostname=owenii
Manager.java
 
import testsuite.group.Group;
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.");
Group group = new Group("Group Migration",
"Migration on an active group objects.");

TestGroupCreation creation = new TestGroupCreation(manager.getLocalVMNode());
group.add(creation);

TestGroupMigration migration = new TestGroupMigration(manager.getRemoteVMNode());
group.add(migration);

FunctionalTest[] params = { creation };
migration.setTests(params);

manager.add(group);

manager.execute(group, migration, true);

manager.setVerbatim(true);
manager.getResults().toOutPutStream(System.out);

System.exit(0);
}
}
TestGroupMigration.java
 
import java.io.Serializable;

import org.objectweb.proactive.core.group.Group;
import org.objectweb.proactive.core.group.ProActiveGroup;
import org.objectweb.proactive.core.node.Node;

import testsuite.test.ProActiveFunctionalTest;

public class TestGroupMigration extends ProActiveFunctionalTest
implements Serializable {
private Agent group = null;

public TestGroupMigration() {
super(null, "Group Migration",
"Migrate all Group Element in a specified node.");
}

public TestGroupMigration(Node node) {
super(node, "Group Migration",
"Migrate all Group Element in a specified 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);
}
}
}

public boolean preConditions() throws Exception {
return getNode() != null;
}

public void action() throws Exception {
throw new Exception("This test doesn't work in standalone mode");
}

public Object action(Agent group) throws Exception {
this.group = group;
this.group.moveTo(getNode().getNodeInformation().getURL());
return null;
}

public void initTest() throws Exception {
// nothing to do
}

public void endTest() throws Exception {
// nothing to do
}
}
TestGroupCreation.java
 
import org.objectweb.proactive.core.group.Group;
import org.objectweb.proactive.core.group.ProActiveGroup;
import org.objectweb.proactive.core.node.Node;

import testsuite.test.ProActiveFunctionalTest;

import java.io.Serializable;

public class TestGroupCreation extends ProActiveFunctionalTest
implements Serializable {
private Agent group = null;

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.");
}

// Default action method
public void action() throws Exception {
createGroupAgent();
}

// For interlinked tests action method
public Agent action(Object o) throws Exception {
createGroupAgent();
return this.group;
}

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);
}

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);
}
}
}

public boolean preConditions() throws Exception {
return getNode() != null;
}

public void initTest() throws Exception {
// nothing to do
}

public void endTest() throws Exception {
// nothing to do
}
}
Agent.java
 
import org.objectweb.proactive.Body;
import org.objectweb.proactive.EndActive;
import org.objectweb.proactive.InitActive;
import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.RunActive;

public class Agent implements InitActive, RunActive, EndActive,
java.io.Serializable {
private String name;
private String nodename;
private String hostname;

public Agent() {
}

public Agent(String name) {
this.name = name;
}

public String getName() {
try {
//return the name of the Host
return java.net.InetAddress.getLocalHost().getHostName()
.toUpperCase();
} catch (Exception e) {
e.printStackTrace();
return "getName failed";
}
}

public String getNodeName() {
try {
//return the name of the Node
return ProActive.getBodyOnThis().getNodeURL().toUpperCase();
} catch (Exception e) {
e.printStackTrace();
return "getNodeName failed";
}
}

public void moveTo(String nodeURL) {
try {
System.out.println(" I am going to migate");
ProActive.migrateTo(nodeURL);
System.out.println("migration done");
} catch (Exception e) {
e.printStackTrace();
}
}

public void endBodyActivity() {
ProActive.getBodyOnThis().terminate();
}

public void initActivity(Body body) {
System.out.println("Initialization of the Activity");
}

public void runActivity(Body body) {
org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body);
while (body.isActive()) {
// The synchro policy is FIFO
service.blockingServeOldest();
}
}

public void endActivity(Body body) {
System.out.println("End of the activity of this Active Object");
}
}