Esempio n. 1
0
        public async Task Catalog_RegistrationDeregistration()
        {
            var svcID   = KVTest.GenerateTestKeyName();
            var service = new AgentService
            {
                ID      = svcID,
                Service = "redis",
                Tags    = new[] { "master", "v1" },
                Port    = 8000
            };

            var check = new AgentCheck
            {
                Node      = "foobar",
                CheckID   = "service:" + svcID,
                Name      = "Redis health check",
                Notes     = "Script based health check",
                Status    = HealthStatus.Passing,
                ServiceID = svcID
            };

            var registration = new CatalogRegistration
            {
                Datacenter = "dc1",
                Node       = "foobar",
                Address    = "192.168.10.10",
                Service    = service,
                Check      = check
            };

            await _client.Catalog.Register(registration);

            var node = await _client.Catalog.Node("foobar");

            Assert.True(node.Response.Services.ContainsKey(svcID));

            var health = await _client.Health.Node("foobar");

            Assert.Equal("service:" + svcID, health.Response[0].CheckID);

            var dereg = new CatalogDeregistration
            {
                Datacenter = "dc1",
                Node       = "foobar",
                Address    = "192.168.10.10",
                CheckID    = "service:" + svcID
            };

            await _client.Catalog.Deregister(dereg);

            health = await _client.Health.Node("foobar");

            Assert.Empty(health.Response);

            dereg = new CatalogDeregistration
            {
                Datacenter = "dc1",
                Node       = "foobar",
                Address    = "192.168.10.10"
            };

            await _client.Catalog.Deregister(dereg);

            node = await _client.Catalog.Node("foobar");

            Assert.Null(node.Response);
        }
Esempio n. 2
0
        public void Catalog_RegistrationDeregistration()
        {
            var c = ClientTest.MakeClient();
            var service = new AgentService()
            {
                ID = "redis1",
                Service = "redis",
                Tags = new[] {"master", "v1"},
                Port = 8000
            };

            var check = new AgentCheck()
            {
                Node = "foobar",
                CheckID = "service:redis1",
                Name = "Redis health check",
                Notes = "Script based health check",
                Status = CheckStatus.Passing,
                ServiceID = "redis1"
            };

            var reg = new CatalogRegistration()
            {
                Datacenter = "dc1",
                Node = "foobar",
                Address = "192.168.10.10",
                Service = service,
                Check = check
            };

            c.Catalog.Register(reg);

            var node = c.Catalog.Node("foobar");
            Assert.IsTrue(node.Response.Services.ContainsKey("redis1"));

            var health = c.Health.Node("foobar");
            Assert.AreEqual("service:redis1", health.Response[0].CheckID);

            var dereg = new CatalogDeregistration()
            {
                Datacenter = "dc1",
                Node = "foobar",
                Address = "192.168.10.10",
                CheckID = "service:redis1"
            };

            c.Catalog.Deregister(dereg);

            health = c.Health.Node("foobar");
            Assert.AreEqual(0, health.Response.Length);

            dereg = new CatalogDeregistration()
            {
                Datacenter = "dc1",
                Node = "foobar",
                Address = "192.168.10.10"
            };

            c.Catalog.Deregister(dereg);

            node = c.Catalog.Node("foobar");
            Assert.IsNull(node.Response);
        }
Esempio n. 3
0
        public async Task Catalog_RegistrationDeregistration()
        {
            var client  = new ConsulClient();
            var service = new AgentService()
            {
                ID      = "redis1",
                Service = "redis",
                Tags    = new[] { "master", "v1" },
                Port    = 8000
            };

            var check = new AgentCheck()
            {
                Node      = "foobar",
                CheckID   = "service:redis1",
                Name      = "Redis health check",
                Notes     = "Script based health check",
                Status    = CheckStatus.Passing,
                ServiceID = "redis1"
            };

            var registration = new CatalogRegistration()
            {
                Datacenter = "dc1",
                Node       = "foobar",
                Address    = "192.168.10.10",
                Service    = service,
                Check      = check
            };

            await client.Catalog.Register(registration);

            var node = await client.Catalog.Node("foobar");

            Assert.True(node.Response.Services.ContainsKey("redis1"));

            var health = await client.Health.Node("foobar");

            Assert.Equal("service:redis1", health.Response[0].CheckID);

            var dereg = new CatalogDeregistration()
            {
                Datacenter = "dc1",
                Node       = "foobar",
                Address    = "192.168.10.10",
                CheckID    = "service:redis1"
            };

            await client.Catalog.Deregister(dereg);

            health = await client.Health.Node("foobar");

            Assert.Equal(0, health.Response.Length);

            dereg = new CatalogDeregistration()
            {
                Datacenter = "dc1",
                Node       = "foobar",
                Address    = "192.168.10.10"
            };

            await client.Catalog.Deregister(dereg);

            node = await client.Catalog.Node("foobar");

            Assert.Null(node.Response);
        }