public override async Task RunAsync(CancellationToken cancellationToken) { using var client = new DaprClientBuilder().Build(); var state = new Widget() { Size = "small", Color = "yellow", }; await client.SaveStateAsync(storeName, stateKeyName, state, cancellationToken : cancellationToken); Console.WriteLine("Saved State!"); state = await client.GetStateAsync <Widget>(storeName, stateKeyName, cancellationToken : cancellationToken); if (state == null) { Console.WriteLine("State not found in store"); } else { Console.WriteLine($"Got State: {state.Size} {state.Color}"); } await client.DeleteStateAsync(storeName, stateKeyName, cancellationToken : cancellationToken); Console.WriteLine("Deleted State!"); }
public async Task DeleteStateAsync_ValidateOptions( ConsistencyMode consistencyMode, ConcurrencyMode concurrencyMode, StateConsistency expectedConsistency, StateConcurrency expectedConcurrency) { // Configure Client var httpClient = new TestHttpClient(); var daprClient = new DaprClientBuilder() .UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient }) .Build(); var stateOptions = new StateOptions { Concurrency = concurrencyMode, Consistency = consistencyMode }; var task = daprClient.DeleteStateAsync("testStore", "test", stateOptions); // Get Request and validate httpClient.Requests.TryDequeue(out var entry).Should().BeTrue(); var request = await GrpcUtils.GetRequestFromRequestMessageAsync <Autogenerated.DeleteStateRequest>(entry.Request); request.StoreName.Should().Be("testStore"); request.Key.Should().Be("test"); request.Options.Concurrency.Should().Be(expectedConcurrency); request.Options.Consistency.Should().Be(expectedConsistency); }
public async Task DeleteStateAsync_CanDeleteState() { var httpClient = new TestHttpClient(); var daprClient = new DaprClientBuilder() .UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient }) .Build(); var task = daprClient.DeleteStateAsync("testStore", "test"); httpClient.Requests.TryDequeue(out var entry).Should().BeTrue(); var request = await GrpcUtils.GetRequestFromRequestMessageAsync <Autogenerated.DeleteStateRequest>(entry.Request); request.StoreName.Should().Be("testStore"); request.Key.Should().Be("test"); }
public async Task DeleteStateAsync_WithCancelledToken() { // Configure Client var httpClient = new TestHttpClient(); var daprClient = new DaprClientBuilder() .UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient, ThrowOperationCanceledOnCancellation = true }) .Build(); var ctSource = new CancellationTokenSource(); CancellationToken ct = ctSource.Token; ctSource.Cancel(); await FluentActions.Awaiting(async() => await daprClient.DeleteStateAsync("testStore", "key", cancellationToken: ct)) .Should().ThrowAsync <OperationCanceledException>(); }
public async Task <string> Delete() { using var client = new DaprClientBuilder() .UseHttpEndpoint(DAPR_SIDECAR_HTTP) .Build(); try { await client.DeleteStateAsync(STATE_STORE_NAME, STATE_KEY); return("删除订单成功!"); } catch (Exception ex) { this._logger.LogError(ex, "删除订单出现错误!"); return(ex.Message); } }
public async Task DeleteStateAsync_ValidateOptions( ConsistencyMode consistencyMode, ConcurrencyMode concurrencyMode, RetryMode retryMode, StateConsistency expectedConsistency, StateConcurrency expectedConcurrency, RetryPattern expectedRetryMode) { // Configure Client var httpClient = new TestHttpClient(); var daprClient = new DaprClientBuilder() .UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient }) .Build(); var stateOptions = new StateOptions { Concurrency = concurrencyMode, Consistency = consistencyMode, RetryOptions = new RetryOptions { RetryInterval = TimeSpan.FromSeconds(5), RetryMode = retryMode, RetryThreshold = 10 } }; var task = daprClient.DeleteStateAsync("testStore", "test", stateOptions); // Get Request and validate httpClient.Requests.TryDequeue(out var entry).Should().BeTrue(); var request = await GrpcUtils.GetRequestFromRequestMessageAsync <Autogenerated.DeleteStateRequest>(entry.Request); request.StoreName.Should().Be("testStore"); request.Key.Should().Be("test"); request.Options.Concurrency.Should().Be(expectedConcurrency); request.Options.Consistency.Should().Be(expectedConsistency); request.Options.RetryPolicy.Pattern.Should().Be(expectedRetryMode); request.Options.RetryPolicy.Threshold.Should().Be(10); request.Options.RetryPolicy.Interval.Seconds.Should().Be(5); }
public async Task DeleteStateAsync_ThrowsForNonSuccess() { // Configure Client var httpClient = new TestHttpClient(); var daprClient = new DaprClientBuilder() .UseGrpcChannelOptions(new GrpcChannelOptions { HttpClient = httpClient }) .Build(); var task = daprClient.DeleteStateAsync("testStore", "test"); // Create Response & Respond httpClient.Requests.TryDequeue(out var entry).Should().BeTrue(); var response = GrpcUtils.CreateResponse(HttpStatusCode.NotAcceptable); entry.Completion.SetResult(response); await FluentActions.Awaiting(async() => await task).Should().ThrowAsync <RpcException>(); }