@VisibleForTesting static void unsafeResetExporter() { synchronized (monitor) { if (instance != null) { instance.intervalMetricReader.stop(); } instance = null; } } }
@VisibleForTesting static void unsafeResetExporter() { synchronized (monitor) { if (exporter != null) { if (exporter.intervalMetricReader != null) { exporter.intervalMetricReader.stop(); } exporter = null; } } }
@Test public void intervalExport() { FakeMetricExporter fakeMetricExporter = new FakeMetricExporter(); IntervalMetricReader intervalMetricReader = IntervalMetricReader.create( fakeMetricExporter, MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager(metricProducerManager) .build()), IntervalMetricReader.Options.builder() .setExportInterval(Duration.create(0, (int) MILLISECONDS.toNanos(100))) .build()); assertThat(fakeMetricExporter.waitForNumberOfExports(1)) .containsExactly(Collections.singletonList(METRIC)); assertThat(fakeMetricExporter.waitForNumberOfExports(2)) .containsExactly(Collections.singletonList(METRIC), Collections.singletonList(METRIC)); intervalMetricReader.stop(); }
@Test public void exportAfterStop() { FakeMetricExporter fakeMetricExporter = new FakeMetricExporter(); IntervalMetricReader intervalMetricReader = IntervalMetricReader.create( fakeMetricExporter, MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager(metricProducerManager) .build()), IntervalMetricReader.Options.builder() .setExportInterval(Duration.create(10, 0)) .build()); // Rely that this will be called in less than 10 seconds. intervalMetricReader.stop(); assertThat(fakeMetricExporter.waitForNumberOfExports(1)) .containsExactly(Collections.singletonList(METRIC)); } }