/// <summary> /// Initializes the strategy with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public ExclusiveConnectionStrategy(Ring nodes, ClusterConfig config) { _nodes = nodes; _config = config; _connections = new ConcurrentStack<Connection>(); _rndGen = new Random((int)DateTime.Now.Ticks); }
/// <summary> /// Initializes a new instance of the <see cref="Cluster" /> class. /// </summary> /// <param name="config"> The config. </param> public Cluster(ClusterConfig config) { //store config _config = config; _loggerManager = new LoggerManager(_config.LoggerFactory, _config.LogLevel); }
/// <summary> /// Initializes a new instance of the <see cref="CqlConnection" /> class. /// </summary> /// <param name="config"> The config. </param> public CqlConnection(ClusterConfig config) { //add the config to the list, or get an existing instance with the same parameters ClusterConfig c = Configs.GetOrAdd(config.ToString(), config); //get the cluster based on the instance Cluster cluster = Clusters.GetOrAdd(c, conf => new Cluster(conf)); //set the connection provider to the found cluster _cluster = cluster; }
/// <summary> /// Initializes a new instance of the <see cref="CqlConnection" /> class. /// </summary> /// <param name="connectionString"> The connection string. </param> public CqlConnection(string connectionString) { //get the cluster config, or add one if none exists ClusterConfig config = Configs.GetOrAdd(connectionString, connString => { //create new config var cc = new ClusterConfig(connString); //get if a similar already exists, or add it otherwise return Configs.GetOrAdd(cc.ToString(), cc); }); //fetch the cluster, or create one Cluster cluster = Clusters.GetOrAdd(config, conf => new Cluster(conf)); //set the connection provider to the cluster _cluster = cluster; }
public async Task BalancedStrategyManyRequestLowMaxConnections() { using (ShimsContext.Create()) { //create cluster var config = new ClusterConfig { NewConnectionTreshold = 5, MaxConnections = 6 }; var cluster = new Cluster(config); //create nodes var n1 = new Node(IPAddress.Parse("127.0.0.1"), cluster); var n2 = new Node(IPAddress.Parse("127.0.0.2"), cluster); var n3 = new Node(IPAddress.Parse("127.0.0.3"), cluster); var n4 = new Node(IPAddress.Parse("127.0.0.4"), cluster); var nodes = new Ring(new List<Node> { n1, n2, n3, n4 }, "RandomPartitioner"); ShimAllConnections(); var logger = cluster.LoggerManager.GetLogger("BalancedStrategyManyRequestLowMaxConnectionsTest"); IConnectionStrategy strategy = new BalancedConnectionStrategy(nodes, config); const int nr = 80; for (int i = 0; i < nr; i++) { Connection connection; using (logger.ThreadBinding()) connection = strategy.GetOrCreateConnection(PartitionKey.None); await connection.SendRequestAsync(new QueryFrame("", CqlConsistency.Any), logger, 10); } Assert.AreEqual(6, nodes.Sum(nd => nd.ConnectionCount)); Assert.IsTrue(nodes.All(n => n.Load == 80 * 10 / 4)); } }
/// <summary> /// Initializes the strategy with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public BalancedConnectionStrategy(Ring nodes, ClusterConfig config) { _nodes = nodes; _config = config; _connectionCount = 0; }
/// <summary> /// Initializes the strategies with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public RandomConnectionStrategy(Ring nodes, ClusterConfig config) { _nodes = nodes; _config = config; _rnd = new Random((int)DateTime.Now.Ticks); }
/// <summary> /// Initializes the strategy with the specified nodes and cluster configuration /// </summary> /// <param name="nodes"> The nodes. </param> /// <param name="config"> The config. </param> public PartitionAwareConnectionStrategy(Ring nodes, ClusterConfig config) { _nodes = nodes; _baseStrategy = new BalancedConnectionStrategy(nodes, config); }