public void addAll(List<SimpleMetricEntity> dataBatch) {
   for (SimpleMetricEntity item : dataBatch) {
     ListMetricQueueItem metricMetadata = new ListMetricQueueItem();
     metricMetadata.setAccountId(item.getAccountId());
     metricMetadata.setNamespace(item.getNamespace());
     metricMetadata.setMetricName(item.getMetricName());
     metricMetadata.setDimensionMap(item.getDimensionMap());
     metricMetadata.setMetricType(item.getMetricType());
     queue(metricMetadata);
   }
 }
  @Test
  public void testDistinctDimensionMaps() {
    final Date now = MetricUtils.stripSeconds(new Date());
    // throw some different dimension order in there...
    final Map<String, String> hashMap = new HashMap<String, String>();
    hashMap.put("dim1", "val1");
    hashMap.put("dim2", "val2");
    final Map<String, String> treeMap = new TreeMap<String, String>();
    treeMap.put("dim2", "val2");
    treeMap.put("dim1", "val1");

    ArrayList<SimpleMetricEntity> list = new ArrayList<SimpleMetricEntity>();
    for (int i = 0; i < 10; i++) {
      SimpleMetricEntity mqi = new SimpleMetricEntity();
      mqi.setAccountId("account1");
      mqi.setDimensionMap((i % 2 == 0) ? null : hashMap);
      mqi.setMetricName("metric1");
      mqi.setMetricType(MetricType.Custom);
      mqi.setNamespace("namespace1");
      mqi.setSampleMax((double) i);
      mqi.setSampleMin((double) i);
      mqi.setSampleSize((double) 1);
      mqi.setSampleSum((double) i);
      mqi.setTimestamp(now);
      mqi.setUnits(Units.None);
      list.add(mqi);
    }

    List<SimpleMetricEntity> aggregateList = MetricDataQueue.aggregate(list);
    // should be two items...
    assertEquals(2, aggregateList.size());
    // since we are not sure which order, one should have dimensionMap null
    // and one should have hashMap
    SimpleMetricEntity odd, even;
    if (aggregateList.get(0).getDimensionMap() == null) {
      even = aggregateList.get(0);
      odd = aggregateList.get(1);
    } else {
      even = aggregateList.get(1);
      odd = aggregateList.get(0);
    }
    // even totals are 0,2,4,6,8 so total = 20, max = 8, min = 0, count = 5
    assertEquals(even.getSampleMax().doubleValue(), 8.0, TOLERANCE);
    assertEquals(even.getSampleMin().doubleValue(), 0.0, TOLERANCE);
    assertEquals(even.getSampleSize().doubleValue(), 5.0, TOLERANCE);
    assertEquals(even.getSampleSum().doubleValue(), 20.0, TOLERANCE);
    assertEquals(even.getAccountId(), "account1");
    assertEquals(even.getDimensionMap(), null);
    assertEquals(even.getMetricName(), "metric1");
    assertEquals(even.getMetricType(), MetricType.Custom);
    assertEquals(even.getNamespace(), "namespace1");
    assertEquals(even.getTimestamp(), now);
    assertEquals(even.getUnits(), Units.None);

    // odd totals are 1,3,5,7,9 so total = 25, max = 9, min = 1, count = 5
    assertEquals(odd.getSampleMax().doubleValue(), 9.0, TOLERANCE);
    assertEquals(odd.getSampleMin().doubleValue(), 1.0, TOLERANCE);
    assertEquals(odd.getSampleSize().doubleValue(), 5.0, TOLERANCE);
    assertEquals(odd.getSampleSum().doubleValue(), 25.0, TOLERANCE);
    assertEquals(odd.getAccountId(), "account1");
    assertEquals(odd.getDimensionMap(), treeMap); // really either should be ok
    assertEquals(odd.getMetricName(), "metric1");
    assertEquals(odd.getMetricType(), MetricType.Custom);
    assertEquals(odd.getNamespace(), "namespace1");
    assertEquals(odd.getTimestamp(), now);
    assertEquals(odd.getUnits(), Units.None);
  }