/*
 * Copyright 2017 LINE Corporation
 *
 * LINE Corporation 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:
 *
 *   https://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 com.linecorp.armeria.common.metric;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Map;

import org.junit.Test;

import io.micrometer.core.instrument.MeterRegistry;

public class MoreMetersTest {
    private static final String ESTIMATED_FOOTPRINT = "armeria.hdrHistogram.estimatedFootprint#value";
    private static final String COUNT = "armeria.hdrHistogram.count#value";

    @Test
    public void hdrHistogramMeters() {
        final MeterRegistry registry = PrometheusMeterRegistries.newRegistry();

        // Register a distribution summary.
        MoreMeters.summaryWithDefaultQuantiles(registry, new MeterId("foo.bar"));

        // Check if estimated footprint is recorded.
        final Map<String, Double> measurement1 = MoreMeters.measureAll(registry);
        assertThat(measurement1).containsEntry(COUNT, 1.0).containsKey(ESTIMATED_FOOTPRINT);
        final double footprint1 = measurement1.get(ESTIMATED_FOOTPRINT);
        assertThat(footprint1).isPositive();

        // Register a timer.
        MoreMeters.timerWithDefaultQuantiles(registry, new MeterId("alice.bob"));

        // Check if estimated footprint has increased, because we created two Quantiles.
        final Map<String, Double> measurement2 = MoreMeters.measureAll(registry);
        assertThat(measurement2).containsEntry(COUNT, 2.0).containsKey(ESTIMATED_FOOTPRINT);
        assertThat(measurement2.get(ESTIMATED_FOOTPRINT)).isGreaterThan(footprint1);
    }
}

@@ -1167,24 +1167,298 @@
 egistry();%0A%0A
+        // Get the baseline stats.%0A        final Map%3CString, Double%3E measurement0 = MoreMeters.measureAll(registry);%0A        final double count0 = measurement0.getOrDefault(COUNT, 0.0);%0A        final double footprint0 = measurement0.getOrDefault(ESTIMATED_FOOTPRINT, 0.0);%0A%0A
         // R
@@ -1489,16 +1489,16 @@
 ummary.%0A
-
         
@@ -1596,39 +1596,67 @@
  if 
-estimated footprint is recorded
+the count and footprint have increased against the baseline
 .%0A  
@@ -1793,11 +1793,18 @@
 NT, 
-1.0
+count0 + 1
 ).co
@@ -1951,16 +1951,42 @@
 sitive()
+.isGreaterThan(footprint0)
 ;%0A%0A     
@@ -2112,24 +2112,28 @@
 heck if 
-estimate
+the count an
 d footpr
@@ -2138,17 +2138,18 @@
 print ha
-s
+ve
  increas
@@ -2154,42 +2154,37 @@
 ased
-, because we created two Quantiles
+ since the first registration
 .%0A  
@@ -2317,19 +2317,26 @@
 (COUNT, 
-2.0
+count0 + 2
 ).contai

Fix incorrect assertions in MoreMetersTest (#806)