Java Code Examples for org.springframework.cloud.commons.util.InetUtilsProperties

The following examples show how to use org.springframework.cloud.commons.util.InetUtilsProperties. These examples are extracted from open source projects. 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
private SanitizingEurekaInstanceConfigBean getDefaults() {
	InetUtilsProperties inetUtilsProperties = new InetUtilsProperties();
	inetUtilsProperties.setDefaultHostname(hostname);
	inetUtilsProperties.setDefaultIpAddress(ip);

	SanitizingEurekaInstanceConfigBean eurekaInstanceConfigBean = new SanitizingEurekaInstanceConfigBean(new InetUtils(inetUtilsProperties));
	eurekaInstanceConfigBean.setHostname(hostname);
	eurekaInstanceConfigBean.setIpAddress(ip);
	Map<String, String> metadataMap = eurekaInstanceConfigBean.getMetadataMap();
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_APP_GUID, cfAppGuid);
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_INSTANCE_INDEX, cfInstanceIndex);
	metadataMap.put(INSTANCE_ID, instanceId);
	metadataMap.put(ZONE, zoneFromUri(zoneUri));

	return eurekaInstanceConfigBean;
}
 
Example 2
private SanitizingEurekaInstanceConfigBean getDefaults() {
	InetUtilsProperties inetUtilsProperties = new InetUtilsProperties();
	inetUtilsProperties.setDefaultHostname(hostname);
	inetUtilsProperties.setDefaultIpAddress(ip);

	SanitizingEurekaInstanceConfigBean eurekaInstanceConfigBean = new SanitizingEurekaInstanceConfigBean(
			new InetUtils(inetUtilsProperties));
	eurekaInstanceConfigBean.setHostname(hostname);
	eurekaInstanceConfigBean.setIpAddress(ip);
	Map<String, String> metadataMap = eurekaInstanceConfigBean.getMetadataMap();
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_APP_GUID, cfAppGuid);
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_INSTANCE_INDEX, cfInstanceIndex);
	metadataMap.put(INSTANCE_ID, instanceId);
	metadataMap.put(ZONE, zoneFromUri(zoneUri));

	return eurekaInstanceConfigBean;
}
 
Example 3
@Test
public void eurekaClientNotShutdownInDeregister() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
	ApplicationInfoManager applicationInfoManager = mock(
			ApplicationInfoManager.class);

	when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));

	EurekaRegistration registration = EurekaRegistration
			.builder(new EurekaInstanceConfigBean(
					new InetUtils(new InetUtilsProperties())))
			.with(eurekaClient).with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	registry.deregister(registration);

	verifyNoInteractions(eurekaClient);
}
 
Example 4
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
    InetUtilsProperties target = new InetUtilsProperties();
    ConfigurationPropertySources.attach(environment);
    Binder.get(environment).bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target));
    try (InetUtils utils = new InetUtils(target)) {
        return utils.findFirstNonLoopbackHostInfo();
    }
}
 
Example 5
@Test
public void should_escape_root() {
	// given:
	ZookeeperDiscoveryProperties zookeeperDiscoveryProperties = new ZookeeperDiscoveryProperties(
			new InetUtils(new InetUtilsProperties()));
	// when:
	zookeeperDiscoveryProperties.setRoot(root);
	// then:
	then(zookeeperDiscoveryProperties.getRoot()).isEqualTo("/es");
}
 
Example 6
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
	InetUtilsProperties target = new InetUtilsProperties();
	ConfigurationPropertySources.attach(environment);
	Binder.get(environment).bind(InetUtilsProperties.PREFIX,
			Bindable.ofInstance(target));
	try (InetUtils utils = new InetUtils(target)) {
		return utils.findFirstNonLoopbackHostInfo();
	}
}
 
Example 7
@Test
public void eurekaClientGetStatus() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(
			new InetUtils(new InetUtilsProperties()));
	config.setAppname("myapp");
	config.setInstanceId("1234");

	InstanceInfo local = InstanceInfo.Builder.newBuilder().setAppName("myapp")
			.setInstanceId("1234").setStatus(DOWN).build();

	InstanceInfo remote = InstanceInfo.Builder.newBuilder().setAppName("myapp")
			.setInstanceId("1234").setStatus(DOWN).setOverriddenStatus(OUT_OF_SERVICE)
			.build();

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
	when(eurekaClient.getInstanceInfo(local.getAppName(), local.getId()))
			.thenReturn(remote);

	ApplicationInfoManager applicationInfoManager = mock(
			ApplicationInfoManager.class);
	when(applicationInfoManager.getInfo()).thenReturn(local);

	EurekaRegistration registration = EurekaRegistration.builder(config)
			.with(eurekaClient).with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	Object status = registry.getStatus(registration);

	assertThat(registration.getInstanceId()).isEqualTo("1234");

	assertThat(status).isInstanceOf(Map.class);

	Map<Object, Object> map = (Map<Object, Object>) status;

	assertThat(map).hasSize(2).containsEntry("status", DOWN.toString())
			.containsEntry("overriddenStatus", OUT_OF_SERVICE.toString());
}
 
Example 8
@Test
public void eurekaClientGetStatusNoInstance() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(
			new InetUtils(new InetUtilsProperties()));
	config.setAppname("myapp");
	config.setInstanceId("1234");

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);

	when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(null);

	ApplicationInfoManager applicationInfoManager = mock(
			ApplicationInfoManager.class);
	when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));

	EurekaRegistration registration = EurekaRegistration.builder(config)
			.with(eurekaClient).with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	Object status = registry.getStatus(registration);

	assertThat(registration.getInstanceId()).isEqualTo("1234");

	assertThat(status).isInstanceOf(Map.class);

	Map<Object, Object> map = (Map<Object, Object>) status;

	assertThat(map).hasSize(1).containsEntry("status", UNKNOWN.toString());
}
 
Example 9
@Test
public void instanceIdIsHostNameByDefault() throws IOException {
	InstanceInfo instanceInfo = setupInstance();
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		assertThat(instanceInfo.getId())
				.isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
	}
}
 
Example 10
@Before
public void init() throws Exception {
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		InetUtils.HostInfo hostInfo = utils.findFirstNonLoopbackHostInfo();
		this.hostName = hostInfo.getHostname();
		this.ipAddress = hostInfo.getIpAddress();
	}
}
 
Example 11
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
	EurekaInstanceConfigBean configBean = new EurekaInstanceConfigBean(
			new InetUtils(new InetUtilsProperties()));
	String springAppName = this.env.getProperty("spring.application.name", "");
	if (StringUtils.hasText(springAppName)) {
		configBean.setSecureVirtualHostName(springAppName);
		configBean.setVirtualHostName(springAppName);
		configBean.setAppname(springAppName);
	}
	return configBean;
}
 
Example 12
@Before
public void setUp() {
	this.properties = new ConsulDiscoveryProperties(
			new InetUtils(new InetUtilsProperties()));
	this.properties.setDefaultQueryTag(DEFAULT_TAG);
	this.properties.setServerListQueryTags(this.serverListQueryTags);
	this.properties.setDatacenters(this.datacenters);
}
 
Example 13
private InetUtils localAddress(byte[] address) throws UnknownHostException {
	InetUtils mocked = Mockito.spy(new InetUtils(new InetUtilsProperties()));
	Mockito.when(mocked.findFirstNonLoopbackAddress())
			.thenReturn(InetAddress.getByAddress(address));
	return mocked;
}
 
Example 14
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
	return new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
}
 
Example 15
private InetUtils getInetUtils() {

			InetUtils.HostInfo hostInfo = new InetUtils(new InetUtilsProperties()).findFirstNonLoopbackHostInfo();

			InetUtils inetUtils = mock(InetUtils.class);
			when(inetUtils.findFirstNonLoopbackHostInfo()).thenReturn(hostInfo);

			return inetUtils;
		}
 
Example 16
private InetUtils getInetUtils() {

			InetUtils.HostInfo hostInfo = new InetUtils(new InetUtilsProperties()).findFirstNonLoopbackHostInfo();

			InetUtils inetUtils = mock(InetUtils.class);
			when(inetUtils.findFirstNonLoopbackHostInfo()).thenReturn(hostInfo);

			return inetUtils;
		}