-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Required and Preferred match filtering unit tests
- Loading branch information
Showing
10 changed files
with
385 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
...erInternal/PlacementFilterTests/PreferredMatchSiloMetadataPlacementFilterDirectorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
using System.Net; | ||
using Orleans.Metadata; | ||
using Orleans.Runtime.MembershipService.SiloMetadata; | ||
using Orleans.Runtime.Placement; | ||
using Orleans.Runtime.Placement.Filtering; | ||
using Xunit; | ||
|
||
namespace UnitTests.PlacementFilterTests; | ||
|
||
[TestCategory("Placement"), TestCategory("Filters"), TestCategory("SiloMetadata")] | ||
public class PreferredMatchSiloMetadataPlacementFilterDirectorTests | ||
{ | ||
[Fact, TestCategory("Functional")] | ||
public void CanBeCreated() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var director = new PreferredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{ testLocalSiloAddress, SiloMetadata.Empty } | ||
})); | ||
Assert.NotNull(director); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void CanBeCalled() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var director = new PreferredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testLocalSiloAddress, SiloMetadata.Empty} | ||
})); | ||
var result = director.Filter(new PreferredMatchSiloMetadataPlacementFilterStrategy(), new PlacementTarget(), | ||
new List<SiloAddress>() { testLocalSiloAddress } | ||
).ToList(); | ||
Assert.NotNull(result); | ||
Assert.NotEmpty(result); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void FiltersToAllWhenNoEntry() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var siloMetadata = new SiloMetadata(); | ||
siloMetadata.AddMetadata("metadata.key", "something"); | ||
var director = new PreferredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress, SiloMetadata.Empty}, | ||
{testLocalSiloAddress, siloMetadata}, | ||
})); | ||
var result = director.Filter(new PreferredMatchSiloMetadataPlacementFilterStrategy(["metadata.key"], 1), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress }).ToList(); | ||
Assert.NotEmpty(result); | ||
} | ||
|
||
|
||
[Theory, TestCategory("Functional")] | ||
[InlineData(1, 3, "no.match")] | ||
[InlineData(2, 3, "no.match")] | ||
[InlineData( 1, 1, "one.match")] | ||
[InlineData( 2, 3, "one.match")] | ||
[InlineData( 1, 2, "two.match")] | ||
[InlineData( 2, 2, "two.match")] | ||
[InlineData( 3, 3, "two.match")] | ||
[InlineData( 1, 3, "all.match")] | ||
[InlineData( 2, 3, "all.match")] | ||
|
||
public void FiltersOnSingleMetadata(int minCandidates, int expectedCount, string key) | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress1 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var testOtherSiloAddress2 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1002, 1); | ||
var testOtherSiloAddress3 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1003, 1); | ||
var localSiloMetadata = new SiloMetadata(); | ||
localSiloMetadata.AddMetadata("all.match", "match"); | ||
localSiloMetadata.AddMetadata("one.match", "match"); | ||
localSiloMetadata.AddMetadata("two.match", "match"); | ||
localSiloMetadata.AddMetadata("no.match", "match"); | ||
var otherSiloMetadata1 = new SiloMetadata(); | ||
otherSiloMetadata1.AddMetadata("all.match", "match"); | ||
otherSiloMetadata1.AddMetadata("one.match", "match"); | ||
otherSiloMetadata1.AddMetadata("two.match", "match"); | ||
otherSiloMetadata1.AddMetadata("no.match", "nomatch"); | ||
var otherSiloMetadata2 = new SiloMetadata(); | ||
otherSiloMetadata2.AddMetadata("all.match", "match"); | ||
otherSiloMetadata2.AddMetadata("one.match", "nomatch"); | ||
otherSiloMetadata2.AddMetadata("two.match", "match"); | ||
otherSiloMetadata2.AddMetadata("no.match", "nomatch"); | ||
var otherSiloMetadata3 = new SiloMetadata(); | ||
otherSiloMetadata3.AddMetadata("all.match", "match"); | ||
otherSiloMetadata3.AddMetadata("one.match", "nomatch"); | ||
otherSiloMetadata3.AddMetadata("two.match", "nomatch"); | ||
otherSiloMetadata3.AddMetadata("no.match", "nomatch"); | ||
var director = new PreferredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress1, otherSiloMetadata1}, | ||
{testOtherSiloAddress2, otherSiloMetadata2}, | ||
{testOtherSiloAddress3, otherSiloMetadata3}, | ||
{testLocalSiloAddress, localSiloMetadata}, | ||
})); | ||
var result = director.Filter(new PreferredMatchSiloMetadataPlacementFilterStrategy([key], minCandidates), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress1, testOtherSiloAddress2, testOtherSiloAddress3 }).ToList(); | ||
Assert.NotEmpty(result); | ||
Assert.Equal(expectedCount, result.Count); | ||
} | ||
|
||
[Theory, TestCategory("Functional")] | ||
[InlineData(1, 3, "no.match", "all.match")] | ||
[InlineData(1, 1, "no.match", "one.match", "two.match")] | ||
[InlineData(2, 2, "no.match", "one.match", "two.match")] | ||
[InlineData(3, 3, "no.match", "one.match", "two.match")] | ||
[InlineData(1, 3, "all.match", "no.match")] | ||
[InlineData(1, 1, "one.match", "all.match")] | ||
[InlineData(2, 3, "one.match", "all.match")] | ||
[InlineData(1, 1, "no.match", "one.match", "all.match")] | ||
[InlineData(2, 3, "no.match", "one.match", "all.match")] | ||
|
||
public void FiltersOnMultipleMetadata(int minCandidates, int expectedCount, params string[] keys) | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress1 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var testOtherSiloAddress2 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1002, 1); | ||
var testOtherSiloAddress3 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1003, 1); | ||
var localSiloMetadata = new SiloMetadata(); | ||
localSiloMetadata.AddMetadata("all.match", "match"); | ||
localSiloMetadata.AddMetadata("one.match", "match"); | ||
localSiloMetadata.AddMetadata("two.match", "match"); | ||
localSiloMetadata.AddMetadata("no.match", "match"); | ||
var otherSiloMetadata1 = new SiloMetadata(); | ||
otherSiloMetadata1.AddMetadata("all.match", "match"); | ||
otherSiloMetadata1.AddMetadata("one.match", "match"); | ||
otherSiloMetadata1.AddMetadata("two.match", "match"); | ||
otherSiloMetadata1.AddMetadata("no.match", "not.match"); | ||
var otherSiloMetadata2 = new SiloMetadata(); | ||
otherSiloMetadata2.AddMetadata("all.match", "match"); | ||
otherSiloMetadata2.AddMetadata("one.match", "nomatch"); | ||
otherSiloMetadata2.AddMetadata("two.match", "match"); | ||
otherSiloMetadata2.AddMetadata("no.match", "not.match"); | ||
var otherSiloMetadata3 = new SiloMetadata(); | ||
otherSiloMetadata3.AddMetadata("all.match", "match"); | ||
otherSiloMetadata3.AddMetadata("one.match", "not.match"); | ||
otherSiloMetadata3.AddMetadata("two.match", "not.match"); | ||
otherSiloMetadata3.AddMetadata("no.match", "not.match"); | ||
var director = new PreferredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress1, otherSiloMetadata1}, | ||
{testOtherSiloAddress2, otherSiloMetadata2}, | ||
{testOtherSiloAddress3, otherSiloMetadata3}, | ||
{testLocalSiloAddress, localSiloMetadata}, | ||
})); | ||
var result = director.Filter(new PreferredMatchSiloMetadataPlacementFilterStrategy(keys, minCandidates), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress1, testOtherSiloAddress2, testOtherSiloAddress3 }).ToList(); | ||
Assert.NotEmpty(result); | ||
Assert.Equal(expectedCount, result.Count); | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
...terInternal/PlacementFilterTests/RequiredMatchSiloMetadataPlacementFilterDirectorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using System.Net; | ||
using Orleans.Runtime.MembershipService.SiloMetadata; | ||
using Orleans.Runtime.Placement; | ||
using Orleans.Runtime.Placement.Filtering; | ||
using Xunit; | ||
|
||
namespace UnitTests.PlacementFilterTests; | ||
|
||
[TestCategory("Placement"), TestCategory("Filters"), TestCategory("SiloMetadata")] | ||
public class RequiredMatchSiloMetadataPlacementFilterDirectorTests | ||
{ | ||
[Fact, TestCategory("Functional")] | ||
public void RequiredMatchSiloMetadataPlacementFilterDirector_CanBeCreated() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var director = new RequiredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testLocalSiloAddress, SiloMetadata.Empty} | ||
})); | ||
Assert.NotNull(director); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void RequiredMatchSiloMetadataPlacementFilterDirector_CanBeCalled() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var director = new RequiredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testLocalSiloAddress, SiloMetadata.Empty} | ||
})); | ||
var result = director.Filter(new RequiredMatchSiloMetadataPlacementFilterStrategy(), new PlacementTarget(), | ||
new List<SiloAddress>() { testLocalSiloAddress } | ||
).ToList(); | ||
Assert.NotNull(result); | ||
Assert.NotEmpty(result); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void RequiredMatchSiloMetadataPlacementFilterDirector_FiltersToNothingWhenNoEntry() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var siloMetadata = new SiloMetadata(); | ||
siloMetadata.AddMetadata("metadata.key", "something"); | ||
var director = new RequiredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress, SiloMetadata.Empty}, | ||
{testLocalSiloAddress, siloMetadata}, | ||
})); | ||
var result = director.Filter(new RequiredMatchSiloMetadataPlacementFilterStrategy(["metadata.key"]), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress }).ToList(); | ||
Assert.Empty(result); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void RequiredMatchSiloMetadataPlacementFilterDirector_FiltersToNothingWhenDifferentValue() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var localSiloMetadata = new SiloMetadata(); | ||
localSiloMetadata.AddMetadata("metadata.key", "local"); | ||
var otherSiloMetadata = new SiloMetadata(); | ||
otherSiloMetadata.AddMetadata("metadata.key", "other"); | ||
var director = new RequiredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress, otherSiloMetadata}, | ||
{testLocalSiloAddress, localSiloMetadata}, | ||
})); | ||
var result = director.Filter(new RequiredMatchSiloMetadataPlacementFilterStrategy(["metadata.key"]), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress }).ToList(); | ||
Assert.Empty(result); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void RequiredMatchSiloMetadataPlacementFilterDirector_FiltersToSiloWhenMatching() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var localSiloMetadata = new SiloMetadata(); | ||
localSiloMetadata.AddMetadata("metadata.key", "same"); | ||
var otherSiloMetadata = new SiloMetadata(); | ||
otherSiloMetadata.AddMetadata("metadata.key", "same"); | ||
var director = new RequiredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress, otherSiloMetadata}, | ||
{testLocalSiloAddress, localSiloMetadata}, | ||
})); | ||
var result = director.Filter(new RequiredMatchSiloMetadataPlacementFilterStrategy(["metadata.key"]), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress }).ToList(); | ||
Assert.NotEmpty(result); | ||
} | ||
|
||
[Fact, TestCategory("Functional")] | ||
public void RequiredMatchSiloMetadataPlacementFilterDirector_FiltersToMultipleSilosWhenMatching() | ||
{ | ||
var testLocalSiloAddress = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1000, 1); | ||
var testOtherSiloAddress1 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1001, 1); | ||
var testOtherSiloAddress2 = SiloAddress.New(IPAddress.Parse("1.1.1.1"), 1002, 1); | ||
var localSiloMetadata = new SiloMetadata(); | ||
localSiloMetadata.AddMetadata("metadata.key", "same"); | ||
var otherSiloMetadata1 = new SiloMetadata(); | ||
otherSiloMetadata1.AddMetadata("metadata.key", "same"); | ||
var otherSiloMetadata2 = new SiloMetadata(); | ||
otherSiloMetadata2.AddMetadata("metadata.key", "same"); | ||
var director = new RequiredMatchSiloMetadataPlacementFilterDirector( | ||
new TestLocalSiloDetails("name", "clusterId", "dnsHostName", | ||
testLocalSiloAddress, | ||
testLocalSiloAddress), | ||
new TestSiloMetadataCache(new Dictionary<SiloAddress, SiloMetadata>() | ||
{ | ||
{testOtherSiloAddress1, otherSiloMetadata1}, | ||
{testOtherSiloAddress2, otherSiloMetadata2}, | ||
{testLocalSiloAddress, localSiloMetadata}, | ||
})); | ||
var result = director.Filter(new RequiredMatchSiloMetadataPlacementFilterStrategy(["metadata.key"]), new PlacementTarget(), | ||
new List<SiloAddress>() { testOtherSiloAddress1, testOtherSiloAddress2 }).ToList(); | ||
Assert.NotEmpty(result); | ||
Assert.Equal(2, result.Count); | ||
} | ||
|
||
} |
Oops, something went wrong.