本文整理汇总了C#中Metadata.AddHost方法的典型用法代码示例。如果您正苦于以下问题:C# Metadata.AddHost方法的具体用法?C# Metadata.AddHost怎么用?C# Metadata.AddHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Metadata
的用法示例。
在下文中一共展示了Metadata.AddHost方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_Schedule_Reconnections_In_The_Background
public void Should_Schedule_Reconnections_In_The_Background()
{
var lbp = new RoundRobinPolicy();
var config = new Configuration(
new Cassandra.Policies(lbp, new ConstantReconnectionPolicy(1000), FallthroughRetryPolicy.Instance),
new ProtocolOptions(),
null,
new SocketOptions(),
new ClientOptions(),
NoneAuthProvider.Instance,
null,
new QueryOptions(),
new DefaultAddressTranslator());
var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
var metadata = new Metadata(config);
metadata.AddHost(new IPEndPoint(IPAddress.Parse(testCluster.InitialContactPoint), ProtocolOptions.DefaultPort));
var clusterMock = new Mock<ICluster>();
clusterMock.Setup(c => c.AllHosts()).Returns(() => metadata.Hosts.ToCollection());
lbp.Initialize(clusterMock.Object);
using (var cc = NewInstance(testCluster, config, metadata))
{
cc.Init();
var host = metadata.Hosts.First();
testCluster.Stop(1);
host.SetDown();
Thread.Sleep(2000);
Assert.False(host.IsUp);
testCluster.Start(1);
host.BringUpIfDown();
//Should reconnect using timer
Thread.Sleep(5000);
Assert.DoesNotThrow(() => cc.Query("SELECT key FROM system.local", false));
}
testCluster.ShutDown();
}
示例2: 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);
}
示例3: UpdatePeersInfoWithNullRpcIgnores
public void UpdatePeersInfoWithNullRpcIgnores()
{
var metadata = new Metadata(new Configuration());
var cc = new ControlConnection(GetCluster(), 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);
}
示例4: NewInstance
private ControlConnection NewInstance(ITestCluster testCluster, Configuration config = null, Metadata metadata = null)
{
var version = GetProtocolVersion();
if (config == null)
{
config = new Configuration();
}
if (metadata == null)
{
metadata = new Metadata(config);
metadata.AddHost(new IPEndPoint(IPAddress.Parse(testCluster.InitialContactPoint), ProtocolOptions.DefaultPort));
}
var cc = new ControlConnection(version, config, metadata);
metadata.ControlConnection = cc;
return cc;
}
示例5: NewInstance
private ControlConnection NewInstance(byte version = 0, Configuration config = null, Metadata metadata = null)
{
if (version == 0)
{
version = (byte) Cluster.MaxProtocolVersion;
}
if (config == null)
{
config = new Configuration();
config.BufferPool = new Microsoft.IO.RecyclableMemoryStreamManager();
}
if (metadata == null)
{
metadata = new Metadata(config);
metadata.AddHost(new IPEndPoint(IPAddress.Parse(_testCluster.InitialContactPoint), ProtocolOptions.DefaultPort));
}
var cc = new ControlConnection(version, config, metadata);
metadata.ControlConnection = cc;
return cc;
}
示例6: 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);
}
示例7: Should_Reconnect_Once_If_Called_Serially
public void Should_Reconnect_Once_If_Called_Serially()
{
var lbp = new RoundRobinPolicy();
var config = new Configuration(
new Cassandra.Policies(lbp, new ConstantReconnectionPolicy(1000), FallthroughRetryPolicy.Instance),
new ProtocolOptions(),
null,
new SocketOptions(),
new ClientOptions(),
NoneAuthProvider.Instance,
null,
new QueryOptions(),
new DefaultAddressTranslator());
config.BufferPool = new Microsoft.IO.RecyclableMemoryStreamManager();
var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
var metadata = new Metadata(config);
metadata.AddHost(new IPEndPoint(IPAddress.Parse(testCluster.InitialContactPoint), ProtocolOptions.DefaultPort));
var clusterMock = new Mock<ICluster>();
clusterMock.Setup(c => c.AllHosts()).Returns(() => metadata.Hosts.ToCollection());
lbp.Initialize(clusterMock.Object);
using (var cc = NewInstance(testCluster, config))
{
cc.Init();
testCluster.Stop(1);
var t1 = cc.Reconnect();
var t2 = cc.Reconnect();
var t3 = cc.Reconnect();
var t4 = cc.Reconnect();
Assert.AreEqual(t1, t2);
Assert.AreEqual(t1, t3);
Assert.AreEqual(t1, t4);
var ex = Assert.Throws<NoHostAvailableException>(() => TaskHelper.WaitToComplete(t1));
Assert.AreEqual(1, ex.Errors.Count);
Assert.IsInstanceOf<SocketException>(ex.Errors.Values.First());
}
testCluster.ShutDown();
}
示例8: Should_Reconnect_After_Several_Failed_Attempts
public void Should_Reconnect_After_Several_Failed_Attempts()
{
var lbp = new RoundRobinPolicy();
var config = new Configuration(
new Cassandra.Policies(lbp, new ConstantReconnectionPolicy(1000), FallthroughRetryPolicy.Instance),
new ProtocolOptions(),
null,
new SocketOptions(),
new ClientOptions(),
NoneAuthProvider.Instance,
null,
new QueryOptions(),
new DefaultAddressTranslator());
var testCluster = TestClusterManager.GetNonShareableTestCluster(1, DefaultMaxClusterCreateRetries, true, false);
var metadata = new Metadata(config);
metadata.AddHost(new IPEndPoint(IPAddress.Parse(testCluster.InitialContactPoint), ProtocolOptions.DefaultPort));
var clusterMock = new Mock<ICluster>();
clusterMock.Setup(c => c.AllHosts()).Returns(() => metadata.Hosts.ToCollection());
lbp.Initialize(clusterMock.Object);
using (var cc = NewInstance(testCluster, config))
{
cc.Init();
testCluster.Stop(1);
Assert.Throws<NoHostAvailableException>(() => TaskHelper.WaitToComplete(cc.Reconnect()));
Assert.Throws<NoHostAvailableException>(() => TaskHelper.WaitToComplete(cc.Reconnect()));
Assert.Throws<NoHostAvailableException>(() => TaskHelper.WaitToComplete(cc.Reconnect()));
Assert.Throws<NoHostAvailableException>(() => TaskHelper.WaitToComplete(cc.Reconnect()));
testCluster.Start(1);
Assert.DoesNotThrow(() => TaskHelper.WaitToComplete(cc.Reconnect()));
}
testCluster.ShutDown();
}