org.springframework.cloud.autoconfigure.RefreshAutoConfiguration Java Examples

The following examples show how to use org.springframework.cloud.autoconfigure.RefreshAutoConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path()
		throws Exception {
	TestPropertyValues
			.of("server.port=8989",
					"management.server.servlet.context-path=/management")
			.applyTo(this.context);

	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().endsWith(":8989/management/actuator/info"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
	assertThat(
			instance.getHealthCheckUrl().endsWith(":8989/management/actuator/health"))
					.as("Wrong health check: " + instance.getHealthCheckUrl())
					.isTrue();
}
 
Example #2
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCloseDiscoveryClient() throws Exception {
	TestPropertyValues.of("eureka.client.healthcheck.enabled=true")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class,
			AutoServiceRegistrationConfiguration.class);

	AtomicBoolean isShutdown = (AtomicBoolean) ReflectionTestUtils
			.getField(getLazyInitEurekaClient(), "isShutdown");

	assertThat(isShutdown.get()).isFalse();

	this.context.close();

	assertThat(isShutdown.get()).isTrue();
}
 
Example #3
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void statusPageAndHealthCheckUrlsShouldSetUserDefinedIpAddress() {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999",
			"eureka.instance.hostname=foo",
			"eureka.instance.ip-address:192.168.13.90",
			"eureka.instance.prefer-ip-address:true").applyTo(this.context);

	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);

	assertThat(instance.getStatusPageUrl()).as("statusPageUrl is wrong")
			.isEqualTo("http://192.168.13.90:9999/actuator/info");
	assertThat(instance.getHealthCheckUrl()).as("healthCheckUrl is wrong")
			.isEqualTo("http://192.168.13.90:9999/actuator/health");
}
 
Example #4
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrlPathAndManagementPortAndContextPath() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"management.server.servlet.context-path=/manage",
					"eureka.instance.status-page-url-path=/myStatusPage")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().endsWith(":9999/manage/myStatusPage"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #5
Source File: ConditionalOnRefreshScopeTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenHavingRefreshAutoConfigurationThenOutcomeShouldMatch() {
    this.context.register(OnRefreshScopeConfig.class, RefreshAutoConfiguration.class);
    this.context.refresh();

    assertThat(this.context.getBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class)).isNotNull();
    assertThat(this.context.containsBean("foo")).isTrue();
}
 
Example #6
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReregisterHealthCheckHandlerAfterRefresh() throws Exception {
	TestPropertyValues.of("eureka.client.healthcheck.enabled=true")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class,
			AutoServiceRegistrationConfiguration.class);

	EurekaClient oldEurekaClient = getLazyInitEurekaClient();

	HealthCheckHandler healthCheckHandler = this.context
			.getBean("eurekaHealthCheckHandler", HealthCheckHandler.class);

	assertThat(healthCheckHandler).isInstanceOf(EurekaHealthCheckHandler.class);
	assertThat(oldEurekaClient.getHealthCheckHandler()).isSameAs(healthCheckHandler);

	ContextRefresher refresher = this.context.getBean("contextRefresher",
			ContextRefresher.class);
	refresher.refresh();

	EurekaClient newEurekaClient = getLazyInitEurekaClient();
	HealthCheckHandler newHealthCheckHandler = this.context
			.getBean("eurekaHealthCheckHandler", HealthCheckHandler.class);

	assertThat(healthCheckHandler).isSameAs(newHealthCheckHandler);
	assertThat(oldEurekaClient).isNotSameAs(newEurekaClient);
	assertThat(newEurekaClient.getHealthCheckHandler()).isSameAs(healthCheckHandler);
}
 
Example #7
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void refreshScopedBeans() {
	setupContext(RefreshAutoConfiguration.class);
	assertThat(this.context.getBeanDefinition("eurekaClient").getBeanClassName())
			.startsWith(
					GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
	assertThat(this.context.getBeanDefinition("eurekaApplicationInfoManager")
			.getBeanClassName()).startsWith(
					GenericScope.class.getName() + "$LockedScopedProxyFactoryBean");
}
 
Example #8
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void hostname() {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999",
			"eureka.instance.hostname=foo").applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().contains("foo"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #9
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void healthCheckUrlPathAndManagementPortUpperCase() {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999")
			.applyTo(this.context);
	addSystemEnvironment(this.context.getEnvironment(),
			"EUREKA_INSTANCE_HEALTH_CHECK_URL_PATH=/myHealthCheck");
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getHealthCheckUrl().contains("/myHealthCheck"))
			.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
}
 
Example #10
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrlPathAndManagementPortUpperCase() {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999")
			.applyTo(this.context);
	addSystemEnvironment(this.context.getEnvironment(),
			"EUREKA_INSTANCE_STATUS_PAGE_URL_PATH=/myStatusPage");
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().contains("/myStatusPage"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #11
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void healthCheckUrlPathAndManagementPortKabobCase() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"eureka.instance.health-check-url-path=/myHealthCheck")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getHealthCheckUrl().contains("/myHealthCheck"))
			.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
}
 
Example #12
Source File: BusAutoConfigurationClassPathTests.java    From spring-cloud-bus with Apache License 2.0 5 votes vote down vote up
@Test
public void refreshListenerCreatedWithoutActuator() {
	new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class,
					ServiceMatcherAutoConfiguration.class,
					BusRefreshAutoConfiguration.class))
			.run(context -> assertThat(context).hasSingleBean(RefreshListener.class)
					.doesNotHaveBean(RefreshBusEndpoint.class));
}
 
Example #13
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrlAndPreferIpAddress() {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999",
			"eureka.instance.hostname=foo", "eureka.instance.prefer-ip-address:true")
			.applyTo(this.context);

	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);

	assertThat(instance.getStatusPageUrl()).as("statusPageUrl is wrong")
			.isEqualTo("http://" + instance.getIpAddress() + ":9999/actuator/info");
	assertThat(instance.getHealthCheckUrl()).as("healthCheckUrl is wrong")
			.isEqualTo("http://" + instance.getIpAddress() + ":9999/actuator/health");
}
 
Example #14
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrlPathAndManagementPortKabobCase() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"eureka.instance.status-page-url-path=/myStatusPage")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().contains("/myStatusPage"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #15
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
	TestPropertyValues.of("server.port=8989",
			"server.servlet.context-path=/servletContextPath",
			"eureka.instance.health-check-url-path=${server.servlet.context-path:}/myHealthCheck")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getHealthCheckUrl())
			.as("Wrong health check: " + instance.getHealthCheckUrl())
			.endsWith(":8989/servletContextPath/myHealthCheck");
}
 
Example #16
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void healthCheckUrlPathAndManagementPortAndContextPathKebobCase() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"management.server.servlet.context-path=/manage",
					"eureka.instance.health-check-url-path=/myHealthCheck")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getHealthCheckUrl().endsWith(":9999/manage/myHealthCheck"))
			.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
}
 
Example #17
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrlPathAndManagementPortAndContextPathKebobCase() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"management.server.servlet.context-path=/manage",
					"eureka.instance.status-page-url-path=/myStatusPage")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().endsWith(":9999/manage/myStatusPage"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #18
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void healthCheckUrlPathAndManagementPortAndContextPath() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"management.server.servlet.context-path=/manage",
					"eureka.instance.health-check-url-path=/myHealthCheck")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getHealthCheckUrl().endsWith(":9999/manage/myHealthCheck"))
			.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
}
 
Example #19
Source File: RefreshScopeConfigurationTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
/**
 * See gh-43
 */
@Test
public void configurationWithRefreshScope() throws Exception {
	this.context = new AnnotationConfigApplicationContext(Application.class,
			PropertyPlaceholderAutoConfiguration.class,
			RefreshAutoConfiguration.class,
			LifecycleMvcEndpointAutoConfiguration.class);
	Application application = this.context.getBean(Application.class);
	then(this.context.getBeanDefinition("scopedTarget.application").getScope())
			.isEqualTo("refresh");
	application.hello();
	refresh();
	String message = application.hello();
	then(message).isEqualTo("Hello Dave!");
}
 
Example #20
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port()
		throws Exception {
	TestPropertyValues
			.of("server.port=0", "management.server.servlet.context-path=/management")
			.applyTo(this.context);

	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrlPath().equals("/management/actuator/info"))
			.as("Wrong status page: " + instance.getStatusPageUrlPath()).isTrue();
	assertThat(instance.getHealthCheckUrlPath().equals("/management/actuator/health"))
			.as("Wrong health check: " + instance.getHealthCheckUrlPath()).isTrue();
}
 
Example #21
Source File: ConditionalOnMissingRefreshScopeTest.java    From memcached-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void whenHavingRefreshAutoConfigurationThenOutcomeShouldNotMatch() {
    this.context.register(OnMissingRefreshScopeConfig.class, RefreshAutoConfiguration.class);
    this.context.refresh();

    assertThat(this.context.getBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class)).isNotNull();
    assertThat(this.context.containsBean("foo")).isFalse();
}
 
Example #22
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path()
		throws Exception {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999",
			"server.contextPath=/service").applyTo(this.context);

	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().endsWith(":9999/actuator/info"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
	assertThat(instance.getHealthCheckUrl().endsWith(":9999/actuator/health"))
			.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
}
 
Example #23
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void healthCheckUrlPathAndManagementPort() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"eureka.instance.healthCheckUrlPath=/myHealthCheck")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getHealthCheckUrl().contains("/myHealthCheck"))
			.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
}
 
Example #24
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void statusPageUrlPathAndManagementPort() {
	TestPropertyValues
			.of("server.port=8989", "management.server.port=9999",
					"eureka.instance.statusPageUrlPath=/myStatusPage")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().contains("/myStatusPage"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #25
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void managementPort() {
	TestPropertyValues.of("server.port=8989", "management.server.port=9999")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);
	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getStatusPageUrl().contains("9999"))
			.as("Wrong status page: " + instance.getStatusPageUrl()).isTrue();
}
 
Example #26
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotResetManagementAndJmxPortsInMetadataMap() throws Exception {
	TestPropertyValues
			.of("management.server.port=9999",
					"eureka.instance.metadata-map.jmx.port=9898",
					"eureka.instance.metadata-map.management.port=7878")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);

	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getMetadataMap().get("management.port")).isEqualTo("7878");
	assertThat(instance.getMetadataMap().get("jmx.port")).isEqualTo("9898");
}
 
Example #27
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
	TestPropertyValues.of("management.server.port=9999",
			"com.sun.management.jmxremote.port=6789").applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);

	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);
	assertThat(instance.getMetadataMap().get("management.port")).isEqualTo("9999");
	assertThat(instance.getMetadataMap().get("jmx.port")).isEqualTo("6789");
}
 
Example #28
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
	TestPropertyValues.of("server.port=8989", "management.server.port=0")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);

	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);

	assertThat(instance.getMetadataMap().get("management.port")).isEqualTo(null);
	assertThat(instance.getMetadataMap().get("jmx.port")).isEqualTo(null);
}
 
Example #29
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetManagementPortInMetadataMapIfEqualToServerPort()
		throws Exception {
	TestPropertyValues.of("server.port=8989").applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class);

	EurekaInstanceConfigBean instance = this.context
			.getBean(EurekaInstanceConfigBean.class);

	assertThat(instance.getMetadataMap().get("management.port")).isEqualTo("8989");
}
 
Example #30
Source File: ConditionalOnRefreshScopeTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void refreshScopeIncludedAndPropertyDisabled() {
	new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
			.withPropertyValues("eureka.client.refresh.enable=false")
			.withUserConfiguration(Beans.class).run(c -> {
				assertThat(c).hasSingleBean(
						org.springframework.cloud.context.scope.refresh.RefreshScope.class);
				assertThat(c).doesNotHaveBean("foo");
				assertThat(c.getBean("bar")).isEqualTo("bar");
			});
}