async Task IBootstrappable.BootStrapAsync() { try { await _context.BootstrapGlobalAsync().ConfigureAwait(false); //if we succeeded set the state of the cluster to bootstrapped _hasBootStrapped = _context.GlobalConfig != null; _deferredExceptions.Clear(); UpdateClusterCapabilities(); } catch (AuthenticationFailureException e) { _deferredExceptions.Add(e); //auth failed so bubble up exception and clean up resources _logger.LogError(e, "Could not authenticate user {username}", _redactor.UserData(_context.ClusterOptions.UserName ?? string.Empty)); _context.RemoveAllNodes(); throw; } catch (Exception e) { _logger.LogDebug("Error encountered bootstrapping cluster; if the cluster is 6.5 or earlier, this can be ignored. {exception}.", e); } }
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()); }
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(); }