Пример #1
0
 public void WriterWithPreviousVersion()
 {
     TimeRunner.Run(async(time, th) =>
     {
         var idBits = ImmutableArray.Create(DataStore.ID_BYTE_1, DataStore.ID_BYTE_2);
         var dir    = new FakeDirectory(th,
                                        ("data.seqid.00000001.version.1.elementsize.8.datastore", Bits.Empty.Concat(idBits).Concat(Bits.Empty.AddInt(1).AddFletcher16))
                                        );
         var writer = new Data.Writer(th, dir);
         var reader = new Data.Reader(th, dir);
         Assert.Equal(new [] { new Data(1, null, null) }, await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
         await writer.AppendAsync(new Data(4, 5, 6)).ConfigureAwait(th);
         Assert.Equal(new [] { new Data(1, null, null), new Data(4, 5, 6) }, await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
     });
 }
 public void ReadEmpty()
 {
     TimeRunner.Run(async(time, th) =>
     {
         var dir    = new FakeDirectory(th);
         var reader = new Data.Reader(th, dir);
         var data   = await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th);
         Assert.Empty(data);
     });
 }
Пример #3
0
 public void WatchTimeoutCancelled() => TimeRunner.Run(async(time, th) =>
 {
     var dir          = new FakeDirectory(th);
     var cts          = new CancellationTokenSource();
     var timedOutTask = dir.AwaitChange("", Duration.FromSeconds(10), cts.Token);
     await th.Delay(Duration.FromSeconds(5));
     cts.Cancel();
     var cancelled = await timedOutTask.ConfigureAwaitHideCancel(th);
     Assert.True(cancelled);
 });
Пример #4
0
 public void WatchTimeout() => TimeRunner.Run(async(time, th) =>
 {
     var dir       = new FakeDirectory(th);
     var timedOut0 = await dir.AwaitChange("", Duration.FromSeconds(10)).ConfigureAwait(th);
     Assert.True(timedOut0);
     var timedOut1Task = dir.AwaitChange("", Duration.FromSeconds(10));
     await th.Delay(Duration.FromSeconds(5));
     await dir.AppendAsync("afile", new byte[] { 0 }).ConfigureAwait(th);
     var timedOut1 = await timedOut1Task.ConfigureAwait(th);
     Assert.False(timedOut1);
 });
Пример #5
0
        public void AddShort()
        {
            TimeRunner.Run(async(time, th) =>
            {
                var dir     = new FakeDirectory(th);
                var strings = new Strings(th, dir);
                var all0    = await(await strings.AllStrings().ConfigureAwait(th)).ToList().ConfigureAwait(th);
                Assert.Empty(all0);

                var index1 = await strings.AddAsync("a").ConfigureAwait(th);
                Assert.Equal(0, index1);
                var all1 = await(await strings.AllStrings().ConfigureAwait(th)).ToList().ConfigureAwait(th);
                Assert.Equal(new[] { (0L, "a") }, all1);
Пример #6
0
 public void WriterReadSingleVersion()
 {
     TimeRunner.Run(async(time, th) =>
     {
         var dir    = new FakeDirectory(th);
         var writer = new Data.Writer(th, dir);
         var reader = new Data.Reader(th, dir);
         Assert.Empty(await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
         await writer.AppendAsync(new Data(1, 2, 3)).ConfigureAwait(th);
         Assert.Equal(new [] { new Data(1, 2, 3) }, await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
         await writer.AppendAsync(new Data(4, 5, 6)).ConfigureAwait(th);
         Assert.Equal(new [] { new Data(1, 2, 3), new Data(4, 5, 6) }, await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
         Assert.Single(await dir.ListFilesAsync().ConfigureAwait(th));
     });
 }
 public void AddEntries()
 {
     TimeRunner.Run(async(time, th) =>
     {
         const string filename = "data.seqid.00000001.version.1.elementsize.8.datastore";
         var e      = Bits.Empty;
         var idBits = e.Concat(ImmutableArray.Create(DataStore.ID_BYTE_1, DataStore.ID_BYTE_2));
         var data   = e.Concat(idBits).Concat(e.AddInt(100).AddFletcher16);
         var dir    = new FakeDirectory(th);
         var reader = new Data.Reader(th, dir);
         Assert.Empty(await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
         await dir.AppendAsync(filename, data);
         Assert.Equal(1, await reader.CountAsync().ConfigureAwait(th));
         Assert.Single(await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th));
         await dir.AppendAsync(filename, data);
         Assert.Equal(2, await reader.CountAsync().ConfigureAwait(th));
         Assert.Equal(2, (await(await reader.ReadAsync().ConfigureAwait(th)).ToArray().ConfigureAwait(th)).Count());
     });
 }