add new test

add new test
This commit is contained in:
coderfengyun 2014-08-21 09:17:52 +08:00
parent 473d4ff063
commit c53abbe0ff
5 changed files with 129 additions and 203 deletions

View File

@ -150,48 +150,49 @@ public class HttpPlugin extends ParameterBarn {
}
private Callable<HttpReturn> buildTasks(final BatchItem item) {
switch (item.getMethod().toLowerCase()) {
case "get":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return get(item.getUrl(), item.getQueryParams(),
item.getHeaders(),
item.getRespVarsToSaveInSession());
}
};
case "post":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return post(item.getUrl(), item.getQueryParams(),
item.getHeaders(), item.getBodyContent(),
item.getBodyparameters(),
item.getRespVarsToSaveInSession());
}
};
case "put":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return put(item.getUrl(), item.getQueryParams(),
item.getHeaders(), item.getBodyContent(),
item.getBodyparameters(),
item.getRespVarsToSaveInSession());
}
};
case "delete":
return new Callable<HttpReturn>() {
@Override
public HttpReturn call() throws Exception {
return delete(item.getUrl(), item.getQueryParams(),
item.getHeaders(),
item.getRespVarsToSaveInSession());
}
};
default:
return null;
}
// switch (item.getMethod().toLowerCase()) {
// case "get":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return get(item.getUrl(), item.getQueryParams(),
// item.getHeaders(),
// item.getRespVarsToSaveInSession());
// }
// };
// case "post":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return post(item.getUrl(), item.getQueryParams(),
// item.getHeaders(), item.getBodyContent(),
// item.getBodyparameters(),
// item.getRespVarsToSaveInSession());
// }
// };
// case "put":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return put(item.getUrl(), item.getQueryParams(),
// item.getHeaders(), item.getBodyContent(),
// item.getBodyparameters(),
// item.getRespVarsToSaveInSession());
// }
// };
// case "delete":
// return new Callable<HttpReturn>() {
// @Override
// public HttpReturn call() throws Exception {
// return delete(item.getUrl(), item.getQueryParams(),
// item.getHeaders(),
// item.getRespVarsToSaveInSession());
// }
// };
// default:
// return null;
// }
return null;
}
/**

View File

@ -74,7 +74,6 @@ public class VUser implements Runnable {
context.getDataStatistics().add(
PageResult.buildPageResult(i, startTime, endTime));
}
}
private void doRunBatch(Map<String, Object> plugins, Batch batch,

View File

@ -1,5 +1,7 @@
package org.bench4q.agent.test;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -14,174 +16,70 @@ import java.util.Set;
import org.junit.Test;
public class Solution {
private Set<String> dict;
public List<List<String>> findLadders(String start, String end,
Set<String> dict) {
if (start == null || end == null || start.length() != end.length()) {
return new ArrayList<List<String>>();
public double findMedianSortedArrays(int A[], int B[]) {
if (A == null && B == null) {
throw new IllegalArgumentException();
}
this.dict = dict;
return broadFirstSearch(start, end);
}
private List<List<String>> broadFirstSearch(String start, String end) {
List<List<String>> result = new ArrayList<List<String>>();
Queue<WordInPath> queue1 = new LinkedList<WordInPath>(), queue2 = new LinkedList<WordInPath>(), currentQueue = queue1, nextQueue = queue2;
Map<String, Integer> footPrints = new HashMap<String, Integer>();
currentQueue.offer(new WordInPath(start, null));
footPrints.put(start, 0);
boolean toCheckNextLevel = true;
while (currentQueue.peek() != null) {
WordInPath current = currentQueue.poll();
if (current.reach(end)) {
result.add(current.buildPath());
toCheckNextLevel = false;
continue;
}
if (!toCheckNextLevel) {
continue;
}
for (String neighbor : current.getNeighbors()) {
if ((!footPrints.containsKey(neighbor))
|| (current.length() <= footPrints.get(neighbor))) {
footPrints.put(neighbor, current.length());
nextQueue.offer(new WordInPath(neighbor, current));
}
}
if (currentQueue.peek() == null) {
Queue<WordInPath> temp = currentQueue;
currentQueue = nextQueue;
nextQueue = temp;
}
if (A == null || A.length == 0) {
return average(B[B.length / 2], B[(B.length - 1) / 2]);
} else if (B == null || B.length == 0) {
return average(A[A.length / 2], A[(A.length - 1) / 2]);
}
return result;
}
private class WordInPath {
private final String word;
private final WordInPath previous;
private final int size;
public WordInPath(String word, WordInPath previous) {
this.word = word;
this.previous = previous;
this.size = previous == null ? 1 : previous.length() + 1;
}
public List<String> buildPath() {
LinkedList<String> result = new LinkedList<String>();
WordInPath current = this;
while (current != null) {
result.push(current.word);
current = current.previous;
}
return result;
}
public int length() {
return this.size;
}
public boolean reach(String target) {
return this.word.equals(target);
}
private List<String> getNeighbors() {
List<String> result = new LinkedList<String>();
StringBuilder changed = new StringBuilder(this.word);
for (int i = 0; i < this.word.length(); i++) {
char ch = this.word.charAt(i);
for (char c = 'a'; c < 'z'; c++) {
if (c == ch) {
continue;
}
changed.setCharAt(i, c);
String temp = changed.toString();
if (Solution.this.dict.contains(temp)) {
result.add(temp);
}
changed.setCharAt(i, ch);
}
}
return result;
}
}
@Test
public void test() {
List<List<String>> result = this.findLadders(
"nape",
"mild",
new HashSet<String>(Arrays.asList("dose", "ends", "dine",
"jars", "prow", "soap", "guns", "hops", "cray", "hove",
"ella", "hour", "lens", "jive", "wiry", "earl", "mara",
"part", "flue", "putt", "rory", "bull", "york", "ruts",
"lily", "vamp", "bask", "peer", "boat", "dens", "lyre",
"jets", "wide", "rile", "boos", "down", "path", "onyx",
"mows", "toke", "soto", "dork", "nape", "mans", "loin",
"jots", "male", "sits", "minn", "sale", "pets", "hugo",
"woke", "suds", "rugs", "vole", "warp", "mite", "pews",
"lips", "pals", "nigh", "sulk", "vice", "clod", "iowa",
"gibe", "shad", "carl", "huns", "coot", "sera", "mils",
"rose", "orly", "ford", "void", "time", "eloy", "risk",
"veep", "reps", "dolt", "hens", "tray", "melt", "rung",
"rich", "saga", "lust", "yews", "rode", "many", "cods",
"rape", "last", "tile", "nosy", "take", "nope", "toni",
"bank", "jock", "jody", "diss", "nips", "bake", "lima",
"wore", "kins", "cult", "hart", "wuss", "tale", "sing",
"lake", "bogy", "wigs", "kari", "magi", "bass", "pent",
"tost", "fops", "bags", "duns", "will", "tart", "drug",
"gale", "mold", "disk", "spay", "hows", "naps", "puss",
"gina", "kara", "zorn", "boll", "cams", "boas", "rave",
"sets", "lego", "hays", "judy", "chap", "live", "bahs",
"ohio", "nibs", "cuts", "pups", "data", "kate", "rump",
"hews", "mary", "stow", "fang", "bolt", "rues", "mesh",
"mice", "rise", "rant", "dune", "jell", "laws", "jove",
"bode", "sung", "nils", "vila", "mode", "hued", "cell",
"fies", "swat", "wags", "nate", "wist", "honk", "goth",
"told", "oise", "wail", "tels", "sore", "hunk", "mate",
"luke", "tore", "bond", "bast", "vows", "ripe", "fond",
"benz", "firs", "zeds", "wary", "baas", "wins", "pair",
"tags", "cost", "woes", "buns", "lend", "bops", "code",
"eddy", "siva", "oops", "toed", "bale", "hutu", "jolt",
"rife", "darn", "tape", "bold", "cope", "cake", "wisp",
"vats", "wave", "hems", "bill", "cord", "pert", "type",
"kroc", "ucla", "albs", "yoko", "silt", "pock", "drub",
"puny", "fads", "mull", "pray", "mole", "talc", "east",
"slay", "jamb", "mill", "dung", "jack", "lynx", "nome",
"leos", "lade", "sana", "tike", "cali", "toge", "pled",
"mile", "mass", "leon", "sloe", "lube", "kans", "cory",
"burs", "race", "toss", "mild", "tops", "maze", "city",
"sadr", "bays", "poet", "volt", "laze", "gold", "zuni",
"shea", "gags", "fist", "ping", "pope", "cora", "yaks",
"cosy", "foci", "plan", "colo", "hume", "yowl", "craw",
"pied", "toga", "lobs", "love", "lode", "duds", "bled",
"juts", "gabs", "fink", "rock", "pant", "wipe", "pele",
"suez", "nina", "ring", "okra", "warm", "lyle", "gape",
"bead", "lead", "jane", "oink", "ware", "zibo", "inns",
"mope", "hang", "made", "fobs", "gamy", "fort", "peak",
"gill", "dino", "dina", "tier")));
for (List<String> item : result) {
for (String word : item) {
System.out.print(word + " -> ");
}
System.out.println();
int firstMedian = (A.length + B.length) / 2 + 1, secondMedian = (A.length
+ B.length - 1) / 2 + 1;
if (firstMedian == secondMedian) {
return find(A, 0, A.length - 1, B, 0, B.length - 1, firstMedian);
} else {
return average(
find(A, 0, A.length - 1, B, 0, B.length - 1, firstMedian),
find(A, 0, A.length - 1, B, 0, B.length - 1, secondMedian));
}
}
@Test
public void test2() {
String test1 = "abc";
StringBuilder builder = new StringBuilder(test1);
builder.setCharAt(1, 'a');
System.out.println(builder.toString());
private int find(int[] A, int beginA, int endA, int[] B, int beginB,
int endB, int k) {
if (beginA > endA) {
return B[beginB + k - 1];
} else if (beginB > endB) {
return A[beginA + k - 1];
}
int pivotIndex = (beginA + endA) / 2, pivotValue = A[pivotIndex], leftLengthA = pivotIndex
- beginA;
int leftLengthB = getLeftLength(B, beginB, endB, pivotValue);
if (k <= leftLengthA + leftLengthB) {
return find(A, beginA, pivotIndex - 1, B, beginB, beginB
+ leftLengthB - 1, k);
} else if (k == leftLengthA + leftLengthB + 1) {
return pivotValue;
} else {
return find(A, pivotIndex + 1, endA, B, beginB + leftLengthB, endB,
k - leftLengthA - leftLengthB - 1);
}
}
private int getLeftLength(int[] A, int begin, int end, int pivotValue) {
int mid = (begin + end) / 2;
int beginIn = begin, endIn = end;
while (beginIn < endIn) {
if (A[mid] > pivotValue) {
endIn = mid - 1;
} else if (A[mid] == pivotValue) {
break;
} else {
beginIn = mid + 1;
}
mid = (beginIn + endIn) / 2;
}
return A[mid] < pivotValue ? mid - begin + 1 : mid - begin;
}
private double average(int partner1, int partner2) {
return ((double) partner1 + (double) partner2) / 2;
}
@Test
public void test3() {
PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
System.out.println(this.findMedianSortedArrays(new int[] { 1, 2, 3 },
new int[] { 1, 2, 2 }));
}
}

View File

@ -82,6 +82,29 @@ public class Test_Scenario extends TestBase {
UUID.randomUUID()).run();
}
@Test
public void test_generateHTTPScenario() throws IOException {
BehaviorModel[] behaviors = new BehaviorModel[10];
for (int i = 0; i < 10; i++) {
behaviors[i] = BehaviorModel.UserBehaviorBuilder(3 * i + 2, "Get",
"HTTP_0", Arrays.asList(ParameterModel.createParameter(
"url", "http://58.211.191.47:8080/")));
}
RunScenarioModel runScenarioModel = buildRunScenarioModelWith(
Arrays.asList(new UsePluginModel("Timer_0", "ConstantTimer",
Collections.<ParameterModel> emptyList()),
new UsePluginModel("Context_0", "Context", null),
new UsePluginModel("HTTP_0", "Http",
new ArrayList<ParameterModel>())), behaviors);
File file = new File("Scripts" + System.getProperty("file.separator")
+ "testBalance.xml");
TestHelper.createFileIfNotExist(file);
FileUtils.writeStringToFile(file,
MarshalHelper.tryMarshal(runScenarioModel));
createVUser(Scenario.scenarioBuilderWithCompile(runScenarioModel),
UUID.randomUUID()).run();
}
@Test
public void test_ScenarioCompile() {
RunScenarioModel inputModel = buildRunScenarioModelWith(

View File

@ -67,4 +67,9 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
assertTrue(testPlanScript.run());
System.out.println("ok?");
}
@Test
public void test_doAfterApplyLoad() {
}
}