use of org.apache.jmeter.services.FileServer in project jmeter by apache.
the class SharedTCLogParser method parse.
/**
* {@inheritDoc}
*/
@Override
public int parse(TestElement el, int parseCount) {
FileServer fileServer = FileServer.getFileServer();
fileServer.reserveFile(FILENAME);
try {
return parse(fileServer, el, parseCount);
} catch (Exception exception) {
log.error("Problem creating samples", exception);
}
// indicate that an error occurred
return -1;
}
use of org.apache.jmeter.services.FileServer in project jmeter by apache.
the class CSVDataSet method iterationStart.
@Override
public void iterationStart(LoopIterationEvent iterEvent) {
FileServer server = FileServer.getFileServer();
final JMeterContext context = getThreadContext();
String delim = getDelimiter();
if ("\\t".equals(delim)) {
// $NON-NLS-1$
// Make it easier to enter a Tab // $NON-NLS-1$
delim = "\t";
} else if (delim.isEmpty()) {
log.debug("Empty delimiter, will use ','");
delim = ",";
}
if (vars == null) {
String fileName = getFilename().trim();
String mode = getShareMode();
int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode);
switch(modeInt) {
case CSVDataSetBeanInfo.SHARE_ALL:
alias = fileName;
break;
case CSVDataSetBeanInfo.SHARE_GROUP:
alias = fileName + "@" + System.identityHashCode(context.getThreadGroup());
break;
case CSVDataSetBeanInfo.SHARE_THREAD:
alias = fileName + "@" + System.identityHashCode(context.getThread());
break;
default:
// user-specified key
alias = fileName + "@" + mode;
break;
}
final String names = getVariableNames();
if (StringUtils.isEmpty(names)) {
String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
try {
vars = CSVSaveService.csvSplitString(header, delim.charAt(0));
firstLineIsNames = true;
} catch (IOException e) {
throw new IllegalArgumentException("Could not split CSV header line from file:" + fileName, e);
}
} else {
server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
// $NON-NLS-1$
vars = JOrphanUtils.split(names, ",");
}
trimVarNames(vars);
}
// TODO: fetch this once as per vars above?
JMeterVariables threadVars = context.getVariables();
String[] lineValues = {};
try {
if (getQuotedData()) {
lineValues = server.getParsedLine(alias, recycle, firstLineIsNames || ignoreFirstLine, delim.charAt(0));
} else {
String line = server.readLine(alias, recycle, firstLineIsNames || ignoreFirstLine);
lineValues = JOrphanUtils.split(line, delim, false);
}
for (int a = 0; a < vars.length && a < lineValues.length; a++) {
threadVars.put(vars[a], lineValues[a]);
}
} catch (IOException e) {
// treat the same as EOF
log.error(e.toString());
}
if (lineValues.length == 0) {
// i.e. EOF
if (getStopThread()) {
throw new JMeterStopThreadException("End of file:" + getFilename() + " detected for CSV DataSet:" + getName() + " configured with stopThread:" + getStopThread() + ", recycle:" + getRecycle());
}
for (String var : vars) {
threadVars.put(var, EOFVALUE);
}
}
}
Aggregations