jmeter-user mailing list archives

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

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:
<bea-home>/user_projects/domains/yourdomain/applications/ejb20_basic_statele
ssSession.jar

Your help would be greatly appreciated.

Thanks,
Krishna

Code:

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 =
"ejb20-statelessSession-TraderHome";
	private Trader trader;
	private TraderHome traderHome;
	private int oneTimeValue;

	public TraderTestClient() {
		super();
	}

	public TraderTestClient(String name) {
		super(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: " +
ref.getClass().getName());

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

	}

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

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

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

    public void oneTimeSetUp() {
        System.out.println("oneTimeSetUp called -- ");
        oneTimeValue=5;
		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) {
			e.printStackTrace();
		}
		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
company");
		System.out.println("oneTimeValue: " + oneTimeValue);
		TradeResult tradeResult = null;
		try {
			tradeResult = trader.buy("Scandent Solutions",
1000);
		} catch (RemoteException re) {
			re.printStackTrace();
		}
		assertNotNull("Number of stocks bought: ", tradeResult);
		assertTrue("Number of stocks bought: ",
tradeResult.getNumberTraded()!=0);
		assertNotNull("Stock symbol: ",
tradeResult.getStockSymbol());
	}

	public static void main(String[] args) throws Exception {
		junit.textui.TestRunner.run(TraderTestClient.class);
	}

} // 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: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Mime
View raw message