cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
woolfel 2005/08/11 15:05:21 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2-1 TCPSampler.java Log: applying bug fix from HEAD to 2.1 branch peter Revision ChangesPath No revision No revision 1.12.2.1 +34 -85 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- TCPSampler.java 12 Jul 2005 20:50:55 - 1.12 +++ TCPSampler.java 11 Aug 2005 22:05:21 - 1.12.2.1 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004 The Apache Software Foundation. + * Copyright 2003-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,19 +26,15 @@ import java.net.Socket; import java.net.UnknownHostException; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Properties; -import java.util.Set; import org.apache.jmeter.config.ConfigTestElement; import org.apache.jmeter.util.JMeterUtils; -import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.samplers.AbstractSampler; import org.apache.jmeter.samplers.Entry; import org.apache.jmeter.samplers.SampleResult; -import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jorphan.logging.LoggingManager; import org.apache.log.Logger; @@ -46,7 +42,7 @@ * A sampler which understands Tcp requests. * */ -public class TCPSampler extends AbstractSampler implements TestListener { +public class TCPSampler extends AbstractSampler implements ThreadListener { private static final Logger log = LoggingManager.getLoggerForClass(); public final static String SERVER = "TCPSampler.server"; //$NON-NLS-1$ @@ -67,9 +63,6 @@ private final static String ERRKEY = "ERR"; //$NON-NLS-1$ key for HashMap - private static Set allSockets = new HashSet();// Keep track of connections - // to allow close - // If set, this is the regex that is used to extract the status from the // response // NOT implemented yet private final static String STATUS_REGEX = @@ -142,7 +135,6 @@ log.debug(this + " Timeout " + getTimeout() + " NoDelay " + getNoDelay()); //$NON-NLS-1$ log.debug("Created new connection " + con); //$NON-NLS-1$ cp.put(TCPKEY, con); - allSockets.add(con);// Save so can be closed } catch (UnknownHostException e) { log.warn("Unknown host for " + getLabel(), e);//$NON-NLS-1$ cp.put(ERRKEY, e.toString()); @@ -302,22 +294,23 @@ } } } - } catch (Exception ex) { + } catch (IOException ex) { log.debug("", ex); res.setResponseCode("500"); res.setResponseMessage(ex.toString()); - } - - // Calculate response time - res.sampleEnd(); - - // Set if we were successful or not - res.setSuccessful(isSuccessful); +closeSocket(); + } finally { + // Calculate response time + res.sampleEnd(); + + // Set if we were successful or not + res.setSuccessful(isSuccessful); +} return res; } - /** +/** * @param rc *response code * @return whether this represents success or not @@ -332,69 +325,25 @@ return true; } - private void disconnectAll() { - synchronized (allSockets) { - Iterator i = allSockets.iterator(); - while (i.hasNext()) { - Socket socket = (Socket) i.next(); - try { - socket.close(); - } catch (IOException e) { - log.warn("Error closing socket ", e); - } finally { - i.remove(); -
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2005/08/06 10:10:02 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Only share sockets with the same host and port Revision ChangesPath 1.15 +32 -22 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- TCPSampler.java 4 Aug 2005 23:48:08 - 1.14 +++ TCPSampler.java 6 Aug 2005 17:10:02 - 1.15 @@ -59,10 +59,6 @@ public final static String REQUEST = "TCPSampler.request"; //$NON-NLS-1$ - private final static String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap - - private final static String ERRKEY = "ERR"; //$NON-NLS-1$ key for HashMap - // If set, this is the regex that is used to extract the status from the // response // NOT implemented yet private final static String STATUS_REGEX = @@ -98,7 +94,11 @@ } } - /** the cache of TCP Connections */ + /* + * The cache of TCP Connections - key is "hostname:port". + * The hostname is used as-is - no case conversion is done. + * This allows for more than one connection to a single host if required. + */ private static ThreadLocal tp = new ThreadLocal() { protected Object initialValue() { return new HashMap(); @@ -106,6 +106,13 @@ }; private transient TCPClient protocolHandler; + +private transient String hashKey=null; // key for cache + +// Must save host details in case need to re-establish connection +private transient String hostName=null; +private transient int portNumber=-1; +private transient Exception except=null; // Used to pass back error from getSocket() public TCPSampler() { log.debug("Created " + this); @@ -113,14 +120,16 @@ log.debug("Using Protocol Handler: " + protocolHandler.getClass().getName()); } - private String getError() { - Map cp = (Map) tp.get(); - return (String) cp.get(ERRKEY); - } - private Socket getSocket() { +// Is this the first call? If so, set up the socket details +if (hashKey == null){ +hostName = getServer(); +portNumber = getPort(); +hashKey=hostName + ":" + portNumber; +log.debug("Initialising socket "+hashKey); +} Map cp = (Map) tp.get(); - Socket con = (Socket) cp.get(TCPKEY); + Socket con = (Socket) cp.get(hashKey); if (con != null) { log.debug(this + " Reusing connection " + con); //$NON-NLS-1$ return con; @@ -128,19 +137,19 @@ // Not in cache, so create new one and cache it try { - con = new Socket(getServer(), getPort()); + con = new Socket(hostName, portNumber); con.setSoTimeout(getTimeout()); con.setTcpNoDelay(getNoDelay()); log.debug(this + " Timeout " + getTimeout() + " NoDelay " + getNoDelay()); //$NON-NLS-1$ log.debug("Created new connection " + con); //$NON-NLS-1$ - cp.put(TCPKEY, con); + cp.put(hashKey, con); } catch (UnknownHostException e) { log.warn("Unknown host for " + getLabel(), e);//$NON-NLS-1$ - cp.put(ERRKEY, e.toString()); +except=e; } catch (IOException e) { log.warn("Could not create socket for " + getLabel(), e); //$NON-NLS-1$ - cp.put(ERRKEY, e.toString()); +except=e; } return con; } @@ -260,7 +269,7 @@ Socket sock = getSocket(); if (sock == null) { res.setResponseCode("500"); - res.setResponseMessage(getError()); + res.setResponseMessage(except.toString()); } else { InputStream is = sock.getInputStream(); OutputStream os = sock.getOutputStream(); @@ -295,7 +304,7 @@ } } } catch (IOException ex) { - log.debug("", ex); + log.debug(getName(), ex);
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2005/08/04 16:48:08 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Close socket if an error is encountered Revision ChangesPath 1.14 +15 -11 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- TCPSampler.java 4 Aug 2005 23:30:47 - 1.13 +++ TCPSampler.java 4 Aug 2005 23:48:08 - 1.14 @@ -294,22 +294,23 @@ } } } - } catch (Exception ex) { + } catch (IOException ex) { log.debug("", ex); res.setResponseCode("500"); res.setResponseMessage(ex.toString()); - } - - // Calculate response time - res.sampleEnd(); - - // Set if we were successful or not - res.setSuccessful(isSuccessful); +closeSocket(); + } finally { + // Calculate response time + res.sampleEnd(); + + // Set if we were successful or not + res.setSuccessful(isSuccessful); +} return res; } - /** +/** * @param rc *response code * @return whether this represents success or not @@ -328,8 +329,7 @@ log.debug("Thread Started"); } -public void threadFinished() { -log.debug("Thread Finished"); +private void closeSocket() { Map cp = (Map) tp.get(); Socket con = (Socket) cp.remove(TCPKEY); if (con != null) { @@ -340,6 +340,10 @@ log.warn("Error closing socket "+e); } } +} +public void threadFinished() { +log.debug("Thread Finished"); +closeSocket(); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2005/08/04 16:30:47 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Use ThreadListener rather than TestListener to close socket at end Revision ChangesPath 1.13 +20 -75 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- TCPSampler.java 12 Jul 2005 20:50:55 - 1.12 +++ TCPSampler.java 4 Aug 2005 23:30:47 - 1.13 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004 The Apache Software Foundation. + * Copyright 2003-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,19 +26,15 @@ import java.net.Socket; import java.net.UnknownHostException; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.Map; import java.util.Properties; -import java.util.Set; import org.apache.jmeter.config.ConfigTestElement; import org.apache.jmeter.util.JMeterUtils; -import org.apache.jmeter.engine.event.LoopIterationEvent; import org.apache.jmeter.samplers.AbstractSampler; import org.apache.jmeter.samplers.Entry; import org.apache.jmeter.samplers.SampleResult; -import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jorphan.logging.LoggingManager; import org.apache.log.Logger; @@ -46,7 +42,7 @@ * A sampler which understands Tcp requests. * */ -public class TCPSampler extends AbstractSampler implements TestListener { +public class TCPSampler extends AbstractSampler implements ThreadListener { private static final Logger log = LoggingManager.getLoggerForClass(); public final static String SERVER = "TCPSampler.server"; //$NON-NLS-1$ @@ -67,9 +63,6 @@ private final static String ERRKEY = "ERR"; //$NON-NLS-1$ key for HashMap - private static Set allSockets = new HashSet();// Keep track of connections - // to allow close - // If set, this is the regex that is used to extract the status from the // response // NOT implemented yet private final static String STATUS_REGEX = @@ -142,7 +135,6 @@ log.debug(this + " Timeout " + getTimeout() + " NoDelay " + getNoDelay()); //$NON-NLS-1$ log.debug("Created new connection " + con); //$NON-NLS-1$ cp.put(TCPKEY, con); - allSockets.add(con);// Save so can be closed } catch (UnknownHostException e) { log.warn("Unknown host for " + getLabel(), e);//$NON-NLS-1$ cp.put(ERRKEY, e.toString()); @@ -332,69 +324,22 @@ return true; } - private void disconnectAll() { - synchronized (allSockets) { - Iterator i = allSockets.iterator(); - while (i.hasNext()) { - Socket socket = (Socket) i.next(); - try { - socket.close(); - } catch (IOException e) { - log.warn("Error closing socket ", e); - } finally { - i.remove(); - } - } - } - } - - /* - * (non-Javadoc) - * - * @see org.apache.jmeter.testelement.TestListener#testStarted() - */ - public void testStarted() // Only called once per class? - { - log.debug(this + " test started"); - } +public void threadStarted() { +log.debug("Thread Started"); +} + +public void threadFinished() { +log.debug("Thread Finished"); +Map cp = (Map) tp.get(); +Socket con = (Socket) cp.remove(TCPKEY); +if (con != null) { +log.debug(this + " Closing connection " + con); //$NON-NLS-1$ +try { +con.close(); +} catch (IOException e) { +log.warn("Error closing socket "+e); +} +} - /* - * (non-Javadoc) - * - * @see org.apache.jmeter.testelement.TestListener#testEnded() - */ - public void testEnded() // Only called once per c
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2005/03/20 13:20:54 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Minor tidy up Revision ChangesPath 1.11 +1 -5 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- TCPSampler.java 6 Oct 2004 14:43:56 - 1.10 +++ TCPSampler.java 20 Mar 2005 21:20:54 - 1.11 @@ -122,7 +122,7 @@ Socket con = (Socket) cp.get(TCPKEY); if (con != null) { log.debug(this+" Reusing connection "+con); //$NON-NLS-1$ - return (Socket) con; + return con; } // Not in cache, so create new one and cache it @@ -419,8 +419,6 @@ public void testStarted(String host) { log.debug(this+" test started on "+host); -// TODO Auto-generated method stub - } /* (non-Javadoc) @@ -439,7 +437,5 @@ public void testIterationStart(LoopIterationEvent event) { log.debug(this+" test iteration start on "+event.getIteration()); -// TODO Auto-generated method stub - } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/10/05 18:56:56 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Show sampler data Revision ChangesPath No revision No revision 1.5.2.7 +3 -2 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5.2.6 retrieving revision 1.5.2.7 diff -u -r1.5.2.6 -r1.5.2.7 --- TCPSampler.java 9 Aug 2004 17:58:31 - 1.5.2.6 +++ TCPSampler.java 6 Oct 2004 01:56:56 - 1.5.2.7 @@ -294,6 +294,7 @@ SampleResult res = new SampleResult(); boolean isSuccessful = false; res.setSampleLabel(getName());//Use the test element name for the label +res.setSamplerData("Host: "+getServer()+" Port: "+getPort()); res.sampleStart(); try { - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/08/09 10:58:43 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Change info message to debug Revision ChangesPath 1.9 +1 -1 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TCPSampler.java 12 Jun 2004 17:11:45 - 1.8 +++ TCPSampler.java 9 Aug 2004 17:58:43 - 1.9 @@ -288,7 +288,7 @@ public SampleResult sample(Entry e)// Entry tends to be ignored ... { - log.info(getLabel()+" "+getFilename()+" "+getUsername()+" "+getPassword()); + log.debug(getLabel()+" "+getFilename()+" "+getUsername()+" "+getPassword()); SampleResult res = new SampleResult(); boolean isSuccessful = false; res.setSampleLabel(getName());//Use the test element name for the label - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/08/09 10:58:31 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Change info message to debug Revision ChangesPath No revision No revision 1.5.2.6 +3 -3 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5.2.5 retrieving revision 1.5.2.6 diff -u -r1.5.2.5 -r1.5.2.6 --- TCPSampler.java 12 Jun 2004 20:30:47 - 1.5.2.5 +++ TCPSampler.java 9 Aug 2004 17:58:31 - 1.5.2.6 @@ -290,7 +290,7 @@ public SampleResult sample(Entry e)// Entry tends to be ignored ... { - log.info(getLabel()+" "+getFilename()+" "+getUsername()+" "+getPassword()); + log.debug(getLabel()+" "+getFilename()+" "+getUsername()+" "+getPassword()); SampleResult res = new SampleResult(); boolean isSuccessful = false; res.setSampleLabel(getName());//Use the test element name for the label - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/06/12 13:30:47 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Make log final and private Revision ChangesPath No revision No revision 1.5.2.5 +3 -3 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5.2.4 retrieving revision 1.5.2.5 diff -u -r1.5.2.4 -r1.5.2.5 --- TCPSampler.java 10 Jun 2004 23:02:07 - 1.5.2.4 +++ TCPSampler.java 12 Jun 2004 20:30:47 - 1.5.2.5 @@ -50,7 +50,7 @@ */ public class TCPSampler extends AbstractSampler implements TestListener { - protected static Logger log = LoggingManager.getLoggerForClass(); + private static final Logger log = LoggingManager.getLoggerForClass(); public final static String SERVER = "TCPSampler.server"; //$NON-NLS-1$ public final static String PORT = "TCPSampler.port"; //$NON-NLS-1$ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/06/10 16:02:07 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Use test element name for the label Revision ChangesPath No revision No revision 1.5.2.4 +3 -3 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5.2.3 retrieving revision 1.5.2.4 diff -u -r1.5.2.3 -r1.5.2.4 --- TCPSampler.java 10 Jun 2004 15:21:14 - 1.5.2.3 +++ TCPSampler.java 10 Jun 2004 23:02:07 - 1.5.2.4 @@ -293,7 +293,7 @@ log.info(getLabel()+" "+getFilename()+" "+getUsername()+" "+getPassword()); SampleResult res = new SampleResult(); boolean isSuccessful = false; -res.setSampleLabel(getLabel()); +res.setSampleLabel(getName());//Use the test element name for the label res.sampleStart(); try { - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/06/10 08:21:15 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Added: status extraction; property file for translation statuses Revision ChangesPath No revision No revision 1.5.2.3 +85 -7 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5.2.2 retrieving revision 1.5.2.3 diff -u -r1.5.2.2 -r1.5.2.3 --- TCPSampler.java 2 Apr 2004 22:56:50 - 1.5.2.2 +++ TCPSampler.java 10 Jun 2004 15:21:14 - 1.5.2.3 @@ -18,6 +18,9 @@ package org.apache.jmeter.protocol.tcp.sampler; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -27,6 +30,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Properties; import java.util.Set; import org.apache.jmeter.config.ConfigTestElement; @@ -61,6 +65,38 @@ private static Set allSockets = new HashSet();// Keep track of connections to allow close + // If set, this is the regex that is used to extract the status from the response + //NOT implemented yet private final static String STATUS_REGEX = JMeterUtils.getPropDefault("tcp.status.regex",""); + + // Otherwise, the response is scanned for these strings + private final static String STATUS_PREFIX = JMeterUtils.getPropDefault("tcp.status.prefix",""); + private final static String STATUS_SUFFIX = JMeterUtils.getPropDefault("tcp.status.suffix",""); + + private final static String STATUS_PROPERTIES = JMeterUtils.getPropDefault("tcp.status.properties",""); + private final static Properties statusProps = new Properties(); + private static boolean haveStatusProps = false; + + static + { + log.info("Protocol Handler name="+getClassname()); + log.info("Status prefix="+STATUS_PREFIX); + log.info("Status suffix="+STATUS_SUFFIX); + log.info("Status properties="+STATUS_PROPERTIES); + if (STATUS_PROPERTIES.length()>0) + { + File f = new File(STATUS_PROPERTIES); + try { + statusProps.load(new FileInputStream(f)); + log.info("Successfully loaded properties"); + haveStatusProps = true; + } catch (FileNotFoundException e) { + log.info("Property file not found"); + } catch (IOException e) { + log.info("Property file error "+e.toString()); + } + } + } + /** the cache of TCP Connections */ private static ThreadLocal tp = new ThreadLocal(){ protected Object initialValue(){ @@ -74,6 +110,8 @@ { log.debug("Created "+this); protocolHandler=getProtocol(); + log.debug("Using Protocol Handler: " + +protocolHandler.getClass().getName()); } private String getError(){ @@ -196,7 +234,7 @@ return ("tcp://" + this.getServer() + ":" + this.getPort());//$NON-NLS-1$ } - private String getClassname() + private static String getClassname() { String className = JMeterUtils.getPropDefault("tcp.handler","TCPClientImpl"); return className; @@ -276,6 +314,33 @@ res.setResponseCode("200"); res.setResponseMessage("OK"); isSuccessful = true; + //Reset the status code if the message contains one + if (STATUS_PREFIX.length() > 0) + { + int i = in.indexOf(STATUS_PREFIX); + int j = in.indexOf(STATUS_SUFFIX,i+STATUS_PREFIX.length()); + if (i != -1 && j > i) + { + String rc = in.substring(i+STATUS_PREFIX.length(),j); + res.setResponseCode(rc); + isSuccessful = checkResponseCode(rc); + if (haveStatusProps) + { + res.setResponseMessage( + statusProps.getProperty(rc,"Status code not found in properties")); +
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/06/06 15:27:39 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Make log final and private Revision ChangesPath 1.7 +3 -3 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TCPSampler.java 16 Apr 2004 13:21:45 - 1.6 +++ TCPSampler.java 6 Jun 2004 22:27:39 - 1.7 @@ -46,7 +46,7 @@ */ public class TCPSampler extends AbstractSampler implements TestListener { - protected static Logger log = LoggingManager.getLoggerForClass(); + private static final Logger log = LoggingManager.getLoggerForClass(); public final static String SERVER = "TCPSampler.server"; //$NON-NLS-1$ public final static String PORT = "TCPSampler.port"; //$NON-NLS-1$ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/04/02 14:56:51 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Make handler transient Revision ChangesPath No revision No revision 1.5.2.2 +3 -3 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -r1.5.2.1 -r1.5.2.2 --- TCPSampler.java 2 Apr 2004 22:45:49 - 1.5.2.1 +++ TCPSampler.java 2 Apr 2004 22:56:50 - 1.5.2.2 @@ -68,7 +68,7 @@ } }; - private TCPClient protocolHandler; + private transient TCPClient protocolHandler; public TCPSampler() { - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2004/04/02 14:45:49 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler Tag: rel-2_0 TCPSampler.java Log: Use requestData; only instantiate handler once Revision ChangesPath No revision No revision 1.5.2.1 +25 -9 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- TCPSampler.java 30 Mar 2004 18:07:37 - 1.5 +++ TCPSampler.java 2 Apr 2004 22:45:49 - 1.5.2.1 @@ -54,6 +54,7 @@ public final static String CLASSNAME = "TCPSampler.classname";//$NON-NLS-1$ public final static String NODELAY= "TCPSampler.nodelay"; //$NON-NLS-1$ public final static String TIMEOUT= "TCPSampler.timeout"; //$NON-NLS-1$ + public final static String REQUEST= "TCPSampler.request"; //$NON-NLS-1$ private final static String TCPKEY = "TCP"; //$NON-NLS-1$ key for HashMap private final static String ERRKEY = "ERR"; //$NON-NLS-1$ key for HashMap @@ -67,9 +68,12 @@ } }; + private TCPClient protocolHandler; + public TCPSampler() { log.debug("Created "+this); + protocolHandler=getProtocol(); } private String getError(){ @@ -147,6 +151,17 @@ } + public void setRequestData(String newRequestData) + { + this.setProperty(REQUEST, newRequestData); + } + + public String getRequestData() + { + return getPropertyAsString(REQUEST); + } + + public void setTimeout(String newTimeout) { this.setProperty(FILENAME, newTimeout); @@ -161,6 +176,7 @@ { this.setProperty(NODELAY, newNoDelay); } + public boolean getNoDelay() { return getPropertyAsBoolean(NODELAY); @@ -211,12 +227,12 @@ } -private Object getProtocol(){ - Object TCPClient = null; +private TCPClient getProtocol(){ + TCPClient TCPClient = null; Class javaClass = getClass(getClassname()); try { - TCPClient = javaClass.newInstance(); + TCPClient = (TCPClient) javaClass.newInstance(); if (log.isDebugEnabled()) { log.debug(this @@ -250,11 +266,11 @@ } else { InputStream is = sock.getInputStream(); OutputStream os = sock.getOutputStream(); - TCPClient proto = (TCPClient) getProtocol(); - log.debug("Found class "+ proto.toString()); - String req=proto.write(os); + String req = getRequestData(); + //TODO handle filenames res.setSamplerData(req); - String in = proto.read(is); + protocolHandler.write(os,req); + String in = protocolHandler.read(is); res.setResponseData(in.getBytes()); res.setDataType(SampleResult.TEXT); res.setResponseCode("200"); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java
sebb2003/12/19 16:58:22 Modified:src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler TCPSampler.java Log: Use sampleStart/End instead of setTime Revision ChangesPath 1.2 +3 -4 jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java Index: TCPSampler.java === RCS file: /home/cvs/jakarta-jmeter/src/protocol/tcp/org/apache/jmeter/protocol/tcp/sampler/TCPSampler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TCPSampler.java 16 Nov 2003 02:09:06 - 1.1 +++ TCPSampler.java 20 Dec 2003 00:58:22 - 1.2 @@ -222,7 +222,7 @@ SampleResult res = new SampleResult(); boolean isSuccessful = false; res.setSampleLabel(getLabel()); -long start = System.currentTimeMillis(); +res.sampleStart(); try { Socket sock = getSocket(); @@ -252,8 +252,7 @@ } // Calculate response time -long end = System.currentTimeMillis(); -res.setTime(end - start); +res.sampleEnd(); // Set if we were successful or not res.setSuccessful(isSuccessful); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]