public async Task BootstrapGlobal_Should_Not_Swallow_AuthenticationFailure()
        {
            var options         = new ClusterOptions().WithConnectionString("couchbases://localhost1,localhost2");
            var mockNodeFactory = new Mock <IClusterNodeFactory>(MockBehavior.Strict);

            mockNodeFactory.Setup(cnf => cnf.CreateAndConnectAsync(It.IsAny <HostEndpointWithPort>(), It.IsAny <CancellationToken>()))
            .Throws(new AuthenticationFailureException());
            options.AddClusterService(mockNodeFactory.Object);
            using var context = new ClusterContext(Mock.Of <ICluster>(), new CancellationTokenSource(), options);
            var ex = await Assert.ThrowsAsync <AuthenticationFailureException>(() => context.BootstrapGlobalAsync());
        }
        /// <summary>
        /// Add Linq2Couchbase support to the cluster.
        /// </summary>
        /// <param name="options">Options to extend.</param>
        /// <param name="setupAction">Action to apply additional configuration to <see cref="CouchbaseLinqConfiguration"/>.</param>
        /// <returns>The <see cref="ClusterOptions"/> to allow chaining.</returns>
        public static ClusterOptions AddLinq(this ClusterOptions options,
                                             Action <CouchbaseLinqConfiguration>?setupAction)
        {
            var configuration = new CouchbaseLinqConfiguration();

            setupAction?.Invoke(configuration);

            return(options
                   .AddClusterService(configuration.DocumentFilterManager)
                   .AddClusterService <ISerializationConverterProvider, ISerializationConverterProvider>(configuration.SerializationConverterProviderFactory));
        }
Exemplo n.º 3
0
        public ClusterContext(ICluster cluster, CancellationTokenSource tokenSource, ClusterOptions options)
        {
            Cluster        = cluster;
            ClusterOptions = options;
            _tokenSource   = tokenSource;

            // Register this instance of ClusterContext
            options.AddClusterService(this);

            ServiceProvider = options.BuildServiceProvider();

            _logger             = ServiceProvider.GetRequiredService <ILogger <ClusterContext> >();
            _redactor           = ServiceProvider.GetRequiredService <IRedactor>();
            _configHandler      = ServiceProvider.GetRequiredService <IConfigHandler>();
            _clusterNodeFactory = ServiceProvider.GetRequiredService <IClusterNodeFactory>();
        }
        public async Task BootstrapGlobal_Should_Continue_After_AuthenticationFailureException()
        {
            var options         = new ClusterOptions().WithConnectionString("couchbase://localhost1,localhost2");
            var mockNodeFactory = new Mock <IClusterNodeFactory>(MockBehavior.Loose);

            mockNodeFactory.Setup(cnf => cnf.CreateAndConnectAsync(new HostEndpointWithPort("localhost1", 11210), It.IsAny <CancellationToken>()))
            .Throws(new AuthenticationFailureException());

            var config = ResourceHelper.ReadResource(@"Documents\Configs\cluster-level-config-rev69.json",
                                                     InternalSerializationContext.Default.BucketConfig);

            config.VBucketServerMap = new Couchbase.Core.Sharding.VBucketServerMapDto();

            var mockClusterNode = new Mock <IClusterNode>();

            mockClusterNode.Setup(cn => cn.GetClusterMap()).Returns(Task.FromResult(config));

            mockNodeFactory.Setup(cnf => cnf.CreateAndConnectAsync(new HostEndpointWithPort("localhost2", 11210), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(mockClusterNode.Object));

            options.AddClusterService(mockNodeFactory.Object);
            using var context = new ClusterContext(Mock.Of <ICluster>(), new CancellationTokenSource(), options);
            await context.BootstrapGlobalAsync();
        }