Skip to content

Commit 2371c67

Browse files
committed
Fixed Auto allocate issue
1 parent 8d6ac58 commit 2371c67

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.di.jmeter.ecsv</groupId>
66
<artifactId>di-extended-csv</artifactId>
7-
<version>1.0</version>
7+
<version>1.1</version>
88

99
<properties>
1010
<jmeter-version>5.4.1</jmeter-version>

src/main/java/com/di/jmeter/config/ExtendedCsvDataSet.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.jmeter.save.CSVSaveService;
2828
import org.apache.jmeter.testbeans.TestBean;
2929
import org.apache.jmeter.threads.JMeterContext;
30+
import org.apache.jmeter.threads.JMeterContextService;
3031
import org.apache.jmeter.threads.JMeterVariables;
3132
import org.apache.jorphan.util.JMeterStopThreadException;
3233
import org.apache.jorphan.util.JOrphanUtils;
@@ -87,7 +88,7 @@ public void iterationStart(LoopIterationEvent iterEvent) {
8788
}catch (IOException e){
8889
LOGGER.error(e.toString());
8990
}
90-
LOGGER.debug("Sequential");
91+
LOGGER.debug("Sequential :: " + lineValues);
9192
break;
9293
case ExtendedCsvDataSetBeanInfo.UNIQUE:
9394
try{
@@ -100,7 +101,7 @@ public void iterationStart(LoopIterationEvent iterEvent) {
100101
}catch (IOException e){
101102
LOGGER.error(e.toString());
102103
}
103-
LOGGER.debug("Unique");
104+
LOGGER.debug("Unique :: " + lineValues);
104105
break;
105106
case ExtendedCsvDataSetBeanInfo.RANDOM:
106107
try{
@@ -113,10 +114,10 @@ public void iterationStart(LoopIterationEvent iterEvent) {
113114
}catch(IOException e){
114115
LOGGER.error(e.toString());
115116
}
116-
LOGGER.info("debug");
117+
LOGGER.debug("Random :: " + lineValues);
117118
break;
118119
default:
119-
LOGGER.info("Default");
120+
LOGGER.debug("Invalid selection on Select row");
120121
throw new JMeterStopThreadException("Invalid selection :" + getFilename() + " detected for Extended CSV DataSet:"
121122
+ getName() + " configured to Select Row Parameter :" + getSelectRow());
122123
}
@@ -141,7 +142,7 @@ public void iterationStart(LoopIterationEvent iterEvent) {
141142
}
142143
break;
143144
default:
144-
LOGGER.info("Default");
145+
LOGGER.debug("Invalid selection on Update Value");
145146
throw new JMeterStopThreadException("Invalid selection :" + getFilename() + " detected for Extended CSV DataSet:"
146147
+ getName() + " configured to Select Row Parameter :" + getUpdateValue());
147148
}
@@ -150,13 +151,14 @@ public void iterationStart(LoopIterationEvent iterEvent) {
150151
private void initBlockFeatures(String filename, JMeterContext context, ExtFileServer fServer, boolean autoAllocate, String blockSize) throws IOException{
151152
int blockSizeInt;
152153
String threadName = context.getThread().getThreadName();
153-
//Integer.parseInt(context.getThread().getThreadName().substring(context.getThread().getThreadName().lastIndexOf('-') + 1)))
154-
if(ExtFileServer.getListSize() < 1){
154+
155+
if(fServer.getListSize() < 1){
155156
fServer.reserveFile(filename, getFileEncoding(), alias, ignoreFirstLine);
156-
fServer.loadCsv(filename, isIgnoreFirstLine());
157+
fServer.loadCsv(filename, ignoreFirstLine);
157158
}
159+
158160
if(autoAllocate){
159-
blockSizeInt = ExtFileServer.getListSize() / context.getThreadGroup().getNumberOfThreads();
161+
blockSizeInt = ExtFileServer.getListSize() / JMeterContextService.getTotalThreads();
160162
}else{
161163
blockSizeInt = Integer.parseInt(blockSize);
162164
}
@@ -186,7 +188,7 @@ private void initVars(ExtFileServer server, final JMeterContext context, String
186188
String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
187189
try {
188190
variables = CSVSaveService.csvSplitString(header, delim.charAt(0));
189-
firstLineIsNames = true;
191+
firstLineIsNames = true;ignoreFirstLine = true;
190192
} catch (IOException e) {
191193
throw new IllegalArgumentException("Could not split CSV header line from file:" + fileName, e);
192194
}
@@ -253,7 +255,10 @@ public String getVariableNames() {
253255
}
254256

255257
public void setVariableNames(String variableNames) {
256-
this.variableNames = variableNames;
258+
// this.variableNames = variableNames;
259+
if(!ignoreFirstLine){
260+
this.variableNames = variableNames;
261+
}
257262
}
258263

259264
public String getDelimiter() {

src/main/java/com/di/jmeter/utils/CSVFileReader.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ public static CSVFileReader getInstance(){
3434
return instance;
3535
}
3636

37-
38-
39-
public static int getAutoAllocateBlockSize() {
40-
return autoAllocateBlockSize;
41-
}
42-
43-
public static void setAutoAllocateBlockSize(int autoAllocateBlockSize) {
44-
CSVFileReader.autoAllocateBlockSize = autoAllocateBlockSize;
45-
}
46-
4737
public static List<String> getList() {
4838
return list;
4939
}
@@ -52,10 +42,6 @@ public static int getListSize(){
5242
return list.size();
5343
}
5444

55-
public static void setList(List<String> list) {
56-
CSVFileReader.list = list;
57-
}
58-
5945
public static void addToList(String line){
6046
CSVFileReader.list.add(line);
6147
}
@@ -64,4 +50,7 @@ public String getFromList(int index) {
6450
return CSVFileReader.list.get(index);
6551
}
6652

53+
public static void removeList() {
54+
CSVFileReader.list.clear();
55+
}
6756
}

src/main/java/com/di/jmeter/utils/ExtFileServer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public synchronized String reserveFile(String filename, String charsetName, Stri
268268
files.put(alias, fileEntry);
269269
if (hasHeader) {
270270
try {
271-
fileEntry.headerLine = readLine(alias, false);
271+
fileEntry.headerLine = readLine(alias, true);
272272
if (fileEntry.headerLine == null) {
273273
fileEntry.exception = new EOFException("File is empty: " + fileEntry.file);
274274
}
@@ -591,8 +591,6 @@ public void setScriptName(String scriptName) {
591591
this.scriptName = scriptName;
592592
}
593593

594-
595-
596594
public synchronized String readSequential(String filename, boolean ignoreFirstLine, String updateValue, String ooValue) throws IOException {
597595
boolean recycle = false;
598596
if(ooValue.equalsIgnoreCase("recycle.continueCyclic")){
@@ -609,9 +607,6 @@ public synchronized String readSequential(String filename, boolean ignoreFirstLi
609607
public synchronized String getRandomLine(String filename, boolean recycle, boolean ignoreFirstLine) throws IOException {
610608
CSVFileReader fileReader = CSVFileReader.getInstance();
611609
SecureRandom random = new SecureRandom();
612-
if(fileReader.getListSize() == 0){
613-
this.loadCsv(filename, ignoreFirstLine);
614-
}
615610
return fileReader.getFromList(random.nextInt(fileReader.getList().size()));
616611
}
617612

@@ -676,6 +671,10 @@ public synchronized void loadCsv(String filename, boolean ignoreFirstLine) throw
676671
}
677672
}
678673

674+
public static void removeList(){
675+
CSVFileReader.removeList();
676+
}
677+
679678
public static int getListSize(){
680679
return CSVFileReader.getListSize();
681680
}

0 commit comments

Comments
 (0)