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

View File

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

View File

@ -2,7 +2,10 @@ package org.bench4q.agent.test.parameterization;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.HashMap;
import org.bench4q.agent.parameterization.impl.InstanceControler; import org.bench4q.agent.parameterization.impl.InstanceControler;
import org.bench4q.agent.parameterization.impl.Para_Table;
import org.bench4q.share.helper.TestHelper; import org.bench4q.share.helper.TestHelper;
import org.junit.Test; import org.junit.Test;
@ -10,11 +13,18 @@ public class TEST_UserName {
@Test @Test
public void testGetParam() throws Exception { 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(); InstanceControler ic = new InstanceControler();
String passwordName = ic 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); System.out.println(passwordName);
assertNotNull(passwordName); assertNotNull(passwordName);
TestHelper.invokePrivate(ic, "releaseAll", null, null); TestHelper.invokePrivate(ic, "releaseAll", null, null);
} }
} }