Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object Store use over leaf-hub domain #900

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NATS.Client/ObjectStore/ObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public ObjectInfo Get(string objectName, Stream outputStream)
}
else {
IJetStreamPushSyncSubscription sub = js.PushSubscribeSync(
PubSubChunkSubject(oi.Nuid),
RawChunkSubject(oi.Nuid),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix/bug

PushSubscribeOptions.Builder()
.WithStream(StreamName)
.WithOrdered(true)
Expand Down
66 changes: 64 additions & 2 deletions src/Tests/IntegrationTests/TestObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
Expand All @@ -32,9 +33,9 @@
namespace IntegrationTests
{
[SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local")]
public class TestObjectStore : TestSuite<OneServerSuiteContext>
public class TestObjectStore : TestSuite<ObjectStoreSuiteContext>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to a context that has support to run a hub and leaf

{
public TestObjectStore(OneServerSuiteContext context) : base(context) { }
public TestObjectStore(ObjectStoreSuiteContext context) : base(context) { }

[Fact]
public void TestWorkFlow()
Expand Down Expand Up @@ -597,6 +598,67 @@ private void ValidateWatcher(object[] expecteds, TestObjectStoreWatcher watcher)
}
}
}

[Fact]
public void TestObjectStoreDomains() {
Context.RunInJsHubLeaf((hubNc, leafNc) =>
{
IObjectStoreManagement hubOsm = hubNc.CreateObjectStoreManagementContext();

// Create main OS on HUB
String hubBucket = Bucket();
ObjectStoreStatus hubStatus = hubOsm.Create(ObjectStoreConfiguration.Builder()
.WithName(hubBucket)
.WithStorageType(StorageType.Memory)
.WithReplicas(1)
.Build());

Assert.Equal(0U, hubStatus.Size);
Assert.Equal(1, hubStatus.Replicas);

IObjectStore hubOs = hubNc.CreateObjectStoreContext(hubBucket);
IObjectStore leafOs = leafNc.CreateObjectStoreContext(hubBucket,
ObjectStoreOptions.Builder().WithJsDomain(SuiteContext.HubDomain).Build());

String objectName = Name();
ObjectMeta meta = ObjectMeta.Builder(objectName)
.WithChunkSize(8 * 1024)
.Build();

Object[] input = GetInput(4 * 8 * 1024, ".", long.MaxValue, null);
FileInfo fileInfo = (FileInfo)input[1];
hubOs.Put(meta, fileInfo.OpenRead());

hubStatus = hubOs.GetStatus();
Assert.True(hubStatus.Size > 0);

ObjectStoreStatus leafStatus = leafOs.GetStatus();

Assert.Equal(hubStatus.BucketName, leafStatus.BucketName);
Assert.Equal(hubStatus.Size, leafStatus.Size);

ObjectInfo hubInfo = hubOs.GetInfo(objectName);
ObjectInfo leafInfo = leafOs.GetInfo(objectName);

Assert.Equal(hubInfo.Nuid, leafInfo.Nuid);
Assert.Equal(hubInfo.Size, leafInfo.Size);
Assert.Equal(hubInfo.ObjectMeta.ObjectName, leafInfo.ObjectMeta.ObjectName);

MemoryStream hubMs = new MemoryStream();
ObjectInfo hubOi = hubOs.Get(objectName, hubMs);
byte[] hubBytes = hubMs.ToArray();

MemoryStream leafMs = new MemoryStream();
ObjectInfo leafOi = leafOs.Get(objectName, leafMs);
byte[] leafBytes = leafMs.ToArray();

Assert.Equal(hubBytes.Length, leafBytes.Length);
for (int x = 0; x < hubBytes.Length; x++)
{
Assert.Equal(hubBytes[x], leafBytes[x]);
}
});
}
}

class TestObjectStoreWatcher : IObjectStoreWatcher
Expand Down
22 changes: 15 additions & 7 deletions src/Tests/IntegrationTests/TestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,29 +226,35 @@ public void RunInJsServer(TestServerInfo testServerInfo, string config, Action<I
}
}

public const string HubDomain = "HUB";
public const string LeafDomain = "LEAF";
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made const so can be known to tests


public void RunInJsHubLeaf(TestServerInfo hubServerInfo,
TestServerInfo hubLeafInfo,
TestServerInfo leafServerInfo, Action<IConnection, IConnection> test)
{
string hubConfFile = TestBase.TempConfFile();
StreamWriter streamWriter = File.CreateText(hubConfFile);
streamWriter.WriteLine("port: " + hubServerInfo.Port);
streamWriter.WriteLine("server_name: HUB");
streamWriter.WriteLine("server_name: " + HubDomain);
streamWriter.WriteLine("jetstream {");
streamWriter.WriteLine(" domain: HUB");
streamWriter.WriteLine(" store_dir: " + TestBase.TempConfDir());
streamWriter.WriteLine(" domain: " + HubDomain);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the constant and specify a unique store dir for each server

streamWriter.WriteLine("}");
streamWriter.WriteLine("leafnodes {");
streamWriter.WriteLine(" listen = 127.0.0.1:" + hubLeafInfo.Port);
streamWriter.WriteLine("}");
streamWriter.Flush();
streamWriter.Close();

string leafConfFile = TestBase.TempConfFile();
string leafJsStoreDir = TestBase.TempConfDir();
streamWriter = File.CreateText(leafConfFile);
streamWriter.WriteLine("port: " + leafServerInfo.Port);
streamWriter.WriteLine("server_name: LEAF");
streamWriter.WriteLine("server_name: " + LeafDomain);
streamWriter.WriteLine("jetstream {");
streamWriter.WriteLine(" domain: LEAF");
streamWriter.WriteLine(" store_dir: " + TestBase.TempConfDir());
streamWriter.WriteLine(" domain: " + LeafDomain);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the constant and specify a unique store dir for each server

streamWriter.WriteLine("}");
streamWriter.WriteLine("leafnodes {");
streamWriter.WriteLine(" remotes = [ { url: \"leaf://127.0.0.1:" + hubLeafInfo.Port + "\" } ]");
Expand Down Expand Up @@ -473,8 +479,10 @@ public class JetStreamPublishSuiteContext : OneServerSuiteContext {}
public class JetStreamPushAsyncSuiteContext : OneServerSuiteContext {}
public class JetStreamPushSyncSuiteContext : OneServerSuiteContext {}
public class JetStreamPushSyncQueueSuiteContext : OneServerSuiteContext {}
public class KeyValueSuiteContext : HubLeafSuiteContext {}
public class ObjectStoreSuiteContext : HubLeafSuiteContext {}

public class KeyValueSuiteContext : SuiteContext
public class HubLeafSuiteContext : SuiteContext
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored for reuse since object store needs the same stuff

{
private const int SeedPort = TestSeedPorts.KvSuite;

Expand All @@ -489,7 +497,7 @@ public class KeyValueSuiteContext : SuiteContext
public void RunInJsHubLeaf(Action<IConnection, IConnection> test) =>
base.RunInJsHubLeaf(Server1, Server2, Server3, test);
}

public class OneServerSuiteContext : SuiteContext
{
public readonly TestServerInfo Server1;
Expand Down
5 changes: 5 additions & 0 deletions src/Tests/UnitTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public static DateTime AsDateTime(string dtString)
return DateTime.Parse(dtString).ToUniversalTime();
}

public static string TempConfDir()
{
return Path.GetTempPath().Replace("\\", "\\\\"); // when on windows this is necessary. unix doesn't have backslash
}

public static string TempConfFile()
{
return Path.GetTempPath() + "nats_net_test" + Guid.NewGuid() + ".conf";
Expand Down
Loading