You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ja...@apache.org on 2018/02/07 07:05:47 UTC
[3/7] eagle git commit: [EAGLE-1080] Fix checkstyle errors in the
eagle-query-base module
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
index 41bc18a..f329a7a 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawAggregator.java
@@ -37,481 +37,482 @@ import org.apache.eagle.log.entity.meta.Qualifier;
import org.apache.eagle.common.ByteUtil;
public class TestRawAggregator {
- private static final Logger LOG = LoggerFactory.getLogger(TestRawAggregator.class);
-
- private EntityDefinition ed;
- @SuppressWarnings("unchecked")
- @Before
- public void setup(){
- ed = new EntityDefinition();
- Qualifier q = new Qualifier();
- q.setDisplayName("numHosts");
- q.setQualifierName("a");
- EntitySerDeser<?> serDeser = new IntSerDeser();
- q.setSerDeser((EntitySerDeser<Object>)(serDeser));
- ed.getDisplayNameMap().put("numHosts", q);
- q = new Qualifier();
- q.setDisplayName("numClusters");
- q.setQualifierName("b");
- serDeser = new LongSerDeser();
- q.setSerDeser((EntitySerDeser<Object>)(serDeser));
- ed.getDisplayNameMap().put("numClusters", q);
- }
-
- private Map<String, byte[]> createQualifiers(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters){
- Map<String, byte[]> qualifiers = new HashMap<String, byte[]>();
- qualifiers.put("cluster", cluster == null ? null : cluster.getBytes());
- qualifiers.put("datacenter", datacenter == null ? null : datacenter.getBytes());
- qualifiers.put("rack", rack == null ? null : rack.getBytes());
- qualifiers.put("numHosts", ByteUtil.intToBytes(numHosts));
- qualifiers.put("numClusters", ByteUtil.longToBytes(numClusters));
- return qualifiers;
- }
-
- @Test
- public void testZeroGroupbyFieldSingleFunctionForSummary(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-
- RawAggregator agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
-
- double total = 0.0;
- for(Map<String, byte[]> e : entities){
- int a = ByteUtil.bytesToInt(e.get("numHosts"));
- total += a;
- }
-
- Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- double total = 0.0;
- for(Map<String, byte[]> e : entities){
- long a = ByteUtil.bytesToLong(e.get("numClusters"));
- total += a;
- }
- Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), 5, 0.0000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testSingleGroupbyFieldSingleFunctionForSummary(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc2", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-
- RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total1 = 0.0;
- total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-
- double total2 = 0.0;
- total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0).doubleValue(), total1, 0.0000000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.00000000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total1 = 0.0;
- total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-
- double total2 = 0.0;
- total2 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.000000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total1 = 0.0;
- total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
- total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
- total1 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
-
- double total2 = 0.0;
- total2 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
- total2 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
-
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total1 = 0.0;
- total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
- total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
- total1 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
- total1 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
-
- double total2 = 0.0;
- total2 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.00000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.00000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
-
- @Test
- public void testSingleGroupbyFieldSingleFunctionForCount(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
-
- RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total1 = 0.0;
- total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
-
- double total2 = 0.0;
- total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
-
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1), 0.00000000000000000000001);
- }catch(Exception ex){
- LOG.error("can not aggregate", ex);
- Assert.fail("can not aggregate");
- }
- }
-
- @Test
- public void testMultipleFieldsSingleFunctionForSummary(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
- entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
-
- RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(3, result.size());
- double total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), total, 0.00000000000000000000000001);
-
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
-
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
-
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), total, 0.0000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(5, result.size());
- double total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), total, 0.0000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), total, 0.0000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), total, 0.0000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), total, 0.0000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), total, 0.0000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testMultipleFieldsSingleFunctionForCount(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
- entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
-
- RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(3, result.size());
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(3), 0.00000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2), 0.0000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1), 0.000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(5, result.size());
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(2), 0.0000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1), 0.0000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1), 0.0000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testSingleGroupbyFieldMultipleFunctions(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
-
- RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
- Arrays.asList("numHosts", "*"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total, 0.0000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3), 0.00000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total, 0.0000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2), 0.0000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum), Arrays.asList("*", "numHosts"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- double total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.00000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum),
- Arrays.asList("*", "numHosts", "numClusters"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000000000001);
- double total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.0000000000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
- total += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
- total += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
- total += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2), total, 0.00000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(1), total, 0.00000000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(2), total, 0.000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testMultipleGroupbyFieldsMultipleFunctions(){
- List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
- entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
- entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
- entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
- entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
-
- RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
- Arrays.asList("numHosts", "*"), ed);
- try{
- for(Map<String, byte[]> e : entities){
- agg.qualifierCreated(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 4);
- double total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
- total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), total, 0.000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2), 0.00000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), total, 0.00000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1), 0.00000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), total, 0.000000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1), 0.0000000000000000000000001);
- total = 0.0;
- total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), total, 0.00000000000000000000000001);
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1), 0.000000000000000000000000001);
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
+ private static final Logger LOG = LoggerFactory.getLogger(TestRawAggregator.class);
+
+ private EntityDefinition ed;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setup() {
+ ed = new EntityDefinition();
+ Qualifier q = new Qualifier();
+ q.setDisplayName("numHosts");
+ q.setQualifierName("a");
+ EntitySerDeser<?> serDeser = new IntSerDeser();
+ q.setSerDeser((EntitySerDeser<Object>)(serDeser));
+ ed.getDisplayNameMap().put("numHosts", q);
+ q = new Qualifier();
+ q.setDisplayName("numClusters");
+ q.setQualifierName("b");
+ serDeser = new LongSerDeser();
+ q.setSerDeser((EntitySerDeser<Object>)(serDeser));
+ ed.getDisplayNameMap().put("numClusters", q);
+ }
+
+ private Map<String, byte[]> createQualifiers(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters) {
+ Map<String, byte[]> qualifiers = new HashMap<String, byte[]>();
+ qualifiers.put("cluster", cluster == null ? null : cluster.getBytes());
+ qualifiers.put("datacenter", datacenter == null ? null : datacenter.getBytes());
+ qualifiers.put("rack", rack == null ? null : rack.getBytes());
+ qualifiers.put("numHosts", ByteUtil.intToBytes(numHosts));
+ qualifiers.put("numClusters", ByteUtil.longToBytes(numClusters));
+ return qualifiers;
+ }
+
+ @Test
+ public void testZeroGroupbyFieldSingleFunctionForSummary() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+
+ RawAggregator agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 1);
+
+ double total = 0.0;
+ for (Map<String, byte[]> e : entities) {
+ int a = ByteUtil.bytesToInt(e.get("numHosts"));
+ total += a;
+ }
+
+ Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 1);
+ double total = 0.0;
+ for (Map<String, byte[]> e : entities) {
+ long a = ByteUtil.bytesToLong(e.get("numClusters"));
+ total += a;
+ }
+ Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), total, 0.00000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 1);
+ Assert.assertEquals(result.get(new ArrayList<String>()).get(0).doubleValue(), 5, 0.0000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+ }
+
+ @Test
+ public void testSingleGroupbyFieldSingleFunctionForSummary() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc2", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+
+ RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total1 = 0.0;
+ total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+
+ double total2 = 0.0;
+ total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0).doubleValue(), total1, 0.0000000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.00000000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total1 = 0.0;
+ total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+
+ double total2 = 0.0;
+ total2 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.000000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total1 = 0.0;
+ total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
+ total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
+ total1 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
+
+ double total2 = 0.0;
+ total2 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
+ total2 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
+
+ Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total1 = 0.0;
+ total1 += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
+ total1 += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
+ total1 += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
+ total1 += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
+
+ double total2 = 0.0;
+ total2 += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), total1, 0.00000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), total2, 0.00000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+ }
+
+
+ @Test
+ public void testSingleGroupbyFieldSingleFunctionForCount() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
+
+ RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total1 = 0.0;
+ total1 += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total1 += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+
+ double total2 = 0.0;
+ total2 += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ total2 += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+
+ Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total1, 0.0000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total2, 0.0000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1), 0.00000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("can not aggregate", ex);
+ Assert.fail("can not aggregate");
+ }
+ }
+
+ @Test
+ public void testMultipleFieldsSingleFunctionForSummary() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+ entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
+
+ RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(3, result.size());
+ double total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), total, 0.00000000000000000000000001);
+
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
+
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), total, 0.0000000000000000000000001);
+
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), total, 0.0000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(5, result.size());
+ double total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), total, 0.0000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), total, 0.0000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), total, 0.0000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), total, 0.0000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(5).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), total, 0.0000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+ }
+
+ @Test
+ public void testMultipleFieldsSingleFunctionForCount() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+ entities.add(createQualifiers("cluster2", null, "rack126", 1, 3));
+
+ RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(3, result.size());
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1")).get(0), (double)(3), 0.00000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2), 0.0000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1), 0.000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(5, result.size());
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack123")).get(0), (double)(2), 0.0000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1), 0.0000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1), 0.0000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1), 0.0000000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+ }
+
+ @Test
+ public void testSingleGroupbyFieldMultipleFunctions() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc2", "rack126", 15, 2));
+
+ RawAggregator agg = new RawAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
+ Arrays.asList("numHosts", "*"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), total, 0.0000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3), 0.00000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), total, 0.0000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2), 0.0000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum), Arrays.asList("*", "numHosts"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ double total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.00000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.00000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+
+ agg = new RawAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum),
+ Arrays.asList("*", "numHosts", "numClusters"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 2);
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000000000001);
+ double total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), total, 0.0000000000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToLong(entities.get(0).get("numClusters"));
+ total += ByteUtil.bytesToLong(entities.get(1).get("numClusters"));
+ total += ByteUtil.bytesToLong(entities.get(2).get("numClusters"));
+ total += ByteUtil.bytesToLong(entities.get(3).get("numClusters"));
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2), total, 0.00000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(4), 0.000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("dc2")).get(1), total, 0.00000000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToLong(entities.get(4).get("numClusters"));
+ Assert.assertEquals(result.get(Arrays.asList("dc2")).get(2), total, 0.000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+ }
+
+ @Test
+ public void testMultipleGroupbyFieldsMultipleFunctions() {
+ List<Map<String, byte[]>> entities = new ArrayList<Map<String, byte[]>>();
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 12, 2));
+ entities.add(createQualifiers("cluster1", "dc1", "rack123", 20, 1));
+ entities.add(createQualifiers("cluster1", "dc1", "rack128", 10, 0));
+ entities.add(createQualifiers("cluster2", "dc1", "rack125", 9, 2));
+ entities.add(createQualifiers("cluster2", "dc1", "rack126", 15, 2));
+
+ RawAggregator agg = new RawAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
+ Arrays.asList("numHosts", "*"), ed);
+ try {
+ for (Map<String, byte[]> e : entities) {
+ agg.qualifierCreated(e);
+ }
+ Map<List<String>, List<Double>> result = agg.result();
+ Assert.assertEquals(result.size(), 4);
+ double total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(0).get("numHosts"));
+ total += ByteUtil.bytesToInt(entities.get(1).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), total, 0.000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2), 0.00000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(2).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), total, 0.00000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1), 0.00000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(3).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), total, 0.000000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1), 0.0000000000000000000000001);
+ total = 0.0;
+ total += ByteUtil.bytesToInt(entities.get(4).get("numHosts"));
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), total, 0.00000000000000000000000001);
+ Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1), 0.000000000000000000000000001);
+ } catch (Exception ex) {
+ LOG.error("Can not aggregate", ex);
+ Assert.fail("Can not aggregate");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
index a304ea9..789ec17 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
@@ -19,8 +19,8 @@ package org.apache.eagle.query.aggregate.raw;
import org.junit.Test;
public class TestRawHBaseLogReaderAndAgg {
- @Test
- public void testRawReaderAndAgg(){
-
- }
+ @Test
+ public void testRawReaderAndAgg() {
+
+ }
}
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
index 4ae4b56..b7e8598 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAggregator.java
@@ -35,217 +35,217 @@ import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
import org.apache.eagle.query.aggregate.Aggregator;
public class TestAggregator {
- private final static Logger LOG = LoggerFactory.getLogger(TestAggregator.class);
-
- public static class AggregatedSampleAPIEntityFactory implements AggregateAPIEntityFactory {
- @Override
- public AggregateAPIEntity create(){
- return new AggregatedSampleAPIEntity();
- }
- }
-
-
- public static class TestAPIEntity extends TaggedLogAPIEntity{
- private String numTotalAlerts;
- private String usedCapacity;
- private String status;
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public String getNumTotalAlerts() {
- return numTotalAlerts;
- }
-
- public void setNumTotalAlerts(String numTotalAlerts) {
- this.numTotalAlerts = numTotalAlerts;
- }
-
- public String getUsedCapacity() {
- return usedCapacity;
- }
-
- public void setUsedCapacity(String usedCapacity) {
- this.usedCapacity = usedCapacity;
- }
- }
-
-
-
- public static class AggregatedSampleAPIEntity extends AggregateAPIEntity{
- private long numTotalAlerts;
-
- @JsonProperty("nTA")
- public long getNumTotalAlerts() {
- return numTotalAlerts;
- }
-
- public void setNumTotalAlerts(long numTotalAlerts) {
- this.numTotalAlerts = numTotalAlerts;
- }
- }
-
- @Test
- public void testAggregate(){
- try{
- final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
- List<String> sumFunctionFields = Arrays.asList("numTotalAlerts");
- boolean counting = true;
- List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "cluster");
- List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
- sortFieldOrders.add(new AggregateParams.SortFieldOrder("numTotalAlerts", false));
- Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, sumFunctionFields);
- List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
- TestAPIEntity entity = new TestAPIEntity();
- entity.setTags(new HashMap<String, String>());
- entity.getTags().put("category", "checkHadoopFS");
- entity.getTags().put("rack", "rack123");
- entity.getTags().put("cluster", "cluster1");
- entity.setNumTotalAlerts("123");
- entity.setUsedCapacity("12.5");
- entity.setStatus("live");
- list.add(entity);
-
- TestAPIEntity entity2 = new TestAPIEntity();
- entity2.setTags(new HashMap<String, String>());
- entity2.getTags().put("category", "checkHadoopFS");
- entity2.getTags().put("rack", "rack124");
- entity2.getTags().put("cluster", "cluster2");
- entity2.setNumTotalAlerts("35");
- entity2.setUsedCapacity("32.1");
- entity2.setStatus("dead");
- list.add(entity2);
-
- TestAPIEntity entity3 = new TestAPIEntity();
- entity3.setTags(new HashMap<String, String>());
- entity3.getTags().put("category", "checkHadoopFS");
- // entity3.getTags().put("rack", "rack124");
- entity3.getTags().put("cluster", "cluster2");
- entity3.setNumTotalAlerts("11");
- entity3.setUsedCapacity("82.11");
- entity3.setStatus("live");
- list.add(entity3);
-
- TestAPIEntity entity4 = new TestAPIEntity();
- entity4.setTags(new HashMap<String, String>());
- entity4.getTags().put("category", "diskfailure");
- entity4.getTags().put("rack", "rack124");
- entity4.getTags().put("cluster", "cluster2");
- entity4.setNumTotalAlerts("61");
- entity4.setUsedCapacity("253.2");
- entity4.setStatus("dead");
- list.add(entity4);
-
- long numTotalAlerts = 0;
- for(TestAPIEntity e : list){
- agg.accumulate(e);
- numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
- }
-
- JsonFactory factory = new JsonFactory();
- ObjectMapper mapper = new ObjectMapper(factory);
- String result = null;
- AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
- result = mapper.writeValueAsString(toBeVerified);
-
- Assert.assertEquals(2, toBeVerified.getNumDirectDescendants());
- Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
- Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
-
- LOG.info(result);
-
- PostAggregateSorting.sort(root, sortFieldOrders);
- toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
- result = mapper.writeValueAsString(toBeVerified);
- LOG.info(result);
- }catch(Exception ex){
- LOG.error("Test aggregator fails", ex);
- Assert.fail("Test aggregator fails");
- }
- }
-
- @Test
- public void testUnassigned(){
- // rack is unassigned
- try{
- final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
- boolean counting = true;
- List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "rack");
- List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
- sortFieldOrders.add(new AggregateParams.SortFieldOrder("count", false));
- sortFieldOrders.add(new AggregateParams.SortFieldOrder("key", false));
- Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, new ArrayList<String>());
- List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
- TestAPIEntity entity = new TestAPIEntity();
- entity.setTags(new HashMap<String, String>());
- entity.getTags().put("category", "checkHadoopFS");
- entity.getTags().put("rack", "rack123");
- entity.getTags().put("cluster", "cluster1");
- entity.setNumTotalAlerts("123");
- entity.setUsedCapacity("12.5");
- entity.setStatus("live");
- list.add(entity);
-
- TestAPIEntity entity2 = new TestAPIEntity();
- entity2.setTags(new HashMap<String, String>());
- entity2.getTags().put("category", "checkHadoopFS");
- entity2.getTags().put("rack", "rack124");
- entity2.getTags().put("cluster", "cluster2");
- entity2.setNumTotalAlerts("35");
- entity2.setUsedCapacity("32.1");
- entity2.setStatus("dead");
- list.add(entity2);
-
- TestAPIEntity entity3 = new TestAPIEntity();
- entity3.setTags(new HashMap<String, String>());
- entity3.getTags().put("category", "checkHadoopFS");
- // entity3.getTags().put("rack", "rack124");
- entity3.getTags().put("cluster", "cluster2");
- entity3.setNumTotalAlerts("11");
- entity3.setUsedCapacity("82.11");
- entity3.setStatus("live");
- list.add(entity3);
-
- TestAPIEntity entity4 = new TestAPIEntity();
- entity4.setTags(new HashMap<String, String>());
- entity4.getTags().put("category", "diskfailure");
- entity4.getTags().put("rack", "rack124");
- entity4.getTags().put("cluster", "cluster2");
- entity4.setNumTotalAlerts("61");
- entity4.setUsedCapacity("253.2");
- entity4.setStatus("dead");
- list.add(entity4);
-
-// long numTotalAlerts = 0;
- for(TestAPIEntity e : list){
- agg.accumulate(e);
-// numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
- }
-
- JsonFactory factory = new JsonFactory();
- ObjectMapper mapper = new ObjectMapper(factory);
- String result = null;
- AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
- result = mapper.writeValueAsString(toBeVerified);
-
- Assert.assertEquals(3, toBeVerified.getNumDirectDescendants());
- Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
-// Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
-
- LOG.info(result);
-
- PostAggregateSorting.sort(root, sortFieldOrders);
- toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
- result = mapper.writeValueAsString(toBeVerified);
- LOG.info(result);
- }catch(Exception ex){
- LOG.error("Test aggregator fails", ex);
- Assert.fail("Test aggregator fails");
- }
- }
+ private static final Logger LOG = LoggerFactory.getLogger(TestAggregator.class);
+
+ public static class AggregatedSampleAPIEntityFactory implements AggregateAPIEntityFactory {
+ @Override
+ public AggregateAPIEntity create() {
+ return new AggregatedSampleAPIEntity();
+ }
+ }
+
+
+ public static class TestAPIEntity extends TaggedLogAPIEntity {
+ private String numTotalAlerts;
+ private String usedCapacity;
+ private String status;
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getNumTotalAlerts() {
+ return numTotalAlerts;
+ }
+
+ public void setNumTotalAlerts(String numTotalAlerts) {
+ this.numTotalAlerts = numTotalAlerts;
+ }
+
+ public String getUsedCapacity() {
+ return usedCapacity;
+ }
+
+ public void setUsedCapacity(String usedCapacity) {
+ this.usedCapacity = usedCapacity;
+ }
+ }
+
+
+
+ public static class AggregatedSampleAPIEntity extends AggregateAPIEntity {
+ private long numTotalAlerts;
+
+ @JsonProperty("nTA")
+ public long getNumTotalAlerts() {
+ return numTotalAlerts;
+ }
+
+ public void setNumTotalAlerts(long numTotalAlerts) {
+ this.numTotalAlerts = numTotalAlerts;
+ }
+ }
+
+ @Test
+ public void testAggregate() {
+ try {
+ final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
+ List<String> sumFunctionFields = Arrays.asList("numTotalAlerts");
+ boolean counting = true;
+ List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "cluster");
+ List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
+ sortFieldOrders.add(new AggregateParams.SortFieldOrder("numTotalAlerts", false));
+ Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, sumFunctionFields);
+ List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
+ TestAPIEntity entity = new TestAPIEntity();
+ entity.setTags(new HashMap<String, String>());
+ entity.getTags().put("category", "checkHadoopFS");
+ entity.getTags().put("rack", "rack123");
+ entity.getTags().put("cluster", "cluster1");
+ entity.setNumTotalAlerts("123");
+ entity.setUsedCapacity("12.5");
+ entity.setStatus("live");
+ list.add(entity);
+
+ TestAPIEntity entity2 = new TestAPIEntity();
+ entity2.setTags(new HashMap<String, String>());
+ entity2.getTags().put("category", "checkHadoopFS");
+ entity2.getTags().put("rack", "rack124");
+ entity2.getTags().put("cluster", "cluster2");
+ entity2.setNumTotalAlerts("35");
+ entity2.setUsedCapacity("32.1");
+ entity2.setStatus("dead");
+ list.add(entity2);
+
+ TestAPIEntity entity3 = new TestAPIEntity();
+ entity3.setTags(new HashMap<String, String>());
+ entity3.getTags().put("category", "checkHadoopFS");
+ // entity3.getTags().put("rack", "rack124");
+ entity3.getTags().put("cluster", "cluster2");
+ entity3.setNumTotalAlerts("11");
+ entity3.setUsedCapacity("82.11");
+ entity3.setStatus("live");
+ list.add(entity3);
+
+ TestAPIEntity entity4 = new TestAPIEntity();
+ entity4.setTags(new HashMap<String, String>());
+ entity4.getTags().put("category", "diskfailure");
+ entity4.getTags().put("rack", "rack124");
+ entity4.getTags().put("cluster", "cluster2");
+ entity4.setNumTotalAlerts("61");
+ entity4.setUsedCapacity("253.2");
+ entity4.setStatus("dead");
+ list.add(entity4);
+
+ long numTotalAlerts = 0;
+ for (TestAPIEntity e : list) {
+ agg.accumulate(e);
+ numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
+ }
+
+ JsonFactory factory = new JsonFactory();
+ ObjectMapper mapper = new ObjectMapper(factory);
+ String result = null;
+ AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
+ result = mapper.writeValueAsString(toBeVerified);
+
+ Assert.assertEquals(2, toBeVerified.getNumDirectDescendants());
+ Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
+ Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
+
+ LOG.info(result);
+
+ PostAggregateSorting.sort(root, sortFieldOrders);
+ toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
+ result = mapper.writeValueAsString(toBeVerified);
+ LOG.info(result);
+ } catch (Exception ex) {
+ LOG.error("Test aggregator fails", ex);
+ Assert.fail("Test aggregator fails");
+ }
+ }
+
+ @Test
+ public void testUnassigned() {
+ // rack is unassigned
+ try {
+ final AggregatedSampleAPIEntity root = new AggregatedSampleAPIEntity();
+ boolean counting = true;
+ List<String> groupbys = Arrays.asList(Aggregator.GROUPBY_ROOT_FIELD_NAME, "rack");
+ List<AggregateParams.SortFieldOrder> sortFieldOrders = new ArrayList<AggregateParams.SortFieldOrder>();
+ sortFieldOrders.add(new AggregateParams.SortFieldOrder("count", false));
+ sortFieldOrders.add(new AggregateParams.SortFieldOrder("key", false));
+ Aggregator agg = new Aggregator(new AggregatedSampleAPIEntityFactory(), root, groupbys, counting, new ArrayList<String>());
+ List<TestAPIEntity> list = new ArrayList<TestAPIEntity>();
+ TestAPIEntity entity = new TestAPIEntity();
+ entity.setTags(new HashMap<String, String>());
+ entity.getTags().put("category", "checkHadoopFS");
+ entity.getTags().put("rack", "rack123");
+ entity.getTags().put("cluster", "cluster1");
+ entity.setNumTotalAlerts("123");
+ entity.setUsedCapacity("12.5");
+ entity.setStatus("live");
+ list.add(entity);
+
+ TestAPIEntity entity2 = new TestAPIEntity();
+ entity2.setTags(new HashMap<String, String>());
+ entity2.getTags().put("category", "checkHadoopFS");
+ entity2.getTags().put("rack", "rack124");
+ entity2.getTags().put("cluster", "cluster2");
+ entity2.setNumTotalAlerts("35");
+ entity2.setUsedCapacity("32.1");
+ entity2.setStatus("dead");
+ list.add(entity2);
+
+ TestAPIEntity entity3 = new TestAPIEntity();
+ entity3.setTags(new HashMap<String, String>());
+ entity3.getTags().put("category", "checkHadoopFS");
+ // entity3.getTags().put("rack", "rack124");
+ entity3.getTags().put("cluster", "cluster2");
+ entity3.setNumTotalAlerts("11");
+ entity3.setUsedCapacity("82.11");
+ entity3.setStatus("live");
+ list.add(entity3);
+
+ TestAPIEntity entity4 = new TestAPIEntity();
+ entity4.setTags(new HashMap<String, String>());
+ entity4.getTags().put("category", "diskfailure");
+ entity4.getTags().put("rack", "rack124");
+ entity4.getTags().put("cluster", "cluster2");
+ entity4.setNumTotalAlerts("61");
+ entity4.setUsedCapacity("253.2");
+ entity4.setStatus("dead");
+ list.add(entity4);
+
+ // long numTotalAlerts = 0;
+ for (TestAPIEntity e : list) {
+ agg.accumulate(e);
+ // numTotalAlerts += Long.valueOf(e.getNumTotalAlerts());
+ }
+
+ JsonFactory factory = new JsonFactory();
+ ObjectMapper mapper = new ObjectMapper(factory);
+ String result = null;
+ AggregatedSampleAPIEntity toBeVerified = (AggregatedSampleAPIEntity)root.getEntityList().get(Aggregator.GROUPBY_ROOT_FIELD_VALUE);
+ result = mapper.writeValueAsString(toBeVerified);
+
+ Assert.assertEquals(3, toBeVerified.getNumDirectDescendants());
+ Assert.assertEquals(4, toBeVerified.getNumTotalDescendants());
+ // Assert.assertEquals(numTotalAlerts, toBeVerified.getNumTotalAlerts());
+
+ LOG.info(result);
+
+ PostAggregateSorting.sort(root, sortFieldOrders);
+ toBeVerified = (AggregatedSampleAPIEntity)root.getSortedList().get(0);
+ result = mapper.writeValueAsString(toBeVerified);
+ LOG.info(result);
+ } catch (Exception ex) {
+ LOG.error("Test aggregator fails", ex);
+ Assert.fail("Test aggregator fails");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
index c2d0a26..630d7c1 100644
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestAlertAggService.java
@@ -23,34 +23,34 @@ import java.util.List;
import org.junit.Test;
public class TestAlertAggService {
- @Test
- public void testCompileAndSplitCondition(){
- List<String> alertTagNameValues = new ArrayList<String>();
- String tagNameValue1 = "cluster=cluster1";
- String tagNameValue2 = "category=checkHadoopFS";
- String tagNameValue3 = "category=highloadDisk";
- String tagNameValue4 = "cluster=dc124";
- String tagNameValue5 = "category=lowloadDisk";
- alertTagNameValues.add(tagNameValue1);
- alertTagNameValues.add(tagNameValue2);
- alertTagNameValues.add(tagNameValue3);
- alertTagNameValues.add(tagNameValue4);
- alertTagNameValues.add(tagNameValue5);
-// AlertAggResource r = new AlertAggResource();
-// List<List<String>> result = r.compileAndSplitConditions(alertTagNameValues);
-// Assert.assertEquals(result.size(), 3);
-// Assert.assertEquals(result.get(0).size(), 3);
-// Assert.assertTrue(result.get(0).contains(tagNameValue2));
-// Assert.assertTrue(result.get(0).contains(tagNameValue1));
-// Assert.assertTrue(result.get(0).contains(tagNameValue4));
-// Assert.assertEquals(result.get(1).size(), 3);
-// Assert.assertTrue(result.get(1).contains(tagNameValue3));
-// Assert.assertTrue(result.get(1).contains(tagNameValue1));
-// Assert.assertTrue(result.get(1).contains(tagNameValue4));
-// Assert.assertEquals(result.get(2).size(), 3);
-// Assert.assertTrue(result.get(2).contains(tagNameValue5));
-// Assert.assertTrue(result.get(2).contains(tagNameValue1));
-// Assert.assertTrue(result.get(2).contains(tagNameValue4));
- }
+ @Test
+ public void testCompileAndSplitCondition() {
+ List<String> alertTagNameValues = new ArrayList<String>();
+ String tagNameValue1 = "cluster = cluster1";
+ String tagNameValue2 = "category = checkHadoopFS";
+ String tagNameValue3 = "category = highloadDisk";
+ String tagNameValue4 = "cluster = dc124";
+ String tagNameValue5 = "category = lowloadDisk";
+ alertTagNameValues.add(tagNameValue1);
+ alertTagNameValues.add(tagNameValue2);
+ alertTagNameValues.add(tagNameValue3);
+ alertTagNameValues.add(tagNameValue4);
+ alertTagNameValues.add(tagNameValue5);
+ // AlertAggResource r = new AlertAggResource();
+ // List<List<String>> result = r.compileAndSplitConditions(alertTagNameValues);
+ // Assert.assertEquals(result.size(), 3);
+ // Assert.assertEquals(result.get(0).size(), 3);
+ // Assert.assertTrue(result.get(0).contains(tagNameValue2));
+ // Assert.assertTrue(result.get(0).contains(tagNameValue1));
+ // Assert.assertTrue(result.get(0).contains(tagNameValue4));
+ // Assert.assertEquals(result.get(1).size(), 3);
+ // Assert.assertTrue(result.get(1).contains(tagNameValue3));
+ // Assert.assertTrue(result.get(1).contains(tagNameValue1));
+ // Assert.assertTrue(result.get(1).contains(tagNameValue4));
+ // Assert.assertEquals(result.get(2).size(), 3);
+ // Assert.assertTrue(result.get(2).contains(tagNameValue5));
+ // Assert.assertTrue(result.get(2).contains(tagNameValue1));
+ // Assert.assertTrue(result.get(2).contains(tagNameValue4));
+ }
}
http://git-wip-us.apache.org/repos/asf/eagle/blob/c970bb42/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
index e44d73b..5e986ac 100755
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
+++ b/eagle-core/eagle-query/eagle-query-base/src/test/java/org/apache/eagle/query/aggregate/test/TestBucketQuery.java
@@ -29,128 +29,128 @@ import java.util.List;
import java.util.Map;
public class TestBucketQuery {
- private static class SampleTaggedLogAPIEntity extends TaggedLogAPIEntity{
- private String description;
-
- @SuppressWarnings("unused")
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testBucketQuery(){
- SampleTaggedLogAPIEntity e1 = new SampleTaggedLogAPIEntity();
- e1.setTags(new HashMap<String, String>());
- e1.getTags().put("cluster", "cluster1");
- e1.getTags().put("rack", "rack123");
- e1.setDescription("this is description 1");
-
- SampleTaggedLogAPIEntity e2 = new SampleTaggedLogAPIEntity();
- e2.setTags(new HashMap<String, String>());
- e2.getTags().put("cluster", "cluster1");
- e2.getTags().put("rack", "rack123");
- e2.setDescription("this is description 2");
-
- List<String> bucketFields = new ArrayList<String>();
- bucketFields.add("cluster");
- int limit = 1;
-
- BucketQuery query1 = new BucketQuery(bucketFields, limit);
- query1.put(e1);
- query1.put(e2);
-
- Map<String, Object> map = query1.get();
-
- List<TaggedLogAPIEntity> o = (List<TaggedLogAPIEntity>)map.get("cluster1");
- Assert.assertEquals(limit, o.size());
-
- JsonFactory factory = new JsonFactory();
- ObjectMapper mapper = new ObjectMapper(factory);
- mapper.setFilters(TaggedLogAPIEntity.getFilterProvider());
- try{
- String result = mapper.writeValueAsString(map);
- System.out.println(result);
- }catch(Exception ex){
- ex.printStackTrace();
- Assert.fail("can not serialize bucket query result");
- }
-
- limit = 2;
- BucketQuery query2 = new BucketQuery(bucketFields, limit);
- query2.put(e1);
- query2.put(e2);
- Map<String, Object> map2 = query2.get();
- o = (List<TaggedLogAPIEntity>)map2.get("cluster1");
- try{
- String result = mapper.writeValueAsString(map2);
- System.out.println(result);
- }catch(Exception ex){
- ex.printStackTrace();
- Assert.fail("can not serialize bucket query result");
- }
- Assert.assertEquals(limit, o.size());
-
-
- SampleTaggedLogAPIEntity e3 = new SampleTaggedLogAPIEntity();
- e3.setTags(new HashMap<String, String>());
- e3.getTags().put("cluster", "cluster1");
- e3.getTags().put("rack", "rack124");
- e3.setDescription("this is description 3");
- bucketFields.add("rack");
- limit = 2;
- BucketQuery query3 = new BucketQuery(bucketFields, limit);
- query3.put(e1);
- query3.put(e2);
- query3.put(e3);
- Map<String, Object> map3 = query3.get();
- Map<String, Object> o3 = (Map<String, Object>)map3.get("cluster1");
- List<TaggedLogAPIEntity> o4 = (List<TaggedLogAPIEntity>)o3.get("rack124");
- Assert.assertEquals(1, o4.size());
- List<TaggedLogAPIEntity> o5 = (List<TaggedLogAPIEntity>)o3.get("rack123");
- Assert.assertEquals(o5.size(), 2);
-
- try{
- String result = mapper.writeValueAsString(map3);
- System.out.println(result);
- }catch(Exception ex){
- ex.printStackTrace();
- Assert.fail("can not serialize bucket query result");
- }
-
-
- SampleTaggedLogAPIEntity e4 = new SampleTaggedLogAPIEntity();
- e4.setTags(new HashMap<String, String>());
- e4.getTags().put("cluster", "cluster1");
- // rack is set to null
-// e4.getTags().put("rack", "rack124");
- e4.setDescription("this is description 3");
- limit = 2;
- BucketQuery query4 = new BucketQuery(bucketFields, limit);
- query4.put(e1);
- query4.put(e2);
- query4.put(e3);
- query4.put(e4);
- Map<String, Object> map4 = query4.get();
- Map<String, Object> o6 = (Map<String, Object>)map4.get("cluster1");
- List<TaggedLogAPIEntity> o7 = (List<TaggedLogAPIEntity>)o6.get("rack124");
- Assert.assertEquals(1, o7.size());
- List<TaggedLogAPIEntity> o8 = (List<TaggedLogAPIEntity>)o6.get("rack123");
- Assert.assertEquals(o8.size(), 2);
- List<TaggedLogAPIEntity> o9 = (List<TaggedLogAPIEntity>)o6.get("unassigned");
- Assert.assertEquals(o9.size(), 1);
-
- try{
- String result = mapper.writeValueAsString(map4);
- System.out.println(result);
- }catch(Exception ex){
- ex.printStackTrace();
- Assert.fail("can not serialize bucket query result");
- }
- }
+ private static class SampleTaggedLogAPIEntity extends TaggedLogAPIEntity {
+ private String description;
+
+ @SuppressWarnings("unused")
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testBucketQuery() {
+ SampleTaggedLogAPIEntity e1 = new SampleTaggedLogAPIEntity();
+ e1.setTags(new HashMap<String, String>());
+ e1.getTags().put("cluster", "cluster1");
+ e1.getTags().put("rack", "rack123");
+ e1.setDescription("this is description 1");
+
+ SampleTaggedLogAPIEntity e2 = new SampleTaggedLogAPIEntity();
+ e2.setTags(new HashMap<String, String>());
+ e2.getTags().put("cluster", "cluster1");
+ e2.getTags().put("rack", "rack123");
+ e2.setDescription("this is description 2");
+
+ List<String> bucketFields = new ArrayList<String>();
+ bucketFields.add("cluster");
+ int limit = 1;
+
+ BucketQuery query1 = new BucketQuery(bucketFields, limit);
+ query1.put(e1);
+ query1.put(e2);
+
+ Map<String, Object> map = query1.get();
+
+ List<TaggedLogAPIEntity> o = (List<TaggedLogAPIEntity>)map.get("cluster1");
+ Assert.assertEquals(limit, o.size());
+
+ JsonFactory factory = new JsonFactory();
+ ObjectMapper mapper = new ObjectMapper(factory);
+ mapper.setFilters(TaggedLogAPIEntity.getFilterProvider());
+ try {
+ String result = mapper.writeValueAsString(map);
+ System.out.println(result);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail("can not serialize bucket query result");
+ }
+
+ limit = 2;
+ BucketQuery query2 = new BucketQuery(bucketFields, limit);
+ query2.put(e1);
+ query2.put(e2);
+ Map<String, Object> map2 = query2.get();
+ o = (List<TaggedLogAPIEntity>)map2.get("cluster1");
+ try {
+ String result = mapper.writeValueAsString(map2);
+ System.out.println(result);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail("can not serialize bucket query result");
+ }
+ Assert.assertEquals(limit, o.size());
+
+
+ SampleTaggedLogAPIEntity e3 = new SampleTaggedLogAPIEntity();
+ e3.setTags(new HashMap<String, String>());
+ e3.getTags().put("cluster", "cluster1");
+ e3.getTags().put("rack", "rack124");
+ e3.setDescription("this is description 3");
+ bucketFields.add("rack");
+ limit = 2;
+ BucketQuery query3 = new BucketQuery(bucketFields, limit);
+ query3.put(e1);
+ query3.put(e2);
+ query3.put(e3);
+ Map<String, Object> map3 = query3.get();
+ Map<String, Object> o3 = (Map<String, Object>)map3.get("cluster1");
+ List<TaggedLogAPIEntity> o4 = (List<TaggedLogAPIEntity>)o3.get("rack124");
+ Assert.assertEquals(1, o4.size());
+ List<TaggedLogAPIEntity> o5 = (List<TaggedLogAPIEntity>)o3.get("rack123");
+ Assert.assertEquals(o5.size(), 2);
+
+ try {
+ String result = mapper.writeValueAsString(map3);
+ System.out.println(result);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail("can not serialize bucket query result");
+ }
+
+
+ SampleTaggedLogAPIEntity e4 = new SampleTaggedLogAPIEntity();
+ e4.setTags(new HashMap<String, String>());
+ e4.getTags().put("cluster", "cluster1");
+ // rack is set to null
+ // e4.getTags().put("rack", "rack124");
+ e4.setDescription("this is description 3");
+ limit = 2;
+ BucketQuery query4 = new BucketQuery(bucketFields, limit);
+ query4.put(e1);
+ query4.put(e2);
+ query4.put(e3);
+ query4.put(e4);
+ Map<String, Object> map4 = query4.get();
+ Map<String, Object> o6 = (Map<String, Object>)map4.get("cluster1");
+ List<TaggedLogAPIEntity> o7 = (List<TaggedLogAPIEntity>)o6.get("rack124");
+ Assert.assertEquals(1, o7.size());
+ List<TaggedLogAPIEntity> o8 = (List<TaggedLogAPIEntity>)o6.get("rack123");
+ Assert.assertEquals(o8.size(), 2);
+ List<TaggedLogAPIEntity> o9 = (List<TaggedLogAPIEntity>)o6.get("unassigned");
+ Assert.assertEquals(o9.size(), 1);
+
+ try {
+ String result = mapper.writeValueAsString(map4);
+ System.out.println(result);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail("can not serialize bucket query result");
+ }
+ }
}