Search in sources :

Example 1 with EurekaClientConfigBean

use of org.springframework.cloud.netflix.eureka.EurekaClientConfigBean in project spring-cloud-netflix by spring-cloud.

the class RefreshablePeerEurekaNodesTests method notUpdatedWhenIrrelevantPropertiesChanged.

@Test
public void notUpdatedWhenIrrelevantPropertiesChanged() {
    // PeerEurekaNodes.updatePeerEurekaNodes() is not public, hence cannot verify with Mockito.
    class VerifyablePeerEurekNode extends RefreshablePeerEurekaNodes {

        public VerifyablePeerEurekNode(PeerAwareInstanceRegistry registry, EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs, ApplicationInfoManager applicationInfoManager) {
            super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager);
        }

        protected void updatePeerEurekaNodes(List<String> newPeerUrls) {
            super.updatePeerEurekaNodes(newPeerUrls);
        }
    }
    // Create stubs.
    final EurekaClientConfigBean configClientBean = mock(EurekaClientConfigBean.class);
    when(configClientBean.isUseDnsForFetchingServiceUrls()).thenReturn(false);
    final VerifyablePeerEurekNode mock = spy(new VerifyablePeerEurekNode(null, null, configClientBean, null, null));
    mock.onApplicationEvent(new EnvironmentChangeEvent(Collections.singleton("some.irrelevant.property")));
    verify(mock, never()).updatePeerEurekaNodes(anyListOf(String.class));
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) RefreshablePeerEurekaNodes(org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration.RefreshablePeerEurekaNodes) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) List(java.util.List) EurekaClientConfigBean(org.springframework.cloud.netflix.eureka.EurekaClientConfigBean) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) ServerCodecs(com.netflix.eureka.resources.ServerCodecs) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with EurekaClientConfigBean

use of org.springframework.cloud.netflix.eureka.EurekaClientConfigBean in project spring-cloud-netflix by spring-cloud.

the class EurekaServiceRegistryTests method eurekaClientGetStatusNoInstance.

@Test
public void eurekaClientGetStatusNoInstance() {
    EurekaServiceRegistry registry = new EurekaServiceRegistry();
    EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
    config.setAppname("myapp");
    config.setInstanceId("1234");
    CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
    when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(null);
    EurekaRegistration registration = EurekaRegistration.builder(config).with(eurekaClient).with(mock(ApplicationInfoManager.class)).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class)).build();
    Object status = registry.getStatus(registration);
    assertThat(status).isInstanceOf(Map.class);
    Map<Object, Object> map = (Map<Object, Object>) status;
    assertThat(map).hasSize(1).containsEntry("status", UNKNOWN.toString());
}
Also used : CloudEurekaClient(org.springframework.cloud.netflix.eureka.CloudEurekaClient) EurekaInstanceConfigBean(org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean) InetUtilsProperties(org.springframework.cloud.commons.util.InetUtilsProperties) EurekaClientConfigBean(org.springframework.cloud.netflix.eureka.EurekaClientConfigBean) InetUtils(org.springframework.cloud.commons.util.InetUtils) Map(java.util.Map) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 3 with EurekaClientConfigBean

use of org.springframework.cloud.netflix.eureka.EurekaClientConfigBean in project spring-cloud-netflix by spring-cloud.

the class EurekaServiceRegistryTests method eurekaClientNotShutdownInDeregister.

@Test
public void eurekaClientNotShutdownInDeregister() {
    EurekaServiceRegistry registry = new EurekaServiceRegistry();
    CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
    ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
    when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
    EurekaRegistration registration = EurekaRegistration.builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()))).with(eurekaClient).with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class)).build();
    registry.deregister(registration);
    verifyZeroInteractions(eurekaClient);
}
Also used : CloudEurekaClient(org.springframework.cloud.netflix.eureka.CloudEurekaClient) EurekaInstanceConfigBean(org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean) InetUtilsProperties(org.springframework.cloud.commons.util.InetUtilsProperties) EurekaClientConfigBean(org.springframework.cloud.netflix.eureka.EurekaClientConfigBean) InstanceInfo(com.netflix.appinfo.InstanceInfo) InetUtils(org.springframework.cloud.commons.util.InetUtils) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 4 with EurekaClientConfigBean

use of org.springframework.cloud.netflix.eureka.EurekaClientConfigBean in project spring-cloud-netflix by spring-cloud.

the class EurekaServiceRegistryTests method eurekaClientGetStatus.

@Test
public void eurekaClientGetStatus() {
    EurekaServiceRegistry registry = new EurekaServiceRegistry();
    EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
    config.setAppname("myapp");
    config.setInstanceId("1234");
    CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("myapp").setInstanceId("1234").setStatus(DOWN).setOverriddenStatus(UNKNOWN).build();
    when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(instanceInfo);
    EurekaRegistration registration = EurekaRegistration.builder(config).with(eurekaClient).with(mock(ApplicationInfoManager.class)).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class)).build();
    Object status = registry.getStatus(registration);
    assertThat(status).isInstanceOf(Map.class);
    Map<Object, Object> map = (Map<Object, Object>) status;
    assertThat(map).hasSize(2).containsEntry("status", DOWN.toString()).containsEntry("overriddenStatus", UNKNOWN.toString());
}
Also used : CloudEurekaClient(org.springframework.cloud.netflix.eureka.CloudEurekaClient) EurekaInstanceConfigBean(org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean) InetUtilsProperties(org.springframework.cloud.commons.util.InetUtilsProperties) EurekaClientConfigBean(org.springframework.cloud.netflix.eureka.EurekaClientConfigBean) InetUtils(org.springframework.cloud.commons.util.InetUtils) InstanceInfo(com.netflix.appinfo.InstanceInfo) Map(java.util.Map) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 5 with EurekaClientConfigBean

use of org.springframework.cloud.netflix.eureka.EurekaClientConfigBean in project spring-cloud-netflix by spring-cloud.

the class EurekaRibbonClientConfigurationTests method testSetProp.

@Test
public void testSetProp() {
    EurekaClientConfigBean client = new EurekaClientConfigBean();
    EurekaInstanceConfigBean configBean = getEurekaInstanceConfigBean();
    EurekaRibbonClientConfiguration preprocessor = new EurekaRibbonClientConfiguration(client, "myService", configBean, false);
    String serviceId = "myService";
    String suffix = "mySuffix";
    String value = "myValue";
    DynamicStringProperty property = getProperty(getRibbonKey(serviceId, suffix));
    assertEquals("property doesn't have default value", VALUE_NOT_SET, property.get());
    setRibbonProperty(serviceId, suffix, value);
    assertEquals("property has wrong value", value, property.get());
    setRibbonProperty(serviceId, suffix, value);
    assertEquals("property has wrong value", value, property.get());
}
Also used : EurekaInstanceConfigBean(org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean) DynamicStringProperty(com.netflix.config.DynamicStringProperty) EurekaClientConfigBean(org.springframework.cloud.netflix.eureka.EurekaClientConfigBean) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 EurekaClientConfigBean (org.springframework.cloud.netflix.eureka.EurekaClientConfigBean)9 EurekaInstanceConfigBean (org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean)8 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)4 InetUtils (org.springframework.cloud.commons.util.InetUtils)3 InetUtilsProperties (org.springframework.cloud.commons.util.InetUtilsProperties)3 CloudEurekaClient (org.springframework.cloud.netflix.eureka.CloudEurekaClient)3 InstanceInfo (com.netflix.appinfo.InstanceInfo)2 Map (java.util.Map)2 DynamicStringProperty (com.netflix.config.DynamicStringProperty)1 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 EurekaServerConfig (com.netflix.eureka.EurekaServerConfig)1 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)1 ServerCodecs (com.netflix.eureka.resources.ServerCodecs)1 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)1 DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)1 List (java.util.List)1 Ignore (org.junit.Ignore)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1