-
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.
Explicitly set service listener serialization (#304)
This is necessary when the default serializer isn't using a Raw serialization for NatsMemory type which is used by the service listener.
- Loading branch information
Showing
4 changed files
with
49 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
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
43 changes: 43 additions & 0 deletions
43
tests/NATS.Client.Services.Tests/ServicesSerializationTest.cs
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,43 @@ | ||
using System.Buffers; | ||
using NATS.Client.Core.Tests; | ||
using NATS.Client.Serializers.Json; | ||
using NATS.Client.Services.Internal; | ||
using NATS.Client.Services.Models; | ||
|
||
namespace NATS.Client.Services.Tests; | ||
|
||
public class ServicesSerializationTest | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public ServicesSerializationTest(ITestOutputHelper output) => _output = output; | ||
|
||
[Fact] | ||
public async Task Service_info_and_stat_request_serialization() | ||
{ | ||
await using var server = NatsServer.Start(); | ||
|
||
// Set serializer registry to use anything but a raw bytes (NatsMemory in this case) serializer | ||
await using var nats = server.CreateClientConnection(new NatsOpts { SerializerRegistry = NatsJsonSerializerRegistry.Default }); | ||
|
||
var svc = new NatsSvcContext(nats); | ||
|
||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
var cancellationToken = cts.Token; | ||
|
||
await using var s1 = await svc.AddServiceAsync("s1", "1.0.0", cancellationToken: cancellationToken); | ||
|
||
var infosTask = nats.FindServicesAsync("$SRV.INFO", 1, NatsSrvJsonSerializer<InfoResponse>.Default, cancellationToken); | ||
var statsTask = nats.FindServicesAsync("$SRV.STATS", 1, NatsSrvJsonSerializer<StatsResponse>.Default, cancellationToken); | ||
|
||
var infos = await infosTask; | ||
Assert.Single(infos); | ||
Assert.Equal("s1", infos[0].Name); | ||
Assert.Equal("1.0.0", infos[0].Version); | ||
|
||
var stats = await statsTask; | ||
Assert.Single(stats); | ||
Assert.Equal("s1", stats[0].Name); | ||
Assert.Equal("1.0.0", stats[0].Version); | ||
} | ||
} |
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