diff --git a/Bench4Q-Agent/Scripts/HBaseScript.xml b/Bench4Q-Agent/Scripts/HBaseScript.xml new file mode 100644 index 00000000..c0ebb87d --- /dev/null +++ b/Bench4Q-Agent/Scripts/HBaseScript.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + hBase + HBase + + + + \ No newline at end of file diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java new file mode 100644 index 00000000..f10bda33 --- /dev/null +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java @@ -0,0 +1,97 @@ +package org.bench4q.agent.test.plugin; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.*; + +import org.bench4q.share.models.agent.ParameterModel; +import org.bench4q.share.models.agent.RunScenarioModel; +import org.bench4q.share.models.agent.scriptrecord.BatchModel; +import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; +import org.bench4q.share.models.agent.scriptrecord.PageModel; +import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; + +public class Test_HBasePlugin { + @Test + public void testBuildScenario() { + RunScenarioModel result = buildScenario(10); + assertEquals(1, result.getUsePlugins().size()); + assertEquals("hBase", result.getUsePlugins().get(0).getId()); + assertEquals("HBase", result.getUsePlugins().get(0).getName()); + assertEquals(1, result.getPages().size()); + assertEquals(1, result.getPages().get(0).getBatches().size()); + assertEquals(10, result.getPages().get(0).getBatches().get(0) + .getBehaviors().size()); + for (int i = 0; i < 10; i++) { + BehaviorModel behavior = result.getPages().get(0).getBatches() + .get(0).getBehaviors().get(i); + assertEquals(i, behavior.getId()); + assertEquals("Send", behavior.getName()); + assertEquals(3, behavior.getParameters().size()); + assertEquals("USERBEHAVIOR", behavior.getType()); + assertEquals("hBase", behavior.getUse()); + assertEquals("beginTime", behavior.getParameters().get(0).getKey()); + assertEquals("201309111715001", behavior.getParameters().get(0) + .getValue()); + assertEquals(1000 * i + 1 + "", behavior.getParameters().get(1) + .getValue()); + assertEquals("beginUser", behavior.getParameters().get(1).getKey()); + assertEquals(1000 * i + 100 + "", behavior.getParameters().get(2) + .getValue()); + assertEquals("endUser", behavior.getParameters().get(2).getKey()); + } + } + + public RunScenarioModel buildScenario(int behaviorSize) { + RunScenarioModel runScenarioModel = new RunScenarioModel(); + + List usePluginList = new ArrayList(); + UsePluginModel plugin = new UsePluginModel(); + plugin.setId("hBase"); + plugin.setName("HBase"); + plugin.setParameters(Collections. emptyList()); + usePluginList.add(plugin); + runScenarioModel.setUsePlugins(usePluginList); + + List pageList = new ArrayList(); + PageModel page = new PageModel(); + List batchModelList = new ArrayList(); + BatchModel batch = new BatchModel(); + batch.setChildId(-1); + batch.setId(0); + batch.setParentId(-1); + + List behaviorList = new ArrayList(); + for (int i = 0; i < behaviorSize; i++) { + behaviorList.add(createABehavior(i)); + } + batch.setBehaviors(behaviorList); + batchModelList.add(batch); + page.setBatches(batchModelList); + pageList.add(page); + runScenarioModel.setPages(pageList); + return runScenarioModel; + } + + private BehaviorModel createABehavior(int i) { + List parameters = new ArrayList(); + ParameterModel beginTimePara = new ParameterModel(); + beginTimePara.setKey("beginTime"); + beginTimePara.setValue("201309111715001"); + parameters.add(beginTimePara); + ParameterModel beginUser = new ParameterModel(); + beginUser.setKey("beginUser"); + beginUser.setValue(1000 * i + 1 + ""); + parameters.add(beginUser); + ParameterModel endUser = new ParameterModel(); + endUser.setKey("endUser"); + endUser.setValue(1000 * i + 100 + ""); + parameters.add(endUser); + return BehaviorModel + .UserBehaviorBuilder(i, "Send", "hBase", parameters); + } +}