From 5c34b0774256a6e1f418acd37af08c2eb6652e2e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 18 Aug 2014 17:28:23 -0700 Subject: [PATCH 1/2] 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 cd6ec2e5b92..f0ad86fd4bc 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 ed522c12e3b..c4d731b7aab 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"); } } From 7685d18ed85bdad26436d0359424cac394db8f2a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 6 Aug 2014 17:27:24 -0700 Subject: [PATCH 2/2] Add clean support for samples Use ant-run to clean spring-boot-samples when `clean` is invoked on the main project. --- spring-boot-integration-tests/pom.xml | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spring-boot-integration-tests/pom.xml b/spring-boot-integration-tests/pom.xml index f58347e1843..19cedb41560 100644 --- a/spring-boot-integration-tests/pom.xml +++ b/spring-boot-integration-tests/pom.xml @@ -63,6 +63,39 @@ + + org.apache.maven.plugins + maven-antrun-plugin + + + clean-samples + clean + + run + + + + + + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + + + clean-samples + clean + + clean + + + +