public void GetServiceTags_should_ignore_all_remaining_matched_replica_properties() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica1 = "http://replica.dev:2222"; var replica2 = "http://replica:2222"; var replica3 = "http://replica.dev.other:2222"; var replica1Tags = new TagCollection { "Tag1" }; var replica2Tags = new TagCollection { "Tag2", "Tag3" }; var replica3Tags = new TagCollection { "Tag3", "Tag4" }; properties = properties .AddReplicaTags(replica1, ReplicaTagKind.Persistent, replica1Tags) .AddReplicaTags(replica2, ReplicaTagKind.Persistent, replica2Tags) .AddReplicaTags(replica3, ReplicaTagKind.Persistent, replica3Tags); properties.GetTags().Should().BeEquivalentTo(new Dictionary <string, TagCollection> { { replica1, replica1Tags }, { replica2, replica2Tags }, { replica3, replica3Tags } }); properties.GetServiceTags().Should().BeEquivalentTo(new Dictionary <Uri, TagCollection> { { new Uri(replica1), replica3Tags } }); }
public void GetTags_should_return_persistent_tags_in_first_priority() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica = "replica"; var persistentTags = new TagCollection { { "tag4", "v1" } }; properties = properties.AddReplicaTags(replica, ReplicaTagKind.Persistent, persistentTags); var ephemeralTags = new TagCollection { { "tag4", "v2" }, { "tag1", "v1" } }; properties = properties.AddReplicaTags(replica, ReplicaTagKind.Ephemeral, ephemeralTags); var expected = new TagCollection { { "tag4", "v1" }, { "tag1", "v1" } }; properties.GetTags().Should().BeEquivalentTo(new Dictionary <string, TagCollection> { { replica, new TagCollection { { "tag4", "v1" }, { "tag1", "v1" } } } }); properties.GetReplicaTags(replica).Should().BeEquivalentTo(expected); properties = properties.RemoveReplicaTags(replica, ReplicaTagKind.Persistent, new List <string> { "tag4" }); properties.GetTags().Should().BeEquivalentTo(new Dictionary <string, TagCollection> { { replica, ephemeralTags } }); properties.GetReplicaTags(replica).Should().BeEquivalentTo(ephemeralTags); }
public void RemoveTags_should_remove_given_replica_tags() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica1 = "replica1"; var replica2 = "replica2"; var replica1Tags = new TagCollection { { "tag1", "value1" }, { "tag2", "value1" }, "tag3" }; var replica2Tags = new TagCollection { "tag4", { "tag5", "value3" }, "tag6" }; properties = properties.AddReplicaTags(replica1, ReplicaTagKind.Persistent, replica1Tags); properties = properties.AddReplicaTags(replica2, ReplicaTagKind.Persistent, replica2Tags); properties = properties.RemoveReplicaTags(replica1, ReplicaTagKind.Persistent, new List <string> { "tag3", "tag1" }); properties.GetReplicaTags(replica1).Should().BeEquivalentTo(new TagCollection { { "tag2", "value1" } }); properties.GetReplicaTags(replica2).Should().BeEquivalentTo(replica2Tags); }
public void RemoveTags_then_remove_all_tags_should_remove_replica_property_key() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica1 = "replica1"; var replica1Tags = new TagCollection { { "tag1", "value1" }, { "tag2", "value1" }, "tag3" }; properties = properties.AddReplicaTags(replica1, ReplicaTagKind.Ephemeral, replica1Tags); properties = properties.RemoveReplicaTags(replica1, ReplicaTagKind.Ephemeral, new List <string> { "tag3", "tag1" }); properties.GetTags().Should().BeEquivalentTo(new Dictionary <string, TagCollection> { { replica1, new TagCollection { { "tag2", "value1" } } } }); properties = properties.RemoveReplicaTags(replica1, ReplicaTagKind.Ephemeral, new List <string> { "tag2" }); properties.GetTags().Should().BeEmpty(); }
public void AddTags_for_given_replica_should_update_property_tags() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica1 = "replica1"; var replica2 = "replica2"; var replica1Tags = new TagCollection { { "tag1", "value1" }, { "tag2", "value1" }, "tag3" }; var replica2Tags = new TagCollection { "tag4", { "tag5", "value3" }, "tag6" }; properties = properties.AddReplicaTags(replica1, ReplicaTagKind.Persistent, replica1Tags); properties.GetReplicaTags(replica1).Should().BeEquivalentTo(replica1Tags); properties.GetReplicaTags(replica2).Should().BeEquivalentTo(new TagCollection()); properties = properties.AddReplicaTags(replica2, ReplicaTagKind.Persistent, replica2Tags); properties.GetReplicaTags(replica1).Should().BeEquivalentTo(replica1Tags); properties.GetReplicaTags(replica2).Should().BeEquivalentTo(replica2Tags); properties.GetTags() .Should() .BeEquivalentTo( new Dictionary <string, TagCollection> { { replica1, replica1Tags }, { replica2, replica2Tags } }); }
public void RemoveTags_should_not_fail_with_empty_property_tags() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica1 = "replica1"; properties = properties.RemoveReplicaTags(replica1, ReplicaTagKind.Persistent, new List <string> { "tag1", "tag2" }); properties.GetReplicaTags(replica1).Should().BeEmpty(); properties.GetTags().Should().BeEmpty(); }
public void ModifyTags_should_update_properties_with_empty_tags_if_func_returns_null() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica = "replica"; var replicaTags = new TagCollection { "tag4" }; properties = properties.AddReplicaTags(replica, ReplicaTagKind.Persistent, replicaTags); properties = properties.ModifyReplicaTags(replica, ReplicaTagKind.Persistent, tags => null); properties.GetReplicaTags(replica).Should().BeEmpty(); properties.GetTags().Should().BeEmpty(); }
public void RemoveFromBlacklist_should_not_fail_with_empty_blacklist() { var properties = new TestApplicationInfoProperties(); var removeReplicas = new[] { new Uri("http://replica:1/vostok"), new Uri("http://replica:2/vostok"), new Uri("http://replica:3/vostok") }; var updated = properties.RemoveFromBlacklist(removeReplicas); updated.GetBlacklist().Should().BeEmpty(); }
public void AddToBlacklist_should_add_blacklist() { var properties = new TestApplicationInfoProperties(); var addReplicas = new[] { new Uri("http://replica:1/vostok"), new Uri("http://replica:2/vostok"), new Uri("http://replica:3/vostok") }; var updated = properties.AddToBlacklist(addReplicas); updated.GetBlacklist().Should().BeEquivalentTo(addReplicas); }
public void RemoveFromBlacklist_should_not_change_blacklist_if_replicas_already_not_present() { var properties = new TestApplicationInfoProperties(); var initReplicas = new[] { new Uri("http://replica:4/vostok") }; var withBlacklist = properties.AddToBlacklist(initReplicas); var removeReplicas = new[] { new Uri("http://replica:1/vostok"), new Uri("http://replica:2/vostok"), new Uri("http://replica:3/vostok") }; var updated = withBlacklist.RemoveFromBlacklist(removeReplicas); updated.GetBlacklist().Should().BeEquivalentTo(new Uri("http://replica:4/vostok")); }
public void AddToBlacklist_should_add_new_replicas_to_existent_blacklist() { var properties = new TestApplicationInfoProperties(); var initReplicas = new[] { new Uri("http://replica:1/vostok"), new Uri("http://replica:2/vostok"), new Uri("http://replica:3/vostok") }; var withBlacklist = properties.AddToBlacklist(initReplicas); var updateReplicas = new[] { new Uri("http://replica:4/vostok"), new Uri("http://replica:5/vostok"), new Uri("http://replica:6/vostok") }; var updated = withBlacklist.AddToBlacklist(updateReplicas); updated.GetBlacklist().Should().BeEquivalentTo(initReplicas.Concat(updateReplicas)); }
public void AddTags_should_update_duplicate_key_property_tags() { var properties = new TestApplicationInfoProperties(); var replica1 = "replica1"; var tagsToAdd = new TagCollection { { "tag1", "value1" }, { "tag2", "value1" }, "tag3" }; var tagsToUpdate = new TagCollection { { "tag1", "updatedValue" } }; var added = properties.AddReplicaTags(replica1, ReplicaTagKind.Ephemeral, tagsToAdd); var updated = added.AddReplicaTags(replica1, ReplicaTagKind.Ephemeral, tagsToUpdate); updated.GetReplicaTags(replica1).Should().BeEquivalentTo(new TagCollection { { "tag1", "updatedValue" }, { "tag2", "value1" }, "tag3" }); }
public void GetTags_should_not_returns_not_valid_tag_kinds() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica = "replica"; var otherTags = new TagCollection { { "tag4", "v1" } }; properties = properties.Set(new TagsPropertyKey(replica, "other").ToString(), otherTags.ToString()); properties.GetTags().Should().BeEmpty(); properties.GetReplicaTags(replica).Should().BeEmpty(); var persistentTags = new TagCollection { { "tag", "value" } }; properties = properties.AddReplicaTags(replica, ReplicaTagKind.Persistent, persistentTags); properties.GetTags().Should().BeEquivalentTo(new Dictionary <string, TagCollection> { { replica, persistentTags } }); properties.GetReplicaTags(replica).Should().BeEquivalentTo(persistentTags); }
public void AddTags_for_given_service_replica_should_correctly_parse_service_replicas() { IApplicationInfoProperties properties = new TestApplicationInfoProperties(); var replica1 = "http://localhost:1234/"; var replica2 = "replica2"; var replica3 = "replica3:1234"; var replica4 = "replica4:5678"; var replica1Tags = new TagCollection { { "tag1", "value1" }, { "tag2", "value1" }, "tag3" }; var replica2Tags = new TagCollection { "tag4", { "tag5", "value3" }, "tag6" }; var replica3Tags = new TagCollection { "tag7", { "tag8", "value4" }, "tag9" }; var replica4Tags = new TagCollection { "tag10", { "tag11", "value5" }, "tag12" }; properties = properties.AddReplicaTags(replica1, ReplicaTagKind.Persistent, replica1Tags); properties.GetReplicaTags(replica1).Should().BeEquivalentTo(replica1Tags); properties.GetReplicaTags(replica2).Should().BeEquivalentTo(new TagCollection()); properties = properties.AddReplicaTags(replica2, ReplicaTagKind.Persistent, replica2Tags); properties.GetReplicaTags(replica1).Should().BeEquivalentTo(replica1Tags); properties.GetReplicaTags(replica2).Should().BeEquivalentTo(replica2Tags); properties = properties.AddReplicaTags(replica3, ReplicaTagKind.Persistent, replica3Tags); properties.GetReplicaTags(replica3).Should().BeEquivalentTo(replica3Tags); properties = properties.AddReplicaTags(replica4, ReplicaTagKind.Persistent, replica4Tags); properties.GetReplicaTags(replica4).Should().BeEquivalentTo(replica4Tags); properties.GetTags() .Should() .BeEquivalentTo( new Dictionary <string, TagCollection> { { replica1, replica1Tags }, { replica2, replica2Tags }, { replica3, replica3Tags }, { replica4, replica4Tags } }); properties.GetServiceTags() .Should() .BeEquivalentTo( new Dictionary <Uri, TagCollection> { { new Uri(replica1), replica1Tags } }); }