|
| 1 | +/* |
| 2 | + * Copyright 2012-2017 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.actuate.metrics.buffer; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.actuate.metrics.CounterService; |
| 22 | +import org.springframework.boot.actuate.metrics.Metric; |
| 23 | + |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; |
| 25 | + |
| 26 | +/** |
| 27 | + * Tests for {@link BufferCounterService}. |
| 28 | + * |
| 29 | + * @author Venil Noronha |
| 30 | + */ |
| 31 | +public class BufferCounterServiceTests { |
| 32 | + |
| 33 | + private CounterBuffers counters = new CounterBuffers(); |
| 34 | + |
| 35 | + private CounterService service = new BufferCounterService(this.counters); |
| 36 | + |
| 37 | + private BufferMetricReader reader = new BufferMetricReader(this.counters, |
| 38 | + new GaugeBuffers()); |
| 39 | + |
| 40 | + @Test |
| 41 | + public void matchExtendedPrefix() { |
| 42 | + this.service.increment("foo"); |
| 43 | + assertThat(this.reader.findOne("foo")).isNull(); |
| 44 | + Metric<?> counterFooMetric = this.reader.findOne("counter.foo"); |
| 45 | + assertThat(counterFooMetric).isNotNull(); |
| 46 | + assertThat(counterFooMetric.getValue()).isEqualTo(1L); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void matchCounterPrefix() { |
| 51 | + this.service.increment("counterfoo"); |
| 52 | + assertThat(this.reader.findOne("counterfoo")).isNull(); |
| 53 | + Metric<?> counterCounterfooMetric = this.reader.findOne("counter.counterfoo"); |
| 54 | + assertThat(counterCounterfooMetric).isNotNull(); |
| 55 | + assertThat(counterCounterfooMetric.getValue()).isEqualTo(1L); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void matchCounterDotPrefix() { |
| 60 | + this.service.increment("counter.foo"); |
| 61 | + assertThat(this.reader.findOne("counter.counter.foo")).isNull(); |
| 62 | + Metric<?> counterFooMetric = this.reader.findOne("counter.foo"); |
| 63 | + assertThat(counterFooMetric).isNotNull(); |
| 64 | + assertThat(counterFooMetric.getValue()).isEqualTo(1L); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void matchMeterPrefix() { |
| 69 | + this.service.increment("meterfoo"); |
| 70 | + assertThat(this.reader.findOne("meterfoo")).isNull(); |
| 71 | + Metric<?> counterMeterfooMetric = this.reader.findOne("counter.meterfoo"); |
| 72 | + assertThat(counterMeterfooMetric).isNotNull(); |
| 73 | + assertThat(counterMeterfooMetric.getValue()).isEqualTo(1L); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + public void matchMeterDotPrefix() { |
| 78 | + this.service.increment("meter.foo"); |
| 79 | + assertThat(this.reader.findOne("counter.meter.foo")).isNull(); |
| 80 | + Metric<?> meterFooMetric = this.reader.findOne("meter.foo"); |
| 81 | + assertThat(meterFooMetric).isNotNull(); |
| 82 | + assertThat(meterFooMetric.getValue()).isEqualTo(1L); |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments