RouterHeartbeatService extends PeriodicService { @VisibleForTesting synchronized void updateStateStore() { String routerId = router.getRouterId(); if (routerId == null) { LOG.error("Cannot heartbeat for router: unknown router id"); return; } if (isStoreAvailable()) { RouterStore routerStore = router.getRouterStateManager(); try { RouterState record = RouterState.newInstance( routerId, router.getStartTime(), router.getRouterState()); StateStoreVersion stateStoreVersion = StateStoreVersion.newInstance( getStateStoreVersion(MembershipStore.class), getStateStoreVersion(MountTableStore.class)); record.setStateStoreVersion(stateStoreVersion); String hostPort = StateStoreUtils.getHostPortString(router.getAdminServerAddress()); record.setAdminAddress(hostPort); RouterHeartbeatRequest request = RouterHeartbeatRequest.newInstance(record); RouterHeartbeatResponse response = routerStore.routerHeartbeat(request); if (!response.getStatus()) { LOG.warn("Cannot heartbeat router {}", routerId); } else { LOG.debug("Router heartbeat for router {}", routerId); } } catch (IOException e) { LOG.error("Cannot heartbeat router {}", routerId, e); } } else { LOG.warn("Cannot heartbeat router {}: State Store unavailable", routerId); } } RouterHeartbeatService(Router router); @Override void periodicInvoke();  }
@Test public void testStateStoreUnavailable() throws IOException { curatorFramework.close(); testingServer.stop(); router.getStateStore().stop(); assertFalse(router.getStateStore().isDriverReady()); RouterHeartbeatService heartbeatService = new RouterHeartbeatService(router); heartbeatService.updateStateStore(); }