本文整理汇总了C#中Metadata.AllHosts方法的典型用法代码示例。如果您正苦于以下问题:C# Metadata.AllHosts方法的具体用法?C# Metadata.AllHosts怎么用?C# Metadata.AllHosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Metadata
的用法示例。
在下文中一共展示了Metadata.AllHosts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePeersInfoModifiesPool
public void UpdatePeersInfoModifiesPool()
{
var metadata = new Metadata(new Configuration());
var cc = NewInstance(metadata);
cc.Host = TestHelper.CreateHost("127.0.0.1");
metadata.AddHost(cc.Host.Address);
var hostAddress2 = IPAddress.Parse("127.0.0.2");
var hostAddress3 = IPAddress.Parse("127.0.0.3");
var rows = TestHelper.CreateRows(new List<Dictionary<string, object>>
{
new Dictionary<string, object>{{"rpc_address", hostAddress2}, {"peer", null}, { "data_center", "ut-dc2" }, { "rack", "ut-rack2" }, {"tokens", null}},
new Dictionary<string, object>{{"rpc_address", IPAddress.Parse("0.0.0.0")}, {"peer", hostAddress3}, { "data_center", "ut-dc3" }, { "rack", "ut-rack3" }, {"tokens", null}}
});
cc.UpdatePeersInfo(rows);
Assert.AreEqual(3, metadata.AllHosts().Count);
//using rpc_address
var host2 = metadata.GetHost(new IPEndPoint(hostAddress2, ProtocolOptions.DefaultPort));
Assert.NotNull(host2);
Assert.AreEqual("ut-dc2", host2.Datacenter);
Assert.AreEqual("ut-rack2", host2.Rack);
//with rpc_address = 0.0.0.0, use peer
var host3 = metadata.GetHost(new IPEndPoint(hostAddress3, ProtocolOptions.DefaultPort));
Assert.NotNull(host3);
Assert.AreEqual("ut-dc3", host3.Datacenter);
Assert.AreEqual("ut-rack3", host3.Rack);
}
示例2: UpdatePeersInfoWithNullRpcIgnores
public void UpdatePeersInfoWithNullRpcIgnores()
{
var metadata = new Metadata(new Configuration());
var cc = NewInstance(metadata);
cc.Host = TestHelper.CreateHost("127.0.0.1");
metadata.AddHost(cc.Host.Address);
var rows = TestHelper.CreateRows(new List<Dictionary<string, object>>
{
new Dictionary<string, object>{{"rpc_address", null}, {"peer", null}, { "data_center", "ut-dc2" }, { "rack", "ut-rack" }, {"tokens", null}}
});
cc.UpdatePeersInfo(rows);
//Only local host present
Assert.AreEqual(1, metadata.AllHosts().Count);
}
示例3: UpdatePeersInfoUsesAddressTranslator
public void UpdatePeersInfoUsesAddressTranslator()
{
var invokedEndPoints = new List<IPEndPoint>();
var translatorMock = new Mock<IAddressTranslator>(MockBehavior.Strict);
translatorMock
.Setup(t => t.Translate(It.IsAny<IPEndPoint>()))
.Callback<IPEndPoint>(invokedEndPoints.Add)
.Returns<IPEndPoint>(e => e);
const int portNumber = 9999;
var metadata = new Metadata(new Configuration());
var config = new Configuration(new Policies(),
new ProtocolOptions(portNumber),
null,
new SocketOptions(),
new ClientOptions(),
NoneAuthProvider.Instance,
null,
new QueryOptions(),
translatorMock.Object);
var cc = NewInstance(config, metadata);
cc.Host = TestHelper.CreateHost("127.0.0.1");
metadata.AddHost(cc.Host.Address);
var hostAddress2 = IPAddress.Parse("127.0.0.2");
var hostAddress3 = IPAddress.Parse("127.0.0.3");
var rows = TestHelper.CreateRows(new List<Dictionary<string, object>>
{
new Dictionary<string, object>{{"rpc_address", hostAddress2}, {"peer", null}, { "data_center", "ut-dc2" }, { "rack", "ut-rack2" }, {"tokens", null}},
new Dictionary<string, object>{{"rpc_address", IPAddress.Parse("0.0.0.0")}, {"peer", hostAddress3}, { "data_center", "ut-dc3" }, { "rack", "ut-rack3" }, {"tokens", null}}
});
cc.UpdatePeersInfo(rows);
Assert.AreEqual(3, metadata.AllHosts().Count);
Assert.AreEqual(2, invokedEndPoints.Count);
Assert.AreEqual(hostAddress2, invokedEndPoints[0].Address);
Assert.AreEqual(portNumber, invokedEndPoints[0].Port);
Assert.AreEqual(hostAddress3, invokedEndPoints[1].Address);
Assert.AreEqual(portNumber, invokedEndPoints[1].Port);
}