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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
            }
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 public ISettingsNode GetSettings(ClusterConfigPath path)
 => serializer.Deserialize(new BinaryBufferReader(Serialized, 0), path.Segments);
コード例 #7
0
 /// <inheritdoc />
 public (ISettingsNode settings, long version) GetWithVersion(ClusterConfigPath prefix)
 => GetSettings(ObtainState(), prefix);
コード例 #8
0
 /// <inheritdoc />
 public ISettingsNode Get(ClusterConfigPath prefix)
 => GetSettings(ObtainState(), prefix).settings;
コード例 #9
0
 public TreeBuilder Add(ClusterConfigPath path, string[] values)
 => Add(TreeFactory.CreateTreeByMultiLevelKey(null, path.Segments.ToArray(), values));
コード例 #10
0
        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);
            }));
        }