You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by wo...@apache.org on 2004/10/31 06:09:00 UTC

cvs commit: jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler BaseJMSSampler.java SubscriberSampler.java PublisherSampler.java

woolfel     2004/10/30 22:09:00

  Modified:    src/protocol/jms/org/apache/jmeter/protocol/jms/sampler
                        BaseJMSSampler.java SubscriberSampler.java
                        PublisherSampler.java
  Log:
  updated the sampler with jndi.properties for providers that use
  jndi.properties. ActiveMq for example doesn't have a jndi server
  yet, so it uses jndi.properties.
  
  peter
  
  Revision  Changes    Path
  1.2       +27 -0     jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java
  
  Index: BaseJMSSampler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/BaseJMSSampler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseJMSSampler.java	28 Oct 2004 04:52:36 -0000	1.1
  +++ BaseJMSSampler.java	31 Oct 2004 05:08:59 -0000	1.2
  @@ -42,6 +42,7 @@
   	public static final String CREDENTIALS = "jms.security_credentials";
   	public static final String ITERATIONS = "jms.iterations";
   	public static final String USE_AUTH = "jms.authenticate";
  +	public static final String USE_PROPERTIES_FILE = "jms.jndi_properties";
   	public static String READ_RESPONSE = "jms.read_response";
   	public static String required = JMeterUtils.getResString("jms_auth_required");
   	public static String not_req = JMeterUtils.getResString("jms_auth_not_required");
  @@ -229,5 +230,31 @@
   	 */	
   	public boolean getReadResponseAsBoolean(){
   		return getPropertyAsBoolean(READ_RESPONSE);
  +	}
  +	
  +	/**
  +	 * if the sampler should use jndi.properties file, call
  +	 * the method with true
  +	 * @param properties
  +	 */
  +	public void setUseJNDIProperties(String properties){
  +		setProperty(USE_PROPERTIES_FILE,properties);
  +	}
  +
  +	/**
  +	 * return whether the sampler should use properties file
  +	 * instead of UI parameters.
  +	 * @return
  +	 */	
  +	public String getUseJNDIProperties(){
  +		return getPropertyAsString(USE_PROPERTIES_FILE);
  +	}
  +
  +	/**
  +	 * return the properties as boolean true/false.
  +	 * @return
  +	 */	
  +	public boolean getUseJNDIPropertiesAsBoolean(){
  +		return getPropertyAsBoolean(USE_PROPERTIES_FILE);
   	}
   }
  
  
  
  1.2       +37 -31    jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java
  
  Index: SubscriberSampler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SubscriberSampler.java	28 Oct 2004 04:52:36 -0000	1.1
  +++ SubscriberSampler.java	31 Oct 2004 05:08:59 -0000	1.2
  @@ -48,8 +48,9 @@
   	static Logger log = LoggingManager.getLoggerForClass();
   	private transient ReceiveSubscriber SUBSCRIBER = null;
   
  -	private StringBuffer BUFFER = null;
  +	private StringBuffer BUFFER = new StringBuffer();
   	private transient int counter = 0;
  +	private transient int loop = 0;
   	private transient boolean RUN = true;
   	
   	public static String CLIENT_CHOICE = "jms.client_choice";
  @@ -88,7 +89,6 @@
        * @see junit.framework.TestListener#startTest(junit.framework.Test)
        */
       public void testStarted() {
  -    	this.BUFFER = new StringBuffer();
       }
   
   	public void testIterationStart(LoopIterationEvent event){
  @@ -99,6 +99,7 @@
           if (sub == null) {
               sub =
                   new OnMessageSubscriber(
  +                    this.getUseJNDIPropertiesAsBoolean(),
                       this.getJNDIInitialContextFactory(),
                       this.getProviderUrl(),
                       this.getConnectionFactory(),
  @@ -107,26 +108,31 @@
                       this.getUsername(),
                       this.getPassword());
               sub.setMessageListener(this);
  +            sub.resume();
               ClientPool.addClient(sub);
               ClientPool.put(this, sub);
  +			log.info("SubscriberSampler.initListenerClient called");
  +			log.info("loop count " + this.getIterations());
           }
           this.RUN = true;
  -        log.info("SubscriberSampler.initClient called");
           return sub;
       }
   
  -	public void initReceiveClient(){	
  -		this.SUBSCRIBER = new ReceiveSubscriber(
  -			this.getJNDIInitialContextFactory(),
  -			this.getProviderUrl(),
  -			this.getConnectionFactory(),
  -			this.getTopic(),
  -			this.getUseAuth(),
  -			this.getUsername(),
  -			this.getPassword());
  -		ClientPool.addClient(this.SUBSCRIBER);
  -		log.info("SubscriberSampler.initReceiveClient called");
  -	}
  +    public void initReceiveClient() {
  +        this.SUBSCRIBER =
  +            new ReceiveSubscriber(
  +                this.getUseJNDIPropertiesAsBoolean(),
  +                this.getJNDIInitialContextFactory(),
  +                this.getProviderUrl(),
  +                this.getConnectionFactory(),
  +                this.getTopic(),
  +                this.getUseAuth(),
  +                this.getUsername(),
  +                this.getPassword());
  +        this.SUBSCRIBER.resume();
  +        ClientPool.addClient(this.SUBSCRIBER);
  +        log.info("SubscriberSampler.initReceiveClient called");
  +    }
   	
       /* (non-Javadoc)
        * @see org.apache.jmeter.samplers.Sampler#sample(org.apache.jmeter.samplers.Entry)
  @@ -157,18 +163,16 @@
   		result.setSampleLabel("SubscriberSampler:" + this.getTopic());
   		OnMessageSubscriber sub = initListenerClient();
   		
  -		int loop = this.getIterationCount();
  +		this.loop = this.getIterationCount();
   		
  -		sub.resume();
           result.sampleStart();
  -        while (this.RUN && this.count(0) < loop) {
  +        while (this.RUN && this.count(0) < this.loop) {
               try {
  -                Thread.sleep(0,500);
  +                Thread.sleep(0,50);
               } catch (Exception e) {
  -                // e.printStackTrace();
  +                log.info(e.getMessage());
               }
           }
  -		sub.pause();
   		result.sampleEnd();
           result.setResponseMessage(loop + " samples messages recieved");
           if (this.getReadResponseAsBoolean()){
  @@ -197,16 +201,15 @@
   			this.initReceiveClient();
   			this.SUBSCRIBER.start();
   		}
  -		int loop = this.getIterationCount();
  -		this.SUBSCRIBER.setLoop(loop);
  +		this.loop = this.getIterationCount();
  +		this.SUBSCRIBER.setLoop(this.loop);
   		
  -		this.SUBSCRIBER.resume();
   		result.sampleStart();
  -		while (this.SUBSCRIBER.count(0) < loop) {
  +		while (this.SUBSCRIBER.count(0) < this.loop) {
   			try {
  -				Thread.sleep(1);
  +				Thread.sleep(0,50);
   			} catch (Exception e) {
  -				e.printStackTrace();
  +				log.info(e.getMessage());
   			}
   		}
   		result.sampleEnd();
  @@ -219,7 +222,7 @@
   		result.setSuccessful(true);
   		result.setResponseCode(loop + " message(s) recieved successfully");
   		result.setSamplerData("Not applicable");
  -		result.setSampleCount(loop);
  +		result.setSampleCount(this.loop);
   
   		this.SUBSCRIBER.clear();
   		this.SUBSCRIBER.resetCount();
  @@ -230,12 +233,15 @@
   	 * The sampler implements MessageListener directly and sets itself
   	 * as the listener with the TopicSubscriber.
   	 */
  -	public void onMessage(Message message){
  +	public synchronized void onMessage(Message message){
   		try {
   			if (message instanceof TextMessage){
   				TextMessage msg = (TextMessage)message;
  -				this.BUFFER.append(msg.getText());
  -				count(1);
  +				String content = msg.getText();
  +				if (content != null){
  +					this.BUFFER.append(content);
  +					count(1);
  +				}
   			}
   		} catch (JMSException e) {
   			log.error(e.getMessage());
  
  
  
  1.2       +1 -1      jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
  
  Index: PublisherSampler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PublisherSampler.java	28 Oct 2004 04:52:36 -0000	1.1
  +++ PublisherSampler.java	31 Oct 2004 05:08:59 -0000	1.2
  @@ -22,7 +22,6 @@
   import org.apache.jmeter.engine.event.LoopIterationEvent;
   
   import org.apache.jmeter.protocol.jms.client.ClientPool;
  -import org.apache.jmeter.protocol.jms.client.InitialContextFactory;
   import org.apache.jmeter.protocol.jms.client.Publisher;
   
   import org.apache.jorphan.logging.LoggingManager;
  @@ -94,6 +93,7 @@
       public synchronized void initClient() {
           this.PUB =
               new Publisher(
  +                this.getUseJNDIPropertiesAsBoolean(),
                   this.getJNDIInitialContextFactory(),
                   this.getProviderUrl(),
                   this.getConnectionFactory(),
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org