-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update InMemoryStream && add InMemoryStreamTest
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Weihan Li. All rights reserved. | ||
// Licensed under the Apache license. | ||
|
||
using WeihanLi.Common.Helpers; | ||
using WeihanLi.Extensions; | ||
|
||
namespace DotNetCoreSample; | ||
internal static class MemoryStreamTest | ||
{ | ||
public static async Task MainTest() | ||
{ | ||
var stream = new InMemoryStream<long>("test"); | ||
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); | ||
await Task.Delay(100); | ||
await stream.AddAsync(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), new Dictionary<string, string> | ||
{ | ||
{ "messages", new { name = $"test-{DateTimeOffset.Now}" } .ToJson() } | ||
}); | ||
Console.WriteLine("stream message added"); | ||
await Task.Delay(1000); | ||
await stream.AddAsync(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), new Dictionary<string, string> | ||
{ | ||
{ "messages", new { name = $"test-{DateTimeOffset.Now}" } .ToJson() } | ||
}); | ||
Console.WriteLine("stream message added"); | ||
// | ||
{ | ||
Console.WriteLine("Fetch messages from stream"); | ||
await foreach (var item in stream.FetchAsync(timestamp, 2)) | ||
{ | ||
Console.WriteLine($"{item.Id} - {item.Timestamp}"); | ||
Console.WriteLine(item.Fields.ToJson()); | ||
} | ||
} | ||
{ | ||
Console.WriteLine("Fetch messages from stream again"); | ||
await foreach (var item in stream.FetchAsync(timestamp, 2)) | ||
{ | ||
Console.WriteLine($"{item.Id} - {item.Timestamp}"); | ||
Console.WriteLine(item.Fields.ToJson()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters