private ExtractorSummary toSummary(Extractor extractor) {
    final ExtractorMetrics metrics =
        ExtractorMetrics.create(
            MetricUtils.buildTimerMap(
                metricRegistry.getTimers().get(extractor.getTotalTimerName())),
            MetricUtils.buildTimerMap(
                metricRegistry.getTimers().get(extractor.getConverterTimerName())));

    return ExtractorSummary.create(
        extractor.getId(),
        extractor.getTitle(),
        extractor.getType().toString().toLowerCase(),
        extractor.getCursorStrategy().toString().toLowerCase(),
        extractor.getSourceField(),
        extractor.getTargetField(),
        extractor.getExtractorConfig(),
        extractor.getCreatorUserId(),
        extractor.converterConfigMap(),
        extractor.getConditionType().toString().toLowerCase(),
        extractor.getConditionValue(),
        extractor.getOrder(),
        extractor.getExceptionCount(),
        extractor.getConverterExceptionCount(),
        metrics);
  }
 private Timer timer(String name) {
   Timer timer = metricRegistry.getTimers().get(name);
   if (timer != null) {
     return timer;
   }
   try {
     return metricRegistry.register(
         name,
         new Timer(new SlidingTimeWindowReservoir(timerReservoirSeconds.get(), TimeUnit.SECONDS)));
   } catch (IllegalArgumentException e) {
     // timer already exists. this happens due to race condition. its fine.
     return metricRegistry.getTimers().get(name);
   }
 }
 @Test
 public void test() throws Exception {
   Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
   JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(parameters));
   Assert.assertEquals(
       jobExecution.getExitStatus().getExitDescription(),
       BatchStatus.COMPLETED,
       jobExecution.getStatus());
   Map<String, Meter> meters = metricRegistry.getMeters();
   assertThat(meters).hasSize(2);
   assertThat(meters)
       .containsKey("batch.sampleJob.job.metered")
       .containsKey("batch.sampleJob.step.chunkStep.step.metered");
   assertThat(extractProperty("count", Number.class).from(meters.values()))
       .contains(1L)
       .doesNotContain(0L);
   Map<String, Timer> timers = metricRegistry.getTimers();
   assertThat(timers).hasSize(6);
   assertThat(timers)
       .containsKey("batch.sampleJob.job.timed")
       .containsKey("batch.sampleJob.step.chunkStep.chunk.timed")
       .containsKey("batch.sampleJob.step.chunkStep.step.timed")
       .containsKey("batch.sampleJob.step.chunkStep.read.timed")
       .containsKey("batch.sampleJob.step.chunkStep.process.timed")
       .containsKey("batch.sampleJob.step.chunkStep.write.timed");
   assertThat(extractProperty("count", Number.class).from(timers.values()))
       .contains(1L, 3L, 4L)
       .doesNotContain(0L);
   Map<String, Gauge> gauges = metricRegistry.getGauges();
   assertThat(gauges).hasSize(0);
 }
  @Test
  public void callLambdaExpressionTimedStaticMethodOnce() {
    // Call the timed static method and assert it's been timed once
    TimedStaticMethodWithNameFromElExpression.lambdaExpressionStaticTimedMethod();

    assertThat(
        "Shared metric registry is not created",
        SharedMetricRegistries.names(),
        hasItem(REGISTRY_NAME));
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);

    assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME));
    Timer timer = registry.getTimers().get(TIMER_NAME);

    assertThat(
        "Timer count is incorrect", timer.getCount(), is(equalTo(TIMER_COUNT.incrementAndGet())));
  }