mstover1 2005/08/17 10:58:57
Modified: src/components/org/apache/jmeter/config CSVDataSet.java
src/core/org/apache/jmeter/services FileServer.java
src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog
LogFilter.java TCLogParser.java SessionFilter.java
Filter.java
src/core/org/apache/jmeter/engine StandardJMeterEngine.java
src/jorphan/org/apache/jorphan/util JOrphanUtils.java
src/protocol/http/org/apache/jmeter/protocol/http/sampler
AccessLogSampler.java
Added: src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog
SharedTCLogParser.java
OrderPreservingLogParser.java
test/src/org/apache/jorphan/util TestJorphanUtils.java
Log:
MERGE from 2-1
Revision Changes Path
1.6 +1 -1
jakarta-jmeter/src/components/org/apache/jmeter/config/CSVDataSet.java
Index: CSVDataSet.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/config/CSVDataSet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CSVDataSet.java 15 Aug 2005 20:33:08 -0000 1.5
+++ CSVDataSet.java 17 Aug 2005 17:58:56 -0000 1.6
@@ -62,7 +62,7 @@
String delim = getDelimiter();
if (delim.equals("\\t"))
delim = "\t";// Make it easier to enter a Tab
- String[] lineValues =
JOrphanUtils.split(server.readLine(getFilename()), delim);
+ String[] lineValues =
JOrphanUtils.split(server.readLine(getFilename()), delim,false);
for (int a = 0; a < vars.length && a <
lineValues.length; a++) {
this.getThreadContext().getVariables().put(vars[a], lineValues[a]);
}
1.10 +3 -3
jakarta-jmeter/src/core/org/apache/jmeter/services/FileServer.java
Index: FileServer.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/services/FileServer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FileServer.java 12 Jul 2005 20:51:08 -0000 1.9
+++ FileServer.java 17 Aug 2005 17:58:56 -0000 1.10
@@ -72,7 +72,6 @@
}
public void setBasedir(String basedir) throws IOException {
- log.info("Setting basedir to: " + basedir);
if (filesOpen()) {
throw new IOException("Files are still open, cannot
change base directory");
}
@@ -90,7 +89,6 @@
}
public synchronized void reserveFile(String filename) {
- log.info("filename = " + filename + " base = " + base);
if (!files.containsKey(filename)) {
Object[] file = new Object[] { new File(base,
filename), null };
files.put(filename, file);
@@ -151,7 +149,7 @@
*/
public synchronized void closeFile(String name) throws IOException {
Object[] file = (Object[]) files.get(name);
- if (file[1] != null) {
+ if (file != null && file.length == 2 && file[1] != null) {
((Reader) file[1]).close();
file[1] = null;
}
@@ -171,6 +169,8 @@
/**
* Method will get a random file in a base directory
+ * TODO hey, not sure this method belongs here. FileServer is for
threadsafe
+ * File access relative to current test's base directory.
*
* @param basedir
* @return
1.14 +9 -8
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/LogFilter.java
Index: LogFilter.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/LogFilter.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- LogFilter.java 12 Jul 2005 20:50:58 -0000 1.13
+++ LogFilter.java 17 Aug 2005 17:58:56 -0000 1.14
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
@@ -207,7 +208,7 @@
* @param path
* @return boolean
*/
- public boolean isFiltered(String path) {
+ public boolean isFiltered(String path,TestElement el) {
// we do a quick check to see if any
// filters are set. If not we just
// return false to be efficient.
@@ -474,7 +475,7 @@
public void testReplaceExtension() {
testf.setReplaceExtension("html", "jsp");
- testf.isFiltered(TESTSTR);// set the required variables
+ testf.isFiltered(TESTSTR,null);// set the required
variables
assertEquals(TESTSTROUT, testf.filter(TESTSTR));
}
@@ -485,7 +486,7 @@
String theFile = td.file;
boolean expect = td.exclfile;
- testf.isFiltered(theFile);
+ testf.isFiltered(theFile,null);
String line = testf.filter(theFile);
if (line != null) {
assertTrue("Expect to accept " +
theFile, expect);
@@ -502,7 +503,7 @@
String theFile = td.file;
boolean expect = td.inclfile;
- testf.isFiltered(theFile);
+ testf.isFiltered(theFile,null);
String line = testf.filter(theFile);
if (line != null) {
assertTrue("Expect to accept " +
theFile, expect);
@@ -520,7 +521,7 @@
String theFile = td.file;
boolean expect = td.exclpatt;
- assertEquals(!expect,
testf.isFiltered(theFile));
+ assertEquals(!expect,
testf.isFiltered(theFile,null));
String line = testf.filter(theFile);
if (line != null) {
assertTrue("Expect to accept " +
theFile, expect);
@@ -537,7 +538,7 @@
String theFile = td.file;
boolean expect = td.inclpatt;
- assertEquals(!expect,
testf.isFiltered(theFile));
+ assertEquals(!expect,
testf.isFiltered(theFile,null));
String line = testf.filter(theFile);
if (line != null) {
assertTrue("Expect to accept " +
theFile, expect);
1.21 +3 -3
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java
Index: TCLogParser.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- TCLogParser.java 12 Jul 2005 20:50:58 -0000 1.20
+++ TCLogParser.java 17 Aug 2005 17:58:56 -0000 1.21
@@ -244,7 +244,7 @@
el.setProperty(HTTPSamplerBase.METHOD, RMETHOD);
if (FILTER != null) {
log.debug("filter is not null");
- if (!FILTER.isFiltered(line)) {
+ if (!FILTER.isFiltered(line,el)) {
log.debug("line was not filtered");
// increment the current count
count++;
1.4 +97 -33
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/SessionFilter.java
Index: SessionFilter.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/SessionFilter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SessionFilter.java 12 Jul 2005 20:50:58 -0000 1.3
+++ SessionFilter.java 17 Aug 2005 17:58:56 -0000 1.4
@@ -21,11 +21,17 @@
package org.apache.jmeter.protocol.http.util.accesslog;
import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.jmeter.protocol.http.control.CookieManager;
+import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.testelement.TestCloneable;
+import org.apache.jmeter.testelement.TestElement;
+import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
@@ -37,37 +43,26 @@
* @author mstover
*
*/
-public class SessionFilter implements Filter, Serializable, TestCloneable {
+public class SessionFilter implements Filter, Serializable,
TestCloneable,ThreadListener {
+ private static final long serialVersionUID = 1;
static Logger log = LoggingManager.getLoggerForClass();
/**
- * This object is static across multiple threads in a test, via clone()
+ * These objects are static across multiple threads in a test, via
clone()
* method.
*/
- protected List excludedIps;
+ protected Map cookieManagers;
+ protected Set managersInUse;
+
+ protected CookieManager lastUsed;
- String ipAddress;
-
- /*
+ /*
* (non-Javadoc)
*
* @see
org.apache.jmeter.protocol.http.util.accesslog.LogFilter#excPattern(java.lang.String)
*/
protected boolean hasExcPattern(String text) {
- synchronized (excludedIps) {
- boolean exclude = false;
- for (Iterator x = excludedIps.iterator(); x.hasNext();)
{
- if (text.indexOf((String) x.next()) > -1) {
- exclude = true;
- break;
- }
- }
- if (!exclude) {
- ipAddress = getIpAddress(text);
- excludedIps.add(ipAddress);
- }
- return exclude;
- }
+ return false;
}
protected String getIpAddress(String logLine) {
@@ -84,12 +79,21 @@
* @see org.apache.jmeter.protocol.http.util.accesslog.Filter#reset()
*/
public void reset() {
- ipAddress = null;
+ cookieManagers.clear();
}
public Object clone() {
+ if(cookieManagers == null)
+ {
+ cookieManagers = Collections.synchronizedMap(new HashMap());
+ }
+ if(managersInUse == null)
+ {
+ managersInUse = Collections.synchronizedSet(new HashSet());
+ }
SessionFilter f = new SessionFilter();
- f.excludedIps = excludedIps;
+ f.cookieManagers = cookieManagers;
+ f.managersInUse = managersInUse;
return f;
}
@@ -97,7 +101,6 @@
*
*/
public SessionFilter() {
- excludedIps = new LinkedList();
}
/*
@@ -146,13 +149,55 @@
*
* @see
org.apache.jmeter.protocol.http.util.accesslog.Filter#isFiltered(java.lang.String)
*/
- public boolean isFiltered(String path) {
- if (ipAddress != null) {
- log.debug("looking for ip address: " + ipAddress + " in
line: " + path);
- return !(path.indexOf(ipAddress) > -1);
- } else
- return hasExcPattern(path);
- }
+ public boolean isFiltered(String path,TestElement sampler) {
+ String ipAddr = getIpAddress(path);
+ CookieManager cm = getCookieManager(ipAddr);
+ ((HTTPSampler)sampler).setCookieManager(cm);
+ return false;
+ }
+
+ protected CookieManager getCookieManager(String ipAddr)
+ {
+ CookieManager cm = null;
+ // First have to release the cookie we were using so other
+ // threads stuck in wait can move on
+ synchronized(managersInUse)
+ {
+ if(lastUsed != null)
+ {
+ managersInUse.remove(lastUsed);
+ managersInUse.notify();
+ }
+ }
+ // let notified threads move on and get lock on managersInUse
+ if(lastUsed != null)
+ {
+ Thread.yield();
+ }
+ // here is the core routine to find appropriate cookie manager and
+ // check it's not being used. If used, wait until whoever's using
it gives
+ // it up
+ synchronized(managersInUse)
+ {
+ cm = (CookieManager)cookieManagers.get(ipAddr);
+ if(cm == null)
+ {
+ cm = new CookieManager();
+ cookieManagers.put(ipAddr,cm);
+ }
+ while(managersInUse.contains(cm))
+ {
+ try {
+ managersInUse.wait();
+ } catch (InterruptedException e) {
+ log.info("SessionFilter wait interrupted");
+ }
+ }
+ managersInUse.add(cm);
+ lastUsed = cm;
+ }
+ return cm;
+ }
/*
* (non-Javadoc)
@@ -162,4 +207,23 @@
*/
public void setReplaceExtension(String oldextension, String
newextension) {
}
+
+ /* (non-Javadoc)
+ * @see org.apache.jmeter.testelement.ThreadListener#threadFinished()
+ */
+ public void threadFinished() {
+ synchronized(managersInUse)
+ {
+ managersInUse.remove(lastUsed);
+ managersInUse.notify();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jmeter.testelement.ThreadListener#threadStarted()
+ */
+ public void threadStarted() {
+ // TODO Auto-generated method stub
+
+ }
}
1.8 +5 -3
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/Filter.java
Index: Filter.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/Filter.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Filter.java 12 Jul 2005 20:50:58 -0000 1.7
+++ Filter.java 17 Aug 2005 17:58:56 -0000 1.8
@@ -18,6 +18,8 @@
package org.apache.jmeter.protocol.http.util.accesslog;
+import org.apache.jmeter.testelement.TestElement;
+
/**
* Description:<br>
* <br>
@@ -82,7 +84,7 @@
* @param path
* @return boolean
*/
- public boolean isFiltered(String path);
+ public boolean isFiltered(String path,TestElement sampler);
/**
* In case the user wants to replace the file extension, log parsers
should
1.2 +93 -0
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/SharedTCLogParser.java
1.2 +27 -0
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/OrderPreservingLogParser.java
1.61 +11 -6
jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
Index: StandardJMeterEngine.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- StandardJMeterEngine.java 12 Jul 2005 20:50:36 -0000 1.60
+++ StandardJMeterEngine.java 17 Aug 2005 17:58:56 -0000 1.61
@@ -204,6 +204,7 @@
}
protected void notifyTestListenersOfEnd() {
+ log.info("Notifying test listeners of end of test");
Iterator iter = testListeners.getSearchResults().iterator();
while (iter.hasNext()) {
TestListener tl = (TestListener) iter.next();
@@ -231,12 +232,16 @@
}
public synchronized void threadFinished(JMeterThread thread) {
- allThreads.remove(thread);
- log.info("Ending thread " + thread.getThreadNum());
- if (!serialized && allThreads.size() == 0 && !schcdule_run) {
- log.info("Stopping test");
- stopTest();
- }
+ try {
+ allThreads.remove(thread);
+ log.info("Ending thread " + thread.getThreadNum());
+ if (!serialized && allThreads.size() == 0 && !schcdule_run) {
+ log.info("Stopping test");
+ stopTest();
+ }
+ } catch (Throwable e) {
+ log.fatalError("Call to threadFinished should never throw an
exception - this can deadlock JMeter",e);
+ }
}
public synchronized void stopTest() {
1.2 +81 -0
jakarta-jmeter/test/src/org/apache/jorphan/util/TestJorphanUtils.java
1.16 +19 -59
jakarta-jmeter/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
Index: JOrphanUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- JOrphanUtils.java 12 Jul 2005 20:51:04 -0000 1.15
+++ JOrphanUtils.java 17 Aug 2005 17:58:57 -0000 1.16
@@ -61,15 +61,18 @@
* Character to split the string on
* @return Array of all the tokens.
*/
- public static String[] split(String splittee, String splitChar) {
+ public static String[] split(String splittee, String splitChar,boolean
truncate) {
if (splittee == null || splitChar == null) {
return new String[0];
}
int spot;
- while ((spot = splittee.indexOf(splitChar + splitChar)) != -1) {
- splittee = splittee.substring(0, spot +
splitChar.length())
- + splittee.substring(spot + 2 *
splitChar.length(), splittee.length());
- }
+ if(truncate) {
+ while ((spot = splittee.indexOf(splitChar + splitChar)) != -1) {
+ splittee = splittee.substring(0, spot +
splitChar.length())
+ + splittee.substring(spot + 2 *
splitChar.length(), splittee.length());
+ }
+ if(splittee.startsWith(splitChar)) splittee =
splittee.substring(splitChar.length());
+ }
Vector returns = new Vector();
int start = 0;
int length = splittee.length();
@@ -78,6 +81,10 @@
if (spot > 0) {
returns.addElement(splittee.substring(start,
spot));
}
+ else
+ {
+ returns.addElement("");
+ }
start = spot + splitChar.length();
}
if (start < length) {
@@ -87,6 +94,11 @@
returns.copyInto(values);
return values;
}
+
+ public static String[] split(String splittee,String splitChar)
+ {
+ return split(splittee,splitChar,true);
+ }
private static final String SPACES = "
";
@@ -280,56 +292,4 @@
return slice;
}
-
- public static class Test extends TestCase {
- public void testReplace1() {
- assertEquals("xyzdef", replaceFirst("abcdef", "abc",
"xyz"));
- }
-
- public void testReplace2() {
- assertEquals("axyzdef", replaceFirst("abcdef", "bc",
"xyz"));
- }
-
- public void testReplace3() {
- assertEquals("abcxyz", replaceFirst("abcdef", "def",
"xyz"));
- }
-
- public void testReplace4() {
- assertEquals("abcdef", replaceFirst("abcdef", "bce",
"xyz"));
- }
-
- public void testReplace5() {
- assertEquals("abcdef", replaceFirst("abcdef", "alt=\"\"
", ""));
- }
-
- public void testReplace6() {
- assertEquals("abcdef", replaceFirst("abcdef", "alt=\"\"
", ""));
- }
-
- public void testReplace7() {
- assertEquals("alt=\"\"", replaceFirst("alt=\"\"",
"alt=\"\" ", ""));
- }
-
- public void testReplace8() {
- assertEquals("img src=xyz ", replaceFirst("img src=xyz
alt=\"\" ", "alt=\"\" ", ""));
- }
-
- public void testSplit1() {
- String in = "a,bc,,"; // Test ignore trailing split
characters
- String out[] = split(in, ",");
- assertEquals(2, out.length);
- assertEquals("a", out[0]);
- assertEquals("bc", out[1]);
- }
-
- public void testSplit2() {
- String in = ",,a,bc"; // Test leading split characters
- String out[] = split(in, ",");
- assertEquals("Should detect the leading split chars; ",
2, out.length - 2);
- assertEquals("", out[0]);
- assertEquals("", out[1]);
- assertEquals("a", out[2]);
- assertEquals("bc", out[3]);
- }
- }
}
1.23 +32 -4
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/AccessLogSampler.java
Index: AccessLogSampler.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/AccessLogSampler.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- AccessLogSampler.java 11 Aug 2005 21:58:26 -0000 1.22
+++ AccessLogSampler.java 17 Aug 2005 17:58:57 -0000 1.23
@@ -25,6 +25,7 @@
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jmeter.testelement.TestCloneable;
+import org.apache.jmeter.testelement.ThreadListener;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JMeterException;
@@ -65,7 +66,7 @@
* @author Peter Lin
* @version $Revision$ last updated $Date$
*/
-public class AccessLogSampler extends HTTPSampler implements TestBean {
+public class AccessLogSampler extends HTTPSampler implements
TestBean,ThreadListener {
private static Logger log = LoggingManager.getLoggerForClass();
public static final String DEFAULT_CLASS =
"org.apache.jmeter.protocol.http.util.accesslog.TCLogParser";
@@ -295,8 +296,16 @@
if
(TestCloneable.class.isAssignableFrom(Class.forName(filterClassName))) {
initFilter();
s.filter = (Filter)
((TestCloneable) filter).clone();
- instantiateParser();
}
+
if(TestCloneable.class.isAssignableFrom(Class.forName(parserClassName)))
+ {
+ instantiateParser();
+ s.PARSER =
(LogParser)((TestCloneable)PARSER).clone();
+ if(filter != null)
+ {
+ s.PARSER.setFilter(s.filter);
+ }
+ }
} catch (Exception e) {
log.warn("Could not clone cloneable
filter", e);
}
@@ -314,6 +323,7 @@
if (PARSER != null) {
PARSER.close();
}
+ filter = null;
started = false;
super.testEnded();
}
@@ -327,4 +337,22 @@
started = true;
super.testStarted();
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.jmeter.testelement.AbstractTestElement#threadFinished()
+ */
+ public void threadFinished() {
+ if(PARSER instanceof ThreadListener)
+ ((ThreadListener)PARSER).threadFinished();
+ if(filter instanceof ThreadListener)
+ ((ThreadListener)filter).threadFinished();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.jmeter.testelement.ThreadListener#threadStarted()
+ */
+ public void threadStarted() {
+ // TODO Auto-generated method stub
+
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]