### Question:
DeletedMetadataReporter { public void reportTaggable(Taggable taggable, MetadataType metadataType) { log.info("Deleted " + metadataType.getTypeName()); MetricTag tag = taggable.getMetricTag(); String metadataMetricName = String.join("-", metadataType.getTypeName(), metricName); Counter counter = Counter.builder(metadataMetricName).tags(createTag(tag)).register(meterRegistry); counter.increment(); } DeletedMetadataReporter(MeterRegistry meterRegistry, boolean dryRunEnabled); void reportTaggable(Taggable taggable, MetadataType metadataType); static final String METRIC_NAME; static final String DRY_RUN_METRIC_NAME; }### Answer:
@Test public void typical() { deletedMetadataReporter.reportTaggable(taggable, HIVE_TABLE); Counter counter = RequiredSearch.in(meterRegistry).name(tableCounterName).tags("table", TABLE).counter(); assertThat(counter).isNotNull(); assertThat(counter.measure().iterator()).toIterable().extracting("statistic").containsExactly(Statistic.COUNT); assertThat(counter.measure().iterator()).toIterable().extracting("value").containsExactly((double) 1); }
@Test public void typicalDryRun() { deletedMetadataReporter = new DeletedMetadataReporter(meterRegistry, true); deletedMetadataReporter.reportTaggable(taggable, HIVE_TABLE); Counter counter = RequiredSearch.in(meterRegistry).name(dryRunTableCounterName).tags("table", TABLE).counter(); assertThat(counter).isNotNull(); assertThat(counter.measure().iterator()).toIterable().extracting("statistic").containsExactly(Statistic.COUNT); assertThat(counter.measure().iterator()).toIterable().extracting("value").containsExactly((double) 1); }
@Test public void multipleTablesDeleted() { Taggable taggable2 = Mockito.mock(Taggable.class); when(taggable2.getMetricTag()).thenReturn(new MetricTag("table", "database2.table2")); deletedMetadataReporter.reportTaggable(taggable, HIVE_TABLE); deletedMetadataReporter.reportTaggable(taggable2, HIVE_TABLE); Counter counter = RequiredSearch.in(meterRegistry).name(tableCounterName).tags("table", TABLE).counter(); assertThat(counter).isNotNull(); assertThat(counter.measure().iterator()).toIterable().extracting("statistic").containsExactly(Statistic.COUNT); assertThat(counter.measure().iterator()).toIterable().extracting("value").containsExactly((double) 1); Counter counter2 = RequiredSearch .in(meterRegistry) .name(tableCounterName) .tags("table", "database2.table2") .counter(); assertThat(counter2).isNotNull(); assertThat(counter2.measure().iterator()).toIterable().extracting("statistic").containsExactly(Statistic.COUNT); assertThat(counter2.measure().iterator()).toIterable().extracting("value").containsExactly((double) 1); }