parent
2cc40c7f24
commit
6ad7385bbd
|
@ -10,11 +10,20 @@ public class HBaseMesseger {
|
|||
public String userId = null;
|
||||
private Configuration conf = HBaseConfiguration.create();
|
||||
|
||||
public boolean send(double sum, double usage, double U, double I,
|
||||
String time_userId) {
|
||||
public HBaseMesseger() {
|
||||
try {
|
||||
@SuppressWarnings({ "unused", "resource" })
|
||||
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean send(double sum, double usage, double U, double I,
|
||||
String time_userId) {
|
||||
try {
|
||||
System.out.println("sum :" + sum + "_usage :" + usage + "_U :" + U
|
||||
+ "_I :" + I + "_time_userId" + time_userId);
|
||||
@SuppressWarnings("resource")
|
||||
HTable table = new HTable(conf, "MeterLogData");
|
||||
Put put = new Put(time_userId.getBytes());
|
||||
|
|
|
@ -46,7 +46,8 @@ public class HBasePlugin {
|
|||
.getRow(0);
|
||||
this.electricCurrentGenerator = RecordGenerator
|
||||
.buildGeneratorWithRow(electricCurrentRow);
|
||||
Row electricityRow = Table.buildTable(electricity, LABEL_LIST).getRow(0);
|
||||
Row electricityRow = Table.buildTable(electricity, LABEL_LIST)
|
||||
.getRow(0);
|
||||
this.electricityGenerator = RecordGenerator
|
||||
.buildGeneratorWithRow(electricityRow);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,13 @@ public abstract class RecordGenerator {
|
|||
legalDataTypes.add("long");
|
||||
}
|
||||
|
||||
Set<String> legalGenerators = new LinkedHashSet<String>();
|
||||
{
|
||||
legalGenerators.add("random");
|
||||
legalGenerators.add("sin");
|
||||
legalGenerators.add("cos");
|
||||
}
|
||||
|
||||
private RecordGenerator(String dataType, String minValue, String maxValue) {
|
||||
this.dataType = dataType.toLowerCase();
|
||||
if (!this.legalDataTypes.contains(this.dataType)) {
|
||||
|
@ -72,7 +79,7 @@ public abstract class RecordGenerator {
|
|||
} else if (generator.equalsIgnoreCase("cos")) {
|
||||
return new CosGenerator(dataType, min, max);
|
||||
} else {
|
||||
return new RandomGenerator(dataType, min, max);
|
||||
throw new Bench4QRunTimeException("illegal generator request");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +114,7 @@ public abstract class RecordGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public static abstract class TrigonometricGenerator extends RecordGenerator {
|
||||
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
|
||||
|
@ -119,7 +126,7 @@ public abstract class RecordGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public static class SinGenerator extends TrigonometricGenerator {
|
||||
static class SinGenerator extends TrigonometricGenerator {
|
||||
private Double currentAngle = 0D;
|
||||
|
||||
private SinGenerator(String dataType, String minValue, String maxValue) {
|
||||
|
@ -141,7 +148,7 @@ public abstract class RecordGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public static class CosGenerator extends TrigonometricGenerator {
|
||||
static class CosGenerator extends TrigonometricGenerator {
|
||||
private Double currentAngle = 0D;
|
||||
|
||||
private CosGenerator(String dataType, String minValue, String maxValue) {
|
||||
|
@ -162,4 +169,5 @@ public abstract class RecordGenerator {
|
|||
this.currentAngle = 0D;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -127,9 +127,9 @@ public class Test_HBasePlugin {
|
|||
|
||||
private static BehaviorModel createABehavior(int i) {
|
||||
List<ParameterModel> parameters = new ArrayList<ParameterModel>();
|
||||
parameters.add(ParameterModel.createParameter("beginTime",
|
||||
parameters.add(ParameterModel.createParameter("beginDay",
|
||||
"201309110000000"));
|
||||
parameters.add(ParameterModel.createParameter("endTime",
|
||||
parameters.add(ParameterModel.createParameter("endDay",
|
||||
"201309150000000"));
|
||||
parameters.add(ParameterModel.createParameter("beginUser", 1000 * i + 1
|
||||
+ ""));
|
||||
|
@ -144,7 +144,8 @@ public class Test_HBasePlugin {
|
|||
HBasePlugin plugin = new HBasePlugin("10", "1",
|
||||
"dataType=Int|generator=Random|min=10|max=50|;",
|
||||
"dataType=Double|generator=Sin|min=216|max=226",
|
||||
"dataType=Float|generator=Cos|min=1056|max=1068");
|
||||
plugin.send("201403270530101", "201403271030101", "1", "100");
|
||||
"dataType=long|generator=Cos|min=1056|max=1068");
|
||||
plugin.send("201403270000000", "201403280000000", "1", "4");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,14 @@ public class Test_RecordGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = Bench4QRunTimeException.class)
|
||||
public void test_buildGeneratorWithIllegalGenerator() {
|
||||
String input = "dataType=Int|generator=hah|min=10|max=50|;";
|
||||
Row inputRow = Table.buildTable(input, HBasePlugin.LABEL_LIST)
|
||||
.getRow(0);
|
||||
RecordGenerator.buildGeneratorWithRow(inputRow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_buildGeneratorWithRandomWithMinGTmax() {
|
||||
String input = "dataType=Int|generator=Random|min=50|max=10|;";
|
||||
|
@ -84,4 +92,32 @@ public class Test_RecordGenerator {
|
|||
assertTrue(resultValue <= 50);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_cosReset() {
|
||||
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);
|
||||
Double firstValue = recordGenerator.getDouble();
|
||||
recordGenerator.reset();
|
||||
Double secondValue = recordGenerator.getDouble();
|
||||
assertEquals(firstValue, secondValue);
|
||||
System.out.println(firstValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_sinReset() {
|
||||
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);
|
||||
Double firstValue = recordGenerator.getDouble();
|
||||
recordGenerator.reset();
|
||||
Double secondValue = recordGenerator.getDouble();
|
||||
assertEquals(firstValue, secondValue);
|
||||
System.out.println(firstValue);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue