public async Task Should_KeepSendingSystemPeersV2Queries_When_ItDoesNotFail() { var fakeRequestHandler = CreateFakeMetadataRequestHandler(withPeersV2: true); var config = new TestConfigurationBuilder { MetadataRequestHandler = fakeRequestHandler }.Build(); _metadata = new Metadata(config); var topologyRefresher = new TopologyRefresher(_metadata, config); var connection = Mock.Of <IConnection>(); await topologyRefresher .RefreshNodeListAsync( new FakeConnectionEndPoint("127.0.0.1", 9042), connection, _serializer).ConfigureAwait(false); Assert.AreEqual(2, fakeRequestHandler.Requests.Count); Assert.AreEqual(TopologyRefresherTests.LocalQuery, fakeRequestHandler.Requests.First().CqlQuery); Assert.AreEqual(TopologyRefresherTests.PeersV2Query, fakeRequestHandler.Requests.ElementAt(1).CqlQuery); await topologyRefresher .RefreshNodeListAsync( new FakeConnectionEndPoint("127.0.0.1", 9042), connection, _serializer).ConfigureAwait(false); Assert.AreEqual(4, fakeRequestHandler.Requests.Count); Assert.AreEqual(TopologyRefresherTests.LocalQuery, fakeRequestHandler.Requests.ElementAt(2).CqlQuery); Assert.AreEqual(TopologyRefresherTests.PeersV2Query, fakeRequestHandler.Requests.ElementAt(3).CqlQuery); }
public async Task Should_SendPeersV1OnlyAfterPeersV2Fails() { var fakeRequestHandler = CreateFakeMetadataRequestHandler(); var config = new TestConfigurationBuilder { MetadataRequestHandler = fakeRequestHandler }.Build(); _metadata = new Metadata(config); var topologyRefresher = new TopologyRefresher(_metadata, config); var connection = Mock.Of <IConnection>(); await topologyRefresher .RefreshNodeListAsync( new FakeConnectionEndPoint("127.0.0.1", 9042), connection, _serializer).ConfigureAwait(false); Assert.AreEqual(3, fakeRequestHandler.Requests.Count); Assert.AreEqual(TopologyRefresherTests.LocalQuery, fakeRequestHandler.Requests.First().CqlQuery); Assert.AreEqual(TopologyRefresherTests.PeersV2Query, fakeRequestHandler.Requests.ElementAt(1).CqlQuery); Assert.AreEqual(TopologyRefresherTests.PeersQuery, fakeRequestHandler.Requests.ElementAt(2).CqlQuery); await topologyRefresher .RefreshNodeListAsync( new FakeConnectionEndPoint("127.0.0.1", 9042), connection, _serializer).ConfigureAwait(false); Assert.AreEqual(5, fakeRequestHandler.Requests.Count); Assert.AreEqual(TopologyRefresherTests.LocalQuery, fakeRequestHandler.Requests.ElementAt(3).CqlQuery); Assert.AreEqual(TopologyRefresherTests.PeersQuery, fakeRequestHandler.Requests.ElementAt(4).CqlQuery); }
/// <inheritdoc /> public IPEndPoint GetOrParseHostIpEndPoint(IRow row, IAddressTranslator translator, int port) { if (_hostIpEndPoint != null) { return(_hostIpEndPoint); } var ipEndPoint = TopologyRefresher.GetAddressForLocalOrPeerHost(row, translator, port); if (ipEndPoint == null) { throw new DriverInternalError("Could not parse the node's ip address from system tables."); } return(ipEndPoint); }
public void Should_SendSystemLocalAndPeersQueries() { var fakeRequestHandler = CreateFakeMetadataRequestHandler(); var config = new TestConfigurationBuilder { MetadataRequestHandler = fakeRequestHandler }.Build(); _metadata = new Metadata(config); var topologyRefresher = new TopologyRefresher(_metadata, config); var connection = Mock.Of <IConnection>(); var _ = topologyRefresher.RefreshNodeListAsync(new FakeConnectionEndPoint("127.0.0.1", 9042), connection, ProtocolVersion.MaxSupported); Assert.AreEqual(TopologyRefresherTests.LocalQuery, fakeRequestHandler.Requests.First().CqlQuery); Assert.AreEqual(TopologyRefresherTests.PeersQuery, fakeRequestHandler.Requests.Last().CqlQuery); }
public async Task 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 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 } } }); var requestHandler = CreateFakeMetadataRequestHandler(peersRows: rows); var config = new TestConfigurationBuilder { ProtocolOptions = new ProtocolOptions(portNumber), AddressTranslator = translatorMock.Object, StartupOptionsFactory = Mock.Of <IStartupOptionsFactory>(), MetadataRequestHandler = requestHandler }.Build(); var topologyRefresher = new TopologyRefresher(metadata, config); await topologyRefresher.RefreshNodeListAsync( new FakeConnectionEndPoint("127.0.0.1", 9042), Mock.Of <IConnection>(), _serializer) .ConfigureAwait(false); 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); }