diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/HBasePlugin.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/HBasePlugin.java index 696b6f1a..482f312d 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/HBasePlugin.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/HBasePlugin.java @@ -22,6 +22,12 @@ public class HBasePlugin { private HBaseMesseger hBaseMesseger = new HBaseMesseger(); private SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddhhmmssS"); + // Give it a default value + private int sendRate = 1; + private int sampleRate = 10; + private static int ONE_DAY_TO_MS = 24 * 60 * 60 * 1000; + private static int ONE_MINUTE_TO_MS = 60 * 1000; + static int ONE_DAY_TO_MINUTE = 24 * 60; public static List LABEL_LIST; static { @@ -32,6 +38,16 @@ public class HBasePlugin { LABEL_LIST.add("max"); } + /** + * + * @param sampleRate + * this param's unit is minute + * @param sendRate + * this param's unit is day + * @param voltage + * @param electricCurrent + * @param electricity + */ @Constructor public HBasePlugin( @Parameter(value = "sampleRate", type = SupportTypes.Field) String sampleRate, @@ -39,17 +55,21 @@ public class HBasePlugin { @Parameter(value = "voltage", type = SupportTypes.Table) String voltage, @Parameter(value = "electricCurrent", type = SupportTypes.Table) String electricCurrent, @Parameter(value = "electricity", type = SupportTypes.Table) String electricity) { + this.sendRate = Integer.parseInt(sendRate); + this.sampleRate = Integer.parseInt(sampleRate); + int sampleCountForSendOnce = this.sendRate * ONE_DAY_TO_MINUTE + / this.sampleRate; Row voltageRow = Table.buildTable(voltage, LABEL_LIST).getRow(0); - this.voltageGenerator = RecordGenerator - .buildGeneratorWithRow(voltageRow); + this.voltageGenerator = RecordGenerator.buildGeneratorWithRow( + voltageRow, sampleCountForSendOnce); Row electricCurrentRow = Table.buildTable(electricCurrent, LABEL_LIST) .getRow(0); - this.electricCurrentGenerator = RecordGenerator - .buildGeneratorWithRow(electricCurrentRow); + this.electricCurrentGenerator = RecordGenerator.buildGeneratorWithRow( + electricCurrentRow, sampleCountForSendOnce); Row electricityRow = Table.buildTable(electricity, LABEL_LIST) .getRow(0); - this.electricityGenerator = RecordGenerator - .buildGeneratorWithRow(electricityRow); + this.electricityGenerator = RecordGenerator.buildGeneratorWithRow( + electricityRow, sampleCountForSendOnce); } @Behavior("Send") @@ -78,7 +98,8 @@ public class HBasePlugin { twoTupple.add(sendForOneUserOneDay(beginUserInt, sumOfEletricity, dayIndex, userIndex)); } - dayIndex = new Date(dayIndex.getTime() + 24 * 60 * 60 * 1000); + dayIndex = new Date(dayIndex.getTime() + ONE_DAY_TO_MS + * this.sendRate); } return new ElectReturn(twoTupple.successCount, twoTupple.failCount); } @@ -100,7 +121,7 @@ public class HBasePlugin { Date sendTime = dayIndex; resetGenerators(); - for (int sampleIndex = 0; sampleIndex < 144; sampleIndex++) { + for (int sampleIndex = 0; sampleIndex < ONE_DAY_TO_MINUTE / 10; sampleIndex++) { electricity = this.electricityGenerator.getDouble(); voltage = this.voltageGenerator.getDouble(); electricCurrent = this.electricCurrentGenerator.getDouble(); @@ -113,7 +134,8 @@ public class HBasePlugin { this.dateFormat.format(sendTime) + "_" + String.valueOf(userIndex)); result.add(ret); - sendTime = new Date(sendTime.getTime() + 10 * 60 * 1000); + sendTime = new Date(sendTime.getTime() + this.sampleRate + * ONE_MINUTE_TO_MS); } return result; } diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/RecordGenerator.java b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/RecordGenerator.java index 1d15299f..34cdff34 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/RecordGenerator.java +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/RecordGenerator.java @@ -11,6 +11,7 @@ public abstract class RecordGenerator { protected String dataType; protected Double minValue; protected Double maxValue; + protected int sampleCountForSendOnce; Set legalDataTypes = new LinkedHashSet(); { @@ -26,7 +27,8 @@ public abstract class RecordGenerator { legalGenerators.add("cos"); } - private RecordGenerator(String dataType, String minValue, String maxValue) { + private RecordGenerator(String dataType, String minValue, String maxValue, + int sampleCountForSendOnce) { this.dataType = dataType.toLowerCase(); if (!this.legalDataTypes.contains(this.dataType)) { throw new Bench4QRunTimeException( @@ -71,21 +73,23 @@ public abstract class RecordGenerator { * @return */ private static RecordGenerator buildGenerator(String dataType, - String generator, String min, String max) { + String generator, String min, String max, int sampleCountForSendOnce) { if (generator.equalsIgnoreCase("random")) { - return new RandomGenerator(dataType, min, max); + return new RandomGenerator(dataType, min, max, + sampleCountForSendOnce); } else if (generator.equalsIgnoreCase("sin")) { - return new SinGenerator(dataType, min, max); + return new SinGenerator(dataType, min, max, sampleCountForSendOnce); } else if (generator.equalsIgnoreCase("cos")) { - return new CosGenerator(dataType, min, max); + return new CosGenerator(dataType, min, max, sampleCountForSendOnce); } else { throw new Bench4QRunTimeException("illegal generator request"); } } - public static RecordGenerator buildGeneratorWithRow(Row row) { + public static RecordGenerator buildGeneratorWithRow(Row row, + int sampleCountForSendOnce) { RecordGenerator result = buildGenerator(row.getCell(0), row.getCell(1), - row.getCell(2), row.getCell(3)); + row.getCell(2), row.getCell(3), sampleCountForSendOnce); result.reset(); return result; } @@ -94,8 +98,8 @@ public abstract class RecordGenerator { private Random random; private RandomGenerator(String dataType, String minValue, - String maxValue) { - super(dataType, minValue, maxValue); + String maxValue, int sampleCountForSendOnce) { + super(dataType, minValue, maxValue, sampleCountForSendOnce); this.random = new Random(); } @@ -116,21 +120,22 @@ public abstract class RecordGenerator { static abstract class TrigonometricGenerator extends RecordGenerator { protected static Double Trigonometric_Cycle = 2 * Math.PI; - protected static int OneDay_SplitBy_TenMinute = 144; + protected static int OneDay_SplitBy_TenMinute = HBasePlugin.ONE_DAY_TO_MINUTE / 10; protected static Double Accumulate_Once = Trigonometric_Cycle / OneDay_SplitBy_TenMinute; private TrigonometricGenerator(String dataType, String minValue, - String maxValue) { - super(dataType, minValue, maxValue); + String maxValue, int sampleCountForSendOnce) { + super(dataType, minValue, maxValue, sampleCountForSendOnce); } } static class SinGenerator extends TrigonometricGenerator { private Double currentAngle = 0D; - private SinGenerator(String dataType, String minValue, String maxValue) { - super(dataType, minValue, maxValue); + private SinGenerator(String dataType, String minValue, String maxValue, + int sampleCountForSendOnce) { + super(dataType, minValue, maxValue, sampleCountForSendOnce); } @Override @@ -151,8 +156,9 @@ public abstract class RecordGenerator { static class CosGenerator extends TrigonometricGenerator { private Double currentAngle = 0D; - private CosGenerator(String dataType, String minValue, String maxValue) { - super(dataType, minValue, maxValue); + private CosGenerator(String dataType, String minValue, String maxValue, + int sampleCountForSendOnce) { + super(dataType, minValue, maxValue, sampleCountForSendOnce); } @Override diff --git a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/ui.xml b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/ui.xml index 4f0d3802..f8646398 100644 --- a/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/ui.xml +++ b/Bench4Q-Agent/src/main/java/org/bench4q/agent/plugin/basic/hbase/ui.xml @@ -3,10 +3,10 @@ - + - + diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_CsvProvider.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_CsvProvider.java index cd980cc4..0c36f058 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_CsvProvider.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/Test_CsvProvider.java @@ -82,17 +82,21 @@ public class Test_CsvProvider extends TestBase { } @Test - public void test_InitialRightly_By_VUser() { + public void test_InitialRightly_By_VUser() throws IOException { final String fileName = "param_csv"; + UUID testId = UUID.randomUUID(); + createFileAndWriteContent(testId, fileName, CONTENT); RunScenarioModel runScenarioModel = buildRunScenarioModel(fileName); - Scenario scenario = Scenario.scenarioBuilderWithCompile(runScenarioModel); - VUser vUser = Test_VUser.createVUser(scenario, UUID.randomUUID()); + Scenario scenario = Scenario + .scenarioBuilderWithCompile(runScenarioModel); + VUser vUser = Test_VUser.createVUser(scenario, testId); try { HashMap plugins = new HashMap(); TestHelper.invokePrivate(vUser, "preparePlugins", new Class[] { Scenario.class, Map.class }, new Object[] { scenario, plugins }); assertTrue(plugins.containsKey("csvProvider0")); + dropFiles(testId); } catch (Exception e) { e.printStackTrace(); fail(); diff --git a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/hbase/Test_RecordGenerator.java b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/hbase/Test_RecordGenerator.java index ba7277e2..1f932b69 100644 --- a/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/hbase/Test_RecordGenerator.java +++ b/Bench4Q-Agent/src/test/java/org/bench4q/agent/test/plugin/hbase/Test_RecordGenerator.java @@ -17,7 +17,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); RecordGenerator resultGenerator = RecordGenerator - .buildGeneratorWithRow(inputRow); + .buildGeneratorWithRow(inputRow, 144); assertTrue(resultGenerator instanceof RandomGenerator); for (int i = 0; i < 100; i++) { Double resultValue = resultGenerator.getDouble(); @@ -32,7 +32,7 @@ public class Test_RecordGenerator { String input = "dataType=Int|generator=hah|min=10|max=50|;"; Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); - RecordGenerator.buildGeneratorWithRow(inputRow); + RecordGenerator.buildGeneratorWithRow(inputRow, 144); } @Test @@ -41,7 +41,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); try { - RecordGenerator.buildGeneratorWithRow(inputRow); + RecordGenerator.buildGeneratorWithRow(inputRow, 144); fail("should not come here"); } catch (Exception e) { assertTrue(e instanceof Bench4QRunTimeException); @@ -55,7 +55,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); try { - RecordGenerator.buildGeneratorWithRow(inputRow); + RecordGenerator.buildGeneratorWithRow(inputRow, 144); fail("should not come here"); } catch (Exception e) { assertTrue(e instanceof Bench4QRunTimeException); @@ -68,7 +68,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); RecordGenerator recordGenerator = RecordGenerator - .buildGeneratorWithRow(inputRow); + .buildGeneratorWithRow(inputRow, 144); for (int i = 0; i < 144; i++) { Double resultValue = recordGenerator.getDouble(); System.out.println(resultValue); @@ -84,7 +84,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); RecordGenerator recordGenerator = RecordGenerator - .buildGeneratorWithRow(inputRow); + .buildGeneratorWithRow(inputRow, 144); for (int i = 0; i < 144; i++) { Double resultValue = recordGenerator.getDouble(); System.out.println(resultValue); @@ -99,7 +99,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); RecordGenerator recordGenerator = RecordGenerator - .buildGeneratorWithRow(inputRow); + .buildGeneratorWithRow(inputRow, 144); Double firstValue = recordGenerator.getDouble(); recordGenerator.reset(); Double secondValue = recordGenerator.getDouble(); @@ -113,7 +113,7 @@ public class Test_RecordGenerator { Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); RecordGenerator recordGenerator = RecordGenerator - .buildGeneratorWithRow(inputRow); + .buildGeneratorWithRow(inputRow, 144); Double firstValue = recordGenerator.getDouble(); recordGenerator.reset(); Double secondValue = recordGenerator.getDouble();