public void Dispose(bool disposing) { lock (_syncObject) { if (!_disposed) { if (disposing) { GC.SuppressFinalize(this); } if (_clusterMonitor != null) { _clusterMonitor.Dispose(); } if (_configMonitor != null) { _configMonitor.Dispose(); } foreach (var pair in _buckets) { DestroyBucket(pair.Value); } foreach (var configProvider in ConfigProviders) { configProvider.Dispose(); } _disposed = true; } } }
public async Task Test_StartMonitoring() { var clientConfig = new ClientConfiguration { Servers = new List <Uri> { new Uri("http://10.111.160.101:8091"), new Uri("http://10.111.160.102:8091"), new Uri("http://10.111.160.104:8091") }, BucketConfigs = new Dictionary <string, BucketConfiguration> { { "default", new BucketConfiguration { BucketName = "default", Username = "******", Password = "" } }, { "travel-sample", new BucketConfiguration { BucketName = "travel-sample", Username = "******", Password = "" } }, }, HeartbeatConfigInterval = 500, OperationTracingEnabled = false, OrphanedResponseLoggingEnabled = false }; clientConfig.Initialize(); var configProvider = new Mock <IConfigProvider>(); var controller = new Mock <IClusterController>(); controller.Setup(x => x.Configuration).Returns(clientConfig); controller.Setup(x => x.ConfigProviders).Returns(new List <IConfigProvider> { configProvider.Object }); var cts = new CancellationTokenSource(); var monitor = new ConfigMonitor(controller.Object, cts); monitor.StartMonitoring(); await Task.Delay(3000); controller.Verify(x => x.LastConfigCheckedTime, Times.AtLeast(1)); monitor.Dispose(); }
public void Test_Dispose() { var clientConfig = new ClientConfiguration { Servers = new List <Uri> { new Uri("http://10.111.160.101:8091"), new Uri("http://10.111.160.102:8091"), new Uri("http://10.111.160.104:8091") }, BucketConfigs = new Dictionary <string, BucketConfiguration> { { "default", new BucketConfiguration { BucketName = "default", Username = "******", Password = "" } }, { "travel-sample", new BucketConfiguration { BucketName = "travel-sample", Username = "******", Password = "" } } }, HeartbeatConfigInterval = 1000 }; clientConfig.Initialize(); var configProvider = new Mock <IConfigProvider>(); var controller = new Mock <IClusterController>(); controller.Setup(x => x.Configuration).Returns(clientConfig); controller.Setup(x => x.ConfigProviders).Returns(new List <IConfigProvider> { configProvider.Object }); var cts = new CancellationTokenSource(); var monitor = new ConfigMonitor(controller.Object, cts); monitor.StartMonitoring(); Thread.Sleep(1500); monitor.Dispose(); Assert.IsTrue(cts.IsCancellationRequested); }
public void Dispose(bool disposing) { lock (_syncObject) { if (!_disposed) { if (disposing) { GC.SuppressFinalize(this); } if (_configQueue != null) { try { _configQueue.CompleteAdding(); while (_configQueue.Any()) { _configQueue.TryTake(out IBucketConfig config); } _configQueue.Dispose(); } catch (Exception e) { Log.Debug(e); } } _configMonitor?.Dispose(); _configQueue?.Dispose(); foreach (var pair in _buckets) { DestroyBucket(pair.Value); } foreach (var configProvider in ConfigProviders) { configProvider.Dispose(); } _semaphoreSlim.Dispose(); _disposed = true; } } }