Ejemplo n.º 1
0
        public async Task ExpectedValue_ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.CompareAndSwap.DefaultResponse)
                .RespondWithJson(Fixtures.CompareAndSwap.DefaultResponse);

                var req = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                          .Atomic.CompareAndSwap(Fixtures.CompareAndSwap.Path)
                          .WithExpectedValue(Fixtures.CompareAndSwap.ExpectedValue)
                          .WithNewValue(Fixtures.CompareAndSwap.NewValue);

                await req;
                await req.Execute();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.CompareAndSwap.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_PrevValue, Fixtures.CompareAndSwap.ExpectedValue)
                    )
                .WithVerb(HttpMethod.Put)
                .WithRequestBody(Fixtures.CompareAndSwap.DefaultRequest())
                .Times(2);
            }
        }
Ejemplo n.º 2
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWith(Fixtures.Statistics.SelfResponse);

                var response = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                               .Statistics
                               .GetServerStatistics();

                http.Should()
                .HaveCalled(Fixtures.EtcdUrl.AppendPathSegment(Constants.Etcd.Path_Stats_Self))
                .WithVerb(HttpMethod.Get)
                .Times(1);

                response.Should().NotBeNull();
                response.Id.Should().NotBeNullOrWhiteSpace();
                response.Name.Should().NotBeNullOrWhiteSpace();

                response.LeaderInfo.Should().NotBeNull();
                response.LeaderInfo.Leader.Should().Be("8a69d5f6b7814500");
                response.LeaderInfo.StartTime.Should().HaveValue().And.NotBe(default(DateTime));
                response.LeaderInfo.Uptime.Should().NotBeNullOrWhiteSpace();

                response.State.Should().Be(StateType.StateFollower);
            }
        }
Ejemplo n.º 3
0
        public async Task Upsert_ShouldHaveTheStringEncodedBodyWhenUsingTheStringValueConverter()
        {
            const long dto      = 389L;
            var        expected = Convert.ToString(dto);

            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                var client = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri());
                client.Configure(x => x.ValueConverter = Converters.String);

                await client
                .UpsertKey(Fixtures.Key.Path)
                .WithValue(dto);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                .WithVerb(HttpMethod.Put)
                .WithRequestBody(Fixtures.Key.DefaultRequest(expected))
                .Times(1);
            }
        }
Ejemplo n.º 4
0
        public async Task Create_ShouldCallTheCorrectUrlWithTimeToLiveOption()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Directory.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .CreateDirectory(Fixtures.Directory.Path)
                .WithTimeToLive(Fixtures.Directory.DefaultTtl);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Directory.Path)
                    )
                .WithVerb(HttpMethod.Put)
                .WithRequestBody(
                    Fixtures.Directory.DefaultRequest
                    .Add(Constants.Etcd.Parameter_Ttl, Fixtures.Directory.DefaultTtl)
                    .AsRequestBody()
                    )
                .Times(1);
            }
        }
Ejemplo n.º 5
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.CreateResponse(Fixtures.EtcdUrl.ToUri()));

                var member = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                             .Cluster
                             .CreateMember()
                             .WithPeerUri(Fixtures.EtcdUrl.ToUri());

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Members)
                    )
                .WithVerb(HttpMethod.Post)
                .WithContentType(Constants.Http.ContentType_ApplicationJson)
                .Times(1);

                member.Should().NotBeNull();

                member.PeerUrls.Should()
                .NotBeEmpty()
                .And
                .ContainSingle(x => Fixtures.EtcdUrl.ToUri().Equals(x));
            }
        }
Ejemplo n.º 6
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWith(Fixtures.Statistics.LeaderResponse);

                var response = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                               .Statistics
                               .GetLeaderStatistics();

                http.Should()
                .HaveCalled(Fixtures.EtcdUrl.AppendPathSegment(Constants.Etcd.Path_Stats_Leader))
                .WithVerb(HttpMethod.Get)
                .Times(1);

                response.Should().NotBeNull();

                response.Leader.Should().NotBeNullOrWhiteSpace();
                response.Followers.Should().NotBeNull()
                .And.HaveCount(2);
                response.Followers.Keys.OrderBy(x => x).Should()
                .HaveCount(2)
                .And.ContainInOrder("6e3bd23ae5f1eae0", "a8266ecf031671f3");
            }
        }
Ejemplo n.º 7
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.ClusterMemberResponse(new[] { Fixtures.EtcdUrl.ToUri() }, new[] { Fixtures.EtcdUrl.ToUri() }));

                var leader = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                             .Cluster
                             .GetLeader();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Members_Leader)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);

                leader.Should().NotBeNull();

                leader.PeerUrls.Should()
                .NotBeEmpty()
                .And
                .ContainSingle(x => Fixtures.EtcdUrl.ToUri().Equals(x));

                leader.ClientUrls.Should()
                .NotBeEmpty()
                .And
                .ContainSingle(x => Fixtures.EtcdUrl.ToUri().Equals(x));
            }
        }
Ejemplo n.º 8
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWith(Fixtures.Statistics.StoreResponse);

                var response = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                               .Statistics
                               .GetStoreStatistics();

                http.Should()
                .HaveCalled(Fixtures.EtcdUrl.AppendPathSegment(Constants.Etcd.Path_Stats_Store))
                .WithVerb(HttpMethod.Get)
                .Times(1);

                response.Should().NotBeNull();
                response.CreateSuccess.Should().Be(2);
                response.GetsFail.Should().Be(4);
                response.GetsSuccess.Should().Be(75);
                response.SetsFail.Should().Be(2);
                response.SetsSuccess.Should().Be(4);
                response.CompareAndDeleteFail.Should().Be(0);
                response.CompareAndDeleteSuccess.Should().Be(0);
                response.CompareAndSwapFail.Should().Be(0);
                response.CompareAndSwapSuccess.Should().Be(0);
                response.DeleteSuccess.Should().Be(0);
                response.DeleteFail.Should().Be(0);
                response.ExpireCount.Should().Be(0);
                response.Watchers.Should().Be(0);
            }
        }
Ejemplo n.º 9
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(
                    Fixtures.Cluster.ClusterMembersResponse(
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse(),
                        Fixtures.Cluster.ClusterMemberResponse()
                        ));

                var members = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                              .Cluster
                              .GetMembers();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Members)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);

                members.Should().NotBeNull()
                .And
                .HaveCount(5);
            }
        }
Ejemplo n.º 10
0
        public void Watch_ShouldRetryOnTimeoutException()
        {
            using (var http = new HttpTest())
            {
                http.SimulateTimeout()
                .SimulateTimeout()
                .SimulateTimeout()
                .RespondWithJson(Fixtures.Watch.DefaultResponse);

                Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .Watch(Fixtures.Watch.Path)
                .SubscribeFor(1)
                .Wait();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Watch.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(4);
            }
        }
Ejemplo n.º 11
0
        public void Watch_ShouldStopPollingWhenSubscriptionIsDisposed()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Watch.DefaultResponse)
                .RespondWithJson(Fixtures.Watch.DefaultResponse)
                .RespondWithJson(Fixtures.Watch.DefaultResponse)
                .RespondWithJson(Fixtures.Watch.DefaultResponse)
                .RespondWithJson(Fixtures.Watch.DefaultResponse);

                Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .Watch(Fixtures.Watch.Path)
                .SubscribeFor(3)
                .Wait();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Watch.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Get);

                http.CallLog.Should()
                .HaveCount(3);
            }
        }
Ejemplo n.º 12
0
        public void WatchOnce_ShouldOnlyBeNotifiedOnce()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Watch.DefaultResponse)
                .RespondWithJson(Fixtures.Watch.DefaultResponse);

                var tcs = new TaskCompletionSource <object>();

                Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .WatchOnce(Fixtures.Watch.Path)
                .Subscribe(tcs.SetResult, tcs.SetException);

                tcs.Task.Wait();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Watch.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);

                http.CallLog.Should()
                .HaveCount(1);

                tcs.Task.IsCompleted.Should().BeTrue();
                tcs.Task.Result.Should().NotBeNull();
            }
        }
Ejemplo n.º 13
0
        public async Task Upsert_ShouldHaveTheJsonEncodedBodyWhenUsingTheJsonValueConverter()
        {
            var dto      = Fixtures.Dto.SimpleDataContract();
            var expected = JsonConvert.SerializeObject(dto);

            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                var client = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri());
                client.Configure(x => x.ValueConverter = Converters.Json);

                await client
                .UpsertKey(Fixtures.Key.Path)
                .WithValue(dto);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                .WithVerb(HttpMethod.Put)
                .WithRequestBody(Fixtures.Key.DefaultRequest(expected))
                .Times(1);
            }
        }
        public EtcdStreamDiscovery(string cluster)
        {
#if DEBUG
            _etcd = Etcd.ClientFor(new Uri("http://192.168.1.100:2379"));
            _key  = "/jellyfish/runtime/" + (cluster ?? "Local");
#else
            _etcd = Etcd.ClientFor(new Uri("http://local-etcd:2379"));
            _key  = "/jellyfish/runtime/" + (cluster ?? Environment.GetEnvironmentVariable("JELLYFISH_CLUSTER"));
#endif
            //Console.WriteLine("Reading " + _key);
        }
Ejemplo n.º 15
0
        public void InstanceConfig_ShouldUseTheStringValueConverterWhenConfiguringWithTheStringValueConverter()
        {
            // Ensure Default
            Etcd.Configuration.ValueConverter
            .Should()
            .Be(Converters.Json);

            var client = (EtcdClient)Etcd.ClientFor(Fixtures.EtcdUrl.ToUri());

            client.Configure(x => x.ValueConverter = Converters.String);

            client.Config.ValueConverter
            .Should()
            .Be(Converters.String);
        }
Ejemplo n.º 16
0
        public async Task Get_ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .GetKey(Fixtures.Key.Path);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Ejemplo n.º 17
0
        public void InstanceConfigure_ShouldNotAffectGlobalConfig()
        {
            // Ensure Default
            Etcd.Configuration.ValueConverter
            .Should()
            .Be(Converters.Json);

            var client = (EtcdClient)Etcd.ClientFor(Fixtures.EtcdUrl.ToUri());

            client.Configure(x => x.ValueConverter = Converters.String);

            client.Config.ValueConverter
            .Should()
            .Be(Converters.String);
            Etcd.Configuration.ValueConverter
            .Should()
            .Be(Converters.Json);
        }
Ejemplo n.º 18
0
        public void ShouldThrowServiceUnavailableExceptionOn503ResponseCode()
        {
            using (var http = new HttpTest())
            {
                http.RespondWith(HttpStatusCode.ServiceUnavailable, string.Empty);

                Func <Task> action = async() =>
                {
                    await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Cluster
                    .GetLeader();
                };

                action.ShouldThrowExactly <ServiceUnavailableException>()
                .And
                .IsServiceUnavailable.Should().BeTrue();
            }
        }
Ejemplo n.º 19
0
        public async Task Delete_ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Directory.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .DeleteDirectory(Fixtures.Directory.Path);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Directory.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Directory, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Delete)
                .Times(1);
            }
        }
Ejemplo n.º 20
0
        public void ShouldThrowExistingPeerAddressExceptionOnDuplicatePeerAddress()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(HttpStatusCode.Conflict, Fixtures.CreateErrorMessage(Constants.Etcd.ErrorCode_ExistingPeerAddress));

                Func <Task> action = async() =>
                {
                    await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Cluster
                    .CreateMember()
                    .WithPeerUri(Fixtures.EtcdUrl.ToUri());
                };

                action.ShouldThrowExactly <ExistingPeerAddressException>()
                .And
                .IsExistingPeerAddress.Should().BeTrue();
            }
        }
Ejemplo n.º 21
0
        public void ShouldThrowInvalidRequestExceptionOn404ResponseCode()
        {
            using (var http = new HttpTest())
            {
                http.RespondWith(HttpStatusCode.NotFound, string.Empty);

                Func <Task> action = async() =>
                {
                    await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                    .Cluster
                    .DeleteMember()
                    .WithMemberId(StaticRandom.Instance.Next().ToString());
                };

                action.ShouldThrowExactly <InvalidRequestException>()
                .And
                .IsInvalidRequest.Should().BeTrue();
            }
        }
Ejemplo n.º 22
0
        public async Task Update_ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Directory.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .UpdateDirectory(Fixtures.Directory.Path);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Directory.Path)
                    )
                .WithVerb(HttpMethod.Put)
                .WithRequestBody(Fixtures.Directory.WithExistingRequest.AsRequestBody())
                .Times(1);
            }
        }
Ejemplo n.º 23
0
        public async Task Get_ShouldCallTheCorrectUrlWithQuorumTrueOption()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .GetKey(Fixtures.Key.Path)
                .WithQuorum();

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Quorum, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Ejemplo n.º 24
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(
                    Fixtures.Cluster.ClusterMemberResponse(
                        peerUris: new[]
                {
                    Fixtures.EtcdUrl.ToUri(),
                    Fixtures.EtcdUrl.ToUri()
                }));

                var memberId = StaticRandom.Instance.Next().ToString();

                var member = await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                             .Cluster
                             .UpdateMemberPeerUrls()
                             .WithMemberId(memberId)
                             .WithPeerUri(Fixtures.EtcdUrl.ToUri(), Fixtures.EtcdUrl.ToUri());

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Members)
                    .AppendPathSegment(memberId)
                    )
                .WithVerb(HttpMethod.Put)
                .WithContentType(Constants.Http.ContentType_ApplicationJson)
                .Times(1);

                member.Should().NotBeNull();
                member.PeerUrls
                .Should()
                .HaveCount(2)
                .And
                .ContainInOrder(
                    Fixtures.EtcdUrl.ToUri(),
                    Fixtures.EtcdUrl.ToUri()
                    );
            }
        }
Ejemplo n.º 25
0
        public async Task Upsert_ShouldCallTheCorrectUrlWithTtlOption()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .UpsertKey(Fixtures.Key.Path)
                .WithValue(Fixtures.Key.DefaultValue)
                .WithTimeToLive(Fixtures.Key.DefaultTtl);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                .WithVerb(HttpMethod.Put)
                .WithRequestBody(Fixtures.Key.TtlRequest())
                .Times(1);
            }
        }
Ejemplo n.º 26
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Queue.DefaultResponse);

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .Atomic
                .Enqueue(Fixtures.Queue.Path)
                .WithValue(Fixtures.Queue.DefaultValue);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Queue.Path)
                    )
                .WithVerb(HttpMethod.Post)
                .WithRequestBody(Fixtures.Queue.DefaultRequest())
                .Times(1);
            }
        }
Ejemplo n.º 27
0
        public void WatchOnce_ShouldCallTheCorrectUrlWithRecursiveOption()
        {
            using (var http = new HttpTest())
            {
                Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .WatchOnce(Fixtures.Watch.Path)
                .WithRecursive(true)
                .SubscribeFor(1);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Watch.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True)
                    .SetQueryParam(Constants.Etcd.Parameter_Recursive, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Ejemplo n.º 28
0
        public async Task Get_ShouldUseConfiguredValueConverter()
        {
            var dto       = Fixtures.Dto.SimpleDataContract();
            var converter = new XmlValueConverter();
            var expected  = converter.Write(dto);

            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Key.UpsertResponse(Fixtures.Key.Path, expected));

                var client = Etcd.ClientFor(Fixtures.EtcdUrl.ToUri());
                client.Configure(x => x.ValueConverter = converter);

                var response = await client
                               .GetKey(Fixtures.Key.Path);

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegments(Constants.Etcd.Path_Keys, Fixtures.Key.Path)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);

                response.Should().NotBeNull();
                response.Data.Should().NotBeNull();
                response.Data.RawValue.Should().NotBeNullOrWhiteSpace();
                response.Data.RawValue.Should().Be(expected);

                SimpleDataContractDto responseDto = null;
                Action getValue = () => responseDto = response.Data.GetValue <SimpleDataContractDto>();
                getValue.ShouldNotThrow();

                responseDto.Should().NotBeNull();

                responseDto.Id.Should().Be(dto.Id);
                responseDto.Name.Should().Be(dto.Name);
            }
        }
Ejemplo n.º 29
0
        public async Task Watch_ShouldStopPollingOnA500LevelResponse()
        {
            using (var http = new HttpTest())
            {
                http.RespondWith(HttpStatusCode.InternalServerError, "Some error string")
                .RespondWithJson(Fixtures.Watch.DefaultResponse)
                .RespondWithJson(Fixtures.Watch.DefaultResponse);

                var tcs  = new TaskCompletionSource <object>();
                var task = tcs.Task;

                Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .Watch(Fixtures.Watch.Path)
                .Subscribe(tcs.SetResult, x => tcs.SetException(x));

                try
                {
                    await task;
                }
                catch
                {
                    // ignored
                }

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Keys)
                    .AppendPathSegment(Fixtures.Watch.Path)
                    .SetQueryParam(Constants.Etcd.Parameter_Wait, Constants.Etcd.Parameter_True)
                    )
                .WithVerb(HttpMethod.Get)
                .Times(1);

                task.IsCompleted.Should().BeTrue();
                task.IsFaulted.Should().BeTrue();
            }
        }
Ejemplo n.º 30
0
        public async Task ShouldCallTheCorrectUrlByAwaitingImmediately()
        {
            using (var http = new HttpTest())
            {
                http.RespondWithJson(Fixtures.Cluster.CreateResponse(Fixtures.EtcdUrl.ToUri()));

                var memberId = StaticRandom.Instance.Next();

                await Etcd.ClientFor(Fixtures.EtcdUrl.ToUri())
                .Cluster
                .DeleteMember()
                .WithMemberId(memberId.ToString());

                http.Should()
                .HaveCalled(
                    Fixtures.EtcdUrl
                    .AppendPathSegment(Constants.Etcd.Path_Members)
                    .AppendPathSegment(memberId.ToString())
                    )
                .WithVerb(HttpMethod.Delete)
                .Times(1);
            }
        }