public void DeserializeProperties_should_ignore_null_and_empty_values()
        {
            var dict = new Dictionary <string, string>
            {
                { "a", "a-value" },
                { "b", null },
                { "c", "" },
                { "d", " " }
            };

            var replicaInfo = new ReplicaInfo(
                "default",
                "vostok",
                "doesntmatter",
                dict);

            var serialized   = ReplicaNodeDataSerializer.Serialize(replicaInfo);
            var deserialized = ReplicaNodeDataSerializer.Deserialize(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica, serialized);

            deserialized.Properties.Should()
            .BeEquivalentTo(
                new Dictionary <string, string>
            {
                { "a", "a-value" },
                { "d", " " }
            });
        }
Exemple #2
0
        public async Task <IReplicaInfo> GetReplicaAsync(string environment, string application, string replica)
        {
            var data = await zooKeeperClient.GetDataAsync(new GetDataRequest(pathHelper.BuildReplicaPath(environment, application, replica))).ConfigureAwait(false);

            if (data.Status == ZooKeeperStatus.NodeNotFound)
            {
                return(null);
            }

            data.EnsureSuccess();
            var envData = ReplicaNodeDataSerializer.Deserialize(environment, application, replica, data.Data);

            return(envData);
        }
Exemple #3
0
        public void Should_use_default_replica_builder()
        {
            CreateEnvironmentNode("default");

            using (var beacon = new ServiceBeacon(ZooKeeperClient))
            {
                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                var builder = ReplicaInfoBuilder.Build(null, true);
                var path    = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance)
                              .BuildReplicaPath(builder.Environment, builder.Application, builder.Replica);
                var data = ZooKeeperClient.GetData(path).Data;
                var dict = ReplicaNodeDataSerializer.Deserialize(builder.Environment, builder.Application, builder.Replica, data).Properties;

                dict[ReplicaInfoKeys.Application].Should().Be(builder.Application);
            }
        }
Exemple #4
0
        public void Start_should_create_node_with_replica_properties()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            replica.SetProperty("key", "value");
            CreateEnvironmentNode(replica.Environment);

            using (var beacon = GetServiceBeacon(replica))
            {
                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance)
                           .BuildReplicaPath(replica.Environment, replica.Application, replica.Replica);
                var data = ZooKeeperClient.GetData(path).Data;
                var dict = ReplicaNodeDataSerializer.Deserialize(replica.Environment, replica.Application, replica.Replica, data).Properties;

                dict["key"].Should().Be("value");
            }
        }
        public void DeserializeProperties_should_deserialize_serialized()
        {
            var dict = new Dictionary <string, string>
            {
                { "a", "a-value" },
                { "asdf", "complex = value" },
                { "a.b.c", "dsfds sdf sdf sdf sd   ,. ,ds . . , .,  ;; ; ;" },
                { "with some spaces  ", "   " }
            };

            var replicaInfo = new ReplicaInfo(
                "default",
                "vostok",
                "doesntmatter",
                dict);

            var serialized   = ReplicaNodeDataSerializer.Serialize(replicaInfo);
            var deserialized = ReplicaNodeDataSerializer.Deserialize(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica, serialized);

            deserialized.Should().BeEquivalentTo(replicaInfo);
        }
Exemple #6
0
        public void Should_use_replica_builder()
        {
            var url = "https://github.com/vostok";

            CreateEnvironmentNode("default");

            using (var beacon = new ServiceBeacon(
                       ZooKeeperClient,
                       setup => setup.SetUrl(new Uri(url)).SetApplication("test")))
            {
                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                var path = new ServiceDiscoveryPathHelper(new ServiceBeaconSettings().ZooKeeperNodesPrefix, ZooKeeperPathEscaper.Instance)
                           .BuildReplicaPath("default", "test", url);
                var data = ZooKeeperClient.GetData(path).Data;
                var dict = ReplicaNodeDataSerializer.Deserialize("default", "test", url, data).Properties;

                dict[ReplicaInfoKeys.Replica].Should().Be(url);
                dict[ReplicaInfoKeys.Application].Should().Be("test");
            }
        }
        public void DeserializeProperties_should_replace_new_line_symbol()
        {
            var dict = new Dictionary <string, string>
            {
                { "a", "a-value\n2" },
                { "b", "b\n\nb" }
            };
            var replicaInfo = new ReplicaInfo(
                "default",
                "vostok",
                "doesntmatter",
                dict);

            var serialized   = ReplicaNodeDataSerializer.Serialize(replicaInfo);
            var deserialized = ReplicaNodeDataSerializer.Deserialize(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica, serialized);

            deserialized.Properties.Should()
            .BeEquivalentTo(
                new Dictionary <string, string>
            {
                { "a", "a-value 2" },
                { "b", "b  b" }
            });
        }