Skip to content

Commit

Permalink
Merge branch 'master' into improvements-dapr-client
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelJCamara authored Oct 24, 2024
2 parents ac635b3 + 94b97e2 commit 9903a1d
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 114 deletions.
2 changes: 1 addition & 1 deletion examples/Actor/ActorClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static async Task Main(string[] args)
var nonRemotingProxy = ActorProxy.Create(actorId, "DemoActor");
await nonRemotingProxy.InvokeMethodAsync("TestNoArgumentNoReturnType");
await nonRemotingProxy.InvokeMethodAsync("SaveData", data);
var res = await nonRemotingProxy.InvokeMethodAsync<MyData>("GetData");
await nonRemotingProxy.InvokeMethodAsync<MyData>("GetData");

Console.WriteLine("Registering the timer and reminder");
await proxy.RegisterTimer();
Expand Down
1 change: 0 additions & 1 deletion examples/AspNetCore/RoutingSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ await JsonSerializer.SerializeAsync(context.Response.Body,

async Task ViewErrorMessage(HttpContext context)
{
var client = context.RequestServices.GetRequiredService<DaprClient>();
var transaction = await JsonSerializer.DeserializeAsync<Transaction>(context.Request.Body, serializerOptions);

logger.LogInformation("The amount cannot be negative: {0}", transaction.Amount);
Expand Down
2 changes: 1 addition & 1 deletion examples/GeneratedActor/ActorClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

var client = new ClientActorClient(proxy);

var state = await client.GetStateAsync(cancellationTokenSource.Token);
await client.GetStateAsync(cancellationTokenSource.Token);

await client.SetStateAsync(new ClientState("Hello, World!"), cancellationTokenSource.Token);

Expand Down
2 changes: 1 addition & 1 deletion examples/Workflow/WorkflowUnitTest/OrderProcessingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task TestInsufficientInventory()
.Returns(Task.FromResult(inventoryResult));

// Run the workflow directly
OrderResult result = await new OrderProcessingWorkflow().RunAsync(mockContext.Object, order);
await new OrderProcessingWorkflow().RunAsync(mockContext.Object, order);

// Verify that ReserveInventoryActivity was called with a specific input
mockContext.Verify(
Expand Down
1 change: 0 additions & 1 deletion src/Dapr.Actors.Generators/ActorClientGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public void Execute(GeneratorExecutionContext context)
{
try
{
var actorInterfaceTypeName = interfaceSymbol.Name;
var fullyQualifiedActorInterfaceTypeName = interfaceSymbol.ToString();

var attributeData = interfaceSymbol.GetAttributes().Single(a => a.AttributeClass?.Equals(generateActorClientAttributeSymbol, SymbolEqualityComparer.Default) == true);
Expand Down
3 changes: 1 addition & 2 deletions src/Dapr.Actors/Runtime/ActorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ internal async Task FireTimerAsync(ActorId actorId, Stream requestBodyStream, Ca
// Create a Func to be invoked by common method.
async Task<byte[]> RequestFunc(Actor actor, CancellationToken ct)
{
var actorTypeName = actor.Host.ActorTypeInfo.ActorTypeName;
var actorType = actor.Host.ActorTypeInfo.ImplementationType;
var methodInfo = actor.GetMethodInfoUsingReflection(actorType, timerData.Callback);

Expand All @@ -241,7 +240,7 @@ async Task<byte[]> RequestFunc(Actor actor, CancellationToken ct)
return default;
}

var result = await this.DispatchInternalAsync(actorId, this.timerMethodContext, RequestFunc, cancellationToken);
await this.DispatchInternalAsync(actorId, this.timerMethodContext, RequestFunc, cancellationToken);
}

internal async Task ActivateActorAsync(ActorId actorId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void MapActorsHandlers_WithoutAddActors_Throws()
// NOTE: in 3.1 TestServer.CreateClient triggers the failure, in 5.0 it's Host.Start
using var host = CreateHost<BadStartup>();
var server = host.GetTestServer();
var client = server.CreateClient();
server.CreateClient();
});

Assert.Equal(
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.Actors.Test/ActorCodeBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ActorCodeBuilderTests
[Fact]
public void TestBuildActorProxyGenerator()
{
ActorProxyGenerator proxyGenerator = ActorCodeBuilder.GetOrCreateProxyGenerator(typeof(ITestActor));
ActorCodeBuilder.GetOrCreateProxyGenerator(typeof(ITestActor));
}

[Fact]
Expand Down
5 changes: 1 addition & 4 deletions test/Dapr.Actors.Test/ActorIdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ public class ActorIdTests
[InlineData(" ")]
public void Initialize_New_ActorId_Object_With_Null_Or_Whitespace_Id(string id)
{
Assert.Throws<ArgumentException>(() =>
{
ActorId actorId = new ActorId(id);
});
Assert.Throws<ArgumentException>(() => new ActorId(id));
}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.Actors.Test/Runtime/ActorManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task DeactivateActorAsync_ExceptionDuringDeactivation_ActorIsRemove

var id = ActorId.CreateRandom();
await manager.ActivateActorAsync(id);
Assert.True(manager.TryGetActorAsync(id, out var actor));
Assert.True(manager.TryGetActorAsync(id, out _));

await Assert.ThrowsAsync<InvalidTimeZoneException>(async () =>
{
Expand Down
2 changes: 0 additions & 2 deletions test/Dapr.Actors.Test/Runtime/ActorRuntimeOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public void TestRegisterActor_SavesActivator()
{
var actorType = typeof(TestActor);
var actorTypeInformation = ActorTypeInformation.Get(actorType, actorTypeName: null);
var host = ActorHost.CreateForTest<TestActor>();
var actor = new TestActor(host);

var activator = Mock.Of<ActorActivator>();

Expand Down
15 changes: 7 additions & 8 deletions test/Dapr.Actors.Test/Serialization/ActorIdJsonConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public void CanDeserializeActorId()
{
var id = ActorId.CreateRandom().GetId();
var document = $@"
{{
""actor"": ""{id}""
}}";
{{
""actor"": ""{id}""
}}";

var deserialized = JsonSerializer.Deserialize<ActorHolder>(document);

Expand All @@ -62,11 +62,10 @@ public void CanDeserializeActorId()
[Fact]
public void CanDeserializeNullActorId()
{
var id = ActorId.CreateRandom().GetId();
var document = $@"
{{
""actor"": null
}}";
const string document = @"
{
""actor"": null
}";

var deserialized = JsonSerializer.Deserialize<ActorHolder>(document);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public async Task ModelBinder_GetFromStateEntryWithKeyNotInStateStore_ReturnsNul
using (var factory = new AppWebApplicationFactory())
{
var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false });
var daprClient = factory.DaprClient;

var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithoutstateentry/test");
var response = await httpClient.SendAsync(request);
Expand Down Expand Up @@ -142,7 +141,6 @@ public async Task ModelBinder_GetFromStateEntryWithStateEntry_WithKeyNotInStateS
using (var factory = new AppWebApplicationFactory())
{
var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false });
var daprClient = factory.DaprClient;

var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/controllerwithstateentry/test");
var response = await httpClient.SendAsync(request);
Expand All @@ -159,7 +157,6 @@ public async Task ModelBinder_CanGetOutOfTheWayWhenTheresNoBinding()
using (var factory = new AppWebApplicationFactory())
{
var httpClient = factory.CreateClient(new Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryClientOptions { HandleCookies = false });
var daprClient = factory.DaprClient;

var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/echo-user?name=jimmy");
var response = await httpClient.SendAsync(request);
Expand Down
6 changes: 3 additions & 3 deletions test/Dapr.AspNetCore.Test/DaprClientBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System;
using System;
using System.Text.Json;
using Dapr.Client;
using Grpc.Core;
Expand Down Expand Up @@ -44,15 +44,15 @@ public void DaprClientBuilder_UsesPropertyNameCaseHandlingAsSpecified()
public void DaprClientBuilder_UsesThrowOperationCanceledOnCancellation_ByDefault()
{
var builder = new DaprClientBuilder();
var daprClient = builder.Build();

Assert.True(builder.GrpcChannelOptions.ThrowOperationCanceledOnCancellation);
}

[Fact]
public void DaprClientBuilder_DoesNotOverrideUserGrpcChannelOptions()
{
var builder = new DaprClientBuilder();
var daprClient = builder.UseGrpcChannelOptions(new GrpcChannelOptions()).Build();
builder.UseGrpcChannelOptions(new GrpcChannelOptions()).Build();
Assert.False(builder.GrpcChannelOptions.ThrowOperationCanceledOnCancellation);
}

Expand Down
4 changes: 2 additions & 2 deletions test/Dapr.Client.Test/DaprApiTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task DaprCall_WithApiTokenSet()
request.Dismiss();

// Get Request and validate
var envelope = await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();
await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();

request.Request.Headers.TryGetValues("dapr-api-token", out var headerValues);
headerValues.Count().Should().Be(1);
Expand All @@ -56,7 +56,7 @@ public async Task DaprCall_WithoutApiToken()
request.Dismiss();

// Get Request and validate
var envelope = await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();
await request.GetRequestEnvelopeAsync<Autogenerated.GetSecretRequest>();

request.Request.Headers.TryGetValues("dapr-api-token", out var headerValues);
headerValues.Should().BeNull();
Expand Down
11 changes: 4 additions & 7 deletions test/Dapr.Client.Test/DaprClientTest.InvokeMethodGrpcAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeAndData_Thr
Data = Any.Pack(data),
};

var response =
client.Call<InvokeResponse>()
await client.Call<InvokeResponse>()
.SetResponse(invokeResponse)
.Build();

Expand Down Expand Up @@ -153,8 +152,7 @@ public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithReturnTypeNoData_Thro
Data = Any.Pack(data),
};

var response =
client.Call<InvokeResponse>()
await client.Call<InvokeResponse>()
.SetResponse(invokeResponse)
.Build();

Expand Down Expand Up @@ -210,8 +208,7 @@ public async Task InvokeMethodGrpcAsync_CanInvokeMethodWithNoReturnTypeAndData_T
Data = Any.Pack(data),
};

var response =
client.Call<InvokeResponse>()
await client.Call<InvokeResponse>()
.SetResponse(invokeResponse)
.Build();

Expand Down Expand Up @@ -294,7 +291,7 @@ public async Task InvokeMethodGrpcAsync_WithReturnTypeAndData()

// Validate Response
var invokedResponse = await request.CompleteWithMessageAsync(response);
invokeResponse.Name.Should().Be(invokeResponse.Name);
invokedResponse.Name.Should().Be(invokeResponse.Name);
}

[Fact]
Expand Down
1 change: 0 additions & 1 deletion test/Dapr.Client.Test/DistributedLockApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public async Task TryLockAsync_WithAllValues_ArgumentVerifierException()
string lockOwner = "owner1";
Int32 expiryInSeconds = 0;
// Get response and validate
var invokeResponse = new ArgumentException();
await Assert.ThrowsAsync<ArgumentException>(async () => await client.Lock(storeName, resourceId, lockOwner, expiryInSeconds));
}

Expand Down
6 changes: 3 additions & 3 deletions test/Dapr.Client.Test/InvocationHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task SendAsync_RewritesUri()
};

var request = new HttpRequestMessage(HttpMethod.Post, uri);
var response = await CallSendAsync(handler, request);
await CallSendAsync(handler, request);

Assert.Equal("https://localhost:5000/v1.0/invoke/bank/method/accounts/17?", capture.RequestUri?.OriginalString);
Assert.Null(capture.DaprApiToken);
Expand All @@ -148,7 +148,7 @@ public async Task SendAsync_RewritesUri_AndAppId()
};

var request = new HttpRequestMessage(HttpMethod.Post, uri);
var response = await CallSendAsync(handler, request);
await CallSendAsync(handler, request);

Assert.Equal("https://localhost:5000/v1.0/invoke/Bank/method/accounts/17?", capture.RequestUri?.OriginalString);
Assert.Null(capture.DaprApiToken);
Expand All @@ -172,7 +172,7 @@ public async Task SendAsync_RewritesUri_AndAddsApiToken()
};

var request = new HttpRequestMessage(HttpMethod.Post, uri);
var response = await CallSendAsync(handler, request);
await CallSendAsync(handler, request);

Assert.Equal("https://localhost:5000/v1.0/invoke/bank/method/accounts/17?", capture.RequestUri?.OriginalString);
Assert.Equal("super-duper-secure", capture.DaprApiToken);
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.Client.Test/InvokeBindingApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public async Task InvokeBindingAsync_WrapsJsonException()
return await daprClient.InvokeBindingAsync<InvokeRequest, Widget>("test", "test", new InvokeRequest() { RequestParameter = "Hello " });
});

var envelope = await request.GetRequestEnvelopeAsync<InvokeBindingRequest>();
await request.GetRequestEnvelopeAsync<InvokeBindingRequest>();
var ex = await Assert.ThrowsAsync<DaprException>(async () =>
{
await request.CompleteWithMessageAsync(response);
Expand Down
2 changes: 0 additions & 2 deletions test/Dapr.Client.Test/PublishEventApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public async Task PublishEventAsync_CanPublishTopicWithNoContent()
request.Dismiss();

var envelope = await request.GetRequestEnvelopeAsync<PublishEventRequest>();
var jsonFromRequest = envelope.Data.ToStringUtf8();

envelope.PubsubName.Should().Be(TestPubsubName);
envelope.Topic.Should().Be("test");
Expand Down Expand Up @@ -214,7 +213,6 @@ public async Task PublishEventAsync_CanPublishCloudEventWithNoContent()
{
await using var client = TestClient.CreateForDaprClient();

var publishData = new PublishData() { PublishObjectParameter = "testparam" };
var cloudEvent = new CloudEvent
{
Source = new Uri("urn:testsource"),
Expand Down
23 changes: 11 additions & 12 deletions test/Dapr.Client.Test/StateApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,7 @@ public async Task TrySaveStateAsync_ValidateNonETagErrorThrowsException()
{
var client = new MockClient();

var response = client.CallStateApi<string>()
.Build();
await client.CallStateApi<string>().Build();

var rpcException = new RpcException(new Status(StatusCode.Internal, "Network Error"));

Expand All @@ -861,8 +860,8 @@ public async Task TrySaveStateAsync_ValidateETagRelatedExceptionReturnsFalse()
{
var client = new MockClient();

var response = client.CallStateApi<string>()
.Build();
await client.CallStateApi<string>()
.Build();

var rpcException = new RpcException(new Status(StatusCode.Aborted, $"failed saving state in state store testStore"));
// Setup the mock client to throw an Rpc Exception with the expected details info
Expand All @@ -879,8 +878,8 @@ public async Task TrySaveStateAsync_NullEtagThrowsArgumentException()
{
var client = new MockClient();

var response = client.CallStateApi<string>()
.Build();
await client.CallStateApi<string>()
.Build();

await FluentActions.Awaiting(async () => await client.DaprClient.TrySaveStateAsync("test", "test", "testValue", null))
.Should().ThrowAsync<ArgumentException>();
Expand All @@ -907,8 +906,8 @@ public async Task TryDeleteStateAsync_ValidateNonETagErrorThrowsException()
{
var client = new MockClient();

var response = client.CallStateApi<string>()
.Build();
await client.CallStateApi<string>()
.Build();

var rpcException = new RpcException(new Status(StatusCode.Internal, "Network Error"));

Expand All @@ -929,8 +928,8 @@ public async Task TryDeleteStateAsync_NullEtagThrowsArgumentException()
{
var client = new MockClient();

var response = client.CallStateApi<string>()
.Build();
await client.CallStateApi<string>()
.Build();

await FluentActions.Awaiting(async () => await client.DaprClient.TryDeleteStateAsync("test", "test", null))
.Should().ThrowAsync<ArgumentException>();
Expand All @@ -957,8 +956,8 @@ public async Task TryDeleteStateAsync_ValidateETagRelatedExceptionReturnsFalse()
{
var client = new MockClient();

var response = client.CallStateApi<string>()
.Build();
await client.CallStateApi<string>()
.Build();

var rpcException = new RpcException(new Status(StatusCode.Aborted, $"failed deleting state with key test"));
// Setup the mock client to throw an Rpc Exception with the expected details info
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.Client.Test/TryLockResponseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task TryLockAsync_WithAllValues_ValidateRequest()
Success = true
};

var domainResponse = await request.CompleteWithMessageAsync(invokeResponse);
await request.CompleteWithMessageAsync(invokeResponse);

//testing unlocking

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task TestGeneratedClientAsync()

var client = new ClientActorClient(actorProxy);

var result = await client.GetStateAsync(cancellationTokenSource.Token);
await client.GetStateAsync(cancellationTokenSource.Token);

await client.SetStateAsync(new ClientState("updated state"), cancellationTokenSource.Token);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Dapr.E2E.Test.App/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var logger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger();

var loggerFactory = LoggerFactory.Create(builder =>
LoggerFactory.Create(builder =>
{
builder.AddSerilog(logger);
});
Expand Down
Loading

0 comments on commit 9903a1d

Please sign in to comment.