diff --git a/Bench4Q-Agent/src/main/java/hbase-site.xml b/Bench4Q-Agent/src/main/java/hbase-site.xml
index 64d67a4b..f5eaecb6 100644
--- a/Bench4Q-Agent/src/main/java/hbase-site.xml
+++ b/Bench4Q-Agent/src/main/java/hbase-site.xml
@@ -26,7 +26,7 @@
hbase.zookeeper.quorum
- 133.133.134.188
+ 133.133.13.154
hbase.zookeeper.property.dataDir
diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java
index 79b67257..699c17fa 100644
--- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java
+++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/HBasePlugin/HBasePlugin.java
@@ -29,12 +29,23 @@ public class HBasePlugin {
private final HTable tableUnderTest;
@Constructor
- public HBasePlugin() {
+ public HBasePlugin(
+ @Parameter(value = "dnsServer", type = SupportTypes.Field) String dnsServer,
+ @Parameter(value = "zookeeperQuorum", type = SupportTypes.Field) String zookeeperQuorum,
+ @Parameter(value = "zookeeperDataDir", type = SupportTypes.Field) String zookeeperDataDir,
+ @Parameter(value = "masterAdrress", type = SupportTypes.Field) String masterAdrress,
+ @Parameter(value = "tableName", type = SupportTypes.Field) String tableName) {
conf = HBaseConfiguration.create();
try {
+ Configuration config = new Configuration();
+ config.set("hbase.master.dns.nameserver", dnsServer);
+ config.setBoolean("hbase.cluster.distributed", true);
+ config.set("hbase.zookeeper.quorum", zookeeperQuorum);
+ config.set("hbase.zookeeper.property.dataDir", zookeeperDataDir);
+ config.set("hbase.master.info.bindAddress", masterAdrress);
@SuppressWarnings({ "unused", "resource" })
- HBaseAdmin admin = new HBaseAdmin(conf);
- tableUnderTest = new HTable(conf, "users");
+ HBaseAdmin admin = new HBaseAdmin(config);
+ tableUnderTest = new HTable(conf, tableName);
} catch (Exception e) {
e.printStackTrace();
throw new Bench4QRunTimeException("Construct HBasePlugin fails!", e);
@@ -47,8 +58,8 @@ public class HBasePlugin {
@Parameter(value = "value", type = SupportTypes.Field) String value) {
try {
Put put = new Put(UUID.randomUUID().toString().getBytes());
- put.add("key".getBytes(), "key".getBytes(), key.getBytes());
- put.add("value".getBytes(), "value".getBytes(), value.getBytes());
+ put.add("key1".getBytes(), "key1".getBytes(), key.getBytes());
+ put.add("value1".getBytes(), "value1".getBytes(), value.getBytes());
this.tableUnderTest.put(put);
} catch (Exception ex) {
Logger.getLogger(HBasePlugin.class).info(ex, ex);
@@ -57,11 +68,12 @@ public class HBasePlugin {
return new HBaseReturn(true);
}
- public HBaseReturn Query(
+ @Behavior(value = "Query", type = BehaviorType.USER_BEHAVIOR)
+ public HBaseReturn query(
@Parameter(value = "key", type = SupportTypes.Field) String key) {
try {
- Filter filter = new SingleColumnValueFilter(Bytes.toBytes("key"),
- Bytes.toBytes("key"), CompareOp.EQUAL, Bytes.toBytes("aaa")); // 当列column1的值为aaa时进行查询
+ Filter filter = new SingleColumnValueFilter(Bytes.toBytes("key1"),
+ Bytes.toBytes("key1"), CompareOp.EQUAL, Bytes.toBytes(key)); // 当列column1的值为aaa时进行查询
Scan s = new Scan();
s.setFilter(filter);
ResultScanner resultScanner = this.tableUnderTest.getScanner(s);
diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/PluginReturn.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/PluginReturn.java
index 537a5d5c..e670ae9b 100644
--- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/PluginReturn.java
+++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/PluginReturn.java
@@ -1,12 +1,8 @@
package org.bench4q.agent.plugin.basic;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
public abstract class PluginReturn {
private int successCount;
private int failCount;
- private Map runTimeParams;
public int getSuccessCount() {
return successCount;
@@ -24,32 +20,14 @@ public abstract class PluginReturn {
this.failCount = failCount;
}
- public Map getRunTimeParams() {
- return runTimeParams;
- }
-
- public void setRunTimeParams(Map runTimeParams) {
- this.runTimeParams = runTimeParams;
- }
-
- public PluginReturn() {
- this.setRunTimeParams(new LinkedHashMap());
- }
-
public PluginReturn(boolean success) {
- this();
this.setSuccessCount(success ? 1 : 0);
this.setFailCount(success ? 0 : 1);
}
public PluginReturn(int successCount, int failCount) {
- this();
this.setSuccessCount(successCount);
this.setFailCount(failCount);
}
- public boolean hasRunTimeParams() {
- return (this.getRunTimeParams() == null || this.getRunTimeParams()
- .size() == 0) ? false : true;
- }
}
diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java
index 82fd9640..ea8f1ed3 100644
--- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java
+++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpPlugin.java
@@ -235,7 +235,8 @@ public class HttpPlugin extends ParameterBarn {
method.getResponseBodyAsString());
}
return new HttpReturn((responseCode % 100) < 4, responseCode,
- contentLength, contentType, responseHeaders);
+ method.getURI().toString(), contentLength, contentType,
+ responseHeaders);
} catch (HttpException e) {
Logger.getLogger(HttpPlugin.class).error(e, e);
return new HttpReturn(false, 400, contentLength, contentType);
diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java
index ee4dcaa4..3ff8160d 100644
--- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java
+++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/http/HttpReturn.java
@@ -10,6 +10,7 @@ import org.bench4q.agent.plugin.basic.PluginReturn;
*
*/
public class HttpReturn extends PluginReturn {
+ private String url;
private int statusCode;
private long contentLength;
private String contentType;
@@ -47,6 +48,14 @@ public class HttpReturn extends PluginReturn {
this.headers = headers;
}
+ public String getUrl() {
+ return url;
+ }
+
+ private void setUrl(String url) {
+ this.url = url;
+ }
+
public HttpReturn(boolean success, int statusCode, long contentLength,
String contentType) {
super(success);
@@ -62,12 +71,12 @@ public class HttpReturn extends PluginReturn {
* @param contentLength
* @param contentType
* @param responseHeaders
- * @param runTimeParams
- * !! to be removed
*/
- public HttpReturn(boolean success, int responseCode, long contentLength,
- String contentType, Header[] responseHeaders) {
+ public HttpReturn(boolean success, int responseCode, String url,
+ long contentLength, String contentType, Header[] responseHeaders) {
this(success, responseCode, contentLength, contentType);
this.setHeaders(responseHeaders);
+ this.setUrl(url);
}
+
}
diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/BehaviorResult.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/BehaviorResult.java
index daa360fe..9f4b502b 100644
--- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/BehaviorResult.java
+++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/BehaviorResult.java
@@ -5,19 +5,19 @@ import java.util.Date;
public class BehaviorResult {
private String pluginId;
private String pluginName;
+ private int behaviorId;
private String behaviorName;
private Date startDate;
private Date endDate;
private long responseTime;
private int successCount;
private int failCount;
+ private boolean shouldBeCountResponseTime;
- private int behaviorId;
private String behaviorUrl;
private long contentLength;
private int statusCode;
private String contentType;
- private boolean shouldBeCountResponseTime;
public String getPluginId() {
return pluginId;
diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java
index daca84df..a7986ac8 100644
--- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java
+++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/scenario/VUser.java
@@ -152,6 +152,7 @@ public class VUser implements Runnable {
Object plugin, Date startDate, PluginReturn pluginReturn,
Date endDate) {
BehaviorResult result = new BehaviorResult();
+ result.setBehaviorId(behavior.getId());
result.setStartDate(startDate);
result.setEndDate(endDate);
result.setSuccessCount(pluginReturn.getSuccessCount());
@@ -164,7 +165,6 @@ public class VUser implements Runnable {
result.setShouldBeCountResponseTime(behavior.shouldBeCount());
if (pluginReturn instanceof HttpReturn) {
HttpReturn httpReturn = (HttpReturn) pluginReturn;
- result.setBehaviorId(behavior.getId());
// TODO: this param in result is not Appropriate
result.setBehaviorUrl(behavior.getSpecificParamValue("url"));
result.setContentLength(httpReturn.getContentLength());
diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java
index b2c52059..570eb1d6 100644
--- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java
+++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/Solution.java
@@ -1,7 +1,5 @@
package org.bench4q.agent.test;
-import static org.junit.Assert.*;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
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..4ed4bc49
--- /dev/null
+++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_HBasePlugin.java
@@ -0,0 +1,101 @@
+package org.bench4q.agent.test.plugin;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.UUID;
+
+import org.apache.commons.io.FileUtils;
+import org.bench4q.agent.plugin.basic.HBasePlugin.HBasePlugin;
+import org.bench4q.agent.plugin.basic.HBasePlugin.HBaseReturn;
+import org.bench4q.agent.scenario.Scenario;
+import org.bench4q.agent.test.TestBase;
+import org.bench4q.share.helper.MarshalHelper;
+import org.bench4q.share.helper.TestHelper;
+import org.bench4q.share.models.agent.ParameterModel;
+import org.bench4q.share.models.agent.RunScenarioModel;
+import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
+import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:application-context.xml" })
+public class Test_HBasePlugin extends TestBase {
+ HBasePlugin hBase = new HBasePlugin("133.133.134.188", "133.133.13.154",
+ "/home/Xinsheng/hbase/tmp/zookeeper_data", "133.133.134.188",
+ "users");
+
+ @Test
+ public void test() {
+ HBaseReturn result = this.hBase.insert("123", "chentienan");
+ assertTrue(result.getSuccessCount() > 0);
+ }
+
+ @Test
+ public void testQuery() {
+ HBaseReturn result = this.hBase.query("123");
+ assertTrue(result.getSuccessCount() > 0);
+ }
+
+ @Test
+ public void testGenerateHBaseScenario() throws IOException {
+ BehaviorModel[] behaviors = new BehaviorModel[19];
+ for (int i = 0; i < 9; i++) {
+ behaviors[2 * i] = BehaviorModel.ControlBehaviorBuilder(2 * i,
+ "Next", "UUID_0", Collections. emptyList());
+ behaviors[2 * i + 1] = BehaviorModel
+ .UserBehaviorBuilder(
+ 2 * i + 1,
+ "Insert",
+ "HBasePlugin_0",
+ Arrays.asList(
+ ParameterModel.createParameter("key",
+ "${UUID_0:var}"),
+ ParameterModel
+ .createParameter(
+ "value",
+ "828731929090399688663513844419156517791913487136162075054396888608979390802698967398774976538053071265086303536432973027547398485897859650637839199967916419278859657562410371550970990533755543895317958490879810955359859803793616914752497927102101107393602107374624265703167902037562601756290624400217677905796841586506540830996528039667809341170671731917392828543425909887469350859806312812589702773082295018742634842159778009485901428286815715514440370336211621120027294867866046842579395402354849290925687231979896816952130161564546780855710443002842992917011602246580128072986737704758180050405202976240171827695507627799312781883033823819663102843159141022325482803101497005554269652897365593399081219143594918151989844361363454642099858085072470136971359171934346214072016627940215525657780835264287095014748952849011967941296078931973149033644269161629346531549579584063826798825958153903463232155174301997795504543310963155667642944030315802981522872371957377604512253881055347955240594154853114826089693318722619283530276507503")));
+ }
+ behaviors[18] = BehaviorModel.TimerBehaviorBuilder(28, "Sleep",
+ "Timer_0",
+ Arrays.asList(ParameterModel.createParameter("time", "10")));
+ RunScenarioModel runScenarioModel = buildRunScenarioModelWith(
+ Arrays.asList(
+ new UsePluginModel("Timer_0", "ConstantTimer",
+ Collections. emptyList()),
+ new UsePluginModel("UUID_0", "UUID", null),
+ new UsePluginModel("Context_0", "Context", null),
+ new UsePluginModel(
+ "HBasePlugin_0",
+ "HBase",
+ Arrays.asList(
+ ParameterModel.createParameter(
+ "dnsServer", "133.133.134.188"),
+ ParameterModel.createParameter(
+ "zookeeperQuorum",
+ "133.133.13.154"),
+ ParameterModel
+ .createParameter(
+ "zookeeperDataDir",
+ "/home/Xinsheng/hbase/tmp/zookeeper_data"),
+ ParameterModel.createParameter(
+ "masterAdrress",
+ "133.133.134.188"),
+ ParameterModel.createParameter(
+ "tableName", "users")))),
+ behaviors);
+ File file = new File("Scripts" + System.getProperty("file.separator")
+ + "hbaseScenario.xml");
+ TestHelper.createFileIfNotExist(file);
+ FileUtils.writeStringToFile(file,
+ MarshalHelper.tryMarshal(runScenarioModel));
+ createVUser(Scenario.scenarioBuilderWithCompile(runScenarioModel),
+ UUID.randomUUID()).run();
+ }
+}
diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java
index 98942cad..c15b57e0 100644
--- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java
+++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/scenario/Test_Scenario.java
@@ -34,7 +34,7 @@ public class Test_Scenario extends TestBase {
private static final String TEST_CASE = "${csvProvider0:userName}$#okOrNot${file.separator}";
@Test
- public void test_RealScenario() throws IOException {
+ public void test_GenerateMongoScenario() throws IOException {
BehaviorModel[] behaviors = new BehaviorModel[28];
for (int i = 0; i < 9; i++) {
behaviors[3 * i] = BehaviorModel