Java 类org.springframework.boot.actuate.metrics.CounterService 实例源码

项目:spring-cloud-spinnaker    文件:ModuleService.java   
public ModuleService(SpinnakerConfiguration spinnakerConfiguration,
                     CloudFoundryAppDeployerFactory appDeployerFactory,
                     ResourcePatternResolver ctx,
                     CounterService counterService,
                     TempFileManager fileManager,
                     MavenProperties mavenProperties,
                     ResourceLoader resourceLoader) {

    this.spinnakerConfiguration = spinnakerConfiguration;
    this.appDeployerFactory = appDeployerFactory;
    this.ctx = ctx;
    this.counterService = counterService;
    this.fileManager = fileManager;
    this.mavenProperties = mavenProperties;
    this.resourceLoader = resourceLoader;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsHttpInteractions() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    final MockHttpServletRequest request = new MockHttpServletRequest("GET",
            "/test/path");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            response.setStatus(200);
            return null;
        }
    }).given(chain).doFilter(request, response);
    filter.doFilter(request, response, chain);
    verify(context.getBean(CounterService.class)).increment("status.200.test.path");
    verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"),
            anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records302HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class, RedirectFilter.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).addFilter(context.getBean(RedirectFilter.class))
            .build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().is3xxRedirection());
    mvc.perform(get("/unknownPath/2")).andExpect(status().is3xxRedirection());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.302.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void controllerMethodThatThrowsUnhandledException() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    try {
        mvc.perform(get("/unhandledException"))
                .andExpect(status().isInternalServerError());
    }
    catch (NestedServletException ex) {
        // Expected
    }
    verify(context.getBean(CounterService.class))
            .increment("status.500.unhandledException");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.unhandledException"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void gaugeServiceThatThrows() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    GaugeService gaugeService = context.getBean(GaugeService.class);
    willThrow(new IllegalStateException()).given(gaugeService).submit(anyString(),
            anyDouble());
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class))
            .increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void correctlyRecordsMetricsForDeferredResultResponse() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    CountDownLatch latch = new CountDownLatch(1);
    MockMvc mvc = MockMvcBuilders
            .standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter)
            .build();
    String attributeName = MetricsFilter.class.getName() + ".StopWatch";
    MvcResult result = mvc.perform(post("/create")).andExpect(status().isOk())
            .andExpect(request().asyncStarted())
            .andExpect(request().attribute(attributeName, is(notNullValue())))
            .andReturn();
    latch.countDown();
    mvc.perform(asyncDispatch(result)).andExpect(status().isCreated())
            .andExpect(request().attribute(attributeName, is(nullValue())));
    verify(context.getBean(CounterService.class)).increment("status.201.create");
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records5xxxHttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class,
            ServiceUnavailableFilter.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter)
            .addFilter(context.getBean(ServiceUnavailableFilter.class)).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().isServiceUnavailable());
    mvc.perform(get("/unknownPath/2")).andExpect(status().isServiceUnavailable());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.503.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(Config.class, MetricFilterAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(context,
            "endpoints.metrics.filter.gauge-submissions=",
            "endpoints.metrics.filter.counter-submissions=");
    context.refresh();
    Filter filter = context.getBean(Filter.class);
    final MockHttpServletRequest request = new MockHttpServletRequest("PUT",
            "/test/path");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            response.setStatus(200);
            return null;
        }
    }).given(chain).doFilter(request, response);
    filter.doFilter(request, response, chain);
    verify(context.getBean(GaugeService.class), never()).submit(anyString(),
            anyDouble());
    verify(context.getBean(CounterService.class), never()).increment(anyString());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsHttpInteractions() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    final MockHttpServletRequest request = new MockHttpServletRequest("GET",
            "/test/path");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            response.setStatus(200);
            return null;
        }
    }).given(chain).doFilter(request, response);
    filter.doFilter(request, response, chain);
    verify(context.getBean(CounterService.class)).increment("status.200.test.path");
    verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"),
            anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records302HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class, RedirectFilter.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).addFilter(context.getBean(RedirectFilter.class))
            .build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().is3xxRedirection());
    mvc.perform(get("/unknownPath/2")).andExpect(status().is3xxRedirection());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.302.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void controllerMethodThatThrowsUnhandledException() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    try {
        mvc.perform(get("/unhandledException"))
                .andExpect(status().isInternalServerError());
    }
    catch (NestedServletException ex) {
        // Expected
    }
    verify(context.getBean(CounterService.class))
            .increment("status.500.unhandledException");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.unhandledException"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void gaugeServiceThatThrows() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    GaugeService gaugeService = context.getBean(GaugeService.class);
    willThrow(new IllegalStateException()).given(gaugeService).submit(anyString(),
            anyDouble());
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class))
            .increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void correctlyRecordsMetricsForDeferredResultResponse() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    CountDownLatch latch = new CountDownLatch(1);
    MockMvc mvc = MockMvcBuilders
            .standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter)
            .build();
    String attributeName = MetricsFilter.class.getName() + ".StopWatch";
    MvcResult result = mvc.perform(post("/create")).andExpect(status().isOk())
            .andExpect(request().asyncStarted())
            .andExpect(request().attribute(attributeName, is(notNullValue())))
            .andReturn();
    latch.countDown();
    mvc.perform(asyncDispatch(result)).andExpect(status().isCreated())
            .andExpect(request().attribute(attributeName, is(nullValue())));
    verify(context.getBean(CounterService.class)).increment("status.201.create");
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records5xxxHttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class,
            ServiceUnavailableFilter.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter)
            .addFilter(context.getBean(ServiceUnavailableFilter.class)).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().isServiceUnavailable());
    mvc.perform(get("/unknownPath/2")).andExpect(status().isServiceUnavailable());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.503.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void doesNotRecordRolledUpMetricsIfConfigured() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(Config.class, MetricFilterAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(context,
            "endpoints.metrics.filter.gauge-submissions=",
            "endpoints.metrics.filter.counter-submissions=");
    context.refresh();
    Filter filter = context.getBean(Filter.class);
    final MockHttpServletRequest request = new MockHttpServletRequest("PUT",
            "/test/path");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            response.setStatus(200);
            return null;
        }
    }).given(chain).doFilter(request, response);
    filter.doFilter(request, response, chain);
    verify(context.getBean(GaugeService.class), never()).submit(anyString(),
            anyDouble());
    verify(context.getBean(CounterService.class), never()).increment(anyString());
    context.close();
}
项目:contestparser    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsHttpInteractions() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    final MockHttpServletRequest request = new MockHttpServletRequest("GET",
            "/test/path");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            response.setStatus(200);
            return null;
        }
    }).given(chain).doFilter(request, response);
    filter.doFilter(request, response, chain);
    verify(context.getBean(CounterService.class)).increment("status.200.test.path");
    verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"),
            anyDouble());
    context.close();
}
项目:contestparser    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records302HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class, RedirectFilter.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).addFilter(context.getBean(RedirectFilter.class))
            .build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().is3xxRedirection());
    mvc.perform(get("/unknownPath/2")).andExpect(status().is3xxRedirection());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.302.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:contestparser    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void controllerMethodThatThrowsUnhandledException() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    try {
        mvc.perform(get("/unhandledException"))
                .andExpect(status().isInternalServerError());
    }
    catch (NestedServletException ex) {
        // Expected
    }
    verify(context.getBean(CounterService.class))
            .increment("status.500.unhandledException");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.unhandledException"), anyDouble());
    context.close();
}
项目:contestparser    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void gaugeServiceThatThrows() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    GaugeService gaugeService = context.getBean(GaugeService.class);
    willThrow(new IllegalStateException()).given(gaugeService).submit(anyString(),
            anyDouble());
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class))
            .increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
项目:contestparser    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void correctlyRecordsMetricsForDeferredResultResponse() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    CountDownLatch latch = new CountDownLatch(1);
    MockMvc mvc = MockMvcBuilders
            .standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter)
            .build();
    String attributeName = MetricsFilter.class.getName() + ".StopWatch";
    MvcResult result = mvc.perform(post("/create")).andExpect(status().isOk())
            .andExpect(request().asyncStarted())
            .andExpect(request().attribute(attributeName, is(notNullValue())))
            .andReturn();
    latch.countDown();
    mvc.perform(asyncDispatch(result)).andExpect(status().isCreated())
            .andExpect(request().attribute(attributeName, is(nullValue())));
    verify(context.getBean(CounterService.class)).increment("status.201.create");
    context.close();
}
项目:jigsaw-payment    文件:TimerAspect.java   
@Autowired
public TimerAspect(GaugeService gaugeService,
        CounterService counterService, ObjectMapper mapper) {
    this.counterService = counterService;
    this.gaugeService = gaugeService;
    this.mapper = mapper;
}
项目:vertx-spring    文件:VertxActuatorMetrics.java   
public AbstractPartMetrics(CounterService counterService, GaugeService gaugeService, P properties) {
    this.properties = properties;
    this.prefix = properties.getPrefix() + ".";
    this.counterService = new PrefixCounterServiceDecorator(counterService, prefix);
    this.gaugeService = new PrefixGaugeServiceDecorator(gaugeService, prefix);

    this.counterService.increment("instances.active");
    this.counterService.increment("instances.total");
}
项目:spring-cloud-spinnaker    文件:Config.java   
@Bean
ModuleService moduleService(SpinnakerConfiguration spinnakerConfiguration,
                            CloudFoundryAppDeployerFactory appDeployerFactoryBean,
                            ApplicationContext ctx,
                            CounterService counterService,
                            TempFileManager fileManager,
                            MavenProperties mavenProperties,
                            LRUCleaningResourceLoader resourceLoader) {
    return new ModuleService(spinnakerConfiguration, appDeployerFactoryBean, ctx, counterService, fileManager, mavenProperties, resourceLoader);
}
项目:spring-cloud-spinnaker    文件:ModuleServiceTests.java   
@Bean
ModuleService moduleService(SpinnakerConfiguration spinnakerConfiguration,
                            CloudFoundryAppDeployerFactory appDeployerFactoryBean,
                            ApplicationContext ctx,
                            CounterService counterService,
                            TempFileManager fileManager,
                            MavenProperties mavenProperties,
                            LRUCleaningResourceLoader resourceLoader) {
    return new ModuleService(spinnakerConfiguration, appDeployerFactoryBean, mockPatternResolver(ctx), counterService, fileManager, mavenProperties, resourceLoader);
}
项目:pivio-server    文件:DocumentController.java   
public DocumentController(Client client, ChangesetService changesetService, ObjectMapper mapper, CounterService counterService) {
    this.client = client;
    this.changesetService = changesetService;
    this.mapper = mapper;
    this.counterService = counterService;
    mandatoryFields = Arrays.asList("id", "type", "name", "owner", "description");
}
项目:pivio-server    文件:DocumentControllerTest.java   
@Before
public void setUp() {
    client = mock(Client.class);
    counterService = mock(CounterService.class);
    objectMapper = new ObjectMapper();
    documentController = new DocumentController(client, new ChangesetService(client, objectMapper), objectMapper, counterService);
}
项目:zipkin    文件:ActuateCollectorMetrics.java   
ActuateCollectorMetrics(CounterService counterService, GaugeService gaugeService,
    @Nullable String transport) {
  this.counterService = counterService;
  this.gaugeService = gaugeService;
  String footer = transport == null ? "" : "." + transport;
  this.messages = "zipkin_collector.messages" + footer;
  this.messagesDropped = "zipkin_collector.messages_dropped" + footer;
  this.messageBytes = "zipkin_collector.message_bytes" + footer;
  this.messageSpans = "zipkin_collector.message_spans" + footer;
  this.bytes = "zipkin_collector.bytes" + footer;
  this.spans = "zipkin_collector.spans" + footer;
  this.spansDropped = "zipkin_collector.spans_dropped" + footer;
}
项目:cat-boot    文件:InvalidClassExceptionSafeRepository.java   
public InvalidClassExceptionSafeRepository(SessionRepository<S> repository,
                                           RedisTemplate<String, ExpiringSession> sessionRedisTemplate,
                                           CounterService counterService) {
    this.repository = repository;
    this.sessionRedisTemplate = sessionRedisTemplate;
    this.counterService = counterService;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricsDropwizardAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean({ DropwizardMetricServices.class, CounterService.class,
        GaugeService.class })
public DropwizardMetricServices dropwizardMetricServices(
        MetricRegistry metricRegistry) {
    return new DropwizardMetricServices(metricRegistry);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsHttpInteractionsWithTemplateVariable() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class))
            .increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable()
        throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/knownPath/foo")).andExpect(status().isNotFound());
    verify(context.getBean(CounterService.class))
            .increment("status.404.knownPath.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.knownPath.someVariable"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records404HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().isNotFound());
    mvc.perform(get("/unknownPath/2")).andExpect(status().isNotFound());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.404.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void correctlyRecordsMetricsForFailedDeferredResultResponse()
        throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    CountDownLatch latch = new CountDownLatch(1);
    MockMvc mvc = MockMvcBuilders
            .standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter)
            .build();
    String attributeName = MetricsFilter.class.getName() + ".StopWatch";
    MvcResult result = mvc.perform(post("/createFailure")).andExpect(status().isOk())
            .andExpect(request().asyncStarted())
            .andExpect(request().attribute(attributeName, is(notNullValue())))
            .andReturn();
    latch.countDown();
    try {
        mvc.perform(asyncDispatch(result));
        fail();
    }
    catch (Exception ex) {
        assertThat(result.getRequest().getAttribute(attributeName)).isNull();
        verify(context.getBean(CounterService.class))
                .increment("status.500.createFailure");
    }
    finally {
        context.close();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void additionallyRecordsMetricsWithHttpMethodNameIfConfigured()
        throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(Config.class, MetricFilterAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(context,
            "endpoints.metrics.filter.gauge-submissions=merged,per-http-method",
            "endpoints.metrics.filter.counter-submissions=merged,per-http-method");
    context.refresh();
    Filter filter = context.getBean(Filter.class);
    final MockHttpServletRequest request = new MockHttpServletRequest("PUT",
            "/test/path");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain chain = mock(FilterChain.class);
    willAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            response.setStatus(200);
            return null;
        }
    }).given(chain).doFilter(request, response);
    filter.doFilter(request, response, chain);
    verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"),
            anyDouble());
    verify(context.getBean(GaugeService.class)).submit(eq("response.PUT.test.path"),
            anyDouble());
    verify(context.getBean(CounterService.class))
            .increment(eq("status.200.test.path"));
    verify(context.getBean(CounterService.class))
            .increment(eq("status.PUT.200.test.path"));
    context.close();
}
项目:Zipkin    文件:TraceMetricsAutoConfiguration.java   
@Bean
@ConditionalOnBean(CounterService.class)
public SpanMetricReporter spanReporterCounterService(CounterService counterService,
        SleuthMetricProperties sleuthMetricProperties) {
    return new CounterServiceBasedSpanMetricReporter(sleuthMetricProperties.getSpan().getAcceptedName(),
            sleuthMetricProperties.getSpan().getDroppedName(), counterService);
}
项目:spring-boot-concourse    文件:MetricsDropwizardAutoConfiguration.java   
@Bean
@ConditionalOnMissingBean({ DropwizardMetricServices.class, CounterService.class,
        GaugeService.class })
public DropwizardMetricServices dropwizardMetricServices(
        MetricRegistry metricRegistry) {
    return new DropwizardMetricServices(metricRegistry);
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsHttpInteractionsWithTemplateVariable() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class))
            .increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable()
        throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/knownPath/foo")).andExpect(status().isNotFound());
    verify(context.getBean(CounterService.class))
            .increment("status.404.knownPath.someVariable");
    verify(context.getBean(GaugeService.class))
            .submit(eq("response.knownPath.someVariable"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void records404HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
            .addFilter(filter).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().isNotFound());
    mvc.perform(get("/unknownPath/2")).andExpect(status().isNotFound());
    verify(context.getBean(CounterService.class), times(2))
            .increment("status.404.unmapped");
    verify(context.getBean(GaugeService.class), times(2))
            .submit(eq("response.unmapped"), anyDouble());
    context.close();
}
项目:spring-boot-concourse    文件:MetricFilterAutoConfigurationTests.java   
@Test
public void correctlyRecordsMetricsForFailedDeferredResultResponse()
        throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
            Config.class, MetricFilterAutoConfiguration.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    CountDownLatch latch = new CountDownLatch(1);
    MockMvc mvc = MockMvcBuilders
            .standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter)
            .build();
    String attributeName = MetricsFilter.class.getName() + ".StopWatch";
    MvcResult result = mvc.perform(post("/createFailure")).andExpect(status().isOk())
            .andExpect(request().asyncStarted())
            .andExpect(request().attribute(attributeName, is(notNullValue())))
            .andReturn();
    latch.countDown();
    try {
        mvc.perform(asyncDispatch(result));
        fail();
    }
    catch (Exception ex) {
        assertThat(result.getRequest().getAttribute(attributeName)).isNull();
        verify(context.getBean(CounterService.class))
                .increment("status.500.createFailure");
    }
    finally {
        context.close();
    }
}