Skip to content

Instantly share code, notes, and snippets.

@przodownikR1
Created August 19, 2016 09:30
Show Gist options
  • Save przodownikR1/b73ad378f1025f695cdafec2cea486bd to your computer and use it in GitHub Desktop.
Save przodownikR1/b73ad378f1025f695cdafec2cea486bd to your computer and use it in GitHub Desktop.
@Controller
@Description("A controller for handling requests for hello messages")
public class SampleController {
@Autowired
private HelloWorldService helloWorldService;
@Autowired
private GaugeService gauges;
@GetMapping("/")
@ResponseBody
public Map<String, String> hello() {
this.gauges.submit("timer.test.value", Math.random() * 1000 + 1000);
return Collections.singletonMap("message",
this.helloWorldService.getHelloMessage());
}
protected static class Message {
@NotBlank(message = "Message value cannot be empty")
private String value;
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
}
}
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class SampleDropwizardMetricsApplicationTests {
@Autowired
private MetricRegistry registry;
@Autowired
private GaugeService gauges;
@Test
public void timerCreated() {
this.gauges.submit("timer.test", 1234);
assertThat(this.registry.getTimers().get("timer.test").getCount()).isEqualTo(1);
}
}
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment