|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright Elasticsearch B.V., and/or licensed to Elasticsearch B.V. | 
|  | 3 | + * under one or more license agreements. See the NOTICE file distributed with | 
|  | 4 | + * this work for additional information regarding copyright | 
|  | 5 | + * ownership. Elasticsearch B.V. licenses this file to you under | 
|  | 6 | + * the Apache License, Version 2.0 (the "License"); you may | 
|  | 7 | + * not use this file except in compliance with the License. | 
|  | 8 | + * You may obtain a copy of the License at | 
|  | 9 | + * | 
|  | 10 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | + * | 
|  | 12 | + * Unless required by applicable law or agreed to in writing, | 
|  | 13 | + * software distributed under the License is distributed on an | 
|  | 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
|  | 15 | + * KIND, either express or implied.  See the License for the | 
|  | 16 | + * specific language governing permissions and limitations | 
|  | 17 | + * under the License. | 
|  | 18 | + * | 
|  | 19 | + * This file is based on a modification of https://github.com/open-telemetry/opentelemetry-java which is licensed under the Apache 2.0 License. | 
|  | 20 | + */ | 
|  | 21 | + | 
|  | 22 | +package org.elasticsearch.exponentialhistogram; | 
|  | 23 | + | 
|  | 24 | +import static org.hamcrest.Matchers.equalTo; | 
|  | 25 | + | 
|  | 26 | +public class ExponentialHistogramToStringTests extends ExponentialHistogramTestCase { | 
|  | 27 | + | 
|  | 28 | +    public void testFullHistogram() { | 
|  | 29 | +        try (FixedCapacityExponentialHistogram histogram = FixedCapacityExponentialHistogram.create(10, breaker())) { | 
|  | 30 | +            histogram.setZeroBucket(ZeroBucket.create(42.0, 7)); | 
|  | 31 | +            histogram.resetBuckets(10); | 
|  | 32 | +            histogram.setMin(-100); | 
|  | 33 | +            histogram.setMax(200); | 
|  | 34 | +            histogram.setSum(1234.5); | 
|  | 35 | +            histogram.tryAddBucket(2, 3, false); // negative bucket | 
|  | 36 | +            histogram.tryAddBucket(3, 4, false); // negative bucket | 
|  | 37 | +            histogram.tryAddBucket(4, 2, false); // negative bucket | 
|  | 38 | +            histogram.tryAddBucket(1, 5, true); // positive bucket | 
|  | 39 | +            histogram.tryAddBucket(5, 7, true); // positive bucket | 
|  | 40 | +            histogram.tryAddBucket(6, 1, true); // positive bucket | 
|  | 41 | +            String expected = "FixedCapacityExponentialHistogram{" | 
|  | 42 | +                + "scale=10, sum=1234.5, valueCount=29, min=-100.0, max=200.0, zeroThreshold=42.0, zeroCount=7," | 
|  | 43 | +                + " negative=[2: 3, 3: 4, 4: 2], positive=[1: 5, 5: 7, 6: 1]}"; | 
|  | 44 | +            assertThat(histogram.toString(), equalTo(expected)); | 
|  | 45 | +        } | 
|  | 46 | +    } | 
|  | 47 | + | 
|  | 48 | +    public void testEmptyHistogram() { | 
|  | 49 | +        ExponentialHistogram emptyHistogram = ExponentialHistogram.empty(); | 
|  | 50 | +        String expected = "EmptyExponentialHistogram{scale=" + emptyHistogram.scale() + ", sum=0.0, valueCount=0, min=NaN, max=NaN}"; | 
|  | 51 | +        assertThat(emptyHistogram.toString(), equalTo(expected)); | 
|  | 52 | +    } | 
|  | 53 | +} | 
0 commit comments