

package com.navercorp.pinpoint.profiler.monitor.metric.rpc.test;

import com.navercorp.pinpoint.common.trace.HistogramSchema;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.profiler.monitor.metric.rpc.HistogramSnapshot;

import com.navercorp.pinpoint.profiler.monitor.metric.rpc.LongAdderHistogram;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class HistogramTest {

    @Test
    public void testAddResponseTime() {
        HistogramSchema schema = ServiceType.STAND_ALONE.getHistogramSchema();
        LongAdderHistogram histogram = new LongAdderHistogram(ServiceType.STAND_ALONE);
        histogram.addResponseTime(1000, false);

        histogram.addResponseTime(3000, false);
        histogram.addResponseTime(3000, false);

        histogram.addResponseTime(5000, false);
        histogram.addResponseTime(5000, false);
        histogram.addResponseTime(5000, false);

        histogram.addResponseTime(6000, false);
        histogram.addResponseTime(6000, false);
        histogram.addResponseTime(6000, false);
        histogram.addResponseTime(6000, false);

        histogram.addResponseTime(schema.getFastSlot().getSlotTime(), true);
        histogram.addResponseTime(schema.getFastSlot().getSlotTime(), true);
        histogram.addResponseTime(schema.getFastSlot().getSlotTime(), true);
        histogram.addResponseTime(schema.getFastSlot().getSlotTime(), true);
        histogram.addResponseTime(schema.getFastSlot().getSlotTime(), true);


        HistogramSnapshot snapshot = histogram.createSnapshot();
        Assertions.assertEquals(snapshot.getFastCount(), 1);
        Assertions.assertEquals(snapshot.getNormalCount(), 2);
        Assertions.assertEquals(snapshot.getSlowCount(), 3);
        Assertions.assertEquals(snapshot.getVerySlowCount(), 4);
        Assertions.assertEquals(snapshot.getFastErrorCount(), 5);
    }

}