Ejemplo n.º 1
0
        public void ConfirmHashingToCorrectValues()
        {
            string servers = "10.10.10.10:6379,20.20.20.20:6379,30.30.30.30:6379,40.40.40.40:6379";
            KetamaContinuum ketamaContinuum = new KetamaContinuum(servers);
            KetamaHashingAlgorithm_FNV1a32Bit ketamaHashingAlgorithm = new KetamaHashingAlgorithm_FNV1a32Bit();

            string key = "ThisIsTheBestHash!!!!";
            string server = ketamaContinuum.FindServerForKey(key);
            uint hash = ketamaHashingAlgorithm.GetHashFromString(key);
            //Console.WriteLine("Hash value for {0} is: {1}, which is found on server: {2}", key, hash, server);
            Assert.AreEqual((uint)hash, (uint)1916906286);
            hash = ketamaHashingAlgorithm.GetHashFromString(key);
            Assert.AreEqual((uint)hash, (uint)1916906286); //Doing it twice to ensure hashing the same string multiple times isn't coming up with different results

            key = "thisistheWORSTHASH:( :( :(";
            server = ketamaContinuum.FindServerForKey(key);
            hash = ketamaHashingAlgorithm.GetHashFromString(key);
            //Console.WriteLine("Hash value for {0} is: {1}, which is found on server: {2}", key, hash, server);
            Assert.AreEqual((uint)hash, (uint)3993883897);
            hash = ketamaHashingAlgorithm.GetHashFromString(key);
            Assert.AreEqual((uint)hash, (uint)3993883897); //Doing it twice to ensure hashing the same string multiple times isn't coming up with different results

            key = "Stevieweevie";
            server = ketamaContinuum.FindServerForKey(key);
            hash = ketamaHashingAlgorithm.GetHashFromString(key);
            //Console.WriteLine("Hash value for {0} is: {1}, which is found on server: {2}", key, hash, server);
            Assert.AreEqual((uint)hash, (uint)3692210458);
            hash = ketamaHashingAlgorithm.GetHashFromString(key);
            Assert.AreEqual((uint)hash, (uint)3692210458); //Doing it twice to ensure hashing the same string multiple times isn't coming up with different results
        }
Ejemplo n.º 2
0
        public void HashComparisonTest()
        {
            string servers = "";

            using (StreamReader reader = new StreamReader("../../../../ketama.servers"))
            {
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    servers = string.Concat(servers, ",", line);
                }

                servers = servers.Substring(1); //Remove the comma at the head of the string, a side effect of the concatination
            }

            if (servers == "")
            {
                Assert.Fail("No servers provided.");
            }

            KetamaContinuum ketamaContinuum = new KetamaContinuum(servers);
            List<uint> hashes = ketamaContinuum.GetAllHashes();

            string key;
            uint hash;
            KetamaHashingAlgorithm_FNV1a32Bit ketamaHashingAlgorithm = new KetamaHashingAlgorithm_FNV1a32Bit();

            using (StreamWriter writer = new StreamWriter("../../../../csharp_test.out"))
            {
                for (int i = 0; i < 100; i++)
                {
                    key = "aab" + i.ToString();

                    hash = (uint)ketamaHashingAlgorithm.GetHashFromString(key);

                    Debug.WriteLine(ketamaContinuum.FindServerForKey(key) + " - " + key);
                    writer.WriteLine(ketamaContinuum.FindServerForKey(key) + " - " + key);
                }
            }
        }