public void EmptyConsistentHashToString() { KevinConsistentHash ch = new KevinConsistentHash(maxNumServers: 100, numReplicasPerServer: 10); Console.WriteLine(ch.ToString()); Assert.AreEqual(ch.GetNumServers(), 0); Assert.AreEqual(ch.GetNumClients(), 0); }
public void FiveServersGetServerForClient() { KevinConsistentHash ch = new KevinConsistentHash(maxNumServers: 100, numReplicasPerServer: 2); List <int> serverIds = new List <int>() { 0, 1, 2, 3, 4 }; serverIds.ForEach(serverId => ch.AddServer(serverId)); Guid clientId = Guid.NewGuid(); int assignedServerId = ch.GetServerForClient(clientId); Assert.AreEqual(ch.GetNumServers(), serverIds.Count); Assert.AreEqual(ch.GetNumClients(), 1); Console.WriteLine( string.Format("ClientId: {0} Assigned Server Id: {1}", clientId, assignedServerId)); Console.WriteLine(ch.ToString()); }
public void FiveServersGetServerForManyClients() { KevinConsistentHash ch = new KevinConsistentHash(maxNumServers: 100, numReplicasPerServer: 2); List <int> serverIds = new List <int>() { 0, 1, 2, 3, 4 }; serverIds.ForEach(serverId => ch.AddServer(serverId)); int numClients = 100; for (int i = 0; i < numClients; i++) { ch.GetServerForClient(Guid.NewGuid()); } Assert.AreEqual(ch.GetNumServers(), serverIds.Count); Assert.AreEqual(ch.GetNumClients(), numClients); Console.WriteLine(ch.ToString()); }