Skip to content

Commit

Permalink
Object store serialization fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmk committed Feb 19, 2024
1 parent f775e91 commit becd978
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NATS.Client.ObjectStore/NatsObjStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public async ValueTask<ObjectMetadata> 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<NatsMemoryOwner<byte>>.Default, cancellationToken: cancellationToken);
ack.EnsureSuccess();

if (eof)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\NATS.Client.ObjectStore\NATS.Client.ObjectStore.csproj" />
<ProjectReference Include="..\..\src\NATS.Client.Serializers.Json\NATS.Client.Serializers.Json.csproj" />
<ProjectReference Include="..\NATS.Client.TestUtilities\NATS.Client.TestUtilities.csproj" />
</ItemGroup>

Expand Down
26 changes: 26 additions & 0 deletions tests/NATS.Client.ObjectStore.Tests/ObjectStoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit becd978

Please sign in to comment.