MappedMetricDataTimestampExtractor implements TimestampExtractor { @Override public long extract(ConsumerRecord<Object, Object> record, long previousTimestamp) { val mappedMetricData = (MappedMetricData) record.value(); if (mappedMetricData == null || mappedMetricData.getMetricData() == null) { return -1L; } return mappedMetricData.getMetricData().getTimestamp() * 1000L; }  @Override long extract(ConsumerRecord<Object, Object> record, long previousTimestamp);  }
@Test public void testExtract() { val mmd = TestObjectMother.mappedMetricData(); val metricData = mmd.getMetricData(); val record = new ConsumerRecord<Object, Object>("some-topic", 1, 0, "some-key", mmd); val expectedTimestamp = metricData.getTimestamp() * 1000L; val actualTimestamp = new MappedMetricDataTimestampExtractor().extract(record, -1L); assertEquals(expectedTimestamp, actualTimestamp); }
@Test public void testExtract_nullMetricData() { val record = new ConsumerRecord<Object, Object>("some-topic", 1, 0, "some-key", null); val actualTimestamp = new MappedMetricDataTimestampExtractor().extract(record, -1L); assertTrue(actualTimestamp < 0L); }