private IControlConnection Create(bool keepContactPointsUnresolved)
        {
            _connectionFactory = new FakeConnectionFactory();
            var config = new TestConfigurationBuilder
            {
                ConnectionFactory           = _connectionFactory,
                KeepContactPointsUnresolved = keepContactPointsUnresolved
            }.Build();

            _cp1 = new TestContactPoint(new List <IConnectionEndPoint>
            {
                new ConnectionEndPoint(_endpoint1, config.ServerNameResolver, _cp1)
            });
            _cp2 = new TestContactPoint(new List <IConnectionEndPoint>
            {
                new ConnectionEndPoint(_endpoint2, config.ServerNameResolver, _cp2)
            });
            _localhost = new TestContactPoint(new List <IConnectionEndPoint>
            {
                new ConnectionEndPoint(_endpoint1, config.ServerNameResolver, _localhost),
                new ConnectionEndPoint(_endpoint2, config.ServerNameResolver, _localhost)
            });
            return(new ControlConnection(
                       Mock.Of <IInternalCluster>(),
                       new ProtocolEventDebouncer(
                           new FakeTimerFactory(), TimeSpan.Zero, TimeSpan.Zero),
                       ProtocolVersion.V3,
                       config,
                       new Metadata(config),
                       new List <IContactPoint>
            {
                _cp1,
                _cp2,
                _localhost
            }));
        }
Пример #2
0
        public void GetUnboundProjects_ValidSolution_SolutionRuleConfigIsMissing(SonarLintMode mode)
        {
            // If the solution ruleset is missing then all projects will be returned as unbound
            // Arrange - no projects created
            var testConfig = new TestConfigurationBuilder(mode, "sqKey1");
            var project1   = testConfig.AddFilteredProject(ProjectSystemHelper.CSharpProjectKind);
            var project2   = testConfig.AddFilteredProject(ProjectSystemHelper.VbCoreProjectKind);
            var project3   = testConfig.AddFilteredProject(ProjectSystemHelper.CppProjectKind);

            testConfig.SetSolutionLevelFilePathForLanguage(Language.CSharp, "c:\\slnConfig.csharp", false);
            testConfig.SetSolutionLevelFilePathForLanguage(Language.VBNET, "c:\\slnConfig.vb", false);
            testConfig.SetSolutionLevelFilePathForLanguage(Language.Cpp, "c:\\slnConfig.cpp", false);

            var testSubject = testConfig.CreateTestSubject();

            // Act
            var result = testSubject.GetUnboundProjects();

            // Assert
            result.Should().BeEquivalentTo(project1, project2, project3);
            testConfig.AssertExistenceOfFileWasChecked("c:\\slnConfig.csharp");
            testConfig.AssertExistenceOfFileWasChecked("c:\\slnConfig.vb");
            testConfig.AssertExistenceOfFileWasChecked("c:\\slnConfig.cpp");
        }
Пример #3
0
        private RequestHandlerMockResult BuildRequestHandler(
            IStatement statement,
            Action <TestConfigurationBuilder> configBuilderAct,
            IExecutionProfile profile)
        {
            var cts        = new CancellationTokenSource();
            var connection = Mock.Of <IConnection>();

            // create config
            var configBuilder = new TestConfigurationBuilder
            {
                ControlConnectionFactory = new FakeControlConnectionFactory(),
                ConnectionFactory        = new FakeConnectionFactory(() => connection),
                Policies = new Cassandra.Policies(new RoundRobinPolicy(), new ConstantReconnectionPolicy(100), new DefaultRetryPolicy())
            };

            configBuilderAct(configBuilder);
            var config          = configBuilder.Build();
            var initializerMock = Mock.Of <IInitializer>();

            Mock.Get(initializerMock).Setup(i => i.ContactPoints).Returns(new List <IPEndPoint>
            {
                new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042),
                new IPEndPoint(IPAddress.Parse("127.0.0.2"), 9042)
            });
            Mock.Get(initializerMock).Setup(i => i.GetConfiguration()).Returns(config);

            // create cluster
            var cluster = Cluster.BuildFrom(initializerMock, new List <string>());

            cluster.Connect();

            // create session
            var session = new Session(cluster, config, null, SerializerManager.Default, null);

            // create request handler
            var options = profile != null
                ? new RequestOptions(profile, null, config.Policies, config.SocketOptions, config.QueryOptions, config.ClientOptions)
                : config.DefaultRequestOptions;
            var requestHandler = new RequestHandler(
                session,
                new SerializerManager(ProtocolVersion.V3).GetCurrentSerializer(),
                statement,
                options);

            // create mock result object
            var mockResult = new RequestHandlerMockResult(requestHandler);

            // mock connection send
            Mock.Get(connection)
            .Setup(c => c.Send(It.IsAny <IRequest>(), It.IsAny <Action <IRequestError, Response> >(), It.IsAny <int>()))
            .Returns <IRequest, Action <IRequestError, Response>, int>((req, act, timeout) =>
            {
                mockResult.SendResults.Enqueue(new ConnectionSendResult {
                    Request = req, TimeoutMillis = timeout
                });
                Task.Run(async() =>
                {
                    var rp  = (FakeRetryPolicy)(statement.RetryPolicy ?? options.RetryPolicy);
                    var sep = (FakeSpeculativeExecutionPolicy)options.SpeculativeExecutionPolicy;
                    if (Interlocked.Read(ref rp.Count) > 0 && Interlocked.Read(ref sep.Count) > 0)
                    {
                        await Task.Delay(1, cts.Token).ConfigureAwait(false);
                        act(null, new ProxyResultResponse(ResultResponse.ResultResponseKind.Void));
                        cts.Cancel();
                    }
                    else
                    {
                        try
                        {
                            await Task.Delay(10, cts.Token).ConfigureAwait(false);
                        }
                        finally
                        {
                            act(RequestError.CreateServerError(new OverloadedException(string.Empty)), null);
                        }
                    }
                });
                return(new OperationState(act, req, timeout, NullOperationObserver.Instance));
            });
            Mock.Get(connection)
            .SetupGet(c => c.EndPoint)
            .Returns(new ConnectionEndPoint(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042), config.ServerNameResolver, null));

            return(mockResult);
        }
Пример #4
0
        public void Should_OnlyInitializePoliciesOnce_When_MultiplePoliciesAreProvidedWithExecutionProfiles()
        {
            var lbps     = Enumerable.Range(1, 5).Select(i => new FakeLoadBalancingPolicy()).ToArray();
            var seps     = Enumerable.Range(1, 5).Select(i => new FakeSpeculativeExecutionPolicy()).ToArray();
            var profile1 =
                new ExecutionProfileBuilder()
                .WithSpeculativeExecutionPolicy(seps[1])
                .WithLoadBalancingPolicy(lbps[1])
                .CastToClass()
                .Build();
            var testConfig = new TestConfigurationBuilder
            {
                ControlConnectionFactory = new FakeControlConnectionFactory(),
                ConnectionFactory        = new FakeConnectionFactory(),
                Policies = new Cassandra.Policies(
                    lbps[0],
                    new ConstantReconnectionPolicy(50),
                    new DefaultRetryPolicy(),
                    seps[0],
                    new AtomicMonotonicTimestampGenerator()),
                ExecutionProfiles = new Dictionary <string, IExecutionProfile>
                {
                    { "profile1", profile1 },
                    {
                        "profile2",
                        new ExecutionProfileBuilder()
                        .WithSpeculativeExecutionPolicy(seps[2])
                        .CastToClass()
                        .Build()
                    },
                    {
                        "profile3",
                        new ExecutionProfileBuilder()
                        .WithLoadBalancingPolicy(lbps[2])
                        .CastToClass()
                        .Build()
                    },
                    {
                        "profile4",
                        new ExecutionProfileBuilder()
                        .Build()
                    },
                    {
                        "profile5",
                        new ExecutionProfile(profile1, new ExecutionProfileBuilder().Build())
                    },
                    {
                        "graphProfile1",
                        new ExecutionProfileBuilder()
                        .WithLoadBalancingPolicy(lbps[4])
                        .WithSpeculativeExecutionPolicy(seps[4])
                        .CastToClass()
                        .Build()
                    },
                    {
                        "default",
                        new ExecutionProfileBuilder()
                        .WithLoadBalancingPolicy(lbps[3])
                        .WithSpeculativeExecutionPolicy(seps[3])
                        .CastToClass()
                        .Build()
                    }
                }
            }.Build();
            var initializerMock = Mock.Of <IInitializer>();

            Mock.Get(initializerMock)
            .Setup(i => i.ContactPoints)
            .Returns(new List <IPEndPoint> {
                new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042)
            });
            Mock.Get(initializerMock)
            .Setup(i => i.GetConfiguration())
            .Returns(testConfig);

            var cluster = Cluster.BuildFrom(initializerMock, new List <string>(), testConfig);

            cluster.Connect();

            Assert.IsTrue(lbps.Skip(1).All(lbp => lbp.InitializeCount == 1));
            Assert.IsTrue(seps.Skip(1).All(sep => sep.InitializeCount == 1));
            Assert.AreEqual(0, lbps[0].InitializeCount);
            Assert.AreEqual(0, seps[0].InitializeCount);
        }
Пример #5
0
 public void SetUp()
 {
     NHibernateInstaller = new TestConfigurationBuilder();
     Configuration = NHibernateInstaller.BuildConfiguration();
     SessionFactory = Configuration.BuildSessionFactory();
     NHibernateInstaller.Registered(SessionFactory, Configuration);
     Session = SessionFactory.OpenSession();
 }
Пример #6
0
        private ControlConnectionCreateResult NewInstance(
            IDictionary <IPEndPoint, IRow> rows = null,
            IInternalCluster cluster            = null,
            Configuration config = null,
            Metadata metadata    = null,
            Action <TestConfigurationBuilder> configBuilderAct = null)
        {
            if (rows == null)
            {
                rows = new Dictionary <IPEndPoint, IRow>
                {
                    {
                        new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042),
                        TestHelper.CreateRow(new Dictionary <string, object>
                        {
                            { "cluster_name", "ut-cluster" },
                            { "data_center", "ut-dc" },
                            { "rack", "ut-rack" },
                            { "tokens", null },
                            { "release_version", "2.2.1-SNAPSHOT" }
                        })
                    }
                };
            }

            if (cluster == null)
            {
                cluster = Mock.Of <IInternalCluster>();
            }

            var connectionFactory = new FakeConnectionFactory();

            if (config == null)
            {
                var builder = new TestConfigurationBuilder
                {
                    ConnectionFactory                  = connectionFactory,
                    TopologyRefresherFactory           = new FakeTopologyRefresherFactory(rows),
                    SchemaParserFactory                = new FakeSchemaParserFactory(),
                    SupportedOptionsInitializerFactory = new FakeSupportedOptionsInitializerFactory(),
                    ProtocolVersionNegotiator          = new FakeProtocolVersionNegotiator(),
                    ServerEventsSubscriber             = new FakeServerEventsSubscriber()
                };
                configBuilderAct?.Invoke(builder);
                config = builder.Build();
            }

            if (metadata == null)
            {
                metadata = new Metadata(config);
            }

            return(new ControlConnectionCreateResult
            {
                ConnectionFactory = connectionFactory,
                Metadata = metadata,
                Cluster = cluster,
                Config = config,
                ControlConnection = new ControlConnection(
                    cluster,
                    GetEventDebouncer(config),
                    ProtocolVersion.MaxSupported,
                    config,
                    metadata,
                    new List <IContactPoint>
                {
                    new IpLiteralContactPoint(
                        IPAddress.Parse("127.0.0.1"),
                        config.ProtocolOptions,
                        config.ServerNameResolver)
                })
            });
        }
Пример #7
0
        public ResetAttribute()
        {
            var configuration = new TestConfigurationBuilder().Build();

            _connectionString = configuration["ConnectionString"];
        }