Merge branch '1.1.x'
This commit is contained in:
commit
fc7823bc42
|
@ -47,7 +47,7 @@ public class DefaultCounterService implements CounterService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(String metricName) {
|
public void reset(String metricName) {
|
||||||
this.writer.increment(new Delta<Long>(wrap(metricName), 0L));
|
this.writer.reset(wrap(metricName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String wrap(String metricName) {
|
private String wrap(String metricName) {
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
package org.springframework.boot.actuate.metrics.writer;
|
package org.springframework.boot.actuate.metrics.writer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -26,6 +29,7 @@ import static org.mockito.Mockito.verify;
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DefaultCounterService}.
|
* Tests for {@link DefaultCounterService}.
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class DefaultCounterServiceTests {
|
public class DefaultCounterServiceTests {
|
||||||
|
|
||||||
private final MetricWriter repository = mock(MetricWriter.class);
|
private final MetricWriter repository = mock(MetricWriter.class);
|
||||||
|
@ -33,22 +37,28 @@ public class DefaultCounterServiceTests {
|
||||||
private final DefaultCounterService service = new DefaultCounterService(
|
private final DefaultCounterService service = new DefaultCounterService(
|
||||||
this.repository);
|
this.repository);
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<Delta<Number>> captor;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void incrementPrependsCounter() {
|
public void incrementPrependsCounter() {
|
||||||
this.service.increment("foo");
|
this.service.increment("foo");
|
||||||
@SuppressWarnings("rawtypes")
|
verify(this.repository).increment(this.captor.capture());
|
||||||
ArgumentCaptor<Delta> captor = ArgumentCaptor.forClass(Delta.class);
|
assertEquals("counter.foo", this.captor.getValue().getName());
|
||||||
verify(this.repository).increment(captor.capture());
|
assertEquals(1L, this.captor.getValue().getValue());
|
||||||
assertEquals("counter.foo", captor.getValue().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decrementPrependsCounter() {
|
public void decrementPrependsCounter() {
|
||||||
this.service.decrement("foo");
|
this.service.decrement("foo");
|
||||||
@SuppressWarnings("rawtypes")
|
verify(this.repository).increment(this.captor.capture());
|
||||||
ArgumentCaptor<Delta> captor = ArgumentCaptor.forClass(Delta.class);
|
assertEquals("counter.foo", this.captor.getValue().getName());
|
||||||
verify(this.repository).increment(captor.capture());
|
assertEquals(-1L, this.captor.getValue().getValue());
|
||||||
assertEquals("counter.foo", captor.getValue().getName());
|
}
|
||||||
assertEquals(-1L, captor.getValue().getValue());
|
|
||||||
|
@Test
|
||||||
|
public void resetResetsCounter() throws Exception {
|
||||||
|
this.service.reset("foo");
|
||||||
|
verify(this.repository).reset("counter.foo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,39 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>clean-samples</id>
|
||||||
|
<phase>clean</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<delete includeemptydirs="true">
|
||||||
|
<fileset dir="${main.basedir}/spring-boot-samples" includes="**/target/" />
|
||||||
|
</delete>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>clean-samples</id>
|
||||||
|
<phase>clean</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>clean</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
Loading…
Reference in New Issue