public void Should_GetAllSettingsFromBaseProfile_When_DerivedProfileHasNoSettings()
        {
            var go  = new GraphOptions();
            var lbp = new RoundRobinPolicy();
            var sep = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var rp  = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var baseProfileBuilder = new ExecutionProfileBuilder();

            baseProfileBuilder
            .WithLoadBalancingPolicy(lbp)
            .WithSpeculativeExecutionPolicy(sep)
            .WithSerialConsistencyLevel(ConsistencyLevel.LocalSerial)
            .WithConsistencyLevel(ConsistencyLevel.Quorum)
            .WithReadTimeoutMillis(3000)
            .WithGraphOptions(go)
            .WithRetryPolicy(rp);

            var baseProfile = baseProfileBuilder.Build();

            var profile = new ExecutionProfile(baseProfile, new ExecutionProfileBuilder().Build());

            Assert.AreSame(lbp, profile.LoadBalancingPolicy);
            Assert.AreSame(sep, profile.SpeculativeExecutionPolicy);
            Assert.AreSame(rp, profile.RetryPolicy);
            Assert.AreEqual(3000, profile.ReadTimeoutMillis);
            Assert.AreEqual(ConsistencyLevel.LocalSerial, profile.SerialConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.Quorum, profile.ConsistencyLevel);
            Assert.AreEqual(go, profile.GraphOptions);
        }
Exemplo n.º 2
0
        public void Should_MapDefaultProfileToDefaultOptionsCorrectly_When_AllSettingsAreProvided()
        {
            var go      = new GraphOptions();
            var lbp     = new RoundRobinPolicy();
            var sep     = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var rp      = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var cluster =
                Cluster
                .Builder()
                .AddContactPoint("127.0.0.1")
                .WithSocketOptions(new SocketOptions().SetReadTimeoutMillis(3000))
                .WithExecutionProfiles(opts =>
            {
                opts.WithProfile("default", profile => profile
                                 .WithConsistencyLevel(ConsistencyLevel.EachQuorum)
                                 .WithSerialConsistencyLevel(ConsistencyLevel.LocalSerial)
                                 .WithReadTimeoutMillis(9999)
                                 .WithLoadBalancingPolicy(lbp)
                                 .WithSpeculativeExecutionPolicy(sep)
                                 .WithRetryPolicy(rp)
                                 .WithGraphOptions(go));
            })
                .Build();

            Assert.AreEqual(1, cluster.Configuration.RequestOptions.Count);
            var options = cluster.Configuration.RequestOptions["default"];

            Assert.AreEqual(ConsistencyLevel.EachQuorum, options.ConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.LocalSerial, options.SerialConsistencyLevel);
            Assert.AreEqual(9999, options.ReadTimeoutMillis);
            Assert.AreSame(lbp, options.LoadBalancingPolicy);
            Assert.AreSame(sep, options.SpeculativeExecutionPolicy);
            Assert.AreSame(rp, options.RetryPolicy);
            Assert.AreSame(go, options.GraphOptions);
        }
        public void Should_MapOptionsToProfileWithAllSettingsFromCluster_When_NoProfileIsChangedOrAdded()
        {
            var lbp     = new RoundRobinPolicy();
            var sep     = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var rp      = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var tg      = new AtomicMonotonicTimestampGenerator();
            var cluster = Cluster
                          .Builder()
                          .AddContactPoint("127.0.0.1")
                          .WithQueryOptions(
                new QueryOptions()
                .SetConsistencyLevel(ConsistencyLevel.EachQuorum)
                .SetSerialConsistencyLevel(ConsistencyLevel.LocalSerial)
                .SetDefaultIdempotence(true)
                .SetPageSize(5)
                .SetPrepareOnAllHosts(false)
                .SetReprepareOnUp(false))
                          .WithSocketOptions(new SocketOptions().SetReadTimeoutMillis(9999))
                          .WithLoadBalancingPolicy(lbp)
                          .WithSpeculativeExecutionPolicy(sep)
                          .WithRetryPolicy(rp)
                          .WithQueryTimeout(30)
                          .WithTimestampGenerator(tg)
                          .Build();

            Assert.AreEqual(1, cluster.Configuration.RequestOptions.Count);
            var profile = cluster.Configuration.ExecutionProfiles["default"];

            Assert.AreEqual(ConsistencyLevel.EachQuorum, profile.ConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.LocalSerial, profile.SerialConsistencyLevel);
            Assert.AreEqual(9999, profile.ReadTimeoutMillis);
            Assert.AreSame(lbp, profile.LoadBalancingPolicy);
            Assert.AreSame(sep, profile.SpeculativeExecutionPolicy);
            Assert.AreSame(rp, profile.RetryPolicy);
        }
        public void Should_MapOptionsToProfileCorrectly_When_AllSettingsAreProvided()
        {
            var lbp     = new RoundRobinPolicy();
            var sep     = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var rp      = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var cluster = Cluster.Builder().AddContactPoint("127.0.0.1").WithExecutionProfiles(opts =>
            {
                opts.WithProfile("test1", profile => profile
                                 .WithConsistencyLevel(ConsistencyLevel.EachQuorum)
                                 .WithSerialConsistencyLevel(ConsistencyLevel.LocalSerial)
                                 .WithReadTimeoutMillis(9999)
                                 .WithLoadBalancingPolicy(lbp)
                                 .WithSpeculativeExecutionPolicy(sep)
                                 .WithRetryPolicy(rp));
            }).Build();

            var execProfile = cluster.Configuration.ExecutionProfiles["test1"];

            Assert.AreEqual(ConsistencyLevel.EachQuorum, execProfile.ConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.LocalSerial, execProfile.SerialConsistencyLevel);
            Assert.AreEqual(9999, execProfile.ReadTimeoutMillis);
            Assert.AreSame(lbp, execProfile.LoadBalancingPolicy);
            Assert.AreSame(sep, execProfile.SpeculativeExecutionPolicy);
            Assert.AreSame(rp, execProfile.RetryPolicy);
        }
        public void Should_MapProfileToOptionsWithSomeSettingsFromBaseProfile_When_ADerivedProfileIsProvided()
        {
            var lbp        = new RoundRobinPolicy();
            var sep        = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var sepProfile = new ConstantSpeculativeExecutionPolicy(200, 50);
            var rp         = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var rpProfile  = new LoggingRetryPolicy(new IdempotenceAwareRetryPolicy(new DefaultRetryPolicy()));
            var tg         = new AtomicMonotonicTimestampGenerator();
            var cluster    = Cluster
                             .Builder()
                             .AddContactPoint("127.0.0.1")
                             .WithQueryOptions(
                new QueryOptions()
                .SetConsistencyLevel(ConsistencyLevel.EachQuorum)
                .SetSerialConsistencyLevel(ConsistencyLevel.Serial)
                .SetDefaultIdempotence(true)
                .SetPageSize(5)
                .SetPrepareOnAllHosts(false)
                .SetReprepareOnUp(false))
                             .WithSocketOptions(new SocketOptions().SetReadTimeoutMillis(300))
                             .WithLoadBalancingPolicy(lbp)
                             .WithSpeculativeExecutionPolicy(sep)
                             .WithRetryPolicy(rp)
                             .WithExecutionProfiles(opts => opts
                                                    .WithProfile("baseProfile", baseProfile => baseProfile
                                                                 .WithConsistencyLevel(ConsistencyLevel.Quorum)
                                                                 .WithSpeculativeExecutionPolicy(sepProfile)
                                                                 .WithRetryPolicy(rpProfile))
                                                    .WithDerivedProfile("test1", "baseProfile", profileBuilder => profileBuilder
                                                                        .WithConsistencyLevel(ConsistencyLevel.All)
                                                                        .WithSerialConsistencyLevel(ConsistencyLevel.LocalSerial)))
                             .WithQueryTimeout(30)
                             .WithTimestampGenerator(tg)
                             .Build();

            Assert.AreEqual(3, cluster.Configuration.RequestOptions.Count);
            var options = cluster.Configuration.RequestOptions["test1"];

            Assert.AreEqual(ConsistencyLevel.All, options.ConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.LocalSerial, options.SerialConsistencyLevel);
            Assert.AreEqual(300, options.ReadTimeoutMillis);
            Assert.AreSame(lbp, options.LoadBalancingPolicy);
            Assert.AreSame(sepProfile, options.SpeculativeExecutionPolicy);
            Assert.AreSame(rpProfile, options.RetryPolicy);
            Assert.AreEqual(true, options.DefaultIdempotence);
            Assert.AreEqual(5, options.PageSize);
            Assert.AreEqual(30, options.QueryAbortTimeout);
            Assert.AreSame(tg, options.TimestampGenerator);
        }
        public void Should_GetNoSettingFromBaseProfile_When_DerivedProfileHasAllSettings()
        {
            var go                 = new GraphOptions().SetName("ee");
            var goProfile          = new GraphOptions().SetName("tt");
            var lbp                = new RoundRobinPolicy();
            var sep                = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var rp                 = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var sepProfile         = new ConstantSpeculativeExecutionPolicy(200, 50);
            var lbpProfile         = new TokenAwarePolicy(new DCAwareRoundRobinPolicy());
            var rpProfile          = new LoggingRetryPolicy(new IdempotenceAwareRetryPolicy(new DefaultRetryPolicy()));
            var baseProfileBuilder = new ExecutionProfileBuilder();

            baseProfileBuilder
            .WithLoadBalancingPolicy(lbp)
            .WithSpeculativeExecutionPolicy(sep)
            .WithSerialConsistencyLevel(ConsistencyLevel.LocalSerial)
            .WithConsistencyLevel(ConsistencyLevel.Quorum)
            .WithReadTimeoutMillis(3000)
            .WithGraphOptions(go)
            .WithRetryPolicy(rp);

            var baseProfile = baseProfileBuilder.Build();

            var derivedProfileBuilder = new ExecutionProfileBuilder();

            derivedProfileBuilder
            .WithLoadBalancingPolicy(lbpProfile)
            .WithSpeculativeExecutionPolicy(sepProfile)
            .WithSerialConsistencyLevel(ConsistencyLevel.Serial)
            .WithConsistencyLevel(ConsistencyLevel.LocalQuorum)
            .WithReadTimeoutMillis(5000)
            .WithGraphOptions(goProfile)
            .WithRetryPolicy(rpProfile);

            var derivedProfile = derivedProfileBuilder.Build();

            var profile = new ExecutionProfile(baseProfile, derivedProfile);

            Assert.AreSame(lbpProfile, profile.LoadBalancingPolicy);
            Assert.AreSame(sepProfile, profile.SpeculativeExecutionPolicy);
            Assert.AreSame(rpProfile, profile.RetryPolicy);
            Assert.AreEqual(5000, profile.ReadTimeoutMillis);
            Assert.AreEqual(ConsistencyLevel.Serial, profile.SerialConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.LocalQuorum, profile.ConsistencyLevel);
            Assert.AreSame(goProfile, profile.GraphOptions);
        }
Exemplo n.º 7
0
        public void Should_MapDefaultProfileToOptionsWithAllSettingsFromCluster_When_NoSettingIsProvided()
        {
            var go      = new GraphOptions();
            var lbp     = new RoundRobinPolicy();
            var sep     = new ConstantSpeculativeExecutionPolicy(1000, 1);
            var rp      = new LoggingRetryPolicy(new DefaultRetryPolicy());
            var tg      = new AtomicMonotonicTimestampGenerator();
            var cluster = Cluster
                          .Builder()
                          .AddContactPoint("127.0.0.1")
                          .WithQueryOptions(
                new QueryOptions()
                .SetConsistencyLevel(ConsistencyLevel.EachQuorum)
                .SetSerialConsistencyLevel(ConsistencyLevel.LocalSerial)
                .SetDefaultIdempotence(true)
                .SetPageSize(5)
                .SetPrepareOnAllHosts(false)
                .SetReprepareOnUp(false))
                          .WithSocketOptions(new SocketOptions().SetReadTimeoutMillis(9999))
                          .WithLoadBalancingPolicy(lbp)
                          .WithSpeculativeExecutionPolicy(sep)
                          .WithRetryPolicy(rp)
                          .WithExecutionProfiles(opts => { opts.WithProfile("default", profile => { }); })
                          .WithQueryTimeout(30)
                          .WithTimestampGenerator(tg)
                          .WithGraphOptions(go)
                          .Build();

            Assert.AreEqual(1, cluster.Configuration.RequestOptions.Count);
            var options = cluster.Configuration.RequestOptions["default"];

            Assert.AreEqual(ConsistencyLevel.EachQuorum, options.ConsistencyLevel);
            Assert.AreEqual(ConsistencyLevel.LocalSerial, options.SerialConsistencyLevel);
            Assert.AreEqual(9999, options.ReadTimeoutMillis);
            Assert.AreSame(lbp, options.LoadBalancingPolicy);
            Assert.AreSame(sep, options.SpeculativeExecutionPolicy);
            Assert.AreSame(rp, options.RetryPolicy);
            Assert.AreEqual(true, options.DefaultIdempotence);
            Assert.AreEqual(5, options.PageSize);
            Assert.AreEqual(30, options.QueryAbortTimeout);
            Assert.AreSame(tg, options.TimestampGenerator);
            Assert.AreSame(go, options.GraphOptions);
        }