refactor(接口测试): CSV隔离加载的同时兼容CSVRead函数取值 #26821
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
1770b7cc2d
commit
8b4c8f56c5
|
@ -236,6 +236,10 @@ public class FileServer {
|
||||||
reserveFile(filename, charsetName, alias, false);
|
reserveFile(filename, charsetName, alias, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasThreadContext() {
|
||||||
|
return JMeterContextService.getContext() != null && JMeterContextService.getContext().getThread() != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an association between a filename and a File inputOutputObject,
|
* Creates an association between a filename and a File inputOutputObject,
|
||||||
* and stores it for later use - unless it is already stored.
|
* and stores it for later use - unless it is already stored.
|
||||||
|
@ -259,10 +263,11 @@ public class FileServer {
|
||||||
log.error("file does not exist [ " + filename + " ]");
|
log.error("file does not exist [ " + filename + " ]");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
if (hasThreadContext()) {
|
||||||
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
||||||
if (!StringUtils.contains(alias, threadName)) {
|
if (!StringUtils.contains(alias, threadName)) {
|
||||||
alias = StringUtils.join(threadName, alias);
|
alias = StringUtils.join(threadName, alias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FileEntry fileEntry = files.get(alias);
|
FileEntry fileEntry = files.get(alias);
|
||||||
if (fileEntry == null) {
|
if (fileEntry == null) {
|
||||||
|
@ -342,11 +347,12 @@ public class FileServer {
|
||||||
*/
|
*/
|
||||||
public synchronized String readLine(String filename, boolean recycle,
|
public synchronized String readLine(String filename, boolean recycle,
|
||||||
boolean ignoreFirstLine) throws IOException {
|
boolean ignoreFirstLine) throws IOException {
|
||||||
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
if (hasThreadContext()) {
|
||||||
if (!StringUtils.contains(filename, threadName)) {
|
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
||||||
filename = StringUtils.join(threadName, filename);
|
if (!StringUtils.contains(filename, threadName)) {
|
||||||
|
filename = StringUtils.join(threadName, filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileEntry fileEntry = files.get(filename);
|
FileEntry fileEntry = files.get(filename);
|
||||||
if (fileEntry != null) {
|
if (fileEntry != null) {
|
||||||
if (fileEntry.inputOutputObject == null) {
|
if (fileEntry.inputOutputObject == null) {
|
||||||
|
@ -398,9 +404,11 @@ public class FileServer {
|
||||||
* @return {@link BufferedReader}
|
* @return {@link BufferedReader}
|
||||||
*/
|
*/
|
||||||
private BufferedReader getReader(String alias, boolean recycle, boolean ignoreFirstLine) throws IOException {
|
private BufferedReader getReader(String alias, boolean recycle, boolean ignoreFirstLine) throws IOException {
|
||||||
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
if (hasThreadContext()) {
|
||||||
if (!StringUtils.contains(alias, threadName)) {
|
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
||||||
alias = StringUtils.join(threadName, alias);
|
if (!StringUtils.contains(alias, threadName)) {
|
||||||
|
alias = StringUtils.join(threadName, alias);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileEntry fileEntry = files.get(alias);
|
FileEntry fileEntry = files.get(alias);
|
||||||
|
@ -459,9 +467,11 @@ public class FileServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void write(String filename, String value) throws IOException {
|
public synchronized void write(String filename, String value) throws IOException {
|
||||||
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
if (hasThreadContext()) {
|
||||||
if (!StringUtils.contains(filename, threadName)) {
|
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
||||||
filename = StringUtils.join(threadName, filename);
|
if (!StringUtils.contains(filename, threadName)) {
|
||||||
|
filename = StringUtils.join(threadName, filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FileEntry fileEntry = files.get(filename);
|
FileEntry fileEntry = files.get(filename);
|
||||||
if (fileEntry != null) {
|
if (fileEntry != null) {
|
||||||
|
@ -519,11 +529,12 @@ public class FileServer {
|
||||||
* @throws IOException when closing of the aliased file fails
|
* @throws IOException when closing of the aliased file fails
|
||||||
*/
|
*/
|
||||||
public synchronized void closeFile(String name) throws IOException {
|
public synchronized void closeFile(String name) throws IOException {
|
||||||
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
if (hasThreadContext()) {
|
||||||
if (!StringUtils.contains(name, threadName)) {
|
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
||||||
name = StringUtils.join(threadName, name);
|
if (!StringUtils.contains(name, threadName)) {
|
||||||
|
name = StringUtils.join(threadName, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileEntry fileEntry = files.get(name);
|
FileEntry fileEntry = files.get(name);
|
||||||
closeFile(name, fileEntry);
|
closeFile(name, fileEntry);
|
||||||
}
|
}
|
||||||
|
@ -580,9 +591,11 @@ public class FileServer {
|
||||||
|
|
||||||
// If path is absolute, then File constructor will simply return it
|
// If path is absolute, then File constructor will simply return it
|
||||||
String alias = path;
|
String alias = path;
|
||||||
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
if (hasThreadContext()) {
|
||||||
if (!StringUtils.contains(alias, threadName)) {
|
String threadName = JMeterContextService.getContext().getThread().getThreadName();
|
||||||
alias = StringUtils.join(threadName, path);
|
if (!StringUtils.contains(alias, threadName)) {
|
||||||
|
alias = StringUtils.join(threadName, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FileEntry fileEntry = files.containsKey(alias) ? files.get(alias) : files.get(path);
|
FileEntry fileEntry = files.containsKey(alias) ? files.get(alias) : files.get(path);
|
||||||
return fileEntry != null ? fileEntry.file : null;
|
return fileEntry != null ? fileEntry.file : null;
|
||||||
|
|
Loading…
Reference in New Issue