use of com.netflix.eureka.cluster.PeerEurekaNode 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);
}
Aggregations