public void KetamaDeadNodeDetectionTest1() { var locator = new KetamaLocator(); locator.Initialize(_nodes); // All nodes but one are dead for (int i = 1; i < _nodes.Count; ++i) { (_nodes[i] as NodeMock).IsDead = true; } for (int i = 0; i < _nodes.Count; ++i) { Assert.IsNotEmpty(locator.Locate(i.ToString()), "KetamaLocator found no node, but at least one is alive"); var chosenNode = locator.Locate(i.ToString()).First <IMemcacheNode>(); Assert.IsFalse(chosenNode.IsDead, "KetamaLocator returned a dead node"); } // Now all nodes are dead (_nodes[0] as NodeMock).IsDead = true; for (int i = 0; i < _nodes.Count; ++i) { CollectionAssert.IsEmpty(locator.Locate(i.ToString()), "KetamaLocator found a node when all are dead"); } for (int i = 0; i < _nodes.Count; ++i) { (_nodes[i] as NodeMock).IsDead = false; } }
public void KetamaDeadNodeDetectionTest2() { var locator = new KetamaLocator(); locator.Initialize(_nodes); for (int i = 0; i < _nodes.Count; ++i) { int j; for (j = 0; j < _nodes.Count; ++j) { (_nodes[j] as NodeMock).IsDead = false; } j = 0; HashSet <IMemcacheNode> nodesSet = new HashSet <IMemcacheNode>(); foreach (var chosenNode in locator.Locate(i.ToString())) { nodesSet.Add(chosenNode); Assert.IsFalse(chosenNode.IsDead, "KetamaLocator returned a dead node"); // Kill one of the nodes (_nodes[j++] as NodeMock).IsDead = true; } Assert.AreNotEqual(0, nodesSet.Count, "KetamaLocator returned no node"); } for (int i = 0; i < _nodes.Count; ++i) { (_nodes[i] as NodeMock).IsDead = false; } }
public void KetamaDeadNodeDetectionTest2() { var locator = new KetamaLocator(); locator.Initialize(_nodes); for (int i = 0; i < _nodes.Count; ++i) { foreach (IMemcacheNode node in _nodes) (node as NodeMock).IsDead = false; var keyAsBytes = i.ToString().Select(c => (byte)c).ToArray(); var locations = locator.Locate(new RequestKeyWrapper(keyAsBytes)); var j = 0; var nodesSet = new HashSet<IMemcacheNode>(); foreach (var chosenNode in locations) { nodesSet.Add(chosenNode); Assert.IsFalse(chosenNode.IsDead, "KetamaLocator returned a dead node"); // Kill one of the nodes (_nodes[j++] as NodeMock).IsDead = true; } Assert.AreNotEqual(0, nodesSet.Count, "KetamaLocator returned no node"); } foreach (var node in _nodes) (node as NodeMock).IsDead = false; }
public void KetamaDeadNodeDetectionTest2() { var locator = new KetamaLocator(); locator.Initialize(_nodes); for (int i = 0; i < _nodes.Count; ++i) { foreach (IMemcacheNode node in _nodes) { (node as NodeMock).IsDead = false; } var keyAsBytes = i.ToString().Select(c => (byte)c).ToArray(); var locations = locator.Locate(new RequestKeyWrapper(keyAsBytes)); var j = 0; var nodesSet = new HashSet <IMemcacheNode>(); foreach (var chosenNode in locations) { nodesSet.Add(chosenNode); Assert.IsFalse(chosenNode.IsDead, "KetamaLocator returned a dead node"); // Kill one of the nodes (_nodes[j++] as NodeMock).IsDead = true; } Assert.AreNotEqual(0, nodesSet.Count, "KetamaLocator returned no node"); } foreach (var node in _nodes) { (node as NodeMock).IsDead = false; } }
public void KetamaDeadNodeDetectionTest1() { var locator = new KetamaLocator(); locator.Initialize(_nodes); // All nodes but one are dead for (int i = 1; i < _nodes.Count; ++i) (_nodes[i] as NodeMock).IsDead = true; for (int i = 0; i < _nodes.Count; ++i) { var keyAsBytes = i.ToString().Select(c => (byte)c).ToArray(); var locations = locator.Locate(new RequestKeyWrapper(keyAsBytes)); Assert.IsNotEmpty(locations, "KetamaLocator found no node, but at least one is alive"); var chosenNode = locations.First<IMemcacheNode>(); Assert.IsFalse(chosenNode.IsDead, "KetamaLocator returned a dead node"); } // Now all nodes are dead (_nodes[0] as NodeMock).IsDead = true; for (int i = 0; i < _nodes.Count; ++i) { var keyAsBytes = i.ToString().Select(c => (byte)c).ToArray(); CollectionAssert.IsEmpty(locator.Locate(new RequestKeyWrapper(keyAsBytes)), "KetamaLocator found a node when all are dead"); } foreach (var node in _nodes) (node as NodeMock).IsDead = false; }
public void KetamaTest() { var locator = new KetamaLocator(); locator.Initialize(_nodes); // Test several keys, and iterate through each key several times for (int idx = 0; idx < _nodes.Count; ++idx) { var nodeSet = new HashSet <IMemcacheNode>(); int nodeCount = 0; foreach (var chosenNode in locator.Locate(idx.ToString())) { Assert.IsNotNull(chosenNode, "KetamaLocator found no node"); nodeSet.Add(chosenNode); nodeCount++; Assert.AreEqual(nodeCount, nodeSet.Count, "For a given key, all nodes returned by the locator should be distinct"); } Assert.AreEqual(_nodes.Count, nodeCount, "KetamaLocator did not return the maximum number of nodes available"); } }
public void KetamaDeadNodeDetectionTest1() { var locator = new KetamaLocator(); locator.Initialize(_nodes); // All nodes but one are dead for (int i = 1; i < _nodes.Count; ++i) { (_nodes[i] as NodeMock).IsDead = true; } for (int i = 0; i < _nodes.Count; ++i) { var keyAsBytes = i.ToString().Select(c => (byte)c).ToArray(); var locations = locator.Locate(new RequestKeyWrapper(keyAsBytes)); Assert.IsNotEmpty(locations, "KetamaLocator found no node, but at least one is alive"); var chosenNode = locations.First <IMemcacheNode>(); Assert.IsFalse(chosenNode.IsDead, "KetamaLocator returned a dead node"); } // Now all nodes are dead (_nodes[0] as NodeMock).IsDead = true; for (int i = 0; i < _nodes.Count; ++i) { var keyAsBytes = i.ToString().Select(c => (byte)c).ToArray(); CollectionAssert.IsEmpty(locator.Locate(new RequestKeyWrapper(keyAsBytes)), "KetamaLocator found a node when all are dead"); } foreach (var node in _nodes) { (node as NodeMock).IsDead = false; } }
public void KetamaTest() { var locator = new KetamaLocator(); locator.Initialize(_nodes); // Test several keys, and iterate through each key several times for (int idx = 0; idx < _nodes.Count; ++idx) { var nodeSet = new HashSet<IMemcacheNode>(); int nodeCount = 0; var keyAsBytes = idx.ToString().Select(c => (byte)c).ToArray(); foreach (var chosenNode in locator.Locate(new RequestKeyWrapper(keyAsBytes))) { Assert.IsNotNull(chosenNode, "KetamaLocator found no node"); nodeSet.Add(chosenNode); nodeCount++; Assert.AreEqual(nodeCount, nodeSet.Count, "For a given key, all nodes returned by the locator should be distinct"); } Assert.AreEqual(_nodes.Count, nodeCount, "KetamaLocator did not return the maximum number of nodes available"); } }
public void TestLocatorOneNodeIsDead() { INodeLocator ketama = new KetamaLocator(); // Kill node 10.0.1.7:11211 by removing it from the list. _test08Nodes.RemoveAt(6); ketama.Initialize(_test08Nodes); foreach (var tuple in _expected08) { var keyAsBytes = Encoding.UTF8.GetBytes(tuple[0]); var locations = ketama.Locate(new RequestKeyWrapper(keyAsBytes)); Assert.IsNotEmpty(locations, "KetamaLocator found no node"); var nodeEnumerator = locations.GetEnumerator(); int expectedIdx = 0; foreach(var _ in Enumerable.Range(0,2)) { nodeEnumerator.MoveNext(); var node = nodeEnumerator.Current; Assert.IsNotNull(node, "Null node"); if (tuple[++expectedIdx] == "10.0.1.7:11211") expectedIdx++; Assert.AreEqual(tuple[expectedIdx], node.EndPoint.ToString(), "Unexpected node returned by the Ketama locator. Key: {0}", tuple[0]); } } }
private void RunTestLocatorAllNodesAlive(List<IMemcacheNode> nodes, IEnumerable<string[]> expected) { INodeLocator ketama = new KetamaLocator(); ketama.Initialize(nodes); foreach (var tuple in expected) { var keyAsBytes = Encoding.UTF8.GetBytes(tuple[0]); var locations = ketama.Locate(new RequestKeyWrapper(keyAsBytes)); Assert.IsNotEmpty(locations, "KetamaLocator found no node"); var nodeEnumerator = locations.GetEnumerator(); int idx = 1; while (idx < tuple.Length) { nodeEnumerator.MoveNext(); var node = nodeEnumerator.Current; Assert.AreEqual(tuple[idx++], node.EndPoint.ToString(), "Unexpected node returned by the Ketama locator. Key: {0}", tuple[0]); } } }