|
|
@ -32,7 +32,6 @@ import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
|
|
|
|
import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
|
|
|
import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
|
|
|
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
|
|
|
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.test.annotation.DirtiesContext;
|
|
|
|
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -40,41 +39,45 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
* @author liujunjie
|
|
|
|
* @author liujunjie
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
|
@SpringBootTest(classes = NacosRibbonClientPropertyOverrideNIWSserverTests.TestConfiguration.class,
|
|
|
|
@SpringBootTest(classes =
|
|
|
|
properties = {"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848",
|
|
|
|
NacosRibbonClientPropertyOverrideTests.TestConfiguration.class,
|
|
|
|
"spring.cloud.nacos.discovery.port=18080",
|
|
|
|
properties = {"spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848",
|
|
|
|
"spring.cloud.nacos.discovery.service=remoteApp",
|
|
|
|
"spring.cloud.nacos.discovery.port=18080",
|
|
|
|
"localApp.ribbon.NIWSServerListClassName=com.netflix.loadbalancer.ConfigurationBasedServerList",
|
|
|
|
"spring.cloud.nacos.discovery.service=remoteApp",
|
|
|
|
"localApp.ribbon.listOfServers=127.0.0.1:19090",
|
|
|
|
"localApp.ribbon.NIWSServerListClassName="
|
|
|
|
"localApp.ribbon.ServerListRefreshInterval=15000"})
|
|
|
|
+ "com.netflix.loadbalancer.ConfigurationBasedServerList",
|
|
|
|
@DirtiesContext
|
|
|
|
"localApp.ribbon.listOfServers=127.0.0.1:19090",
|
|
|
|
public class NacosRibbonClientPropertyOverrideNIWSserverTests {
|
|
|
|
"localApp.ribbon.ServerListRefreshInterval=15000"})
|
|
|
|
|
|
|
|
public class NacosRibbonClientPropertyOverrideTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SpringClientFactory factory;
|
|
|
|
private SpringClientFactory factory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void serverListOverridesToTest() {
|
|
|
|
public void serverListOverridesToTest() {
|
|
|
|
ConfigurationBasedServerList.class
|
|
|
|
ConfigurationBasedServerList.class
|
|
|
|
.cast(getLoadBalancer("localApp").getServerListImpl());
|
|
|
|
.cast(getLoadBalancer("localApp").getServerListImpl());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void serverListRemoteTest(){
|
|
|
|
|
|
|
|
NacosServerList.class
|
|
|
|
|
|
|
|
.cast(getLoadBalancer("remoteApp").getServerListImpl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Test
|
|
|
|
private ZoneAwareLoadBalancer<Server> getLoadBalancer(String name) {
|
|
|
|
public void serverListRemoteTest() {
|
|
|
|
return (ZoneAwareLoadBalancer<Server>) this.factory.getLoadBalancer(name);
|
|
|
|
NacosServerList.class
|
|
|
|
}
|
|
|
|
.cast(getLoadBalancer("remoteApp").getServerListImpl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@RibbonClients
|
|
|
|
private ZoneAwareLoadBalancer<Server> getLoadBalancer(String name) {
|
|
|
|
@EnableAutoConfiguration
|
|
|
|
return (ZoneAwareLoadBalancer<Server>) this.factory.getLoadBalancer(name);
|
|
|
|
@ImportAutoConfiguration({UtilAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
}
|
|
|
|
ArchaiusAutoConfiguration.class, RibbonNacosAutoConfiguration.class, NacosDiscoveryClientConfiguration.class})
|
|
|
|
|
|
|
|
protected static class TestConfiguration {
|
|
|
|
@Configuration
|
|
|
|
}
|
|
|
|
@RibbonClients
|
|
|
|
|
|
|
|
@EnableAutoConfiguration
|
|
|
|
|
|
|
|
@ImportAutoConfiguration({UtilAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
|
|
|
|
ArchaiusAutoConfiguration.class, RibbonNacosAutoConfiguration.class,
|
|
|
|
|
|
|
|
NacosDiscoveryClientConfiguration.class})
|
|
|
|
|
|
|
|
protected static class TestConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|