private void SomeActionThatRequiresAuthentication(string username, string password, ILog logger = null) { var settings = node.CreateSettings(); settings.Credentials = new Credentials(username, password); using (var cluster = new CassandraCluster(settings, logger ?? new SilentLog())) cluster.RetrieveClusterConnection().RetrieveKeyspaces(); }
public void SetUp() { cluster = new CassandraCluster(SingleCassandraNodeSetUpFixture.Node.CreateSettings(), Logger.Instance); var clusterConnection = cluster.RetrieveClusterConnection(); var keyspaceName = TestSchemaUtils.GetRandomKeyspaceName(); var createdKeyspace = new Keyspace { Name = keyspaceName, ReplicationStrategy = SimpleReplicationStrategy.Create(1) }; clusterConnection.AddKeyspace(createdKeyspace); keyspaceConnection = cluster.RetrieveKeyspaceConnection(keyspaceName); }
// todo (a.dobrynin, 08.02.2022): replace with depends_on.condition.service_healthy when appveyor updates docker compose to 1.29+ on windows hosts private static ICassandraCluster TryConnectToCassandra(string cassandraAddress, ILog log) { var timeout = TimeSpan.FromMinutes(2); var interval = TimeSpan.FromSeconds(10); var sw = Stopwatch.StartNew(); while (sw.Elapsed < timeout) { try { var localEndPoint = new IPEndPoint(GetIpV4Address(cassandraAddress), 9160); var cassandraClusterSettings = new CassandraClusterSettings { Endpoints = new[] { localEndPoint }, EndpointForFierceCommands = localEndPoint, ReadConsistencyLevel = ConsistencyLevel.QUORUM, WriteConsistencyLevel = ConsistencyLevel.QUORUM, Attempts = 5, Timeout = 6000, FierceTimeout = 6000, ConnectionIdleTimeout = TimeSpan.FromMinutes(10), }; ICassandraCluster cassandraCluster = new CassandraCluster(cassandraClusterSettings, log); _ = cassandraCluster.RetrieveClusterConnection().DescribeVersion(); log.Info($"Successfully connected to cassandra after {sw.Elapsed.TotalSeconds} seconds"); return(cassandraCluster); } catch (Exception e) { log.Info(e, "Connection attempt failed"); } Thread.Sleep(interval); } throw new Exception($"Failed to wait for local cassandra node to start in {timeout.TotalSeconds} seconds"); }