Configuring Datapools, Synchronization Points, and Shared Variables |
A test script that uses a datapool must include, somewhere in its body, a block of code such as:
public static class DatapoolConfig extends DatapoolInfo { public DatapoolConfig() { setDatapoolName(java.lang.String name); setDatapoolAccessFlags(int accessFlags); } }
The name
argument of setDatapoolName
() -- a method of DatapoolInfo
-- is the same as the name
argument of TSSDatapool.open()
, and should contain the same value. Thus, if with open()
you specify a datapool named custdata
, specify custdata
with setDatapoolName() also.
The accessFlags
argument of setDatapoolAccessFlags()
-- also a method of DatapoolInfo
-- accepts the same values as argument accessFlags
of the datapool open()
method. The datapool open()
call in a script must specify the same accessFlags
that are specified with setDatapoolAccessFlags()
. Otherwise, the datapool is not correctly configured.
There is an override version of open()
that does not require the accessFlags
argument because it opens the datapool with the default access flags. Unless setDatapoolAccessFlags()
specifies the default access flags (shown in the code fragment above), the override open()
method cannot be used.
The following is an example of a Java program that opens and configures a datapool named squaredp
. Relevant lines appear 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_datapool 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 long answer = 0; TSSDatapool dp = new TSSDatapool();dp.open("squaredp");
boolean bret = dp.fetch(); int dpnum = dp.value("Number").intValue(); System.out.println( "Getting square of " + dpnum); TSSMeasure.think(2000); TSSMeasure.commandStart("square001", "getSquare", MST_WAITRESP); answer = square.getSquare(dpnum); 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_datapool() { 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 DatapoolConfig extends DatapoolInfo { public DatapoolConfig() { setDatapoolName("squaredp"); setDatapoolAccessFlags(TSS_DP_WRAP | TSS_DP_SEQUENTIAL | TSS_DP_SHARED); } }
public static void main(String args[]) { SquareClientTM_datapool sctm = new SquareClientTM_datapool(); sctm.testMain(args); } }
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 |