Beispiel #1
0
        private void GivenThereIsAFakeEurekaServiceDiscoveryProvider(string url, string serviceName)
        {
            _serviceHandler.GivenThereIsAServiceRunningOn(url, async context =>
            {
                if (context.Request.Path.Value == "/eureka/apps/")
                {
                    var apps = new List <Application>();

                    foreach (var serviceInstance in _eurekaInstances)
                    {
                        var a = new Application
                        {
                            name     = serviceName,
                            instance = new List <Instance>
                            {
                                new Instance
                                {
                                    instanceId       = $"{serviceInstance.Host}:{serviceInstance}",
                                    hostName         = serviceInstance.Host,
                                    app              = serviceName,
                                    ipAddr           = "127.0.0.1",
                                    status           = "UP",
                                    overriddenstatus = "UNKNOWN",
                                    port             = new Port {
                                        value = serviceInstance.Port, enabled = "true"
                                    },
                                    securePort = new SecurePort {
                                        value = serviceInstance.Port, enabled = "true"
                                    },
                                    countryId      = 1,
                                    dataCenterInfo = new DataCenterInfo {
                                        value = "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo", name = "MyOwn"
                                    },
                                    leaseInfo = new LeaseInfo
                                    {
                                        renewalIntervalInSecs = 30,
                                        durationInSecs        = 90,
                                        registrationTimestamp = 1457714988223,
                                        lastRenewalTimestamp  = 1457716158319,
                                        evictionTimestamp     = 0,
                                        serviceUpTimestamp    = 1457714988223,
                                    },
                                    metadata = new Metadata
                                    {
                                        value = "java.util.Collections$EmptyMap",
                                    },
                                    homePageUrl    = $"{serviceInstance.Host}:{serviceInstance.Port}",
                                    statusPageUrl  = $"{serviceInstance.Host}:{serviceInstance.Port}",
                                    healthCheckUrl = $"{serviceInstance.Host}:{serviceInstance.Port}",
                                    vipAddress     = serviceName,
                                    isCoordinatingDiscoveryServer = "false",
                                    lastUpdatedTimestamp          = "1457714988223",
                                    lastDirtyTimestamp            = "1457714988172",
                                    actionType = "ADDED",
                                },
                            },
                        };

                        apps.Add(a);
                    }

                    var applications = new EurekaApplications
                    {
                        applications = new Applications
                        {
                            application     = apps,
                            apps__hashcode  = "UP_1_",
                            versions__delta = "1",
                        },
                    };

                    var json = JsonConvert.SerializeObject(applications);
                    context.Response.Headers.Add("Content-Type", "application/json");
                    await context.Response.WriteAsync(json);
                }
            });
        }
Beispiel #2
0
        private void GivenThereIsAFakeEurekaServiceDiscoveryProvider(string url, string serviceName)
        {
            _fakeConsulBuilder = new WebHostBuilder()
                                 .UseUrls(url)
                                 .UseKestrel()
                                 .UseContentRoot(Directory.GetCurrentDirectory())
                                 .UseIISIntegration()
                                 .UseUrls(url)
                                 .Configure(app =>
            {
                app.Run(async context =>
                {
                    if (context.Request.Path.Value == "/eureka/apps/")
                    {
                        var apps = new List <Application>();

                        foreach (var serviceInstance in _eurekaInstances)
                        {
                            var a = new Application
                            {
                                name     = serviceName,
                                instance = new List <Instance>
                                {
                                    new Instance
                                    {
                                        instanceId       = $"{serviceInstance.Host}:{serviceInstance}",
                                        hostName         = serviceInstance.Host,
                                        app              = serviceName,
                                        ipAddr           = "127.0.0.1",
                                        status           = "UP",
                                        overriddenstatus = "UNKNOWN",
                                        port             = new Port {
                                            value = serviceInstance.Port, enabled = "true"
                                        },
                                        securePort = new SecurePort {
                                            value = serviceInstance.Port, enabled = "true"
                                        },
                                        countryId      = 1,
                                        dataCenterInfo = new DataCenterInfo {
                                            value = "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo", name = "MyOwn"
                                        },
                                        leaseInfo = new LeaseInfo
                                        {
                                            renewalIntervalInSecs = 30,
                                            durationInSecs        = 90,
                                            registrationTimestamp = 1457714988223,
                                            lastRenewalTimestamp  = 1457716158319,
                                            evictionTimestamp     = 0,
                                            serviceUpTimestamp    = 1457714988223
                                        },
                                        metadata = new Metadata
                                        {
                                            value = "java.util.Collections$EmptyMap"
                                        },
                                        homePageUrl    = $"{serviceInstance.Host}:{serviceInstance.Port}",
                                        statusPageUrl  = $"{serviceInstance.Host}:{serviceInstance.Port}",
                                        healthCheckUrl = $"{serviceInstance.Host}:{serviceInstance.Port}",
                                        vipAddress     = serviceName,
                                        isCoordinatingDiscoveryServer = "false",
                                        lastUpdatedTimestamp          = "1457714988223",
                                        lastDirtyTimestamp            = "1457714988172",
                                        actionType = "ADDED"
                                    }
                                }
                            };

                            apps.Add(a);
                        }

                        var applications = new EurekaApplications
                        {
                            applications = new Applications
                            {
                                application     = apps,
                                apps__hashcode  = "UP_1_",
                                versions__delta = "1"
                            }
                        };

                        await context.Response.WriteJsonAsync(applications);
                    }
                });
            })
                                 .Build();

            _fakeConsulBuilder.Start();
        }