-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Watcher fix and API naming fix (#273)
* Watcher fix and API naming fix * Fixed watcher not to exit after receiving initial set of objects. Introduced a new option to accomodate for that behaviour rather than returning null for example. * Also fixed the method naming to be affixed 'Async'. * Build and format fixes
- Loading branch information
Showing
9 changed files
with
74 additions
and
22 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using NATS.Client.Core.Tests; | ||
|
||
namespace NATS.Client.ObjectStore.Tests; | ||
|
||
public class WatcherTest | ||
{ | ||
[Fact] | ||
public async Task Watcher_test() | ||
{ | ||
await using var server = NatsServer.StartJS(); | ||
await using var nats = server.CreateClientConnection(); | ||
var js = new NatsJSContext(nats); | ||
var ob = new NatsObjContext(js); | ||
|
||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); | ||
var cancellationToken = cts.Token; | ||
|
||
var store = await ob.CreateObjectStoreAsync("b1", cancellationToken); | ||
|
||
await store.PutAsync("k0", new byte[] { 0 }, cancellationToken); | ||
|
||
var signal = new WaitSignal(); | ||
|
||
var watcher = Task.Run( | ||
async () => | ||
{ | ||
var count = 0; | ||
await foreach (var info in store.WatchAsync(cancellationToken: cancellationToken)) | ||
{ | ||
count++; | ||
signal.Pulse(); | ||
Assert.Equal(count, info.Size); | ||
if (count == 3) | ||
break; | ||
} | ||
}, | ||
cancellationToken); | ||
|
||
await signal; | ||
|
||
await store.PutAsync("k1", new byte[] { 0, 1 }, cancellationToken); | ||
await store.PutAsync("k1", new byte[] { 0, 1, 3 }, cancellationToken); | ||
|
||
await watcher; | ||
} | ||
} |
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