From becd978407097231c4092106ea5e3ec6b34b1796 Mon Sep 17 00:00:00 2001 From: Ziya Suzen Date: Mon, 19 Feb 2024 22:59:16 +0000 Subject: [PATCH] Object store serialization fix --- src/NATS.Client.ObjectStore/NatsObjStore.cs | 2 +- .../NATS.Client.ObjectStore.Tests.csproj | 1 + .../ObjectStoreTest.cs | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/NATS.Client.ObjectStore/NatsObjStore.cs b/src/NATS.Client.ObjectStore/NatsObjStore.cs index 54b8eea13..6059d7885 100644 --- a/src/NATS.Client.ObjectStore/NatsObjStore.cs +++ b/src/NATS.Client.ObjectStore/NatsObjStore.cs @@ -254,7 +254,7 @@ public async ValueTask PutAsync(ObjectMetadata meta, Stream stre var buffer = memoryOwner.Slice(0, currentChunkSize); // Chunks - var ack = await _context.PublishAsync(GetChunkSubject(nuid), buffer, cancellationToken: cancellationToken); + var ack = await _context.PublishAsync(GetChunkSubject(nuid), buffer, serializer: NatsRawSerializer>.Default, cancellationToken: cancellationToken); ack.EnsureSuccess(); if (eof) diff --git a/tests/NATS.Client.ObjectStore.Tests/NATS.Client.ObjectStore.Tests.csproj b/tests/NATS.Client.ObjectStore.Tests/NATS.Client.ObjectStore.Tests.csproj index bc1b6633a..0139097b5 100644 --- a/tests/NATS.Client.ObjectStore.Tests/NATS.Client.ObjectStore.Tests.csproj +++ b/tests/NATS.Client.ObjectStore.Tests/NATS.Client.ObjectStore.Tests.csproj @@ -31,6 +31,7 @@ + diff --git a/tests/NATS.Client.ObjectStore.Tests/ObjectStoreTest.cs b/tests/NATS.Client.ObjectStore.Tests/ObjectStoreTest.cs index 65e49dd3e..0f8250d1b 100644 --- a/tests/NATS.Client.ObjectStore.Tests/ObjectStoreTest.cs +++ b/tests/NATS.Client.ObjectStore.Tests/ObjectStoreTest.cs @@ -4,6 +4,7 @@ using NATS.Client.JetStream.Models; using NATS.Client.ObjectStore.Internal; using NATS.Client.ObjectStore.Models; +using NATS.Client.Serializers.Json; namespace NATS.Client.ObjectStore.Tests; @@ -415,4 +416,29 @@ public async Task Compressed_storage() Assert.Equal("OBJ_b2", status2.Info.Config.Name); Assert.Equal(StreamConfigCompression.S2, status2.Info.Config.Compression); } + + [Fact] + public async Task Put_get_serialization_when_default_serializer_is_not_used() + { + await using var server = NatsServer.StartJS(); + await using var nats = server.CreateClientConnection(options: new NatsOpts + { + SerializerRegistry = NatsJsonSerializerRegistry.Default, + }); + var js = new NatsJSContext(nats); + var ob = new NatsObjContext(js); + + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + var cancellationToken = cts.Token; + + var store = await ob.CreateObjectStoreAsync(new NatsObjConfig("b1"), cancellationToken); + + await store.PutAsync("k1", new byte[] { 42 }, cancellationToken: cancellationToken); + + var bytes = await store.GetBytesAsync("k1", cancellationToken); + Assert.Equal(new byte[] { 42 }, bytes); + + var info = await store.GetInfoAsync("k1", cancellationToken: cancellationToken); + Assert.Equal("k1", info.Name); + } }