Skip to content

Commit

Permalink
Object Store client compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmk committed Oct 17, 2023
1 parent 5430c18 commit 957ba86
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
7 changes: 7 additions & 0 deletions NATS.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATS.Client.ObjectStore.Tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.ObjectStore", "sandbox\Example.ObjectStore\Example.ObjectStore.csproj", "{51882883-A66E-4F95-A1AB-CFCBF71B4376}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nats.Client.Compat.ObjectStore", "tests\Nats.Client.Compat.ObjectStore\Nats.Client.Compat.ObjectStore.csproj", "{35578296-FF6C-4BA4-BEE5-C1A6E7DB7024}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.TlsFirst", "sandbox\Example.TlsFirst\Example.TlsFirst.csproj", "{88625045-978F-417F-9F51-A4E3A9718945}"
EndProject
Global
Expand Down Expand Up @@ -203,6 +205,10 @@ Global
{51882883-A66E-4F95-A1AB-CFCBF71B4376}.Debug|Any CPU.Build.0 = Debug|Any CPU
{51882883-A66E-4F95-A1AB-CFCBF71B4376}.Release|Any CPU.ActiveCfg = Release|Any CPU
{51882883-A66E-4F95-A1AB-CFCBF71B4376}.Release|Any CPU.Build.0 = Release|Any CPU
{35578296-FF6C-4BA4-BEE5-C1A6E7DB7024}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35578296-FF6C-4BA4-BEE5-C1A6E7DB7024}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35578296-FF6C-4BA4-BEE5-C1A6E7DB7024}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35578296-FF6C-4BA4-BEE5-C1A6E7DB7024}.Release|Any CPU.Build.0 = Release|Any CPU
{88625045-978F-417F-9F51-A4E3A9718945}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88625045-978F-417F-9F51-A4E3A9718945}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88625045-978F-417F-9F51-A4E3A9718945}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -242,6 +248,7 @@ Global
{3F8840BA-4F91-4359-AA53-6B26823E7F55} = {4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}
{BB2F4EEE-1AB3-43F7-B004-6C9B3D52353E} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{51882883-A66E-4F95-A1AB-CFCBF71B4376} = {95A69671-16CA-4133-981C-CC381B7AAA30}
{35578296-FF6C-4BA4-BEE5-C1A6E7DB7024} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{88625045-978F-417F-9F51-A4E3A9718945} = {95A69671-16CA-4133-981C-CC381B7AAA30}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
2 changes: 1 addition & 1 deletion NATS.Client.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=HMSG/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=HPUB/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Msgs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nuid/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nuid/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/NATS.Client.ObjectStore/NatsObjConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public record NatsObjConfig(string Bucket)
/// <summary>
/// Type of backing storage to use.
/// </summary>
public NatsObjStorageType? Storage { get; init; }
public NatsObjStorageType Storage { get; init; }

/// <summary>
/// How many replicas to keep for each key.
Expand Down
1 change: 1 addition & 0 deletions src/NATS.Client.ObjectStore/NatsObjContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public async ValueTask<NatsObjStore> CreateObjectStore(NatsObjConfig config, Can
AllowDirect = true,
Metadata = config.Metadata!,
Retention = StreamConfigurationRetention.limits,
Compression = StreamConfigurationCompression.none,
};

var stream = await _context.CreateStreamAsync(streamConfiguration, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

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

</Project>
66 changes: 66 additions & 0 deletions tests/Nats.Client.Compat.ObjectStore/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using NATS.Client.Core;
using NATS.Client.JetStream;
using NATS.Client.ObjectStore;

/*
* Use nats-server > 2.10
* .\client-compatibility.exe suite object-store default-bucket
*/

var url = Environment.GetEnvironmentVariable("NATS_URL") ?? NatsOpts.Default.Url;
var opts = NatsOpts.Default with { Url = url };
await using var nats = new NatsConnection(opts);
var js = new NatsJSContext(nats);
var ob = new NatsObjContext(js);

Log($"Connected to NATS server {url}");

await using var sub = await nats.SubscribeAsync<Memory<byte>>("tests.object-store.default-bucket.>");

Log($"Subscribed to {sub.Subject}");
var msg = await sub.Msgs.ReadAsync();

var config = JsonSerializer.Deserialize<ObjectStepConfig<BucketConfig>>(msg.Data.Span);

Log($"Test message received: {config}");

await ob.CreateObjectStore(new NatsObjConfig(config!.Config.Bucket!));

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / memory test (release/v2.9.23)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet (release/v2.9.23)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / memory test (latest)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet (latest)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / memory test (main)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

Dereference of a possibly null reference.

Check warning on line 29 in tests/Nats.Client.Compat.ObjectStore/Program.cs

View workflow job for this annotation

GitHub Actions / dotnet (main)

Dereference of a possibly null reference.

await msg.ReplyAsync<object>(default);

void Log(string message)
{
Console.WriteLine($"{DateTime.Now:hh:mm:ss} {message}");
}

public record ObjectStepConfig<T>
{
[JsonPropertyName("suite")]
public string? Suite { get; set; }

[JsonPropertyName("test")]
public string? Test { get; set; }

[JsonPropertyName("command")]
public string? Command { get; set; }

[JsonPropertyName("url")]
public string? Url { get; set; }

[JsonPropertyName("bucket")]
public string? Bucket { get; set; }

[JsonPropertyName("object")]
public string? Object { get; set; }

[JsonPropertyName("config")]
public T? Config { get; set; }
}

public record BucketConfig
{
[JsonPropertyName("bucket")]
public string? Bucket { get; set; }
}

0 comments on commit 957ba86

Please sign in to comment.