From b65a47523be85c0be75aaa6d2cad934e9dbdf4b3 Mon Sep 17 00:00:00 2001 From: coderfengyun Date: Fri, 25 Apr 2014 15:18:24 +0800 Subject: [PATCH] current HBase Plugin just fix the send rate and sample rate current HBase Plugin just fix the send rate and sample rate , i'll fulfill this later --- .../plugin/basic/hbase/RecordGenerator.java | 24 ++++++++++---- .../plugin/hbase/Test_RecordGenerator.java | 33 ++++++++++++++++++- 2 files changed, 50 insertions(+), 7 deletions(-) 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 3bf534ea..cc7d6ec6 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 @@ -107,7 +107,19 @@ public abstract class RecordGenerator { } } - public static class SinGenerator extends RecordGenerator { + public static abstract class TrigonometricGenerator extends RecordGenerator { + protected static Double Trigonometric_Cycle = 2 * Math.PI; + protected static int OneDay_SplitBy_TenMinute = 144; + protected static Double Accumulate_Once = Trigonometric_Cycle + / OneDay_SplitBy_TenMinute; + + private TrigonometricGenerator(String dataType, String minValue, + String maxValue) { + super(dataType, minValue, maxValue); + } + } + + public static class SinGenerator extends TrigonometricGenerator { private Double currentAngle = 0D; private SinGenerator(String dataType, String minValue, String maxValue) { @@ -116,10 +128,10 @@ public abstract class RecordGenerator { @Override public String getValue() { - Double value = (this.maxValue - this.minValue) + Double value = (this.maxValue - this.minValue) / 2 * Math.sin(this.currentAngle) + (this.maxValue + this.minValue) / 2; - this.currentAngle += Math.PI / 144; + this.currentAngle += Accumulate_Once; return convertAsDataType(String.valueOf(value)); } @@ -129,7 +141,7 @@ public abstract class RecordGenerator { } } - public static class CosGenerator extends RecordGenerator { + public static class CosGenerator extends TrigonometricGenerator { private Double currentAngle = 0D; private CosGenerator(String dataType, String minValue, String maxValue) { @@ -138,10 +150,10 @@ public abstract class RecordGenerator { @Override public String getValue() { - Double value = (this.maxValue - this.minValue) + Double value = (this.maxValue - this.minValue) / 2 * Math.cos(this.currentAngle) + (this.maxValue + this.minValue) / 2; - this.currentAngle += Math.PI / 144; + this.currentAngle += Accumulate_Once; return convertAsDataType(String.valueOf(value)); } 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 182a713f..d6d91d79 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 @@ -43,7 +43,7 @@ public class Test_RecordGenerator { @Test public void test_buildGeneratorWithRandomWithIllegalDataType() { - String input = "dataType=String|generator=Random|min=50|max=10|;"; + String input = "dataType=String|generator=Random|min=10|max=50|;"; Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) .getRow(0); try { @@ -53,4 +53,35 @@ public class Test_RecordGenerator { assertTrue(e instanceof Bench4QRunTimeException); } } + + @Test + public void test_getValueOfSin() { + String input = "dataType=double|generator=Sin|min=10|max=50|;"; + Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) + .getRow(0); + RecordGenerator recordGenerator = RecordGenerator + .buildGeneratorWithRow(inputRow); + for (int i = 0; i < 144; i++) { + Double resultValue = recordGenerator.getDouble(); + System.out.println(resultValue); + assertTrue(resultValue >= 10); + assertTrue(resultValue <= 50); + } + + } + + @Test + public void test_getCosValue() { + String input = "dataType=double|generator=Cos|min=10|max=50|;"; + Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST) + .getRow(0); + RecordGenerator recordGenerator = RecordGenerator + .buildGeneratorWithRow(inputRow); + for (int i = 0; i < 144; i++) { + Double resultValue = recordGenerator.getDouble(); + System.out.println(resultValue); + assertTrue(resultValue >= 10); + assertTrue(resultValue <= 50); + } + } }