diff --git a/Bench4Q-Agent/ScenarioParameters/0c36237f-ee4c-44da-b3fa-525bd6deae06/param1.txt b/Bench4Q-Agent/ScenarioParameters/0c36237f-ee4c-44da-b3fa-525bd6deae06/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/0c36237f-ee4c-44da-b3fa-525bd6deae06/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/1b11d571-8979-438c-aae0-eefe62978336/param1.txt b/Bench4Q-Agent/ScenarioParameters/1b11d571-8979-438c-aae0-eefe62978336/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/1b11d571-8979-438c-aae0-eefe62978336/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/35169179-fc87-49d1-ad45-2f05d31b7b36/param1.txt b/Bench4Q-Agent/ScenarioParameters/35169179-fc87-49d1-ad45-2f05d31b7b36/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/35169179-fc87-49d1-ad45-2f05d31b7b36/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/3da766c9-5801-4caa-a815-b8974e895a79/param1.txt b/Bench4Q-Agent/ScenarioParameters/3da766c9-5801-4caa-a815-b8974e895a79/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/3da766c9-5801-4caa-a815-b8974e895a79/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/4c0bfe0d-73f6-4a69-b1fe-261904cde45a/param1.txt b/Bench4Q-Agent/ScenarioParameters/4c0bfe0d-73f6-4a69-b1fe-261904cde45a/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/4c0bfe0d-73f6-4a69-b1fe-261904cde45a/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/4cdce873-5429-4827-a0fa-6bef54b2a569/param1.txt b/Bench4Q-Agent/ScenarioParameters/4cdce873-5429-4827-a0fa-6bef54b2a569/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/4cdce873-5429-4827-a0fa-6bef54b2a569/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/5084255e-6799-4f6d-96da-c5aefa209035/param1.txt b/Bench4Q-Agent/ScenarioParameters/5084255e-6799-4f6d-96da-c5aefa209035/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/5084255e-6799-4f6d-96da-c5aefa209035/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/7e091ab8-7002-4fe0-af28-4520420bcf45/param1.txt b/Bench4Q-Agent/ScenarioParameters/7e091ab8-7002-4fe0-af28-4520420bcf45/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/7e091ab8-7002-4fe0-af28-4520420bcf45/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/8895ad81-4ac9-4d73-a3d8-068905f5720f/param1.txt b/Bench4Q-Agent/ScenarioParameters/8895ad81-4ac9-4d73-a3d8-068905f5720f/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/8895ad81-4ac9-4d73-a3d8-068905f5720f/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/88d22d82-4689-4a57-b55f-200915f6fa5e/param1.txt b/Bench4Q-Agent/ScenarioParameters/88d22d82-4689-4a57-b55f-200915f6fa5e/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/88d22d82-4689-4a57-b55f-200915f6fa5e/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/9498332b-6856-4de5-93fd-605e183dba68/param1.txt b/Bench4Q-Agent/ScenarioParameters/9498332b-6856-4de5-93fd-605e183dba68/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/9498332b-6856-4de5-93fd-605e183dba68/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/96bec1dd-f706-490a-9af3-a7577fadf9c9/param1.txt b/Bench4Q-Agent/ScenarioParameters/96bec1dd-f706-490a-9af3-a7577fadf9c9/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/96bec1dd-f706-490a-9af3-a7577fadf9c9/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/b2870112-ebc0-4d58-bd87-601a071fe252/param1.txt b/Bench4Q-Agent/ScenarioParameters/b2870112-ebc0-4d58-bd87-601a071fe252/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/b2870112-ebc0-4d58-bd87-601a071fe252/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/b4e1a13c-3e41-4f00-90ed-8f0df700e1ec/param1.txt b/Bench4Q-Agent/ScenarioParameters/b4e1a13c-3e41-4f00-90ed-8f0df700e1ec/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/b4e1a13c-3e41-4f00-90ed-8f0df700e1ec/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/c5f6d832-0041-4f32-9de1-13738c92f792/param1.txt b/Bench4Q-Agent/ScenarioParameters/c5f6d832-0041-4f32-9de1-13738c92f792/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/c5f6d832-0041-4f32-9de1-13738c92f792/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/c97ff82b-65a3-4ad2-b447-d1fe2b8b1d87/param1.txt b/Bench4Q-Agent/ScenarioParameters/c97ff82b-65a3-4ad2-b447-d1fe2b8b1d87/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/c97ff82b-65a3-4ad2-b447-d1fe2b8b1d87/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/d4a7ef4b-f4d3-44ad-af3f-e1acb9762953/param1.txt b/Bench4Q-Agent/ScenarioParameters/d4a7ef4b-f4d3-44ad-af3f-e1acb9762953/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/d4a7ef4b-f4d3-44ad-af3f-e1acb9762953/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/d7b7e9fc-4caf-456d-a305-6ad8301a5931/param1.txt b/Bench4Q-Agent/ScenarioParameters/d7b7e9fc-4caf-456d-a305-6ad8301a5931/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/d7b7e9fc-4caf-456d-a305-6ad8301a5931/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/e9e915a1-1561-4510-af15-48c49929aaff/param1.txt b/Bench4Q-Agent/ScenarioParameters/e9e915a1-1561-4510-af15-48c49929aaff/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/e9e915a1-1561-4510-af15-48c49929aaff/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/ead3a96d-d60b-450c-8428-1032836b46eb/param1.txt b/Bench4Q-Agent/ScenarioParameters/ead3a96d-d60b-450c-8428-1032836b46eb/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/ead3a96d-d60b-450c-8428-1032836b46eb/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/ef75bcc6-f9f4-4e10-a874-24517fbd9dfd/param1.txt b/Bench4Q-Agent/ScenarioParameters/ef75bcc6-f9f4-4e10-a874-24517fbd9dfd/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/ef75bcc6-f9f4-4e10-a874-24517fbd9dfd/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/ScenarioParameters/fae336cb-46c9-486e-81fd-2428dfe61588/param1.txt b/Bench4Q-Agent/ScenarioParameters/fae336cb-46c9-486e-81fd-2428dfe61588/param1.txt deleted file mode 100644 index 748dc5f7..00000000 --- a/Bench4Q-Agent/ScenarioParameters/fae336cb-46c9-486e-81fd-2428dfe61588/param1.txt +++ /dev/null @@ -1 +0,0 @@ -row1;10;11~row2;20;21~row3,30,31~ \ No newline at end of file diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/UpdateStrategy.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/UpdateStrategy.java index 3bdc959f..73bc94f4 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/UpdateStrategy.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/UpdateStrategy.java @@ -1,5 +1,32 @@ package org.bench4q.agent.parameterization; public enum UpdateStrategy { - ONCE, EACH_ITERATION, EACH_OCCURRENCE + ONCE, EACH_ITERATION, EACH_OCCURRENCE; + + public static interface UpdateRestriction { + public boolean isSatisfiedBy(UpdateStrategy updateStrategy); + } + + public static class OnceRestriction implements UpdateRestriction { + public boolean isSatisfiedBy(UpdateStrategy updateStrategy) { + return doesMeet(ONCE, updateStrategy); + } + } + + public static class IterationRestriction implements UpdateRestriction { + public boolean isSatisfiedBy(UpdateStrategy updateStrategy) { + return doesMeet(EACH_ITERATION, updateStrategy); + } + } + + public static class OccurrenceRestriction implements UpdateRestriction { + public boolean isSatisfiedBy(UpdateStrategy updateStrategy) { + return doesMeet(EACH_OCCURRENCE, updateStrategy); + } + } + + private static boolean doesMeet(UpdateStrategy expected, + UpdateStrategy actual) { + return expected == actual; + } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/BasePara.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/BasePara.java index bd21eb42..fff2b0d3 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/BasePara.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/BasePara.java @@ -24,4 +24,6 @@ public abstract class BasePara { return Main.SCENARIO_PARAMETERS_FOLDER + FILE_SEPARATOR + testId.toString() + FILE_SEPARATOR + paramName + ".txt"; } + + public abstract String getCurrentValue(); } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_File.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_File.java new file mode 100644 index 00000000..7ad92c64 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_File.java @@ -0,0 +1,50 @@ +package org.bench4q.agent.parameterization.impl; + +import java.io.File; +import java.util.List; +import java.util.Random; +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.utils.ParameterParser; + +@ParameterizedClass(name = "Para_File") +public class Para_File extends BasePara { + private String currentValue; + + public String getCurrentValue() { + return currentValue; + } + + private void setCurrentValue(String currentValue) { + this.currentValue = currentValue; + } + + public Para_File(UUID testId, PickOrder pickOrder, + UpdateStrategy updateStrategy, String paramName) { + super(testId); + initialValue(paramName); + } + + private void initialValue(String paramName) { + // In a sequential way + File paramFile = new File(getParamFileFullPath(paramName)); + List nField = null; + try { + String content = FileUtils.readFileToString(paramFile); + nField = ParameterParser.buildNField(content); + } catch (Exception e) { + e.printStackTrace(); + } + Random random = new Random(); + if (nField.size() == 0) { + throw new NullPointerException( + "The parameter file has no valid content"); + } + this.setCurrentValue(nField.get(random.nextInt(nField.size()) + % nField.size())); + } +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_Table.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_Table.java index 7f296862..9c6fbd08 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_Table.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/Para_Table.java @@ -30,10 +30,10 @@ public class Para_Table extends BasePara { } public abstract class Reader { - public final Table t; + public final Table table; public Reader(Table table) { - this.t = table; + this.table = table; } public abstract TableRow nextRow(); @@ -55,7 +55,7 @@ public class Para_Table extends BasePara { if (queue.size() == 0) { synchronized (queue) { if (queue.size() == 0) { - List rows = t.readRows(); + List rows = table.readRows(); int n = rows.size(); Random r = new Random(); for (int i = 0; i < n; i++) { @@ -90,7 +90,7 @@ public class Para_Table extends BasePara { if (queue.size() == 0) { synchronized (queue) { if (queue.size() == 0) { - List rows = t.readRows(); + List rows = table.readRows(); queue.addAll(rows); } } @@ -242,4 +242,9 @@ public class Para_Table extends BasePara { public void unreg(UUID id) { } + + @Override + public String getCurrentValue() { + return null; + } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationManager.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationManager.java index dc9d0cc5..5c5132f8 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationManager.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/ParameterizationManager.java @@ -2,6 +2,7 @@ package org.bench4q.agent.parameterization.impl; import java.lang.reflect.Constructor; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -13,7 +14,9 @@ import org.bench4q.agent.helper.ClassHelper; import org.bench4q.agent.helper.ClassLoadRestriction; import org.bench4q.agent.parameterization.ParameterizedClass; import org.bench4q.agent.parameterization.PickOrder; +import org.bench4q.agent.parameterization.SessionObject; import org.bench4q.agent.parameterization.UpdateStrategy; +import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction; import org.bench4q.agent.scenario.DefinedParameter; public class ParameterizationManager { @@ -83,7 +86,7 @@ public class ParameterizationManager { } - public VUserContext buildVUserContext() { + public SessionObject buildVUserContext() { return new VUserContext(this); } @@ -142,12 +145,42 @@ public class ParameterizationManager { * * @param definedParameter */ + + public Map createParaInstancesWith( + DefinedParameter[] definedParameters, + UpdateRestriction updateRestriction) { + Map result = new LinkedHashMap(); + if (definedParameters == null || definedParameters.length == 0) { + return result; + } + for (DefinedParameter definedParameter : definedParameters) { + try { + UpdateStrategy updateStrategy = UpdateStrategy + .valueOf(definedParameter.getUpdateStrategy()); + PickOrder pickOrder = PickOrder.valueOf(definedParameter + .getPickOrder()); + if (!updateRestriction.isSatisfiedBy(updateStrategy)) { + continue; + } + result.put( + definedParameter.getName(), + createInstanceWith(definedParameter.getType(), + definedParameter.getName(), pickOrder, + updateStrategy)); + } catch (Exception e) { + Logger.getLogger(ParameterizationManager.class).error(e, e); + } + } + return result; + } + public boolean createParaInstanceWith(DefinedParameter definedParameter) { try { this.getParameterMap().put( definedParameter.getName(), - loadClassWith(definedParameter.getType(), PickOrder - .valueOf(definedParameter.getPickOrder()), + createInstanceWith(definedParameter.getType(), + definedParameter.getName(), PickOrder + .valueOf(definedParameter.getPickOrder()), UpdateStrategy.valueOf(definedParameter .getUpdateStrategy()))); @@ -158,20 +191,37 @@ public class ParameterizationManager { } } - private Object loadClassWith(String name, PickOrder pickOrder, - UpdateStrategy updateStrategy) { - if (!this.getParaClasses().containsKey(name)) { - throw new NullPointerException("There's no class with " + name); + private BasePara createInstanceWith(String className, String paramName, + PickOrder pickOrder, UpdateStrategy updateStrategy) { + if (!this.getParaClasses().containsKey(className)) { + throw new NullPointerException("There's no class with " + className); } - Class clazz = this.getParaClasses().get(name); + Class clazz = this.getParaClasses().get(className); try { Constructor constructor = clazz.getConstructor(UUID.class, - PickOrder.class, UpdateStrategy.class); - return constructor.newInstance(this.getTestId(), pickOrder, - updateStrategy); + PickOrder.class, UpdateStrategy.class, String.class); + return (BasePara) constructor.newInstance(this.getTestId(), + pickOrder, updateStrategy, paramName); } catch (Exception e) { throw new NullPointerException( - "There's no constructor with three params"); + "There's no constructor with four params whose className is " + + className); } } + + /** + * + * @param paramName + * @return the currentValue of the parameter + * @throws NullPointerException + * if not find the parameter with name paramName + */ + public String getParameterValue(String paramName) { + if (!this.getParameterMap().containsKey(paramName)) { + throw new NullPointerException("There is not parameter with name " + + paramName); + } + BasePara para = (BasePara) this.getParameterMap().get(paramName); + return para.getCurrentValue(); + } } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VUserContext.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VUserContext.java index 9816d637..89fdcbd4 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VUserContext.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VUserContext.java @@ -33,9 +33,9 @@ public class VUserContext implements SessionObject { private VUserContext() { } - public VUserContext(ParameterizationManager parametersFactory) { + public VUserContext(ParameterizationManager parameterizationManager) { this(); - this.setParamterFactory(parametersFactory); + this.setParamterFactory(parameterizationManager); } private String getParameter(ParamFormatParser paraFormat) { diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VuserContextNew.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VuserContextNew.java new file mode 100644 index 00000000..e1701792 --- /dev/null +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/parameterization/impl/VuserContextNew.java @@ -0,0 +1,44 @@ +package org.bench4q.agent.parameterization.impl; + +import java.util.Map; + +import org.apache.log4j.Logger; +import org.bench4q.agent.parameterization.SessionObject; + +public class VuserContextNew implements SessionObject { + private Map staticParameters; + + private Map getStaticParameters() { + return staticParameters; + } + + private void setStaticParameters(Map staticParameters) { + this.staticParameters = staticParameters; + } + + public VuserContextNew(Map initStaticParameters) { + this.setStaticParameters(initStaticParameters); + } + + public String getParam(String name) { + try { + return this.getStaticParameters().get(name).getCurrentValue(); + } catch (Exception e) { + Logger.getLogger(VuserContextNew.class).error(e, e); + return name; + } + } + + public void saveRuntimeParam(String name, String value) { + + } + + public void doCleanUp() { + + } + + public void saveRuntimeParams(Map runTimeParams) { + + } + +} diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java index 8a86cafd..eeb9a12d 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/ScenarioContext.java @@ -1,6 +1,9 @@ package org.bench4q.agent.scenario; import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.UUID; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -9,11 +12,16 @@ import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy; import org.bench4q.agent.datacollector.DataCollector; import org.bench4q.agent.datacollector.impl.ScenarioResultCollector; +import org.bench4q.agent.parameterization.SessionObject; +import org.bench4q.agent.parameterization.UpdateStrategy; +import org.bench4q.agent.parameterization.UpdateStrategy.UpdateRestriction; +import org.bench4q.agent.parameterization.impl.BasePara; import org.bench4q.agent.parameterization.impl.ParameterizationManager; -import org.bench4q.agent.parameterization.impl.VUserContext; +import org.bench4q.agent.parameterization.impl.VuserContextNew; public class ScenarioContext { private static final long keepAliveTime = 10; + Map updateOnceParameters; private Date startDate; private Date endDate; private ThreadPoolExecutor executor; @@ -78,7 +86,17 @@ public class ScenarioContext { this.parameterFactory = parameterFactory; } + private Map getUpdateOnceParameters() { + return updateOnceParameters; + } + + private void setUpdateOnceParameters( + Map updateOnceParameters) { + this.updateOnceParameters = updateOnceParameters; + } + private ScenarioContext() { + this.setUpdateOnceParameters(new HashMap()); } public static ScenarioContext buildScenarioContext(UUID testId, @@ -94,20 +112,33 @@ public class ScenarioContext { scenarioContext.setDataStatistics(new ScenarioResultCollector(testId)); scenarioContext.setParameterFactory(new ParameterizationManager(testId, scenario.getDefinedParameters().length)); - scenarioContext.prepareForParameterization(); + scenarioContext.initForUpdateOnce(); return scenarioContext; } - private void prepareForParameterization() { - if (scenario.getDefinedParameters() == null) - return; - for (DefinedParameter dP : this.getScenario().getDefinedParameters()) { - // TODO: - this.getParameterFactory().createParaInstanceWith(dP); - } + private void initForUpdateOnce() { + this.getUpdateOnceParameters().putAll( + initForParameterization(new UpdateStrategy.OnceRestriction())); } - public VUserContext buildVUserContext() { - return this.getParameterFactory().buildVUserContext(); + private Map initForParameterization( + UpdateRestriction updateRestriction) { + if (scenario.getDefinedParameters() == null) + return new LinkedHashMap(); + + return this.getParameterFactory().createParaInstancesWith( + scenario.getDefinedParameters(), updateRestriction); + } + + public SessionObject buildVUserContext() { + Map initParameters = new HashMap(); + initParameters.putAll(getUpdateOnceParameters()); + initParameters.putAll(initForUpdateEachIteration()); + VuserContextNew vuserContextNew = new VuserContextNew(initParameters); + return vuserContextNew; + } + + private Map initForUpdateEachIteration() { + return initForParameterization(new UpdateStrategy.IterationRestriction()); } } diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterManager.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterManager.java index abd2dfc5..51ba18ed 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterManager.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/parameterization/Test_ParameterManager.java @@ -2,14 +2,23 @@ package org.bench4q.agent.test.parameterization; import static org.junit.Assert.*; +import java.io.File; +import java.io.IOException; import java.util.Map; import java.util.UUID; +import org.apache.commons.io.FileUtils; import org.bench4q.agent.parameterization.PickOrder; import org.bench4q.agent.parameterization.UpdateStrategy; +import org.bench4q.agent.parameterization.impl.BasePara; import org.bench4q.agent.parameterization.impl.ParameterizationManager; import org.bench4q.agent.scenario.DefinedParameter; +import org.bench4q.agent.scenario.Scenario; +import org.bench4q.agent.scenario.ScenarioContext; +import org.bench4q.agent.scenario.VUser; import org.bench4q.share.helper.TestHelper; +import org.bench4q.share.models.agent.DefinedParameterModel; +import org.bench4q.share.models.agent.RunScenarioModel; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -21,17 +30,21 @@ public class Test_ParameterManager { @Test public void test_createParaInstanceWith() throws Exception { + UUID testId = UUID.randomUUID(); + String paramName = "param1"; ParameterizationManager parameterizationManager = new ParameterizationManager( - UUID.randomUUID(), 1); + testId, 1); + createFileAndWriteContent(testId, paramName); @SuppressWarnings("unchecked") Map parameterMapBeforeCreate = (Map) TestHelper .invokePrivate(parameterizationManager, "getParameterMap", null, null); assertEquals(0, parameterMapBeforeCreate.size()); + assertTrue(parameterizationManager - .createParaInstanceWith(new DefinedParameter("param1", - "Para_Table", PickOrder.SEQUENTIAL.name(), - UpdateStrategy.EACH_ITERATION.name()))); + .createParaInstanceWith(new DefinedParameter(paramName, + "Para_File", PickOrder.SEQUENTIAL.name(), + UpdateStrategy.ONCE.name()))); @SuppressWarnings("unchecked") Map parameterMapAfterCreate = (Map) TestHelper .invokePrivate(parameterizationManager, "getParameterMap", @@ -39,6 +52,109 @@ public class Test_ParameterManager { assertEquals(1, parameterMapAfterCreate.size()); } + @Test + public void test_createParaInstancesWith_Null() throws IOException { + UUID testId = UUID.randomUUID(); + final String paramName = "param1"; + ParameterizationManager parameterizationManager = new ParameterizationManager( + testId, 1); + createFileAndWriteContent(testId, paramName); + Map parameterMap = parameterizationManager + .createParaInstancesWith(null, + new UpdateStrategy.OnceRestriction()); + assertEquals(0, parameterMap.size()); + } + + @Test + public void test_createParaInstancesWith_ONCE() throws IOException { + UUID testId = UUID.randomUUID(); + final String paramName = "param1"; + ParameterizationManager parameterizationManager = new ParameterizationManager( + testId, 1); + createFileAndWriteContent(testId, paramName); + Map parameterMap = parameterizationManager + .createParaInstancesWith( + new DefinedParameter[] { new DefinedParameter( + paramName, "Para_File", PickOrder.SEQUENTIAL + .toString(), UpdateStrategy.ONCE + .toString()) }, + new UpdateStrategy.OnceRestriction()); + assertEquals(1, parameterMap.size()); + assertEquals("12", parameterMap.get(paramName).getCurrentValue()); + } + + @Test + public void test_createParaInstanceWith_UpdateStrategy_Once() + throws Exception { + UUID testId = UUID.randomUUID(); + String paramName = "param1"; + createFileAndWriteContent(testId, paramName); + Scenario scenario = Scenario + .scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter( + paramName, "Para_File", PickOrder.SEQUENTIAL.name(), + UpdateStrategy.ONCE.name()))); + ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext( + testId, scenario, 1); + VUser vUser = new VUser(scenarioContext); + String v1_firstValue = vUser.getParam(paramName); + String v1_secondValue = vUser.getParam(paramName); + assertEquals("12", v1_firstValue); + assertEquals(v1_firstValue, v1_secondValue); + VUser vUser2 = new VUser(scenarioContext); + String v2_firstValue = vUser2.getParam(paramName); + String v2_secondValue = vUser2.getParam(paramName); + assertEquals(v1_firstValue, v2_firstValue); + assertEquals(v2_firstValue, v2_secondValue); + } + + private void createFileAndWriteContent(UUID testId, String paramName) + throws IOException { + File paramFile = new File((new BasePara(testId) { + @Override + public String getCurrentValue() { + return null; + } + }).getParamFileFullPath(paramName)); + TestHelper.createFileIfNotExist(paramFile); + FileUtils.writeStringToFile(paramFile, "12;13;14;15"); + } + + @Test + public void test_createParaInstanceWith_UpdateStrategy_EACH_ITERATION() + throws IOException { + UUID testId = UUID.randomUUID(); + String paramName = "param1"; + createFileAndWriteContent(testId, paramName); + Scenario scenario = Scenario + .scenarioBuilder(buildATestScenarioModelWith(new DefinedParameter( + paramName, "Para_File", PickOrder.SEQUENTIAL.name(), + UpdateStrategy.EACH_ITERATION.name()))); + ScenarioContext scenarioContext = ScenarioContext.buildScenarioContext( + testId, scenario, 1); + VUser vUser = new VUser(scenarioContext); + String v1_firstValue = vUser.getParam(paramName); + String v1_secondeValue = vUser.getParam(paramName); + assertNotEquals(paramName, v1_firstValue); + assertEquals(v1_firstValue, v1_secondeValue); + VUser vUser2 = new VUser(scenarioContext); + String v2_firstValue = vUser2.getParam(paramName); + String v2_secondValue = vUser2.getParam(paramName); + assertNotEquals(paramName, v2_firstValue); + assertEquals(v2_firstValue, v2_secondValue); + assertNotEquals(v1_firstValue, v2_firstValue); + } + + private RunScenarioModel buildATestScenarioModelWith( + DefinedParameter definedParameter) { + RunScenarioModel runScenarioModel = new RunScenarioModel(); + runScenarioModel.getDefinedParameters().add( + new DefinedParameterModel(definedParameter.getName(), + definedParameter.getType(), definedParameter + .getPickOrder(), definedParameter + .getUpdateStrategy())); + return runScenarioModel; + } + @Test public void test_getParaClasses() throws Exception { ParameterizationManager parameterizationManager = new ParameterizationManager( @@ -47,7 +163,7 @@ public class Test_ParameterManager { Map> paraClasses = (Map>) TestHelper .invokePrivate(parameterizationManager, "getParaClasses", null, null); - assertEquals(6, paraClasses.size()); + assertEquals(7, paraClasses.size()); assertTrue(paraClasses.containsKey("Para_Table")); assertTrue(paraClasses.containsKey("Para_GetEletronicCombine")); assertTrue(paraClasses.containsKey("Para_IteratorNumber")); @@ -55,4 +171,5 @@ public class Test_ParameterManager { assertTrue(paraClasses.containsKey("Para_UniqueNumber")); assertTrue(paraClasses.containsKey("Para_UserNameAndPassword")); } + } diff --git a/Bench4Q-Master/report/7e73a8a5-b9bd-41ab-a100-2c8c2c0ecc57.pdf b/Bench4Q-Master/report/7e73a8a5-b9bd-41ab-a100-2c8c2c0ecc57.pdf new file mode 100644 index 00000000..7470b360 Binary files /dev/null and b/Bench4Q-Master/report/7e73a8a5-b9bd-41ab-a100-2c8c2c0ecc57.pdf differ