Search in sources :

Example 1 with EurekaTransportConfig

use of com.netflix.discovery.shared.transport.EurekaTransportConfig in project eureka by Netflix.

the class ResolverUtilsTest method testInstanceInfoToEndpoint.

@Test
public void testInstanceInfoToEndpoint() throws Exception {
    EurekaClientConfig clientConfig = mock(EurekaClientConfig.class);
    when(clientConfig.getEurekaServerURLContext()).thenReturn("/eureka");
    when(clientConfig.getRegion()).thenReturn("region");
    EurekaTransportConfig transportConfig = mock(EurekaTransportConfig.class);
    when(transportConfig.applicationsResolverUseIp()).thenReturn(false);
    AmazonInfo amazonInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, "us-east-1c").build();
    InstanceInfo instanceWithAWSInfo = InstanceInfo.Builder.newBuilder().setAppName("appName").setHostName("hostName").setPort(8080).setDataCenterInfo(amazonInfo).build();
    AwsEndpoint awsEndpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceWithAWSInfo);
    assertEquals("zone not equals.", "us-east-1c", awsEndpoint.getZone());
    MyDataCenterInfo myDataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
    InstanceInfo instanceWithMyDataInfo = InstanceInfo.Builder.newBuilder().setAppName("appName").setHostName("hostName").setPort(8080).setDataCenterInfo(myDataCenterInfo).add("zone", "us-east-1c").build();
    awsEndpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceWithMyDataInfo);
    assertEquals("zone not equals.", "us-east-1c", awsEndpoint.getZone());
}
Also used : MyDataCenterInfo(com.netflix.appinfo.MyDataCenterInfo) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) AwsEndpoint(com.netflix.discovery.shared.resolver.aws.AwsEndpoint) EurekaTransportConfig(com.netflix.discovery.shared.transport.EurekaTransportConfig) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 2 with EurekaTransportConfig

use of com.netflix.discovery.shared.transport.EurekaTransportConfig in project eureka by Netflix.

the class StatusUtilTest method getStatusUtil.

/**
 * @param replicas the number of replicas to mock
 * @param instances the number of instances to mock
 * @param minimum the minimum number of peers
 * @return the status utility with the mocked replicas/instances
 */
private StatusUtil getStatusUtil(int replicas, int instances, int minimum) {
    EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
    List<InstanceInfo> mockInstanceInfos = getMockInstanceInfos(instances);
    Application mockApplication = mock(Application.class);
    when(mockApplication.getInstances()).thenReturn(mockInstanceInfos);
    ApplicationInfoManager mockAppInfoManager = mock(ApplicationInfoManager.class);
    when(mockAppInfoManager.getInfo()).thenReturn(mockInstanceInfos.get(0));
    when(mockEurekaServerContext.getApplicationInfoManager()).thenReturn(mockAppInfoManager);
    PeerAwareInstanceRegistry mockRegistry = mock(PeerAwareInstanceRegistry.class);
    when(mockRegistry.getApplication("stuff", false)).thenReturn(mockApplication);
    when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
    List<PeerEurekaNode> mockNodes = getMockNodes(replicas);
    EurekaTransportConfig mockTransportConfig = mock(EurekaTransportConfig.class);
    when(mockTransportConfig.applicationsResolverUseIp()).thenReturn(false);
    EurekaClientConfig mockClientConfig = mock(EurekaClientConfig.class);
    when(mockClientConfig.getTransportConfig()).thenReturn(mockTransportConfig);
    EurekaServerConfig mockServerConfig = mock(EurekaServerConfig.class);
    when(mockServerConfig.getHealthStatusMinNumberOfAvailablePeers()).thenReturn(minimum);
    PeerEurekaNodes peerEurekaNodes = new PeerEurekaNodes(mockRegistry, mockServerConfig, mockClientConfig, null, mockAppInfoManager);
    PeerEurekaNodes spyPeerEurekaNodes = spy(peerEurekaNodes);
    when(spyPeerEurekaNodes.getPeerEurekaNodes()).thenReturn(mockNodes);
    when(mockEurekaServerContext.getPeerEurekaNodes()).thenReturn(spyPeerEurekaNodes);
    return new StatusUtil(mockEurekaServerContext);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) InstanceInfo(com.netflix.appinfo.InstanceInfo) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) EurekaServerContext(com.netflix.eureka.EurekaServerContext) PeerEurekaNode(com.netflix.eureka.cluster.PeerEurekaNode) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) EurekaTransportConfig(com.netflix.discovery.shared.transport.EurekaTransportConfig) Application(com.netflix.discovery.shared.Application) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Aggregations

InstanceInfo (com.netflix.appinfo.InstanceInfo)2 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)2 EurekaTransportConfig (com.netflix.discovery.shared.transport.EurekaTransportConfig)2 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1 MyDataCenterInfo (com.netflix.appinfo.MyDataCenterInfo)1 Application (com.netflix.discovery.shared.Application)1 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)1 EurekaServerConfig (com.netflix.eureka.EurekaServerConfig)1 EurekaServerContext (com.netflix.eureka.EurekaServerContext)1 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)1 PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)1 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)1 Test (org.junit.Test)1