From 5c34b0774256a6e1f418acd37af08c2eb6652e2e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 18 Aug 2014 17:28:23 -0700 Subject: [PATCH] Fix DefaultCounterService.reset Fix DefaultCounterService.reset to call the reset method of the underlying MetricWriter. Fixes gh-1391 --- .../metrics/writer/DefaultCounterService.java | 2 +- .../writer/DefaultCounterServiceTests.java | 28 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterService.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterService.java index cd6ec2e5b9..f0ad86fd4b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterService.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterService.java @@ -47,7 +47,7 @@ public class DefaultCounterService implements CounterService { @Override public void reset(String metricName) { - this.writer.increment(new Delta(wrap(metricName), 0L)); + this.writer.reset(wrap(metricName)); } private String wrap(String metricName) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java index ed522c12e3..c4d731b7aa 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/DefaultCounterServiceTests.java @@ -17,7 +17,10 @@ package org.springframework.boot.actuate.metrics.writer; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; @@ -26,6 +29,7 @@ import static org.mockito.Mockito.verify; /** * Tests for {@link DefaultCounterService}. */ +@RunWith(MockitoJUnitRunner.class) public class DefaultCounterServiceTests { private final MetricWriter repository = mock(MetricWriter.class); @@ -33,22 +37,28 @@ public class DefaultCounterServiceTests { private final DefaultCounterService service = new DefaultCounterService( this.repository); + @Captor + private ArgumentCaptor> captor; + @Test public void incrementPrependsCounter() { this.service.increment("foo"); - @SuppressWarnings("rawtypes") - ArgumentCaptor captor = ArgumentCaptor.forClass(Delta.class); - verify(this.repository).increment(captor.capture()); - assertEquals("counter.foo", captor.getValue().getName()); + verify(this.repository).increment(this.captor.capture()); + assertEquals("counter.foo", this.captor.getValue().getName()); + assertEquals(1L, this.captor.getValue().getValue()); } @Test public void decrementPrependsCounter() { this.service.decrement("foo"); - @SuppressWarnings("rawtypes") - ArgumentCaptor captor = ArgumentCaptor.forClass(Delta.class); - verify(this.repository).increment(captor.capture()); - assertEquals("counter.foo", captor.getValue().getName()); - assertEquals(-1L, captor.getValue().getValue()); + verify(this.repository).increment(this.captor.capture()); + assertEquals("counter.foo", this.captor.getValue().getName()); + assertEquals(-1L, this.captor.getValue().getValue()); + } + + @Test + public void resetResetsCounter() throws Exception { + this.service.reset("foo"); + verify(this.repository).reset("counter.foo"); } }