refactor and add tests

This commit is contained in:
coderfengyun 2014-03-27 22:54:16 +08:00
parent 111666f3e4
commit 78c3c9a353
6 changed files with 115 additions and 18 deletions

View File

@ -13,6 +13,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>1</value>
@ -33,6 +37,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>1001</value>
@ -53,6 +61,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>2001</value>
@ -73,6 +85,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>3001</value>
@ -93,6 +109,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>4001</value>
@ -113,6 +133,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>5001</value>
@ -133,6 +157,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>6001</value>
@ -153,6 +181,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>7001</value>
@ -173,6 +205,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>8001</value>
@ -193,6 +229,10 @@
<key>beginTime</key>
<value>201309111715001</value>
</parameter>
<parameter>
<key>endTime</key>
<value>201309112215001</value>
</parameter>
<parameter>
<key>beginUser</key>
<value>9001</value>

View File

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- /** * * Licensed to the Apache Software Foundation (ASF) under one *
or more contributor license agreements. See the NOTICE file * distributed
with this work for additional information * regarding copyright ownership.
The ASF licenses this file * to you under the Apache License, Version 2.0
(the * "License"); you may not use this file except in compliance * with
the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0
* * Unless required by applicable law or agreed to in writing, software *
distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the
License for the specific language governing permissions and * limitations
under the License. */ -->
<configuration>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.master.dns.nameserver</name>
<value>133.133.134.188</value>
<description>The host name or IP address of the name server (DNS)
which a master should use to determine the host name used
forcommunication and display purposes.
</description>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>133.133.134.188</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/Xinsheng/hbase/tmp/zookeeper_data</value>
</property>
<property>
<name>hbase.master.info.bindAddress</name>
<value>133.133.134.188</value>
<description>The bind address for the HBase Master web UI
</description>
</property>
</configuration>

View File

@ -14,6 +14,7 @@ public class GenerateDevices {
// TODO Auto-generated method stub
Configuration conf = HBaseConfiguration.create();
try {
System.out.println(conf.get("hbase.zookeeper.quorum"));
@SuppressWarnings({ "unused", "resource" })
HBaseAdmin admin = new HBaseAdmin(conf);
@SuppressWarnings("resource")

View File

@ -12,7 +12,7 @@ import org.bench4q.agent.plugin.Plugin;
import org.bench4q.agent.utils.Type.SupportTypes;
@Plugin("Hbase")
public class hBasePlugin {
public class HBasePlugin {
@Behavior("Send")
public ElectReturn send(

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.junit.Assert.*;
@ -240,4 +241,12 @@ public class TestWithScriptFile {
}
}
@Test
public void testHBasePluginScenario() throws IOException {
String scenarioContent = FileUtils.readFileToString(new File(
"Scripts/HBaseScript.xml"));
HttpResponse httpResponse = this.getHttpRequester().sendPostXml(
url + "/runWithoutParams", scenarioContent, null);
}
}

View File

@ -11,6 +11,7 @@ import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.commons.io.FileUtils;
import org.bench4q.agent.plugin.basic.hbase.HBasePlugin;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.helper.TestHelper;
import org.bench4q.share.models.agent.ParameterModel;
@ -36,18 +37,21 @@ public class Test_HBasePlugin {
.get(0).getBehaviors().get(i);
assertEquals(i, behavior.getId());
assertEquals("Send", behavior.getName());
assertEquals(3, behavior.getParameters().size());
assertEquals(4, 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)
assertEquals("endTime", behavior.getParameters().get(1).getKey());
assertEquals("201309112215001", behavior.getParameters().get(1)
.getValue());
assertEquals("beginUser", behavior.getParameters().get(1).getKey());
assertEquals(1000 * i + 100 + "", behavior.getParameters().get(2)
assertEquals(1000 * i + 1 + "", behavior.getParameters().get(2)
.getValue());
assertEquals("endUser", behavior.getParameters().get(2).getKey());
assertEquals("beginUser", behavior.getParameters().get(2).getKey());
assertEquals(1000 * i + 100 + "", behavior.getParameters().get(3)
.getValue());
assertEquals("endUser", behavior.getParameters().get(3).getKey());
}
try {
File scriptFile = new File("Scripts"
@ -93,19 +97,21 @@ public class Test_HBasePlugin {
private BehaviorModel createABehavior(int i) {
List<ParameterModel> parameters = new ArrayList<ParameterModel>();
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);
parameters.add(ParameterModel.createParameter("beginTime",
"201309111715001"));
parameters.add(ParameterModel.createParameter("endTime",
"201309112215001"));
parameters.add(ParameterModel.createParameter("beginUser", 1000 * i + 1
+ ""));
parameters.add(ParameterModel.createParameter("endUser", 1000 * i + 100
+ ""));
return BehaviorModel
.UserBehaviorBuilder(i, "Send", "hBase", parameters);
}
@Test
public void testSend() {
HBasePlugin plugin = new HBasePlugin();
plugin.send("201403270530101", "201403271030101", "1", "100");
}
}