jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krishnasankar R <>
Subject JMeter JUnit sampler - how to use oneTimeSetup
Date Fri, 11 Nov 2005 07:07:26 GMT

I'd like to know how to use the onetimesetup method in the JUnit sampler.
When I tried, the data that was set up in oneTimeSetUp is not visible in the
test methods.

Please see the JUnit testcase code below where the variable oneTimeValue is
being set in the oneTimeSetUp method.  Its value is not visible in the test
method.  In the JMX, there's a single thread group to which two JUnit
samplers are attached.  The first sampler uses the oneTimeSetUp, does not
call setup and teardown.  The second sampler calls the actual test method.

For the example, pl add WebLogic.jar or the client jars (WebLogic v8.1.4)
and the jars and the following to user.classpath in jmeter.bat:

Your help would be greatly appreciated.



import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import java.util.Properties;
import java.rmi.RemoteException;

import javax.naming.*;
import javax.rmi.PortableRemoteObject;

import examples.ejb20.basic.statelessSession.*;

public class TraderTestClient extends TestCase {

	private static final String REMOTE_REFERENCE_IS_NULL
			= "Remote interface reference is null";
	private static final String JNDI_NAME =
	private Trader trader;
	private TraderHome traderHome;
	private int oneTimeValue;

	public TraderTestClient() {

	public TraderTestClient(String name) {

	public void initialize() {
		try {
			//get naming context
			Context context = getInitialContext();

			//look up jndi name
			Object ref = context.lookup(JNDI_NAME);

			System.out.println("ref: " +

			//look up jndi name and cast to Home interface
			traderHome = (TraderHome)
PortableRemoteObject.narrow(ref, TraderHome.class);
		} catch (Exception e) {


	public Context getInitialContext() {
		InitialContext initialContext = null;
		try {
			String url = "t3://localhost:7001";
			Properties properties = new Properties();
			properties.put(Context.PROVIDER_URL, url);
			initialContext = new InitialContext(properties);
		} catch (Exception e) {
		return initialContext;

	public void setUp() {
		System.out.println("In setUp()");

	public void tearDown() {
		System.out.println("In tearDown()");
		traderHome = null;
		trader = null;

    public void oneTimeSetUp() {
        System.out.println("oneTimeSetUp called -- ");
		System.out.println("oneTimeValue: " + oneTimeValue);

    public void oneTimeTearDown() {
        System.out.println("oneTimeTearDown called -- ");

	public void create() {
		try {
			trader = (Trader) PortableRemoteObject.narrow
(traderHome.create(), Trader.class);
		} catch (Exception e) {
		assertNotNull("Unable to create Trader", trader);

	 * Invoke a method on the Trader bean
	public void testTraderBuy() {
		// buy specified # of shares of a company
		System.out.println("buy specified # of shares of a
		System.out.println("oneTimeValue: " + oneTimeValue);
		TradeResult tradeResult = null;
		try {
			tradeResult ="Scandent Solutions",
		} catch (RemoteException re) {
		assertNotNull("Number of stocks bought: ", tradeResult);
		assertTrue("Number of stocks bought: ",
		assertNotNull("Stock symbol: ",

	public static void main(String[] args) throws Exception {;

} // class

This communication contains information, which is confidential and may also
be privileged. It is for the exclusive use of the intended recipient(s). If
you are not the intended recipient(s), please note that any distribution,
printing, copying or use of this communication or the information in it is
strictly prohibited. If you have received this communication in error,
please notify the sender immediately and then destroy any copies of it.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message