public async Task UpdatesTimeOfLastRead() { const string knownId = "known id"; using (var source = new MemoryStream(new byte[0])) { await _storage.Save(knownId, source); } var hadLastReadTime = (await _storage.ReadMetadata(knownId)).ContainsKey(MetadataKeys.ReadTime); Assert.That(hadLastReadTime, Is.False, "Did not expect the {0} key to be set", MetadataKeys.ReadTime); var justSomeTime = new DateTimeOffset(1.January(2016)); RebusTimeMachine.FakeIt(justSomeTime); _storage.Read(knownId).Result.Dispose(); var metadata = await _storage.ReadMetadata(knownId); Assert.That(metadata.ContainsKey(MetadataKeys.ReadTime), Is.True); var readTimeMetadata = metadata[MetadataKeys.ReadTime]; var readTime = DateTimeOffset.Parse(readTimeMetadata); Assert.That(readTime, Is.EqualTo(justSomeTime), $"Expected that the '{MetadataKeys.ReadTime}' metadata value '{readTimeMetadata}' would equal {justSomeTime} when passed to DateTimeOffset.Parse(...)"); }
public async Task ReadingIsLazy(int byteCount) { const string dataId = "known id"; Console.WriteLine($"Generating {byteCount/(double)(1024*1024):0.00} MB of data..."); var data = GenerateData(byteCount); Console.WriteLine("Saving data..."); await _storage.Save(dataId, new MemoryStream(data)); Console.WriteLine("Reading data..."); var stopwatch = Stopwatch.StartNew(); await using var source = await _storage.Read(dataId); await using var destination = new MemoryStream(); var elapsedWhenStreamIsOpen = stopwatch.Elapsed; Console.WriteLine($"Opening stream took {elapsedWhenStreamIsOpen.TotalSeconds:0.00} s"); await source.CopyToAsync(destination); var elapsedWhenStreamHasBeenRead = stopwatch.Elapsed; Console.WriteLine($"Entire operation took {elapsedWhenStreamHasBeenRead.TotalSeconds:0.00} s"); var fraction = elapsedWhenStreamHasBeenRead.TotalSeconds / 1; Assert.That(elapsedWhenStreamIsOpen.TotalSeconds, Is.LessThan(fraction), "Expected time to open stream to be less than 1/1 of the time it takes to read the entire stream"); }
/// <summary> /// Opens the data stored under the given ID for reading /// </summary> public async Task <Stream> Read(string id) { var metadata = await _innerDataBusStorage.ReadMetadata(id).ConfigureAwait(false); if (!metadata.TryGetValue(MetadataKeys.ContentEncoding, out var contentEncoding)) { return(await _innerDataBusStorage.Read(id).ConfigureAwait(false)); } if (!string.Equals(contentEncoding, "gzip", StringComparison.OrdinalIgnoreCase)) { // unknown content encoding - the user must know best how to decode this! return(await _innerDataBusStorage.Read(id).ConfigureAwait(false)); } var sourceStream = await _innerDataBusStorage.Read(id).ConfigureAwait(false); return(new GZipStream(sourceStream, CompressionMode.Decompress)); }
public async Task UpdatesTimeOfLastRead() { const string knownId = "known id"; using (var source = new MemoryStream(new byte[0])) { await _storage.Save(knownId, source); } var hadLastReadTime = (await _storage.ReadMetadata(knownId)).ContainsKey(MetadataKeys.ReadTime); Assert.That(hadLastReadTime, Is.False, "Did not expect the {0} key to be set", MetadataKeys.ReadTime); var justSomeTime = new DateTimeOffset(1.January(2016)); RebusTimeMachine.FakeIt(justSomeTime); _storage.Read(knownId).Result.Dispose(); var metadata = await _storage.ReadMetadata(knownId); Assert.That(metadata.ContainsKey(MetadataKeys.ReadTime), Is.True); Assert.That(metadata[MetadataKeys.ReadTime], Is.EqualTo(justSomeTime.ToString("O"))); }
public async Task CanQueryByTimeStamps_ReadTime() { if (NoManagement()) { return; } async Task CreateAttachment(DateTime readTime, string attachmendId) { _factory.FakeIt(DateTimeOffset.Now); using (var source = new MemoryStream(new byte[0])) { await _storage.Save(attachmendId, source); } // update read time _factory.FakeIt(readTime); using (await _storage.Read(attachmendId)) { } } await CreateAttachment(new DateTime(2019, 01, 01), "id1"); await CreateAttachment(new DateTime(2019, 02, 01), "id2"); await CreateAttachment(new DateTime(2019, 03, 01), "id3"); await CreateAttachment(new DateTime(2019, 04, 01), "id4"); await CreateAttachment(new DateTime(2019, 05, 01), "id5"); var ids1 = _management.Query(readTime: new TimeRange(from: new DateTime(2019, 02, 01))).InOrder().ToList(); var ids2 = _management.Query(readTime: new TimeRange(from: new DateTime(2019, 03, 01))).InOrder().ToList(); var ids3 = _management.Query(readTime: new TimeRange(from: new DateTime(2019, 03, 01), to: new DateTime(2019, 05, 01))).InOrder().ToList(); Assert.That(ids1, Is.EqualTo(new[] { "id2", "id3", "id4", "id5" })); Assert.That(ids2, Is.EqualTo(new[] { "id3", "id4", "id5" })); Assert.That(ids3, Is.EqualTo(new[] { "id3", "id4" })); }
public Task <Stream> OpenRead(string dataBusAttachmentId) => _dataBusStorage.Read(dataBusAttachmentId);
/// <inheritdoc /> public async Task <Stream> OpenRead(string dataBusAttachmentId) { return(await _dataBusStorage.Read(dataBusAttachmentId).ConfigureAwait(false)); }
public async Task <Stream> OpenRead(string dataBusAttachmentId) { return(await _dataBusStorage.Read(dataBusAttachmentId)); }