|
![]() |
This section describes how to write simple test and execute it.
For this example, we choose to test the object creation in ProActive API with newActive() method. This test aims to perform object creation on the same JVM, on an other local JVM and on a remote JVM.
Create a new class who extends testsuite.test.ProActiveFunctionalTest, it is an abstract class.
See this template code :
import testsuite.test.ProActiveFunctionalTest;
import org.objectweb.proactive.core.node.Node;
public class TestNewActive extends ProActiveFunctionalTest {
public TestNewActive() {
super();
setName("newActive");
setDescription("Test object creation with newActive in a node.");
}
public TestNewActive(Node node, String name) {
super(node,name,
"Test object creation with newActive in a node.");
}
public void initTest() throws Exception {
}
public void action() throws Exception {
}
public void endTest() throws Exception {
}
}
We also override two methods from the super-super class : testsuite.test.FunctionalTest, to check if post and pre-conditions are verified :
public boolean postConditions() throws Exception {
}
public boolean preConditions() throws Exception {
}
In this example both methods are empty, but they could be overridden in order to initialize and finalyze the test.
We will simply verify if the node is created :
public boolean preConditions() throws Exception {
return getNode() != null;
}
This method is the test, we will create an active object :
private ReifiableObject active = null;
public void action() throws Exception {
active = (ReifiableObject) ProActive.newActive(ReifiableObject.class.getName(),
null, getNode());
}
Remarks : The ReifiableObject class is a simple class who just extends java.lang.Object, implements java.io.Serilizable and has an empty constructor with no argument.
We will check if active is different of null and if the node contains active :
public boolean postConditions() throws Exception {
Object[] activeObjects = getNode().getActiveObjects();
return (active != null) && (activeObjects != null) &&
(activeObjects.length == 1) && activeObjects[0].equals(active);
}
import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.node.Node;
import testsuite.test.ProActiveFunctionalTest;
public class TestNewActive extends ProActiveFunctionalTest {
private ReifiableObject active = null;
public TestNewActive() {
super();
setName("newActive");
setDescription("Test object creation with newActive in a node.");
}
public TestNewActive(Node node, String name) {
super(node, name,
"Test object creation with newActive in a node.");
}
public void initTest() throws Exception {
// nothing to do
}
public boolean preConditions() throws Exception {
return getNode() != null;
}
public void action() throws Exception {
active = (ReifiableObject) ProActive.newActive(ReifiableObject.class.getName(),
null, getNode());
}
public boolean postConditions() throws Exception {
Object[] activeObjects = getNode().getActiveObjects();
return (active != null) && (activeObjects != null) &&
(activeObjects.length == 1) && activeObjects[0].equals(active);
}
public void endTest() throws Exception {
// nothing to do
}
}
Tips : if you want to make a trace in your test or in all classes who extends a testsuite class, you have access to a log4j logger by : getLogger()
Now, we will write a Manager to execute our test.
For this example it is very simple, you have just to extends testsuite.manager.ProActiveFuncTestManager :
import testsuite.manager.ProActiveFuncTestManager;
public class ObjectCreationManager extends ProActiveFuncTestManager {
public ObjectCreationManager() {
super("Object Creation","Manage objects creation tests.");
}
}
Normaly, you have nothing to do to initialize the manager. In this example, we choose to create tests and group in this method , but you can do this in the same place where you create the manager.
Create group by the initManager() :
import testsuite.group.Group;
public void initManager() throws Exception {
Group testGroup = new Group("Test Group", "no description.");
// adding a test in same VM
testGroup.add(new TestNewActive(getSameVMNode(),"NewActive same VM"));
// adding a test in local VM
testGroup.add(new TestNewActive(getLocalVMNode(),"NewActive local VM"));
// adding a test in remote VM
testGroup.add(new TestNewActive(getRemoteVMNode(),"NewActive remote VM"));
// adding the group
add(testGroup);
}
Create group in the same place of the manager :
ObjectCreationManager manager = new ObjectCreationManager();
Group testGroup = new Group("Test Group", "no description.");
// adding a test in same VM
testGroup.add(new TestNewActive(getSameVMNode(),"NewActive same VM"));
// adding a test in local VM
testGroup.add(new TestNewActive(getLocalVMNode(),"NewActive local VM"));
// adding a test in remote VM
testGroup.add(new TestNewActive(getRemoteVMNode(),"NewActive remote VM"));
// adding the group
manager.add(testGroup);
Warning : if you override endManager() method in a ProActiveManager you must to add in this code :
super.endManager()
The reason is to delete the ProActive nodes create at the beginning.
Our manager is a ProActiveManager, so an attibutes file is mandatory.
Create a file ObjectCreationManager.prop in the same directory of the manager. This file must contains the name (or URL) of the remote host, like this :
RemoteHostname=owenii
Warning : respect the upper an lower cases.
Tips : you can use this file to specify attributes for your
tests classes. You can also use a different file, in this case
you must specify its path in the execute()
method of the
manager.
Add this code in your main method :
ObjectCreationManager manager = new ObjectCreationManager();
// the argument must have true value, because it is a ProActiveManager
// and the attributes file is obligatory
manager.execute(true);
Warning : when you use a ProActiveManager you must had System.exit(0) at the end of the main method. If you don't do that, the manager can't stop properly.
System.out.println(manager.getResults());
If you want all details :
manager.setVerbatim(true);
You can also have the results in a HTML or XML file or in a stream, for more details see the results section for : testssuite.result.ResultsExporter
8/22/03 13:48:10.450 [MESSAGE] Local hostname : amda.inria.fr
8/22/03 13:48:10.450 [MESSAGE] Remote hostname : owenii
8/22/03 13:48:10.452 [MESSAGE] Starting ...
8/22/03 13:48:10.458 [MESSAGE] Init Manager with success
8/22/03 13:48:10.749 [RESULT] NewActive same VM : Test run with success [SUCCESS]
8/22/03 13:48:11.141 [RESULT] NewActive local VM : Test run with success [SUCCESS]
8/22/03 13:48:12.195 [RESULT] NewActive remote VM : Test run with success [SUCCESS]
8/22/03 13:48:12.195 [RESULT] Group : Test Group Runs : 3 Errors : 0 [SUCCESS]
8/22/03 13:48:12.195 [MESSAGE] ... Finish
TestNewActive.java |
---|
|
ReaifiableObject.java |
---|
|
ObjectCreationManager.prop |
---|
|
ObjectCreationManager.java |
---|
|