use of org.apache.apex.examples.machinedata.data.MachineInfo in project apex-malhar by apache.
the class CalculatorOperatorTest method testMax.
public void testMax(CalculatorOperator oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.maxOutputPort.setSink(sortSink);
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
String timeKey = minuteDateFormat.format(date);
String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
Integer vs = new Integer(1);
MachineKey mk = new MachineKey(timeKey, day, vs, vs, vs, vs, vs, vs, vs);
oper.beginWindow(0);
MachineInfo info = new MachineInfo(mk, 1, 1, 1);
oper.dataPort.process(info);
info.setCpu(2);
oper.dataPort.process(info);
info.setCpu(3);
oper.dataPort.process(info);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
LOG.debug(o.toString());
KeyValPair<TimeBucketKey, Map<ResourceType, Double>> keyValPair = (KeyValPair<TimeBucketKey, Map<ResourceType, Double>>) o;
Assert.assertEquals("emitted value for 'cpu' was ", 3, keyValPair.getValue().get(ResourceType.CPU), 0);
Assert.assertEquals("emitted value for 'hdd' was ", 1, keyValPair.getValue().get(ResourceType.HDD), 0);
Assert.assertEquals("emitted value for 'ram' was ", 1, keyValPair.getValue().get(ResourceType.RAM), 0);
}
LOG.debug("Done max testing\n");
}
Aggregations