Skip to content

Commit

Permalink
Parallelised unit tests
Browse files Browse the repository at this point in the history
Contributed by Graham Russell
This closes #350

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1817424 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pmouawad committed Dec 7, 2017
1 parent a84a2ad commit 32c5b11
Show file tree
Hide file tree
Showing 24 changed files with 616 additions and 558 deletions.
57 changes: 24 additions & 33 deletions src/core/org/apache/jmeter/services/FileServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*
*/

/*
* Created on Oct 19, 2004
*/
package org.apache.jmeter.services;

import java.io.BufferedReader;
Expand Down Expand Up @@ -46,8 +43,7 @@
import org.slf4j.LoggerFactory;

/**
*
* The point of this class is to provide thread-safe access to files, and to
* This class provides thread-safe access to files, and to
* provide some simplifying assumptions about where to find files and how to
* name them. For instance, putting supporting files in the same directory as
* the saved test plan file allows users to refer to the file with just it's
Expand Down Expand Up @@ -378,13 +374,13 @@ public synchronized String[] getParsedLine(String alias, boolean recycle, boolea
}

/**
* Return BufferedReader handling close if EOF reached and recycle is true
* Return BufferedReader handling close if EOF reached and recycle is true
* and ignoring first line if ignoreFirstLine is true
* @param alias String alias
* @param recycle Recycle at eof
*
* @param alias String alias
* @param recycle Recycle at eof
* @param ignoreFirstLine Ignore first line
* @return {@link BufferedReader}
* @throws IOException
*/
private BufferedReader getReader(String alias, boolean recycle, boolean ignoreFirstLine) throws IOException {
FileEntry fileEntry = files.get(alias);
Expand All @@ -396,7 +392,7 @@ private BufferedReader getReader(String alias, boolean recycle, boolean ignoreFi
if (ignoreFirstLine) {
// read first line and forget
reader.readLine(); //NOSONAR
}
}
} else if (!(fileEntry.inputOutputObject instanceof Reader)) {
throw new IOException("File " + alias + " already in use");
} else {
Expand All @@ -411,7 +407,7 @@ private BufferedReader getReader(String alias, boolean recycle, boolean ignoreFi
if (ignoreFirstLine) {
// read first line and forget
reader.readLine(); //NOSONAR
}
}
} else { // OK, we still have some data, restore it
reader.reset();
}
Expand Down Expand Up @@ -457,7 +453,7 @@ public synchronized void write(String filename, String value) throws IOException

private BufferedWriter createBufferedWriter(FileEntry fileEntry) throws IOException {
FileOutputStream fos = new FileOutputStream(fileEntry.file);
OutputStreamWriter osw = null;
OutputStreamWriter osw;
// If file encoding is specified, write using that encoding, otherwise use default platform encoding
String charsetName = fileEntry.charSetEncoding;
if(!JOrphanUtils.isBlank(charsetName)) {
Expand Down Expand Up @@ -493,28 +489,21 @@ private void closeFile(String name, FileEntry fileEntry) throws IOException {
}

boolean filesOpen() { // package access for test code only
for (FileEntry fileEntry : files.values()) {
if (fileEntry.inputOutputObject != null) {
return true;
}
}
return false;
return files.values().stream()
.anyMatch(fileEntry -> fileEntry.inputOutputObject != null);
}

/**
* Method will get a random file in a base directory
* Method will get a random file in a base directory
* <p>
* TODO hey, not sure this
* method belongs here. FileServer is for threadsafe File access relative to
* current test's base directory.
* TODO hey, not sure this method belongs here.
* FileServer is for thread safe File access relative to current test's base directory.
*
* @param basedir
* name of the directory in which the files can be found
* @param extensions
* array of allowed extensions, if <code>null</code> is given,
* any file be allowed
* @param basedir name of the directory in which the files can be found
* @param extensions array of allowed extensions, if <code>null</code> is given,
* any file be allowed
* @return a random File from the <code>basedir</code> that matches one of
* the extensions
* the extensions
*/
public File getRandomFile(String basedir, String[] extensions) {
File input = null;
Expand All @@ -533,8 +522,9 @@ public File getRandomFile(String basedir, String[] extensions) {
/**
* Get {@link File} instance for provided file path,
* resolve file location relative to base dir or script dir when needed
*
* @param path original path to file, maybe relative
* @return {@link File} instance
* @return {@link File} instance
*/
public File getResolvedFile(String path) {
reserveFile(path);
Expand All @@ -547,10 +537,11 @@ private static class FileEntry{
private final File file;
private Closeable inputOutputObject;
private final String charSetEncoding;
FileEntry(File f, Closeable o, String e){
file=f;
inputOutputObject=o;
charSetEncoding=e;

FileEntry(File f, Closeable o, String e) {
file = f;
inputOutputObject = o;
charSetEncoding = e;
}
}

Expand Down
Loading

0 comments on commit 32c5b11

Please sign in to comment.