Search in sources :

Example 6 with EnvironmentChangeEvent

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

the class RefreshablePeerEurekaNodesTests method notUpdatedForRelaxedKeys.

@Test
public void notUpdatedForRelaxedKeys() {
    changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", // to force defaultZone
    "eureka.client.region=unavailable-region", "eureka.client.service-url.defaultZone=http://defaul-host6:8678/eureka/");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("eureka.client.serviceUrl.defaultZone")));
    assertFalse("PeerEurekaNodes' are updated for keys with relaxed binding", serviceUrlMatches("http://defaul-host6:8678/eureka/"));
}
Also used : EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with EnvironmentChangeEvent

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

the class RefreshablePeerEurekaNodesTests method updatedWhenRegionChanged.

@Test
// FIXME 2.0.0
@Ignore
public void updatedWhenRegionChanged() {
    changeProperty("eureka.client.use-dns-for-fetching-service-urls=false", "eureka.client.region=region1", "eureka.client.availability-zones.region1=region1-zone", "eureka.client.availability-zones.region2=region2-zone", "eureka.client.service-url.region1-zone=http://region1-zone-host:8678/eureka/", "eureka.client.service-url.region2-zone=http://region2-zone-host:8678/eureka/");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton(REGION)));
    assertTrue("PeerEurekaNodes' are not updated when eureka.client.region is changed", serviceUrlMatches("http://region1-zone-host:8678/eureka/"));
    changeProperty("eureka.client.region=region2");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton(REGION)));
    assertTrue("PeerEurekaNodes' are not updated when eureka.client.region is changed", serviceUrlMatches("http://region2-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)

Example 8 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent in project cas by apereo.

the class RegisteredServicesEventListenerTests method verifyServiceExpirationWithRemovalEvent.

@Test
public void verifyServiceExpirationWithRemovalEvent() {
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    val contact = new DefaultRegisteredServiceContact();
    contact.setName("Test");
    contact.setEmail("casuser@example.org");
    contact.setPhone("13477465421");
    registeredService.getContacts().add(contact);
    val listener = new DefaultRegisteredServicesEventListener(this.servicesManager, casProperties, communicationsManager);
    listener.handleRefreshEvent(new CasRegisteredServicesRefreshEvent(this));
    listener.handleEnvironmentChangeEvent(new EnvironmentChangeEvent(Set.of()));
    val event = new CasRegisteredServiceExpiredEvent(this, registeredService, true);
    listener.handleRegisteredServiceExpiredEvent(event);
}
Also used : lombok.val(lombok.val) EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) CasRegisteredServicesRefreshEvent(org.apereo.cas.support.events.service.CasRegisteredServicesRefreshEvent) CasRegisteredServiceExpiredEvent(org.apereo.cas.support.events.service.CasRegisteredServiceExpiredEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with EnvironmentChangeEvent

use of org.springframework.cloud.context.environment.EnvironmentChangeEvent in project cas by apereo.

the class DefaultServiceRegistryInitializerEventListenerTests method verifyOperation.

@Test
public void verifyOperation() {
    val listener = new DefaultServiceRegistryInitializerEventListener(mock(ServiceRegistryInitializer.class));
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() {
            listener.handleConfigurationModifiedEvent(new CasConfigurationModifiedEvent(this, true));
        }
    });
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() {
            listener.handleRefreshEvent(new EnvironmentChangeEvent(Set.of()));
        }
    });
}
Also used : lombok.val(lombok.val) EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) CasConfigurationModifiedEvent(org.apereo.cas.support.events.config.CasConfigurationModifiedEvent) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 10 with EnvironmentChangeEvent

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

the class ArchaiusAutoConfigurationTests method environmentChangeEventPropagated.

@Test
public void environmentChangeEventPropagated() {
    this.context = new AnnotationConfigApplicationContext(ArchaiusAutoConfiguration.class);
    ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName().equals("my.prop")) {
                ArchaiusAutoConfigurationTests.this.propertyValue = event.getPropertyValue();
            }
        }
    });
    EnvironmentTestUtils.addEnvironment(this.context, "my.prop=my.newval");
    this.context.publishEvent(new EnvironmentChangeEvent(Collections.singleton("my.prop")));
    assertEquals("my.newval", this.propertyValue);
}
Also used : ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EnvironmentChangeEvent(org.springframework.cloud.context.environment.EnvironmentChangeEvent) Test(org.junit.Test)

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