public void GetHashCode_should_be_case_insensitive() { var path1 = new ClusterConfigPath("foo"); var path2 = new ClusterConfigPath("FOO"); var path3 = new ClusterConfigPath("bar"); path1.GetHashCode().Should().Be(path2.GetHashCode()); path1.GetHashCode().Should().NotBe(path3.GetHashCode()); }
public void Equals_should_be_case_insensitive() { var path1 = new ClusterConfigPath("foo"); var path2 = new ClusterConfigPath("FOO"); var path3 = new ClusterConfigPath("bar"); path1.Should().Be(path2); path1.Should().NotBe(path3); }
private void TestNavigation(ClusterConfigPath path) { var writer = new BinaryBufferWriter(64); writer.Write(Guid.NewGuid()); serializer.Serialize(tree, writer); var reader = new BinaryBufferReader(writer.Buffer, 16); var deserializedTree = serializer.Deserialize(reader, path.Segments); deserializedTree.Should().Be(tree.ScopeTo(path.Segments)); }
private static IEnumerable <ClusterConfigPath> EnumeratePrefixes(ClusterConfigPath path) { var segments = path.Segments.ToArray(); var builder = new StringBuilder(); for (var i = 0; i < segments.Length - 1; i++) { if (i > 0) { builder.Append(ClusterConfigPath.Separator); } builder.Append(segments[i]); yield return(builder.ToString()); } }
private ISettingsNode Extract(ClusterConfigPath path) { if (state == null) { RemoteTree remote; if (remoteTree == null) { remote = null; } else { var writer = new BinaryBufferWriter(64); TreeSerializers.V1.Serialize(remoteTree, writer); remote = new RemoteTree(writer.Buffer.Take(writer.Length).ToArray(), TreeSerializers.V1); } state = new ClusterConfigClientState(localTree, remote, new RecyclingBoundedCache <ClusterConfigPath, ISettingsNode>(10), Int64.MaxValue); } return(TreeExtractor.Extract(state, path, null)); }
public ISettingsNode GetSettings(ClusterConfigPath path) => serializer.Deserialize(new BinaryBufferReader(Serialized, 0), path.Segments);
/// <inheritdoc /> public (ISettingsNode settings, long version) GetWithVersion(ClusterConfigPath prefix) => GetSettings(ObtainState(), prefix);
/// <inheritdoc /> public ISettingsNode Get(ClusterConfigPath prefix) => GetSettings(ObtainState(), prefix).settings;
public TreeBuilder Add(ClusterConfigPath path, string[] values) => Add(TreeFactory.CreateTreeByMultiLevelKey(null, path.Segments.ToArray(), values));
public static ISettingsNode Extract([NotNull] ClusterConfigClientState state, ClusterConfigPath path, [CanBeNull] SettingsMergeOptions mergeOptions) { mergeOptions = mergeOptions ?? DefaultMergeOptions; return(state.Cache.Obtain( path, p => { foreach (var prefix in EnumeratePrefixes(p)) { if (state.Cache.TryGetValue(prefix, out var tree)) { return tree.ScopeTo(path.Segments.Skip(prefix.Segments.Count())); } } var remoteSettings = state.RemoteTree?.GetSettings(p); var localSettings = state.LocalTree?.ScopeTo(p.Segments); return SettingsNodeMerger.Merge(remoteSettings, localSettings, mergeOptions); })); }