Search in sources :

Example 1 with MyDataCenterInfo

use of com.netflix.appinfo.MyDataCenterInfo in project spring-cloud-netflix by spring-cloud.

the class EurekaControllerTests method setup.

@Before
public void setup() throws Exception {
    PeerEurekaNodes peerEurekaNodes = mock(PeerEurekaNodes.class);
    when(peerEurekaNodes.getPeerNodesView()).thenReturn(Collections.<PeerEurekaNode>emptyList());
    InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test").setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).build();
    this.infoManager = mock(ApplicationInfoManager.class);
    this.original = ApplicationInfoManager.getInstance();
    setInstance(this.infoManager);
    when(this.infoManager.getInfo()).thenReturn(instanceInfo);
    Application myapp = new Application("myapp");
    myapp.addInstance(InstanceInfo.Builder.newBuilder().setAppName("myapp").setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).setInstanceId("myapp:1").build());
    ArrayList<Application> applications = new ArrayList<>();
    applications.add(myapp);
    PeerAwareInstanceRegistry registry = mock(PeerAwareInstanceRegistry.class);
    when(registry.getSortedApplications()).thenReturn(applications);
    EurekaServerContext serverContext = mock(EurekaServerContext.class);
    EurekaServerContextHolder.initialize(serverContext);
    when(serverContext.getRegistry()).thenReturn(registry);
    when(serverContext.getPeerEurekaNodes()).thenReturn(peerEurekaNodes);
    when(serverContext.getApplicationInfoManager()).thenReturn(this.infoManager);
}
Also used : MyDataCenterInfo(com.netflix.appinfo.MyDataCenterInfo) EurekaServerContext(com.netflix.eureka.EurekaServerContext) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(com.netflix.discovery.shared.Application) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) Before(org.junit.Before)

Example 2 with MyDataCenterInfo

use of com.netflix.appinfo.MyDataCenterInfo 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 3 with MyDataCenterInfo

use of com.netflix.appinfo.MyDataCenterInfo in project eureka by Netflix.

the class EurekaCodecCompatibilityTest method testInstanceInfoFullEncodeMiniDecodeJacksonWithMyOwnDataCenterInfo.

@Test
public void testInstanceInfoFullEncodeMiniDecodeJacksonWithMyOwnDataCenterInfo() throws Exception {
    final InstanceInfo base = infoIterator.next();
    final InstanceInfo instanceInfo = new InstanceInfo.Builder(base).setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).build();
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedValue), is(true));
        }
    };
    verifyForPair(codingAction, InstanceInfo.class, new CodecWrappers.JacksonJson(), new CodecWrappers.JacksonJsonMini());
}
Also used : MyDataCenterInfo(com.netflix.appinfo.MyDataCenterInfo) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 4 with MyDataCenterInfo

use of com.netflix.appinfo.MyDataCenterInfo in project ribbon by Netflix.

the class LoadBalancerTestUtils method getDummyInstanceInfo.

static List<InstanceInfo> getDummyInstanceInfo(String appName, String host, String ipAddr, int port) {
    List<InstanceInfo> list = new ArrayList<InstanceInfo>();
    InstanceInfo info = InstanceInfo.Builder.newBuilder().setAppName(appName).setHostName(host).setIPAddr(ipAddr).setPort(port).setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).build();
    list.add(info);
    return list;
}
Also used : MyDataCenterInfo(com.netflix.appinfo.MyDataCenterInfo) ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 5 with MyDataCenterInfo

use of com.netflix.appinfo.MyDataCenterInfo in project eureka by Netflix.

the class ConfigClusterResolverTest method setUp.

@Before
public void setUp() {
    when(clientConfig.shouldUseDnsForFetchingServiceUrls()).thenReturn(false);
    when(clientConfig.getRegion()).thenReturn("us-east-1");
    when(clientConfig.getAvailabilityZones("us-east-1")).thenReturn(new String[] { "us-east-1c", "us-east-1d", "us-east-1e" });
    when(clientConfig.getEurekaServerServiceUrls("us-east-1c")).thenReturn(endpointsC);
    when(clientConfig.getEurekaServerServiceUrls("us-east-1d")).thenReturn(endpointsD);
    when(clientConfig.getEurekaServerServiceUrls("us-east-1e")).thenReturn(endpointsWithBasicAuth);
    InstanceInfo instanceInfo = new InstanceInfo.Builder(InstanceInfoGenerator.takeOne()).setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).build();
    resolver = new ConfigClusterResolver(clientConfig, instanceInfo);
}
Also used : MyDataCenterInfo(com.netflix.appinfo.MyDataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Aggregations

InstanceInfo (com.netflix.appinfo.InstanceInfo)6 MyDataCenterInfo (com.netflix.appinfo.MyDataCenterInfo)6 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)2 Test (org.junit.Test)2 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)1 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)1 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)1 Application (com.netflix.discovery.shared.Application)1 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)1 EurekaTransportConfig (com.netflix.discovery.shared.transport.EurekaTransportConfig)1 EurekaServerContext (com.netflix.eureka.EurekaServerContext)1 PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)1 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)1 Server (com.netflix.loadbalancer.Server)1