Search in sources :

Example 1 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent in project spring-cloud-netflix by spring-cloud.

the class RefreshablePeerEurekaNodesTests method forceUpdate.

/*
	 * Refreshes the context with properties satisfying to invoke update.
	 */
private void forceUpdate() {
    changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", // to force defaultZone
    "eureka.client.region=unavailable-region");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("eureka.client.service-url.defaultZone")));
}
Also used : EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent)

Example 2 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent 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 3 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent in project spring-cloud-netflix by spring-cloud.

the class RefreshablePeerEurekaNodesTests method updatedWhenDnsIsFalse.

@Test
public void updatedWhenDnsIsFalse() {
    changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", // to force defaultZone
    "eureka.client.region=unavailable-region", "eureka.client.service-url.defaultZone=http://default-host2:8678/eureka/");
    this.context.publishEvent(new EnvironmentChangeEvent(new HashSet<String>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
    assertTrue("PeerEurekaNodes' are not updated when eureka.client.use-dns-for-fetching-service-urls is false", serviceUrlMatches("http://default-host2:8678/eureka/"));
}
Also used : EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent in project spring-cloud-netflix by spring-cloud.

the class RefreshablePeerEurekaNodesTests method notUpdatedWhenDnsIsTrue.

@Test
public void notUpdatedWhenDnsIsTrue() {
    changeProperty("eureka.client.use-dns-for-fetching-service-urls=true", // to force defaultZone
    "eureka.client.region=unavailable-region", "eureka.client.service-url.defaultZone=http://default-host1:8678/eureka/");
    this.context.publishEvent(new EnvironmentChangeEvent(new HashSet<String>(Arrays.asList(USE_DNS, DEFAULT_ZONE))));
    assertFalse("PeerEurekaNodes' are updated when eureka.client.use-dns-for-fetching-service-urls is true", serviceUrlMatches("http://default-host1:8678/eureka/"));
}
Also used : EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) HashSet(java.util.HashSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent in project spring-cloud-netflix by spring-cloud.

the class RefreshablePeerEurekaNodesTests method updatedWhenAvailabilityZoneChanged.

@Test
// FIXME 2.0.0
@Ignore
public void updatedWhenAvailabilityZoneChanged() {
    changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", "eureka.client.region=region4", "eureka.client.availability-zones.region3=region3-zone", "eureka.client.service-url.region4-zone=http://region4-zone-host:8678/eureka/", "eureka.client.service-url.defaultZone=http://default-host3:8678/eureka/");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("eureka.client.availability-zones.region3")));
    assertTrue(this.peerEurekaNodes.getPeerEurekaNodes().get(0).getServiceUrl().equals("http://default-host3:8678/eureka/"));
    changeProperty("eureka.client.availability-zones.region4=region4-zone");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("eureka.client.availability-zones.region4")));
    assertTrue("PeerEurekaNodes' are not updated when eureka.client.availability-zones are changed", serviceUrlMatches("http://region4-zone-host:8678/eureka/"));
}
Also used : EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

EnvironmentChangeEvent (org.springframework.cloud.context.environment.EnvironmentChangeEvent)12 Test (org.junit.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 HashSet (java.util.HashSet)3 lombok.val (lombok.val)2 Ignore (org.junit.Ignore)2 Test (org.junit.jupiter.api.Test)2 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)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 File (java.io.File)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ConfigurationEvent (org.apache.commons.configuration.event.ConfigurationEvent)1 ConfigurationListener (org.apache.commons.configuration.event.ConfigurationListener)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Source (org.apache.logging.log4j.core.util.Source)1 CasConfigurationModifiedEvent (org.apereo.cas.support.events.config.CasConfigurationModifiedEvent)1