Configuring Datapools, Synchronization Points, and Shared Variables

prevnext

Synchronization Point Configuration


A test script that uses a synchronization point must include, somewhere in its body, a block of code such as:

public static class SyncPointConfig extends SyncPointInfo {
        public SyncPointConfig() {
            setSyncPointNames(java.lang.String[] points);
        }
    }

The points argument of setSyncPointNames() -- a method of SyncPointInfo -- is an array containing the names of one or more synchronization points. Add to this array the name of each synchronization point in the script that you specified with TSSSync.syncPoint().

The following is an example of a Java program that uses a synchronization point named square_syncpoint. Relevant lines apear in bold.

/**
 * SquareClientTM demonstrates an EJB client that can be executed
 * from Rational Suite TestStudio using TestManager.
 *
 */

// EJB itself
import com.rational.square.Square;
import com.rational.square.SquareHome;

// Misc
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.ListResourceBundle;
import java.rmi.RemoteException;

// JNDI-related
import javax.naming.Context;
import javax.naming.InitialContext;

// TestManager
import com.rational.test.tss.*;


// Java test scripts must extend the TestScript interface.

public class SquareClientTM_syncpoint
    extends com.rational.test.tss.TestScript {

    public void testMain(String[] args) {
        try {

            // Create EJB
            TSSMeasure.commandStart("home001", "getHome",
	 	 	 	 	 	 	 	 	 	 	 	 	 	 MST_XCLNTCONN);
            Square square = getHome().create();
            TSSMeasure.commandEnd((short)TSS_CMD_STAT_PASS);

            // Call Square method
            System.out.println( "Getting square of 123" );
            long answer = 0;
            TSSSync.syncPoint("square_syncpoint");
            TSSMeasure.think(2000);
            TSSMeasure.commandStart("square001", "getSquare",
	 	 	 	 	 	 	 	 	 	 	 	 	 	 MST_WAITRESP);
            answer = square.getSquare(123);
            TSSMeasure.commandEnd((short)TSS_CMD_STAT_PASS);
            System.out.println(answer);

            // Destroy EJB
            square.remove();
        }
        catch (RemoteException e) {
            System.err.println( "remoteException" + e.getMessage() );
            e.printStackTrace();
        }
        catch (NullPointerException e) {
            if (getHome() == null)
                System.err.println( "noHome" + e.getMessage() );
            else
                e.printStackTrace();
        }
        catch (Exception e) {
            System.err.println( "generalException" + e.getMessage() );
            e.printStackTrace();
        }
    }


    // Constructor

    public SquareClientTM_syncpoint() {
        super();
    }


    // Helper method to get the EJB's home.

    private static SquareHome getHome() {


        // Specify the name of the server so we can find the Square EJB.

        String homeName = "com/rational/square/SquareHome";


        // Specify the name of the host machine with the name server.
        // This example is intended to run locally.  Also, specify
        // the class name of the JNDI initial naming factory.

        Properties env = new Properties();
        env.put(Context.PROVIDER_URL, "iiop:///");
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.ibm.ejb.cb.runtime.CBCtxFactory");


        try {
            // The following is the simplest way to get the
	 	 	 	 	 //InitialContext.

            InitialContext ctx = new InitialContext(env);
            java.lang.Object obj=ctx.lookup( homeName );

            if (obj == null) {
                System.out.println( "ctx.lookup returned null object" );
                return null;  // fail
            }

            return ((SquareHome)
	 	 	 	 	 javax.rmi.PortableRemoteObject.narrow(obj,
	 	 	 	 	 	 	 	 	 	 	 com.rational.square.SquareHome.class));

        } catch (javax.naming.NamingException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static class SyncPointConfig extends SyncPointInfo {
        public SyncPointConfig() {
            String points[] = {
                "square_syncpoint"};
            setSyncPointNames(points);
        }
    }

    public static void main(String args[]) {
        SquareClientTM_syncpoint sctm = new SquareClientTM_syncpoint();
        sctm.testMain(args);
    }
}

prevnext


Rational Test Script Services for Java Rational Software Corporation
Copyright (c) 2003, Rational Software Corporation http://www.rational.com
support@rational.com
info@rational.com