Search in sources :

Example 1 with FileServer

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;
}
Also used : FileServer(org.apache.jmeter.services.FileServer) IOException(java.io.IOException)

Example 2 with FileServer

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);
        }
    }
}
Also used : JMeterStopThreadException(org.apache.jorphan.util.JMeterStopThreadException) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) IOException(java.io.IOException) FileServer(org.apache.jmeter.services.FileServer)

Aggregations

IOException (java.io.IOException)2 FileServer (org.apache.jmeter.services.FileServer)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)1