protected override IDistributor<int> CreateDistributor( Func<Lease<int>, Task> onReceive = null, Leasable<int>[] leasables = null, int maxDegreesOfParallelism = 1, string name = null, TimeSpan? waitInterval = null, string pool = null) { leasables = leasables ?? DefaultLeasable; pool = pool ?? DateTimeOffset.UtcNow.Ticks.ToString(); distributor = new SqlBrokeredDistributor<int>( leasables, Database, pool, maxDegreesOfParallelism, waitInterval, DefaultLeaseDuration); if (onReceive != null) { distributor.OnReceive(onReceive); } Database.RegisterLeasableResources(leasables, pool).Wait(); return distributor; }
protected abstract IDistributor<int> CreateDistributor( Func<Lease<int>, Task> onReceive = null, Leasable<int>[] leasables = null, int maxDegreesOfParallelism = 5, [CallerMemberName] string name = null, TimeSpan? waitInterval = null, string pool = null);
/// <summary> /// This will try and fail if it cannot get the lease first time. /// </summary> /// <returns></returns> public Task RunMutexWithOptionsAsync() { var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator()) { LeasePolicy = new LeasePolicy { Duration = TimeSpan.FromSeconds(15), Name = "LeasingTestHarness", ActorName = this.Name }, RetryStrategy = new DoNotRetry(), RetryPolicy = new DoNotRetryPolicy() }; return leasable.MutexWithOptionsAsync(this.DoSomethingAsync); }
/// <summary> /// This will try and fail if it cannot get the lease first time. /// </summary> /// <returns></returns> public Task RunMutexWithOptionsAsync() { var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator()) { LeasePolicy = new LeasePolicy { Duration = TimeSpan.FromSeconds(15), Name = "LeasingTestHarness", ActorName = this.Name }, RetryStrategy = new DoNotRetry(), RetryPolicy = new DoNotRetryPolicy() }; return(leasable.MutexWithOptionsAsync(this.DoSomethingAsync)); }
public async Task Leases_record_the_time_when_they_were_last_released() { Leasable <int> leasable = null; var received = default(DateTimeOffset); var distributor = CreateDistributor(async l => { received = DateTimeOffset.UtcNow; leasable = l.Leasable; }); await distributor.Distribute(1); leasable.LeaseLastReleased .ToUniversalTime() .Should() .BeCloseTo(received, precision: (int)ClockDriftTolerance.TotalMilliseconds); }
protected override IDistributor<int> CreateDistributor( Func<Lease<int>, Task> onReceive = null, Leasable<int>[] leasables = null, int maxDegreesOfParallelism = 5, string name = null, TimeSpan? waitInterval = null, string pool = null) { distributor = new InMemoryDistributor<int>( leasables ?? DefaultLeasable, pool ?? DateTimeOffset.UtcNow.Ticks.ToString(), maxDegreesOfParallelism, waitInterval, DefaultLeaseDuration); if (onReceive != null) { distributor.OnReceive(onReceive); } return distributor; }
public CouchbaseLiteHttpClient(HttpClient client, DefaultAuthHandler authHandler) { _httpClient = client; _authHandler = authHandler; SetConcurrencyLimit(ReplicationOptions.DefaultMaxOpenHttpConnections); }
/// <summary> /// This will retry until it sucessfully executes. /// </summary> /// <returns></returns>new public Task RunSimpleMutexAsync() { var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator()); return(leasable.MutexAsync(this.DoSomethingAsync, "LeasingTestHarness", this.Name)); }
public void SetUp() { DefaultLeasable = Enumerable.Range(1, 10) .Select(i => new Leasable<int>(i, i.ToString())) .ToArray(); }
public void Setup(ReplicationOptions options) { _remoteRequestCancellationSource?.Cancel(); _remoteRequestCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationTokenSource.Token); ClientFactory.SocketTimeout = options.SocketTimeout; var clientObj = ClientFactory.GetHttpClient(CookieStore, options.RetryStrategy); clientObj.Timeout = options.RequestTimeout; clientObj.SetConcurrencyLimit(options.MaxOpenHttpConnections); clientObj.Authenticator = Authenticator; _client = clientObj; }
/// <summary> /// This will retry until it sucessfully executes. /// </summary> /// <returns></returns>new public Task RunSimpleMutexAsync() { var leasable = new Leasable(new AzureLeaseProviderFactory(new ConnectionStringProvider()), new AzureLeasePolicyValidator()); return leasable.MutexAsync(this.DoSomethingAsync, "LeasingTestHarness", this.Name); }