DefaultMetaCache implements MetaCache { @Override public RouteMeta getRouteIfPossible(HostPort hostPort) { XpipeMetaManager xpipeMetaManager = meta.getValue(); XpipeMetaManager.MetaDesc metaDesc = xpipeMetaManager.findMetaDesc(hostPort); if (metaDesc == null) { logger.warn("[getRouteIfPossible]HostPort corresponding meta not found: {}", hostPort); return null; } return xpipeMetaManager .consoleRandomRoute(CONSOLE_IDC, XpipeMetaManager.ORG_ID_FOR_SHARED_ROUTES, metaDesc.getDcId()); } DefaultMetaCache(); @PostConstruct void postConstruct(); @PreDestroy void shutdown(); @Override XpipeMeta getXpipeMeta(); @Override boolean inBackupDc(HostPort hostPort); @Override HostPort findMasterInSameShard(HostPort hostPort); @Override Pair<String, String> findClusterShard(HostPort hostPort); @Override String getActiveDc(HostPort hostPort); @Override long getLastUpdateTime(); @Override RouteMeta getRouteIfPossible(HostPort hostPort); @Override boolean isCrossRegion(String activeDc, String backupDc); @Override List<HostPort> getAllActiveRedisOfDc(String activeDc, String dcId); @Override Set<HostPort> getAllKeepers(); @Override String getSentinelMonitorName(String clusterId, String shardId); @Override Set<HostPort> getActiveDcSentinels(String clusterId, String shardId); @Override HostPort findMaster(String clusterId, String shardId); @Override String getDc(HostPort hostPort); @Override Pair<String, String> findClusterShardBySentinelMonitor(String monitor); @Override String getActiveDc(String clusterId, String shardId); @Override ClusterType getClusterType(String clusterId);  }
@Test public void getRouteIfPossible() { HostPort hostPort = new HostPort("127.0.0.1", 6379); XpipeMetaManager xpipeMetaManager = mock(XpipeMetaManager.class); when(xpipeMetaManager.findMetaDesc(hostPort)).thenReturn(null); metaCache.setMeta(new Pair<>(mock(XpipeMeta.class), xpipeMetaManager)); metaCache.getRouteIfPossible(hostPort); }