Search in sources :

Example 6 with MachineInfo

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");
}
Also used : Calendar(java.util.Calendar) ResourceType(org.apache.apex.examples.machinedata.data.ResourceType) Date(java.util.Date) TimeBucketKey(org.apache.apex.malhar.lib.util.TimeBucketKey) MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) Map(java.util.Map) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink)

Aggregations

MachineInfo (org.apache.apex.examples.machinedata.data.MachineInfo)6 MachineKey (org.apache.apex.examples.machinedata.data.MachineKey)6 Calendar (java.util.Calendar)5 Date (java.util.Date)5 Map (java.util.Map)3 ResourceType (org.apache.apex.examples.machinedata.data.ResourceType)3 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)3 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)3 TimeBucketKey (org.apache.apex.malhar.lib.util.TimeBucketKey)3 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1