KubernetesDiscoveryService implements DiscoveryService { @Override public List<ServiceDTO> getServiceInstances(String serviceId) { String configName = SERVICE_ID_TO_CONFIG_NAME.get(serviceId); if (configName == null) { return Collections.emptyList(); } return assembleServiceDTO(serviceId, bizConfig.getValue(configName)); } KubernetesDiscoveryService(final BizConfig bizConfig); @Override List<ServiceDTO> getServiceInstances(String serviceId);  }
@Test public void testGetServiceInstancesWithInvalidServiceId() { String someInvalidServiceId = "someInvalidServiceId"; assertTrue(kubernetesDiscoveryService.getServiceInstances(someInvalidServiceId).isEmpty()); }
@Test public void testGetServiceInstancesWithNullConfig() { when(bizConfig.getValue(configServiceConfigName)).thenReturn(null); assertTrue( kubernetesDiscoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE) .isEmpty()); verify(bizConfig, times(1)).getValue(configServiceConfigName); }
@Test public void testGetConfigServiceInstances() { String someUrl = "http: when(bizConfig.getValue(configServiceConfigName)).thenReturn(someUrl); List<ServiceDTO> serviceDTOList = kubernetesDiscoveryService .getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE); assertEquals(1, serviceDTOList.size()); ServiceDTO serviceDTO = serviceDTOList.get(0); assertEquals(ServiceNameConsts.APOLLO_CONFIGSERVICE, serviceDTO.getAppName()); assertEquals(String.format("%s:%s", ServiceNameConsts.APOLLO_CONFIGSERVICE, someUrl), serviceDTO.getInstanceId()); assertEquals(someUrl, serviceDTO.getHomepageUrl()); }
@Test public void testGetAdminServiceInstances() { String someUrl = "http: String anotherUrl = "http: when(bizConfig.getValue(adminServiceConfigName)) .thenReturn(String.format("%s,%s", someUrl, anotherUrl)); List<ServiceDTO> serviceDTOList = kubernetesDiscoveryService .getServiceInstances(ServiceNameConsts.APOLLO_ADMINSERVICE); assertEquals(2, serviceDTOList.size()); ServiceDTO serviceDTO = serviceDTOList.get(0); assertEquals(ServiceNameConsts.APOLLO_ADMINSERVICE, serviceDTO.getAppName()); assertEquals(String.format("%s:%s", ServiceNameConsts.APOLLO_ADMINSERVICE, someUrl), serviceDTO.getInstanceId()); assertEquals(someUrl, serviceDTO.getHomepageUrl()); ServiceDTO anotherServiceDTO = serviceDTOList.get(1); assertEquals(ServiceNameConsts.APOLLO_ADMINSERVICE, anotherServiceDTO.getAppName()); assertEquals(String.format("%s:%s", ServiceNameConsts.APOLLO_ADMINSERVICE, anotherUrl), anotherServiceDTO.getInstanceId()); assertEquals(anotherUrl, anotherServiceDTO.getHomepageUrl()); }