Removes unused TurbinePortApplicationListener.

parent 97eea5bd
package org.springframework.cloud.netflix.turbine.stream;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.MapPropertySource;
public class TurbinePortApplicationListener implements
ApplicationListener<ApplicationEnvironmentPreparedEvent> {
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
Integer serverPort = event.getEnvironment().getProperty("server.port",
Integer.class);
Integer managementPort = event.getEnvironment().getProperty("management.port",
Integer.class);
Integer turbinePort = event.getEnvironment().getProperty("turbine.stream.port",
Integer.class);
if (serverPort == null && managementPort == null) {
return;
}
if (serverPort != Integer.valueOf(-1)) {
Map<String, Object> ports = new HashMap<>();
if (turbinePort == null) {
// The actual server.port used by the application forced to be -1 (no user
// endpoints) because no value was provided for turbine
ports.put("server.port", -1);
if (serverPort != null) {
// Turbine port defaults to server port value supplied by user
ports.put("turbine.stream.port", serverPort);
}
}
else if (managementPort != null && managementPort != -1 && serverPort == null) {
// User wants 2 ports, but hasn't specified server.port explicitly
ports.put("server.port", managementPort);
}
event.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("ports", ports));
}
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.netflix.turbine.stream.TurbineStreamAutoConfiguration
#org.springframework.context.ApplicationListener=\
#org.springframework.cloud.netflix.turbine.stream.TurbinePortApplicationListener
\ No newline at end of file
package org.springframework.cloud.netflix.turbine.stream;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
public class TurbinePortApplicationListenerTests {
private TurbinePortApplicationListener listener = new TurbinePortApplicationListener();
private ConfigurableEnvironment environment = new StandardEnvironment();
private ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(new SpringApplication(), null, environment);
@Test
public void noop() {
listener.onApplicationEvent(event);
}
@Test
public void serverPortOnly() {
EnvironmentTestUtils.addEnvironment(environment, "server.port=9999");
listener.onApplicationEvent(event);
assertEquals("-1", environment.resolvePlaceholders("${server.port}"));
assertEquals("9999", environment.resolvePlaceholders("${turbine.stream.port}"));
}
@Test
public void turbinePortOnly() {
EnvironmentTestUtils.addEnvironment(environment, "turbine.stream.port=9999");
listener.onApplicationEvent(event);
assertEquals("9999", environment.resolvePlaceholders("${turbine.stream.port}"));
assertEquals("0", environment.resolvePlaceholders("${server.port:0}"));
}
@Test
public void turbineAndManagementPorts() {
EnvironmentTestUtils.addEnvironment(environment, "turbine.stream.port=9999", "management.port=9000");
listener.onApplicationEvent(event);
assertEquals("9999", environment.resolvePlaceholders("${turbine.stream.port}"));
assertEquals("9000", environment.resolvePlaceholders("${server.port:0}"));
assertEquals("9000", environment.resolvePlaceholders("${management.port:0}"));
}
@Test
public void turbineAndServerPorts() {
EnvironmentTestUtils.addEnvironment(environment, "turbine.stream.port=9999", "server.port=9000");
listener.onApplicationEvent(event);
assertEquals("9999", environment.resolvePlaceholders("${turbine.stream.port}"));
assertEquals("9000", environment.resolvePlaceholders("${server.port:0}"));
assertEquals("0", environment.resolvePlaceholders("${management.port:0}"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment