### Question:
FateMetrics extends MasterMetrics { void overrideRefresh(final long minimumRefreshDelay) { long delay = Math.max(0, minimumRefreshDelay); this.minimumRefreshDelay = TimeUnit.SECONDS.toMillis(delay); } FateMetrics(final ServerContext context, final long minimumRefreshDelay);   }### Answer:
@Test public void noFates() { FateMetrics metrics = new FateMetrics(context, 10); metrics.overrideRefresh(0); InMemTestCollector collector = new InMemTestCollector(); metrics.getMetrics(collector, true); log.debug("Collector: {}", collector); assertTrue(collector.contains("currentFateOps")); assertTrue(collector.contains("totalFateOps")); assertTrue(collector.contains("totalZkConnErrors")); assertTrue(collector.contains("FateTxState_NEW")); assertTrue(collector.contains("FateTxState_IN_PROGRESS")); assertTrue(collector.contains("FateTxState_FAILED_IN_PROGRESS")); assertTrue(collector.contains("FateTxState_FAILED")); assertTrue(collector.contains("FateTxState_SUCCESSFUL")); assertTrue(collector.contains("FateTxState_UNKNOWN")); assertFalse(collector.contains("FateTxOpType_FakeOp")); assertEquals(0L, collector.getValue("FateTxState_IN_PROGRESS")); assertEquals(0L, collector.getValue("currentFateOps")); EasyMock.verify(master); }
@Test public void fateNewStatus() { long tx1Id = zooStore.create(); log.debug("ZooStore tx1 id {}", tx1Id); FateMetrics metrics = new FateMetrics(context, 10); metrics.overrideRefresh(0); InMemTestCollector collector = new InMemTestCollector(); metrics.getMetrics(collector, true); log.debug("Collector: {}", collector); assertTrue(collector.contains("FateTxState_NEW")); assertEquals(1L, collector.getValue("FateTxState_NEW")); assertEquals(1L, collector.getValue("currentFateOps")); assertTrue(collector.contains("FateTxState_IN_PROGRESS")); assertEquals(0L, collector.getValue("FateTxState_IN_PROGRESS")); EasyMock.verify(master); }
@Test public void oneInProgress() throws Exception { long tx1Id = seedTransaction(); log.debug("FATE tx: {}", prettyStat( zookeeper.exists(MOCK_ZK_ROOT + "/fate/" + String.format("tx_%016x", tx1Id), false))); FateMetrics metrics = new FateMetrics(context, 10); metrics.overrideRefresh(0); InMemTestCollector collector = new InMemTestCollector(); metrics.getMetrics(collector, true); log.debug("Collector: {}", collector); assertTrue(collector.contains("FateTxState_IN_PROGRESS")); assertEquals(1L, collector.getValue("FateTxState_IN_PROGRESS")); assertEquals(1L, collector.getValue("FateTxOpType_FakeOp")); EasyMock.verify(master); }
@Test public void typeClears() throws Exception { long txId = seedTransaction(); zooStore.reserve(txId); zooStore.setStatus(txId, ReadOnlyTStore.TStatus.SUCCESSFUL); zooStore.unreserve(txId, 50); FateMetrics metrics = new FateMetrics(context, 10); metrics.overrideRefresh(0); InMemTestCollector collector = new InMemTestCollector(); metrics.getMetrics(collector, true); assertEquals(0L, collector.getValue("FateTxState_IN_PROGRESS")); assertEquals(1L, collector.getValue("FateTxState_SUCCESSFUL")); assertNull(collector.getValue("FateTxOpType_FakeOp")); }