fix para bug

This commit is contained in:
yxsh 2014-03-19 19:04:54 +08:00
parent 259042343e
commit 0bf9cf3dc0
4 changed files with 43 additions and 16 deletions

View File

@ -99,10 +99,10 @@ public class InstanceControler implements SessionObject {
Object instance = pf.getObj(className);
Object result = null;
try {
Class<?>[] argTypeArr = new Class<?>[args.length + 1];
Class<?>[] argTypeArr = new Class<?>[args.length + 2];
argTypeArr[0] = instandid.getClass();
argTypeArr[1] = this.cacheObjMap.getClass();
Object[] totalArgs = new Object[args.length + 1];
Object[] totalArgs = new Object[args.length + 2];
totalArgs[0] = instandid;
totalArgs[1] = this.cacheObjMap;
for (int i = 2; i < args.length + 2; i++) {

View File

@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
@ -57,7 +58,7 @@ public class Para_Table {
}
}
result = queue.poll();
} while (result != null);
} while (result == null);
return result;
}
@ -84,7 +85,7 @@ public class Para_Table {
}
}
result = queue.poll();
} while (result != null);
} while (result == null);
return result;
}
@ -119,7 +120,12 @@ public class Para_Table {
super(sourceValue, firstRow);
this.splitChar = splitChar;
this.lineChar = lineChar;
try {
createBFR();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void createBFR() throws IOException {
@ -136,23 +142,26 @@ public class Para_Table {
@Override
public List<TableRow> readRows() {
CharBuffer target = CharBuffer.allocate(readCharSize);
StringBuilder target = new StringBuilder();
List<TableRow> result = new ArrayList<TableRow>();
TableRow tempTableRow = new TableRow();
try {
for (int i = 0; i < cacheSize;) {
char readBuff = (char) bfr.read();
if (readBuff == -1) {
int tt = bfr.read();
char readBuff = (char)tt;
if (tt == -1) {
createBFR();
break;
} else if (readBuff == this.splitChar) {
tempTableRow.AddCell(target.toString());
target.clear();
String cellString = target.toString();
tempTableRow.AddCell(cellString);
target = new StringBuilder();
continue;
} else if (readBuff == this.lineChar) {
tempTableRow.AddCell(target.toString());
result.add(tempTableRow);
target.clear();
tempTableRow = new TableRow();
target = new StringBuilder();
i++;
continue;
}
@ -164,7 +173,7 @@ public class Para_Table {
if (target.length() > 0) {
tempTableRow.AddCell(target.toString());
result.add(tempTableRow);
target.clear();
target = new StringBuilder();
}
return result;
}
@ -209,7 +218,11 @@ public class Para_Table {
}
}
public String getTableColumnValue(UUID id, Map<String, Object> objCache,
// 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 source, String sourceValue, String firstRow, String nextRow,
String splitChar, String lineChar, String column) {
int fRow = Integer.parseInt(firstRow);
@ -245,4 +258,8 @@ public class Para_Table {
return resultRow.cells.get(col);
}
public void unreg(UUID id) {
}
}

View File

@ -29,7 +29,7 @@ public class ParametersFactory {
public Object getObj(String className) {
Object result = null;
mapRWLock.readLock().lock();
objMap.get(className);
result = objMap.get(className);
mapRWLock.readLock().unlock();
return result;
}
@ -48,7 +48,7 @@ public class ParametersFactory {
objMap.put(className, instance);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
mapRWLock.writeLock().unlock();
return true;

View File

@ -2,7 +2,10 @@ package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.*;
import java.util.HashMap;
import org.bench4q.agent.parameterization.impl.InstanceControler;
import org.bench4q.agent.parameterization.impl.Para_Table;
import org.bench4q.share.helper.TestHelper;
import org.junit.Test;
@ -10,11 +13,18 @@ public class TEST_UserName {
@Test
public void testGetParam() throws Exception {
Para_Table table = new Para_Table();
String ret = table.getTableColumnValue(java.util.UUID.randomUUID(),
new HashMap<String, Object>(), "file",
"ScenarioParameters\\param1.txt", "0", "sequence", ";", "~",
"2");
System.out.println(ret);
InstanceControler ic = new InstanceControler();
String passwordName = ic
.getParam("<parameters class=\"Para_Table\" method=\"getTableColumnValue\" args=\"file,ScenarioParameters\\param1.txt,0,sequence,;,~,2\" />");
.getParam("<parameters class=\"Para_Table\" type=\"crossThread\" method=\"getTableColumnValue\" args=\"file,ScenarioParameters\\param1.txt,0,sequence,;,~,2\" />");
System.out.println(passwordName);
assertNotNull(passwordName);
TestHelper.invokePrivate(ic, "releaseAll", null, null);
}
}