You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2015/11/19 11:47:13 UTC
[06/55] [abbrv] [partial] incubator-eagle git commit: [EAGLE-46]
Rename package name as "org.apache.eagle"
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestGroupbyKey.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestGroupbyKey.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestGroupbyKey.java
deleted file mode 100755
index 79d3e83..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestGroupbyKey.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.raw;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-
-public class TestGroupbyKey {
- @Test
- public void testGroupbyKey(){
- GroupbyKey key1 = new GroupbyKey();
- Assert.assertEquals(0, key1.getValue().size());
-
- key1.addValue(new byte[]{1, 3, 5});
- Assert.assertEquals(1, key1.getValue().size());
-
- key1.clear();
- Assert.assertEquals(0, key1.getValue().size());
-
- key1.addValue(new byte[]{1, 3, 5});
- GroupbyKey key2 = new GroupbyKey();
- key2.addValue(new byte[]{1, 3, 5});
- Assert.assertEquals(key1, key2);
-
- GroupbyKey key3 = new GroupbyKey(key1);
- Assert.assertEquals(key1, key3);
- Assert.assertEquals(key2, key3);
- }
-
- @Test
- public void testGroupbyKeyComparator(){
- GroupbyKeyComparator comparator = new GroupbyKeyComparator();
- GroupbyKey key1 = new GroupbyKey();
- key1.addValue("hello".getBytes());
- GroupbyKey key2 = new GroupbyKey();
- key2.addValue("world".getBytes());
- int r = comparator.compare(key1, key2);
- Assert.assertTrue(r < 0);
-
- key2.clear();
- key2.addValue("friend".getBytes());
- r = comparator.compare(key1, key2);
- Assert.assertTrue(r > 0);
-
- key2.clear();
- key2.addValue("hello".getBytes());
- r = comparator.compare(key1, key2);
- Assert.assertTrue(r == 0);
-
- key1.clear();
- key2.clear();
- key1.addValue("hello".getBytes());
- key1.addValue("tom".getBytes());
- key2.addValue("hello".getBytes());
- key2.addValue("jackie".getBytes());
- r = comparator.compare(key1, key2);
- Assert.assertTrue(r > 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawAggregator.java
deleted file mode 100644
index 68619f7..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawAggregator.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.raw;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import eagle.query.aggregate.AggregateFunctionType;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import eagle.log.entity.meta.EntityDefinition;
-import eagle.log.entity.meta.EntitySerDeser;
-import eagle.log.entity.meta.IntSerDeser;
-import eagle.log.entity.meta.LongSerDeser;
-import eagle.log.entity.meta.Qualifier;
-import 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");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
deleted file mode 100644
index 1217590..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/raw/TestRawHBaseLogReaderAndAgg.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.raw;
-
-import org.junit.Test;
-
-public class TestRawHBaseLogReaderAndAgg {
- @Test
- public void testRawReaderAndAgg(){
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAggregator.java
deleted file mode 100644
index 0d1a319..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAggregator.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import eagle.query.aggregate.*;
-import junit.framework.Assert;
-
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.annotate.JsonProperty;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.query.aggregate.AggregateAPIEntity;
-import eagle.query.aggregate.AggregateAPIEntityFactory;
-import eagle.query.aggregate.Aggregator;
-import eagle.query.aggregate.PostAggregateSorting;
-
-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");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAlertAggService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAlertAggService.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAlertAggService.java
deleted file mode 100644
index a6a3fd1..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestAlertAggService.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.test;
-
-import java.util.ArrayList;
-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));
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery.java
deleted file mode 100755
index 21dc69b..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.test;
-
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.query.aggregate.BucketQuery;
-import junit.framework.Assert;
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-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");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery2.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery2.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery2.java
deleted file mode 100644
index a159f48..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestBucketQuery2.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.test;
-
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.query.aggregate.BucketQuery;
-import junit.framework.Assert;
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class TestBucketQuery2 {
- 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);
- 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");
- }
- }
-
- @Test
- public void test() {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestFlatAggregator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestFlatAggregator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestFlatAggregator.java
deleted file mode 100755
index 5c33470..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestFlatAggregator.java
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.test;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import eagle.query.aggregate.timeseries.FlatAggregator;
-import junit.framework.Assert;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import eagle.log.entity.test.TestEntity;
-import eagle.query.aggregate.AggregateFunctionType;
-
-public class TestFlatAggregator {
- private static final Logger LOG = LoggerFactory.getLogger(TestFlatAggregator.class);
- @Test
- public void testCounting(){
-
- }
-
- @Test
- public void testSummary(){
-
- }
-
- @Test
- public void testAverage(){
-
- }
-
- @Test
- public void testIterativeAggregation(){
-
- }
-
- @SuppressWarnings("serial")
- private TestEntity createEntity(final String cluster, final String datacenter, final String rack, int numHosts, long numClusters){
- TestEntity entity = new TestEntity();
- Map<String, String> tags = new HashMap<String, String>(){{
- put("cluster", cluster);
- put("datacenter", datacenter);
- put("rack", rack);
- }};
- entity.setTags(tags);
- entity.setNumHosts(numHosts);
- entity.setNumClusters(numClusters);
- return entity;
- }
-
- @Test
- public void testZeroGroupbyFieldSingleFunctionForSummary(){
- TestEntity[] entities = new TestEntity[5];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-
- FlatAggregator agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+
- entities[2].getNumHosts()+entities[3].getNumHosts()+entities[4].getNumHosts()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+
- entities[2].getNumClusters()+entities[3].getNumClusters()+entities[4].getNumClusters()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(new ArrayList<String>(), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- Assert.assertEquals(result.get(new ArrayList<String>()).get(0), (double)(5));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testSingleGroupbyFieldSingleFunctionForSummary(){
- TestEntity[] entities = new TestEntity[5];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc2", "rack126", 15, 2);
-
- FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts())+entities[3].getNumHosts());
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(entities[4].getNumHosts()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumClusters()+entities[4].getNumClusters()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numClusters"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters())+entities[3].getNumClusters());
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(entities[4].getNumClusters()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
-
- @Test
- public void testSingleGroupbyFieldSingleFunctionForCount(){
- TestEntity[] entities = new TestEntity[5];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc2", "rack126", 15, 2);
-
- FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(3));
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(2));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(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));
- Assert.assertEquals(result.get(Arrays.asList("dc2")).get(0), (double)(1));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testMultipleFieldsSingleFunctionForSummary(){
- TestEntity[] entities = new TestEntity[6];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
- entities[5] = createEntity("cluster2", null, "rack126", 1, 3);
-
- FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(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)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(entities[5].getNumHosts()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.sum), Arrays.asList("numHosts"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(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)(entities[0].getNumHosts()+entities[1].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(entities[2].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(entities[3].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(entities[4].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(entities[5].getNumHosts()));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testMultipleFieldsSingleFunctionForCount(){
- TestEntity[] entities = new TestEntity[6];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
- entities[5] = createEntity("cluster2", null, "rack126", 1, 3);
-
- FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "datacenter"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(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));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1")).get(0), (double)(2));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned")).get(0), (double)(1));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("cluster", "datacenter", "rack"), Arrays.asList(AggregateFunctionType.count), Arrays.asList("*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(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));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "dc1", "rack128")).get(0), (double)(1));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack125")).get(0), (double)(1));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "dc1", "rack126")).get(0), (double)(1));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "unassigned", "rack126")).get(0), (double)(1));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testSingleGroupbyFieldMultipleFunctions(){
- TestEntity[] entities = new TestEntity[5];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-
- FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
- Arrays.asList("numHosts", "*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 2);
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster1")).get(1), (double)(3));
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(0), (double)(entities[3].getNumHosts()+entities[4].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2")).get(1), (double)(2));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum), Arrays.asList("*", "numHosts"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(5));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts())+entities[4].getNumHosts());
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
-
- agg = new FlatAggregator(Arrays.asList("datacenter"), Arrays.asList(AggregateFunctionType.count, AggregateFunctionType.sum, AggregateFunctionType.sum),
- Arrays.asList("*", "numHosts", "numClusters"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 1);
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(0), (double)(5));
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(1), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()+entities[2].getNumHosts()+entities[3].getNumHosts())+entities[4].getNumHosts());
- Assert.assertEquals(result.get(Arrays.asList("dc1")).get(2), (double)(entities[0].getNumClusters()+entities[1].getNumClusters()+entities[2].getNumClusters()+entities[3].getNumClusters())+entities[4].getNumClusters());
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-
- @Test
- public void testMultipleGroupbyFieldsMultipleFunctions(){
- TestEntity[] entities = new TestEntity[5];
- entities[0] = createEntity("cluster1", "dc1", "rack123", 12, 2);
- entities[1] = createEntity("cluster1", "dc1", "rack123", 20, 1);
- entities[2] = createEntity("cluster1", "dc1", "rack128", 10, 0);
- entities[3] = createEntity("cluster2", "dc1", "rack125", 9, 2);
- entities[4] = createEntity("cluster2", "dc1", "rack126", 15, 2);
-
- FlatAggregator agg = new FlatAggregator(Arrays.asList("cluster", "rack"), Arrays.asList(AggregateFunctionType.sum, AggregateFunctionType.count),
- Arrays.asList("numHosts", "*"));
- try{
- for(TestEntity e : entities){
- agg.accumulate(e);
- }
- Map<List<String>, List<Double>> result = agg.result();
- Assert.assertEquals(result.size(), 4);
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(0), (double)(entities[0].getNumHosts()+entities[1].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack123")).get(1), (double)(2));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(0), (double)(entities[2].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster1", "rack128")).get(1), (double)(1));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(0), (double)(entities[3].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack125")).get(1), (double)(1));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(0), (double)(entities[4].getNumHosts()));
- Assert.assertEquals(result.get(Arrays.asList("cluster2", "rack126")).get(1), (double)(1));
- }catch(Exception ex){
- LOG.error("Can not aggregate", ex);
- Assert.fail("Can not aggregate");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestGroupbyFieldComparator.java b/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
deleted file mode 100644
index ce5b1d0..0000000
--- a/eagle-core/eagle-query/eagle-query-base/src/test/java/eagle/query/aggregate/test/TestGroupbyFieldComparator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package eagle.query.aggregate.test;
-
-import java.util.Arrays;
-
-import eagle.query.aggregate.timeseries.GroupbyFieldsComparator;
-import org.junit.Assert;
-import org.junit.Test;
-
-
-public class TestGroupbyFieldComparator {
- @Test
- public void testStringListCompare(){
- GroupbyFieldsComparator c = new GroupbyFieldsComparator();
- Assert.assertTrue(c.compare(Arrays.asList("ab"), Arrays.asList("ac"))<0);
- Assert.assertTrue(c.compare(Arrays.asList("xy"), Arrays.asList("cd"))>0);
- Assert.assertTrue(c.compare(Arrays.asList("xy"), Arrays.asList("xy"))==0);
- Assert.assertTrue(c.compare(Arrays.asList("xy", "ab"), Arrays.asList("xy", "ac"))<0);
- }
-}