private ISession GetSession(
     ISpeculativeExecutionPolicy speculativeExecutionPolicy = null, bool warmup = true,
     ILoadBalancingPolicy lbp = null, PoolingOptions pooling = null)
 {
     if (_testCluster == null)
     {
         throw new Exception("Test cluster not initialized");
     }
     var builder = Cluster.Builder()
         .AddContactPoint(_testCluster.InitialContactPoint)
         .WithSpeculativeExecutionPolicy(speculativeExecutionPolicy)
         .WithLoadBalancingPolicy(lbp ?? Cassandra.Policies.DefaultLoadBalancingPolicy)
         .WithRetryPolicy(DowngradingConsistencyRetryPolicy.Instance)
         .WithSocketOptions(new SocketOptions().SetReadTimeoutMillis(0));
     if (pooling != null)
     {
         builder.WithPoolingOptions(pooling);
     }
     var cluster = builder.Build();
     _clusters.Add(cluster);
     var session = cluster.Connect();
     if (warmup)
     {
         TestHelper.ParallelInvoke(() => session.Execute(QueryLocal), 10);
     }
     _addressNode1 = IPAddress.Parse(_testCluster.ClusterIpPrefix + "1");
     return session;
 }
 /// <summary>
 /// Creates a new instance of <see cref="DseLoadBalancingPolicy"/> wrapping the provided child policy.
 /// </summary>
 public DseLoadBalancingPolicy(ILoadBalancingPolicy childPolicy)
 {
     if (childPolicy == null)
     {
         throw new ArgumentNullException("childPolicy");
     }
     _childPolicy = childPolicy;
 }
Example #3
0
 /// <summary>
 ///  Creates a new <code>Policies</code> object using the provided policies.
 /// </summary>
 /// <param name="loadBalancingPolicy"> the load balancing policy to use. </param>
 /// <param name="reconnectionPolicy"> the reconnection policy to use. </param>
 /// <param name="retryPolicy"> the retry policy to use.</param>
 public Policies(ILoadBalancingPolicy loadBalancingPolicy,
                 IReconnectionPolicy reconnectionPolicy,
                 IRetryPolicy retryPolicy)
 {
     this._loadBalancingPolicy = loadBalancingPolicy;
     this._reconnectionPolicy = reconnectionPolicy;
     this._retryPolicy = retryPolicy;
 }
Example #4
0
 /// <summary>
 ///  Configure the load balancing policy to use for the new cluster. <p> If no
 ///  load balancing policy is set through this method,
 ///  <link>Policies#DefaultLoadBalancingPolicy</link> will be used instead.</p>
 /// </summary>
 /// <param name="policy"> the load balancing policy to use </param>
 /// 
 /// <returns>this Builder</returns>
 public Builder WithLoadBalancingPolicy(ILoadBalancingPolicy policy)
 {
     this._loadBalancingPolicy = policy;
     return this;
 }
Example #5
0
 internal Policies(ILoadBalancingPolicy loadBalancingPolicy,
     IReconnectionPolicy reconnectionPolicy,
     IRetryPolicy retryPolicy,
     ISpeculativeExecutionPolicy speculativeExecutionPolicy)
 {
     _loadBalancingPolicy = loadBalancingPolicy;
     _reconnectionPolicy = reconnectionPolicy;
     _retryPolicy = retryPolicy;
     _speculativeExecutionPolicy = speculativeExecutionPolicy;
 }
Example #6
0
 public OrderedLoadBalancingPolicy()
 {
     _childPolicy = new RoundRobinPolicy();
 }
 /// <summary>
 ///  Creates a new <code>TokenAware</code> policy that wraps the provided child
 ///  load balancing policy.
 /// </summary>
 /// <param name="childPolicy"> the load balancing policy to wrap with token
 ///  awareness.</param>
 public TokenAwarePolicy(ILoadBalancingPolicy childPolicy)
 {
     this._childPolicy = childPolicy;
 }
 /// <summary>
 /// Configures the load balancing policy to use for the new cluster.
 /// <para> 
 /// If no load balancing policy is set through this method, <see cref="DseLoadBalancingPolicy"/>
 /// will be used instead.
 /// </para>
 /// </summary>
 /// <param name="policy"> the load balancing policy to use </param>
 /// <returns>this instance</returns>
 public new DseClusterBuilder WithLoadBalancingPolicy(ILoadBalancingPolicy policy)
 {
     base.WithLoadBalancingPolicy(policy);
     return this;
 }
Example #9
0
 public RetryLoadBalancingPolicy(ILoadBalancingPolicy loadBalancingPolicy, IReconnectionPolicy reconnectionPolicy)
 {
     _reconnectionPolicy  = reconnectionPolicy;
     _loadBalancingPolicy = loadBalancingPolicy;
 }
Example #10
0
 /// <summary>
 /// <para>
 /// Configure the load balancing policy to use for the new cluster.
 /// </para>
 /// <para>
 /// If no load balancing policy is set through this method, <see cref="Policies.DefaultLoadBalancingPolicy"/> will be used instead.
 /// </para>
 /// <para>
 /// To specify the local datacenter with the default load balancing policy, use the following method to create a
 /// new policy instance: <see cref="Policies.NewDefaultLoadBalancingPolicy"/>.
 /// </para>
 /// </summary>
 /// <param name="policy"> the load balancing policy to use.</param>
 /// <returns>this Builder</returns>
 public Builder WithLoadBalancingPolicy(ILoadBalancingPolicy policy)
 {
     _addedLbp            = true;
     _loadBalancingPolicy = policy;
     return(this);
 }
Example #11
0
 public BlackListedDCLoadBalancingPolicy(IList <string> blacklistedDC, ILoadBalancingPolicy childPolicy)
 {
     _childPolicy       = childPolicy ?? throw new ArgumentException(string.Format("Base child policy wasn't specified"));
     this.blacklistedDC = blacklistedDC;
 }
Example #12
0
 /// <summary>
 /// Configures the load balancing policy to use for the new cluster.
 /// <para>
 /// If no load balancing policy is set through this method, <see cref="DseLoadBalancingPolicy"/>
 /// will be used instead.
 /// </para>
 /// </summary>
 /// <param name="policy"> the load balancing policy to use </param>
 /// <returns>this instance</returns>
 public new DseClusterBuilder WithLoadBalancingPolicy(ILoadBalancingPolicy policy)
 {
     base.WithLoadBalancingPolicy(policy);
     return(this);
 }
 /// <summary>
 /// Creates a new instance of <see cref="DseLoadBalancingPolicy"/> given the name of the local datacenter and
 /// the amount of host per remote datacenter to use for failover for the local hosts.
 /// </summary>
 /// <param name="localDc">The name of the local datacenter (case-sensitive)</param>
 /// <param name="usedHostsPerRemoteDc">
 /// The amount of host per remote datacenter that the policy should yield in a new query plan after the local
 /// nodes.
 /// </param>
 public DseLoadBalancingPolicy(string localDc, int usedHostsPerRemoteDc = 0)
 {
     _childPolicy = new TokenAwarePolicy(new DCAwareRoundRobinPolicy(localDc, usedHostsPerRemoteDc));
 }
Example #14
0
 /// <summary>
 /// Creates a new instance of <see cref="DefaultLoadBalancingPolicy"/> wrapping the provided child policy.
 /// </summary>
 internal DefaultLoadBalancingPolicy(ILoadBalancingPolicy childPolicy)
 {
     ChildPolicy = childPolicy ?? throw new ArgumentNullException(nameof(childPolicy));
 }
Example #15
0
 public PartitionAwarePolicy(ILoadBalancingPolicy childPolicy)
 {
     _childPolicy = childPolicy;
 }
Example #16
0
 /// <summary>
 /// Creates a new <c>Policies</c> object using the provided policies.
 /// </summary>
 /// <param name="loadBalancingPolicy"> the load balancing policy to use. </param>
 /// <param name="reconnectionPolicy"> the reconnection policy to use. </param>
 /// <param name="retryPolicy"> the retry policy to use.</param>
 public Policies(ILoadBalancingPolicy loadBalancingPolicy, IReconnectionPolicy reconnectionPolicy, IRetryPolicy retryPolicy)
     : this(loadBalancingPolicy, reconnectionPolicy, retryPolicy, DefaultSpeculativeExecutionPolicy, DefaultTimestampGenerator)
 {
     //Part of the public API can not be removed
 }
 public RetryLoadBalancingPolicy(ILoadBalancingPolicy loadBalancingPolicy, IReconnectionPolicy reconnectionPolicy)
 {
     _reconnectionPolicy = reconnectionPolicy;
     _loadBalancingPolicy = loadBalancingPolicy;
 }
 public IExecutionProfileBuilder WithLoadBalancingPolicy(ILoadBalancingPolicy loadBalancingPolicy)
 {
     _loadBalancingPolicy = loadBalancingPolicy ?? throw new ArgumentNullException(nameof(loadBalancingPolicy));
     return(this);
 }
Example #19
0
        /// <summary>
        /// Gets a query plan as determined by the load-balancing policy.
        /// In the special case when a Host is provided at Statement level, it will return a query plan with a single
        /// host.
        /// </summary>
        private static IEnumerable <Host> GetQueryPlan(ISession session, IStatement statement, ILoadBalancingPolicy lbp)
        {
            // Single host iteration
            var host = (statement as Statement)?.Host;

            return(host == null
                ? lbp.NewQueryPlan(session.Keyspace, statement)
                : Enumerable.Repeat(host, 1));
        }
Example #20
0
 public TestBlackListLbp(ILoadBalancingPolicy parent, params IPEndPoint[] blacklisted)
 {
     _parent      = parent;
     _blacklisted = blacklisted;
 }
 /// <summary>
 /// Creates a new instance of <see cref="DseLoadBalancingPolicy"/> given the name of the local datacenter and
 /// the amount of host per remote datacenter to use for failover for the local hosts.
 /// </summary>
 /// <param name="localDc">The name of the local datacenter (case-sensitive)</param>
 /// <param name="usedHostsPerRemoteDc">
 /// The amount of host per remote datacenter that the policy should yield in a new query plan after the local
 /// nodes.
 /// </param>
 public DseLoadBalancingPolicy(string localDc, int usedHostsPerRemoteDc = 0)
 {
     _childPolicy = new TokenAwarePolicy(new DCAwareRoundRobinPolicy(localDc, usedHostsPerRemoteDc));
 }
Example #22
0
 /// <summary>
 ///  Creates a new <c>TokenAware</c> policy that wraps the provided child
 ///  load balancing policy.
 /// </summary>
 /// <param name="childPolicy"> the load balancing policy to wrap with token
 ///  awareness.</param>
 public TokenAwarePolicy(ILoadBalancingPolicy childPolicy)
 {
     _childPolicy = childPolicy;
 }
Example #23
0
 public TestDisallowListLbp(ILoadBalancingPolicy parent, params IPEndPoint[] disallowed)
 {
     _parent     = parent;
     _disallowed = disallowed;
 }
Example #24
0
 /// <summary>
 ///  Configure the load balancing policy to use for the new cluster. <p> If no
 ///  load balancing policy is set through this method,
 ///  <link>Policies.DefaultLoadBalancingPolicy</link> will be used instead.</p>
 /// </summary>
 /// <param name="policy"> the load balancing policy to use </param>
 ///
 /// <returns>this Builder</returns>
 public Builder WithLoadBalancingPolicy(ILoadBalancingPolicy policy)
 {
     _loadBalancingPolicy = policy;
     return(this);
 }
Example #25
0
 /// <summary>
 ///  Creates a new <c>Policies</c> object using the provided policies.
 /// </summary>
 /// <param name="loadBalancingPolicy"> the load balancing policy to use. </param>
 /// <param name="reconnectionPolicy"> the reconnection policy to use. </param>
 /// <param name="retryPolicy"> the retry policy to use.</param>
 public Policies(ILoadBalancingPolicy loadBalancingPolicy,
                 IReconnectionPolicy reconnectionPolicy,
                 IRetryPolicy retryPolicy)
     : this(loadBalancingPolicy, reconnectionPolicy, retryPolicy, NoSpeculativeExecutionPolicy.Instance)
 {
     //Part of the public API can not be removed
 }