refactoring and need to test
refactoring and need to test
This commit is contained in:
parent
b4dec63ba0
commit
110780d7fd
|
@ -1,39 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
|
||||
@ParameterizedClass(name = "Para_IteratorNumber", permittedPickOrders = { PickOrder.SEQUENTIAL }, permittedUpdateStrategies = { UpdateStrategy.EACH_ITERATION })
|
||||
public class Para_IteratorNumber {
|
||||
public Long iteratorNum = new Long(0);
|
||||
|
||||
@Constructor
|
||||
public Para_IteratorNumber() {
|
||||
}
|
||||
|
||||
/**
|
||||
* For all methods, they will has these two params
|
||||
*
|
||||
* @param id
|
||||
* @param a
|
||||
* @return
|
||||
*/
|
||||
public String getIteratorNumber(UUID id, Map<String, Object> a) {
|
||||
long result = 0;
|
||||
synchronized (iteratorNum) {
|
||||
iteratorNum++;
|
||||
result = iteratorNum;
|
||||
}
|
||||
String ret = String.valueOf(result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void unreg(UUID id) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.utils.ParameterParser;
|
||||
|
||||
@ParameterizedClass(name = "Para_List", permittedPickOrders = {
|
||||
PickOrder.RANDOM, PickOrder.SEQUENTIAL, PickOrder.UNIQUE }, permittedUpdateStrategies = {
|
||||
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE,
|
||||
UpdateStrategy.ONCE })
|
||||
public class Para_List extends BasePara {
|
||||
private String currentValue;
|
||||
|
||||
public String getCurrentValue() {
|
||||
if (this.getUpdateStrategy() == UpdateStrategy.EACH_OCCURRENCE) {
|
||||
initialValue();
|
||||
}
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
private void setCurrentValue(String currentValue) {
|
||||
this.currentValue = currentValue;
|
||||
}
|
||||
|
||||
@Constructor
|
||||
public Para_List(UUID testId, PickOrder pickOrder,
|
||||
UpdateStrategy updateStrategy, String paramName, int currentIndex) {
|
||||
super(testId, paramName, updateStrategy, pickOrder, currentIndex);
|
||||
initialValue();
|
||||
}
|
||||
|
||||
private void initialValue() {
|
||||
File paramFile = new File(getParamFileFullPath(this.getParamName()));
|
||||
List<String> nField = null;
|
||||
try {
|
||||
String content = FileUtils.readFileToString(paramFile);
|
||||
nField = ParameterParser.buildNField(content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (nField.size() == 0) {
|
||||
throw new NullPointerException(
|
||||
"The parameter file has no valid content");
|
||||
}
|
||||
this.setCurrentValue(nField.get(getNextIndex(nField.size())
|
||||
% nField.size()));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
|
||||
@ParameterizedClass(name = "Para_RandomNumber", permittedPickOrders = { PickOrder.RANDOM }, permittedUpdateStrategies = {
|
||||
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE,
|
||||
UpdateStrategy.ONCE })
|
||||
public class Para_RandomNumber {
|
||||
|
||||
@Constructor
|
||||
public Para_RandomNumber() {
|
||||
}
|
||||
|
||||
public String getRandomIntegerNumber(UUID id, String begin, String end,
|
||||
String stringformat) {
|
||||
|
||||
Random r = new Random();
|
||||
int beginNum = Integer.parseInt(begin);
|
||||
int endNum = Integer.parseInt(end);
|
||||
|
||||
int result = r.nextInt(endNum - beginNum) + beginNum;
|
||||
return String.format(stringformat, result);
|
||||
}
|
||||
|
||||
public String getRandomDouble(UUID id, String begin, String end,
|
||||
String stringformat) {
|
||||
Random r = new Random();
|
||||
double beginNum = Integer.parseInt(begin);
|
||||
double endNum = Integer.parseInt(end);
|
||||
|
||||
double result = r.nextDouble() * (endNum - beginNum) + beginNum;
|
||||
return String.format(stringformat, result);
|
||||
}
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
package org.bench4q.agent.parameterization.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bench4q.agent.parameterization.ParameterizedClass;
|
||||
import org.bench4q.agent.parameterization.PickOrder;
|
||||
import org.bench4q.agent.parameterization.UpdateStrategy;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
|
||||
@ParameterizedClass(name = "Para_Table", permittedPickOrders = {
|
||||
PickOrder.RANDOM, PickOrder.SEQUENTIAL, PickOrder.UNIQUE }, permittedUpdateStrategies = {
|
||||
UpdateStrategy.EACH_ITERATION, UpdateStrategy.EACH_OCCURRENCE })
|
||||
public class Para_Table extends BasePara {
|
||||
public final int cacheCap = 5000;// 1 sequence 2 random
|
||||
public final int cacheSize = 1000;// 1 sequence 2 random
|
||||
public ConcurrentHashMap<String, Reader> readerMap = new ConcurrentHashMap<String, Para_Table.Reader>();
|
||||
|
||||
@Constructor
|
||||
public Para_Table(UUID testId, PickOrder pickOrder,
|
||||
UpdateStrategy updateStrategy, String parameterName, int lastIndex) {
|
||||
super(testId, parameterName, updateStrategy, pickOrder, lastIndex);
|
||||
}
|
||||
|
||||
public abstract class Reader {
|
||||
public final Table table;
|
||||
|
||||
public Reader(Table table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public abstract TableRow nextRow();
|
||||
|
||||
}
|
||||
|
||||
public class RandomReader extends Reader {
|
||||
public ArrayBlockingQueue<TableRow> queue;
|
||||
|
||||
public RandomReader(ArrayBlockingQueue<TableRow> queue, Table t) {
|
||||
super(t);
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableRow nextRow() {
|
||||
TableRow result = null;
|
||||
do {
|
||||
if (queue.size() == 0) {
|
||||
synchronized (queue) {
|
||||
if (queue.size() == 0) {
|
||||
List<TableRow> rows = table.readRows();
|
||||
int n = rows.size();
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < n; i++) {
|
||||
int next = r.nextInt(n);
|
||||
TableRow tempRow = rows.get(i);
|
||||
rows.set(i, rows.get(next));
|
||||
rows.set(next, tempRow);
|
||||
}
|
||||
queue.addAll(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
result = queue.poll();
|
||||
} while (result == null);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SequenceReader extends Reader {
|
||||
public ArrayBlockingQueue<TableRow> queue;
|
||||
|
||||
public SequenceReader(ArrayBlockingQueue<TableRow> queue, Table t) {
|
||||
super(t);
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableRow nextRow() {
|
||||
TableRow result = null;
|
||||
do {
|
||||
if (queue.size() == 0) {
|
||||
synchronized (queue) {
|
||||
if (queue.size() == 0) {
|
||||
List<TableRow> rows = table.readRows();
|
||||
queue.addAll(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
result = queue.poll();
|
||||
} while (result == null);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class Table {
|
||||
String sourceValue;
|
||||
int firstRow;
|
||||
|
||||
public Table(String sourceValue, int firstRow) {
|
||||
this.sourceValue = sourceValue;
|
||||
}
|
||||
|
||||
public abstract List<TableRow> readRows();
|
||||
|
||||
public List<TableRow> rows = new ArrayList<TableRow>();
|
||||
|
||||
public int getTime = 0;
|
||||
|
||||
public boolean add(TableRow r) {
|
||||
return rows.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
public class FileTable extends Table {
|
||||
private BufferedReader bfr;
|
||||
char splitChar;
|
||||
char lineChar;
|
||||
|
||||
public FileTable(String paramFilePath, int firstRow, char splitChar,
|
||||
char lineChar) {
|
||||
super(paramFilePath, firstRow);
|
||||
this.splitChar = splitChar;
|
||||
this.lineChar = lineChar;
|
||||
try {
|
||||
createBFR();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createBFR() throws IOException {
|
||||
FileInputStream fis = new FileInputStream(sourceValue);
|
||||
InputStreamReader ir = new InputStreamReader(fis);
|
||||
bfr = new BufferedReader(ir);
|
||||
for (int i = 0; i < firstRow;) {
|
||||
char readChar = (char) bfr.read();
|
||||
if (readChar == lineChar)
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableRow> readRows() {
|
||||
StringBuilder target = new StringBuilder();
|
||||
List<TableRow> result = new ArrayList<TableRow>();
|
||||
TableRow tempTableRow = new TableRow();
|
||||
try {
|
||||
for (int i = 0; i < cacheSize;) {
|
||||
int tt = bfr.read();
|
||||
char readBuff = (char) tt;
|
||||
if (tt == -1) {
|
||||
createBFR();
|
||||
break;
|
||||
} else if (readBuff == this.splitChar) {
|
||||
String cellString = target.toString();
|
||||
tempTableRow.AddCell(cellString);
|
||||
target = new StringBuilder();
|
||||
continue;
|
||||
} else if (readBuff == this.lineChar) {
|
||||
tempTableRow.AddCell(target.toString());
|
||||
result.add(tempTableRow);
|
||||
tempTableRow = new TableRow();
|
||||
target = new StringBuilder();
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
target.append(readBuff);
|
||||
}
|
||||
} catch (IOException ioex) {
|
||||
return result;
|
||||
}
|
||||
if (target.length() > 0) {
|
||||
tempTableRow.AddCell(target.toString());
|
||||
result.add(tempTableRow);
|
||||
target = new StringBuilder();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TableRow {
|
||||
public List<String> cells = new ArrayList<String>();
|
||||
|
||||
public void AddCell(String s) {
|
||||
cells.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
// org.bench4q.agent.parameterization.impl.Para_Table.getTableColumnValue(java.util.UUID,
|
||||
// java.util.HashMap, java.lang.String, java.lang.String, java.lang.String,
|
||||
// java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
|
||||
public String getTableColumnValue(UUID id,
|
||||
HashMap<String, Object> objCache, String paramName,
|
||||
String firstRow, String nextRow, String columnSplitor,
|
||||
String rowSplitor, String column) {
|
||||
int fRow = Integer.parseInt(firstRow);
|
||||
char sChar = columnSplitor.charAt(0);
|
||||
char lChar = rowSplitor.charAt(0);
|
||||
int col = Integer.parseInt(column);
|
||||
TableRow resultRow = null;
|
||||
Table table = null;
|
||||
Reader reader = null;
|
||||
if (objCache.containsKey(paramName) == true) {
|
||||
resultRow = (TableRow) objCache.get(paramName);
|
||||
return resultRow.cells.get(col);
|
||||
}
|
||||
|
||||
if (this.readerMap.containsKey(paramName)) {
|
||||
reader = readerMap.get(paramName);
|
||||
} else {
|
||||
table = new FileTable(getParamFileFullPath(paramName), fRow, sChar,
|
||||
lChar);
|
||||
if (nextRow.equals("random")) {
|
||||
ArrayBlockingQueue<TableRow> queue = new ArrayBlockingQueue<Para_Table.TableRow>(
|
||||
cacheCap);
|
||||
reader = new RandomReader(queue, table);
|
||||
} else if (nextRow.equals("sequence")) {
|
||||
ArrayBlockingQueue<TableRow> queue = new ArrayBlockingQueue<Para_Table.TableRow>(
|
||||
cacheCap);
|
||||
reader = new SequenceReader(queue, table);
|
||||
}
|
||||
readerMap.put(paramName, reader);
|
||||
}
|
||||
resultRow = reader.nextRow();
|
||||
objCache.put(paramName, resultRow);
|
||||
return resultRow.cells.get(col);
|
||||
}
|
||||
|
||||
public void unreg(UUID id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNextIndex(int size) {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<ui>
|
||||
<plugin name="Http">
|
||||
<params>
|
||||
</params>
|
||||
</plugin>
|
||||
<behavior name="Get">
|
||||
<params>
|
||||
<param name="url" label="The Url to request">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="queryParams" label="The query params of this request">
|
||||
<nfield />
|
||||
</param>
|
||||
<param name="headers" label="The headers of this request">
|
||||
<table cols="header;value" />
|
||||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
<behavior name="delete">
|
||||
<params>
|
||||
<param name="url" label="The Url to request">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="queryParams" label="The query params of this request">
|
||||
<nfield />
|
||||
</param>
|
||||
<param name="headers" label="The headers of this request">
|
||||
<table cols="header;value" />
|
||||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
<behavior name="post">
|
||||
<params>
|
||||
<param name="url" label="The Url to request">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="queryParams" label="The query params of this request">
|
||||
<nfield />
|
||||
</param>
|
||||
<param name="headers" label="The headers of this request">
|
||||
<table cols="header;value" />
|
||||
</param>
|
||||
<param name="bodyContent" label="The body that will be post">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="bodyParameters" label="The parameters will be post in the body">
|
||||
<nfield />
|
||||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
<behavior name="put">
|
||||
<params>
|
||||
<param name="url" label="The Url to request">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="queryParams" label="The query params of this request">
|
||||
<nfield />
|
||||
</param>
|
||||
<param name="headers" label="The headers of this request">
|
||||
<table cols="header;value" />
|
||||
</param>
|
||||
<param name="bodyContent" label="The body that will be put">
|
||||
<field size="7" />
|
||||
</param>
|
||||
<param name="bodyParameters" label="The parameters will be put in the body">
|
||||
<nfield />
|
||||
</param>
|
||||
<param name="respVarsToSaveInSession"
|
||||
label="The regular expression of extracting variables from response">
|
||||
<field size="7" />
|
||||
</param>
|
||||
</params>
|
||||
</behavior>
|
||||
</ui>
|
|
@ -0,0 +1,38 @@
|
|||
package org.bench4q.agent.plugin.basic.iterator;
|
||||
|
||||
import org.bench4q.agent.plugin.BaseParameterization;
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.utils.Type.SupportTypes;
|
||||
|
||||
@Plugin(value = "IteratorNumber")
|
||||
public class IteratorNumber extends BaseParameterization {
|
||||
private Long iteratorNum;
|
||||
private String format;
|
||||
|
||||
@Constructor
|
||||
public IteratorNumber(
|
||||
@Parameter(type = SupportTypes.Field, value = "testId") String testId,
|
||||
@Parameter(type = SupportTypes.Field, value = "begin") String begin,
|
||||
@Parameter(type = SupportTypes.Field, value = "format") String format) {
|
||||
super(testId);
|
||||
this.iteratorNum = Long.parseLong(begin);
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Behavior(value = "next")
|
||||
public void next() {
|
||||
synchronized (iteratorNum) {
|
||||
iteratorNum++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String var) {
|
||||
return (this.format == null || this.format.isEmpty()) ? String
|
||||
.valueOf(this.iteratorNum) : String.format(this.format,
|
||||
this.iteratorNum);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<ui>
|
||||
<plugin name="IteratorNumber">
|
||||
<params>
|
||||
<param name="begin" label="The Beginning of the Iteration">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
<param name="format" label="The format of the value">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
</params>
|
||||
</plugin>
|
||||
<behavior name="next">
|
||||
<params />
|
||||
</behavior>
|
||||
</ui>
|
|
@ -0,0 +1,40 @@
|
|||
package org.bench4q.agent.plugin.basic.random;
|
||||
|
||||
import org.bench4q.agent.plugin.BaseParameterization;
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
import org.bench4q.agent.utils.Type.SupportTypes;
|
||||
|
||||
@Plugin(value = "Random")
|
||||
public class Random extends BaseParameterization {
|
||||
private String format;
|
||||
private int begin;
|
||||
private int end;
|
||||
private String currentValue;
|
||||
|
||||
@Constructor
|
||||
public Random(
|
||||
@Parameter(type = SupportTypes.Field, value = "testId") String testId,
|
||||
@Parameter(type = SupportTypes.Field, value = "begin") String begin,
|
||||
@Parameter(type = SupportTypes.Field, value = "end") String end,
|
||||
@Parameter(type = SupportTypes.Field, value = "format") String format) {
|
||||
super(testId);
|
||||
this.format = format;
|
||||
this.begin = Integer.parseInt(begin);
|
||||
this.end = Integer.parseInt(end);
|
||||
}
|
||||
|
||||
@Behavior(value = "next")
|
||||
public void next() {
|
||||
java.util.Random r = new java.util.Random();
|
||||
int result = r.nextInt(this.end - this.begin) + this.begin;
|
||||
this.currentValue = String.valueOf(result);
|
||||
}
|
||||
|
||||
public String getValue(String var) {
|
||||
return (this.format == null || this.format.isEmpty()) ? this.currentValue
|
||||
: String.format(this.format, this.currentValue);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
|
||||
<ui>
|
||||
<plugin name="Random">
|
||||
<params>
|
||||
<param name="begin" label="The Beginning of the range">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
<param name="end" label="The end of the range">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
<param name="format" label="The format of the value">
|
||||
<field size="5"></field>
|
||||
</param>
|
||||
</params>
|
||||
</plugin>
|
||||
<behavior name="next">
|
||||
<params />
|
||||
</behavior>
|
||||
</ui>
|
Loading…
Reference in New Issue