EvalMultipleData extends EvalData<EvalMultipleData> { public EvalMultipleData tagFilter(String key, String value) { return createNew(dataList.stream().filter(m -> m.hasSameTag(key, value)).collect(Collectors.toList())); } EvalMultipleData(String meterName);  EvalMultipleData(String meterName, List<EvalData> dataList); EvalMultipleData tagFilter(String key, String value); @Override EvalMultipleData multiply(double value); @Override EvalMultipleData multiply(EvalMultipleData value); @Override EvalMultipleData add(double value); @Override EvalMultipleData add(EvalMultipleData value); @Override EvalMultipleData scale(Integer value); @Override EvalMultipleData minus(double value); @Override EvalMultipleData minus(EvalMultipleData value); @Override EvalMultipleData divide(double value); @Override EvalMultipleData divide(EvalMultipleData value); @Override EvalMultipleData irate(String range); @Override EvalMultipleData rate(String range); @Override EvalMultipleData increase(String range);  }
@Test public void testTagFilter() { final EvalMultipleData filedData = singleMultiple.tagFilter("k1", "v1"); final List<EvalData> dataList = Whitebox.getInternalState(filedData, "dataList"); Assert.assertEquals(1, dataList.size()); EvalSingleData singleData = (EvalSingleData) dataList.get(0); Assert.assertEquals("test_counter", singleData.getName()); Assert.assertEquals("v1", singleData.getLabels().get("k1")); Assert.assertEquals(10d, singleData.getValue(), 0.0); }
@Test public void testOperation() { assertSingleOperation(singleMultiple, EvalMultipleData::add, 10, 20, 30, 40); assertSingleOperation(singleMultiple, EvalMultipleData::add, singleMultiple.tagFilter("k1", "v1"), 20, 30, 40); assertSingleOperation(singleMultiple, EvalMultipleData::add, singleMultiple.tagFilter("unknown", "unknown"), 10, 20 , 30); assertSingleOperationThrowArgs(singleMultiple, EvalMultipleData::add, singleMultiple); assertSingleOperation(singleMultiple, EvalMultipleData::minus, 10, 0, 10, 20); assertSingleOperation(singleMultiple, EvalMultipleData::minus, singleMultiple.tagFilter("k1", "v1"), 0, 10, 20); assertSingleOperation(singleMultiple, EvalMultipleData::minus, singleMultiple.tagFilter("unknown", "unknown"), 10, 20 , 30); assertSingleOperationThrowArgs(singleMultiple, EvalMultipleData::minus, singleMultiple); assertSingleOperation(singleMultiple, EvalMultipleData::multiply, 10, 100, 200, 300); assertSingleOperation(singleMultiple, EvalMultipleData::multiply, singleMultiple.tagFilter("k1", "v1"), 100, 200, 300); assertSingleOperation(singleMultiple, EvalMultipleData::multiply, singleMultiple.tagFilter("unknown", "unknown"), 10, 20 , 30); assertSingleOperationThrowArgs(singleMultiple, EvalMultipleData::multiply, singleMultiple); assertSingleOperation(singleMultiple, EvalMultipleData::divide, 10, 1, 2, 3); assertSingleOperation(singleMultiple, EvalMultipleData::divide, singleMultiple.tagFilter("k1", "v1"), 1, 2, 3); assertSingleOperation(singleMultiple, EvalMultipleData::divide, singleMultiple.tagFilter("unknown", "unknown"), 10, 20 , 30); assertSingleOperationThrowArgs(singleMultiple, EvalMultipleData::divide, singleMultiple); assertSingleOperation(singleMultiple, EvalMultipleData::irate, "PT15S", 0d, 0d, 0d); assertSingleOperation(singleMultiple, EvalMultipleData::rate, "PT15S", 0d, 0d, 0d); assertSingleOperation(singleMultiple, EvalMultipleData::increase, "PT15S", 0, 0, 0); }