Il seguente codice mostra come avviare una transazione. Le transazioni generate dai servizi di esecuzione del test creano e gestiscono automaticamente le statistiche.
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.services.ITransaction;
/**
* @author IBM Custom Code Samples
*/
public class BeginTransaction implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public BeginTransaction() {
}
/**
* Per le informazioni Javadoc sulle interfacce ICustomCode2 e ITestExecutionServices,
* consultare l'argomento della guida 'Classi e interfacce dei servizi di esecuzione del test'.
*/
public String exec(ITestExecutionServices tes, String[] args) {
// il nome della transazione è stato trasferito mediante la correlazione dati.
ITransaction foo = tes.getTransaction("foo");
foo.start();
return null;
}
}
Il seguente codice mostra come raccogliere le statistiche aggiuntive durante una transazione.
package customcode;
import com.ibm.rational.test.lt.kernel.ITime;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.statistics.IScalar;
import com.ibm.rational.test.lt.kernel.statistics.IStat;
import com.ibm.rational.test.lt.kernel.statistics.IStatTree;
import com.ibm.rational.test.lt.kernel.statistics.impl.StatType;
/**
* @author IBM Custom Code Samples
*/
public class BodyTransaction implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public BodyTransaction() {
}
/**
* Per le informazioni Javadoc sulle interfacce ICustomCode2 e ITestExecutionServices,
* consultare l'argomento della guida 'Classi e interfacce dei servizi di esecuzione del test'.
*/
public String exec(ITestExecutionServices tes, String[] args) {
IStatTree tranStat;
IStatTree timeStat;
IStatTree countStat;
IStat timeDataStat = null; // contatore per RANGE temporale
IScalar countDataStat = null; // contatore per SCALAR del conteggio
ITime timer = tes.getTime();
IStatTree rootStat = tes.getStatisticsManager().getStatTree();
if (rootStat != null) {
// questi contatori impostano la gerarchia
tranStat = rootStat.getStat("Transactions", StatType.STRUCTURE);
timeStat = tranStat.getStat("Body Time", StatType.STRUCTURE);
countStat = tranStat.getStat("Bocy Count", StatType.STRUCTURE);
// il nome dei contatori è stato trasferito mediante la correlazione dati
timeDataStat = (IStat) timeStat.getStat("foo", StatType.RANGE);
countDataStat = (IScalar) countStat.getStat("foo", StatType.SCALAR);
}
// ottenere l'ora di inizio
long startTime = timer.timeInTest();
// eseguire il lavoro
// attività del lavoro
// ottenere l'ora di fine
long endTime = timer.timeInTest();
// aggiornare timeDataStat con il tempo trascorso
if (timeDataStat != null)
timeDataStat.submitDataPoint(endTime - startTime);
// aggiornare countDataStat
if (countDataStat != null)
countDataStat.increment();
return null;
}
}
Il seguente codice mostra come arrestare una transazione.
package customcode;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import com.ibm.rational.test.lt.kernel.services.ITransaction;
/**
* @author IBM Custom Code Samples
*/
public class EndTransaction implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
/**
* Instances of this will be created using the no-arg constructor.
*/
public EndTransaction() {
}
/**
* Per le informazioni Javadoc sulle interfacce ICustomCode2 e ITestExecutionServices,
* consultare l'argomento della guida 'Classi e interfacce dei servizi di esecuzione del test'.
*/
public String exec(ITestExecutionServices tes, String[] args) {
// il nome della transazione è stato trasferito mediante la correlazione dati.
ITransaction foo = tes.getTransaction("foo");
foo.stop();
return null;
}
}