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")));
}
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));
}
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/"));
}
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/"));
}
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/"));
}
Aggregations