Created
October 31, 2020 19:33
-
-
Save joao-r-reis/511552c249b2486bea36ec71eb037592 to your computer and use it in GitHub Desktop.
CoarseTest.cs
This file contains hidden or 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
[Test] | |
public void Build_Should_OnlyCallOncePerReplicationConfiguration_When_MultipleKeyspacesWithSameReplicationOptions() | |
{ | |
var hosts = new List<Host> | |
{ | |
{ TestHelper.CreateHost("192.168.0.0", "dc1", "rack", new HashSet<string>{"0"})}, | |
{ TestHelper.CreateHost("192.168.0.1", "dc1", "rack", new HashSet<string>{"10"})}, | |
{ TestHelper.CreateHost("192.168.0.2", "dc1", "rack", new HashSet<string>{"20"})}, | |
{ TestHelper.CreateHost("192.168.0.3", "dc2", "rack", new HashSet<string>{"30"})}, | |
{ TestHelper.CreateHost("192.168.0.4", "dc2", "rack", new HashSet<string>{"40"})} | |
}; | |
var factory = new ProxyReplicationStrategyFactory(); | |
var keyspaces = new List<KeyspaceMetadata> | |
{ | |
// unique configurations | |
FakeSchemaParserFactory.CreateSimpleKeyspace("ks1", 2, factory), | |
FakeSchemaParserFactory.CreateSimpleKeyspace("ks2", 10, factory), | |
FakeSchemaParserFactory.CreateSimpleKeyspace("ks3", 5, factory), | |
FakeSchemaParserFactory.CreateNetworkTopologyKeyspace("ks4", new Dictionary<string, string> {{"dc1", "2"}, {"dc2", "2"}}, factory), | |
FakeSchemaParserFactory.CreateNetworkTopologyKeyspace("ks5", new Dictionary<string, string> {{"dc1", "1"}, {"dc2", "2"}}, factory), | |
FakeSchemaParserFactory.CreateNetworkTopologyKeyspace("ks6", new Dictionary<string, string> {{"dc1", "1"}}, factory), | |
// duplicate configurations | |
FakeSchemaParserFactory.CreateNetworkTopologyKeyspace("ks7", new Dictionary<string, string> {{"dc1", "2"}, {"dc2", "2"}}, factory), | |
FakeSchemaParserFactory.CreateNetworkTopologyKeyspace("ks8", new Dictionary<string, string> {{"dc1", "1"}}, factory), | |
FakeSchemaParserFactory.CreateNetworkTopologyKeyspace("ks9", new Dictionary<string, string> {{"dc1", "1"}, {"dc2", "2"}}, factory), | |
FakeSchemaParserFactory.CreateSimpleKeyspace("ks10", 10, factory), | |
FakeSchemaParserFactory.CreateSimpleKeyspace("ks11", 2, factory) | |
}; | |
var tokenMap = TokenMap.Build("Murmur3Partitioner", hosts, keyspaces); | |
var proxyStrategies = keyspaces.Select(k => (ProxyReplicationStrategy)k.Strategy).ToList(); | |
Assert.AreEqual(6, proxyStrategies.Count(strategy => strategy.Calls > 0)); | |
AssertOnlyOneStrategyIsCalled(proxyStrategies, 0, 10); | |
AssertOnlyOneStrategyIsCalled(proxyStrategies, 1, 9); | |
AssertOnlyOneStrategyIsCalled(proxyStrategies, 2); | |
AssertOnlyOneStrategyIsCalled(proxyStrategies, 3, 6); | |
AssertOnlyOneStrategyIsCalled(proxyStrategies, 4, 8); | |
AssertOnlyOneStrategyIsCalled(proxyStrategies, 5, 7); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment