public async Task Reading_WithoutOffset_Throws()
        {
            var @ref = new LogRef("grargrgrgrgh");

            await Should.ThrowAsync <LogException>(async() => {
                await Client.AppendTo(@ref, "asdadadsad");
            });
        }
        public async Task ReadingWithOffset_ReturnsFromOffsetOnwards()
        {
            await Redis.StringSetAsync("squeeak", "0123456789");

            var @ref = new LogRef("squeeak", 5);

            var result = await Client.ReadFrom(@ref);

            result.Value.ShouldBe("56789");
            result.Next.Offset.ShouldBe(10);
        }
        public async Task AppendingFails_WhenOffsetIsGazumped()
        {
            var @ref = new LogRef("squawk!", 0);

            var result1 = await Client.AppendTo(@ref, "12345");

            result1.Success.ShouldBeTrue();

            var result2 = await Client.AppendTo(@ref, "9876");

            result2.Success.ShouldBeFalse();
        }
        public async Task Client_Appends_ToExistingString()
        {
            await Redis.StringSetAsync("flap", "12345");

            var @ref = new LogRef("flap", 5);

            @ref = await Client.AppendTo(@ref, "6789").ExpectOK();

            var val = (string)await Redis.StringGetAsync(@ref.Key);

            val.ShouldBe("123456789");
        }
        public async Task Client_AppendsStrings()
        {
            var @ref = new LogRef("blah", 0);

            @ref = await Client.AppendTo(@ref, "12345").ExpectOK();

            @ref = await Client.AppendTo(@ref, "6789").ExpectOK();

            var val = (string)await Redis.StringGetAsync(@ref.Key);

            val.ShouldBe("123456789");
        }
        public async Task Client_Appends_AndReadsStrings()
        {
            var @ref = new LogRef("oof", 0);

            @ref = await Client.AppendTo(@ref, "12345").ExpectOK();

            @ref = await Client.AppendTo(@ref, "6789").ExpectOK();

            var result = await Client.ReadFrom(@ref.WithoutOffset());

            result.Success.ShouldBeTrue();
            result.Value.ShouldBe("123456789");
        }
        public async Task OnlyOneAppenderCanWin_GivenCompetition()
        {
            var @ref = new LogRef("piffle", 0);

            @ref = await Client.AppendTo(@ref, "abcdef").ExpectOK();

            var results = await Enumerable.Range(0, 20)
                          .Map(async _ => {
                await Task.Delay(10);
                return(await Client.AppendTo(@ref, "ghij"));
            })
                          .WhenAll();

            results.Count(r => r.Success).ShouldBe(1);
        }
        public async Task Reading_WithoutOffset_ReturnsFullLog_AndOffsetToo()
        {
            var @ref = new LogRef("schnooo");

            await Redis.StringSetAsync(@ref.Key, "12345678");

            @ref = await Client.ReadFrom(@ref);

            @ref.Offset.ShouldBe(8);

            @ref = await Client.AppendTo(@ref, "9");

            @ref.Offset.ShouldBe(9);

            var result = (string)await Redis.StringGetAsync(@ref.Key);

            result.ShouldBe("123456789");
        }
Пример #9
0
 internal ReadResult(bool success, T value, LogRef next)
 {
     Success = true;
     Value   = value;
     Next    = next;
 }
Пример #10
0
 internal AppendResult(bool success, LogRef next)
 {
     Success = success;
     Next    = next;
 }
Пример #11
0
 internal static ReadResult <T> Ok <T>(T value, LogRef next)
 => new ReadResult <T>(true, value, next);
Пример #12
0
 internal static AppendResult Ok(LogRef next)
 => new AppendResult(true, next);