Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to grpc-dotnet #517

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/aspnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
- run: docker pull camunda/zeebe:1.0.0
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '3.1.x'
dotnet-version: '7.0.x'
- name: Build
run: dotnet build --configuration Release
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: csharp
solution: Zeebe.sln
mono: none
dotnet: 2.1.502
dotnet: 7.0.203
install:
- dotnet restore Zeebe.sln
script:
Expand Down
2 changes: 1 addition & 1 deletion Client.Cloud.Example/Client.Cloud.Example.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
Expand Down
6 changes: 2 additions & 4 deletions Client.Examples/Client.Examples.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -12,8 +12,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.19" />
<PackageReference Include="Newtonsoft.Json" version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.0" />
Expand Down
4 changes: 1 addition & 3 deletions Client.IntegrationTests/Client.IntegrationTests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.19" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.0" />
<PackageReference Include="nunit" Version="3.13.3" />
Expand Down
25 changes: 16 additions & 9 deletions Client.IntegrationTests/ZeebeIntegrationTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class ZeebeIntegrationTestHelper

public const ushort ZeebePort = 26500;

private ITestcontainersContainer container;
private readonly string version;
private IZeebeClient client;

private readonly string version;
private ITestcontainersContainer container;
private int count = 1;

private ZeebeIntegrationTestHelper(string version)
Expand Down Expand Up @@ -55,10 +55,16 @@ public async Task<IZeebeClient> SetupIntegrationTest()

public async Task TearDownIntegrationTest()
{
client.Dispose();
client = null;
await container.StopAsync();
container = null;
try
{
client.Dispose();
client = null;
}
finally
{
await container.StopAsync();
container = null;
}
}

private TestcontainersContainer CreateZeebeContainer()
Expand All @@ -81,7 +87,9 @@ private IZeebeClient CreateZeebeClient()
loggingBuilder.AddNLog(path);
});

var host = container.Hostname + ":" + container.GetMappedPublicPort(ZeebePort);
// It has to be a valid Uri
// e.g. IP address without scheme or hostname with scheme
var host = "http://" + container.Hostname + ":" + container.GetMappedPublicPort(ZeebePort);

return ZeebeClient.Builder()
.UseLoggerFactory(loggerFactory)
Expand All @@ -104,8 +112,7 @@ private async Task AwaitBrokerReadiness()
{
// retry
}
}
while (!ready);
} while (!ready);
}
}
}
21 changes: 11 additions & 10 deletions Client.UnitTests/ActivateJobTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GatewayProtocol;
using Grpc.Core;
using NUnit.Framework;
using Zeebe.Client.Helpers;
using static Zeebe.Client.JobWorkerTest;

namespace Zeebe.Client
Expand All @@ -25,7 +26,7 @@ public async Task ShouldSendRequestReceiveResponseAsExpected()
RequestTimeout = 5_000L
};

TestService.AddRequestHandler(typeof(ActivateJobsRequest), request => CreateExpectedResponse());
TestService.AddRequestHandler<ActivateJobsRequest>(_ => CreateExpectedResponse());

// when
var response = await ZeebeClient.NewActivateJobsCommand()
Expand All @@ -52,6 +53,7 @@ public async Task ShouldSendRequestReceiveResponseAsExpected()
public void ShouldTimeoutRequest()
{
// given
TestService.Reset();

// when
var task = ZeebeClient.NewActivateJobsCommand()
Expand All @@ -61,17 +63,17 @@ public void ShouldTimeoutRequest()
.WorkerName("jobWorker")
.PollingTimeout(TimeSpan.FromSeconds(5))
.Send(TimeSpan.Zero);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];
var rpcException = Assert.Throws<RpcException>(() => task.GetAwaiter().GetResult());

// then
Assert.AreEqual(Grpc.Core.StatusCode.DeadlineExceeded, rpcException.Status.StatusCode);
Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException!.Status.StatusCode);
}

[Test]
public void ShouldCancelRequest()
{
// given
TestService.Reset();

// when
var task = ZeebeClient.NewActivateJobsCommand()
Expand All @@ -81,11 +83,10 @@ public void ShouldCancelRequest()
.WorkerName("jobWorker")
.PollingTimeout(TimeSpan.FromSeconds(5))
.Send(new CancellationTokenSource(TimeSpan.Zero).Token);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];
var rpcException = Assert.Throws<RpcException>(() => task.GetAwaiter().GetResult());

// then
Assert.AreEqual(Grpc.Core.StatusCode.Cancelled, rpcException.Status.StatusCode);
Assert.AreEqual(StatusCode.Cancelled, rpcException!.Status.StatusCode);
}

[Test]
Expand All @@ -102,7 +103,7 @@ public async Task ShouldSendRequestWithFetchVariablesReceiveResponseAsExpected()
RequestTimeout = 1_000L
};

TestService.AddRequestHandler(typeof(ActivateJobsRequest), request => CreateExpectedResponse());
TestService.AddRequestHandler<ActivateJobsRequest>(_ => CreateExpectedResponse());

// when
var response = await ZeebeClient.NewActivateJobsCommand()
Expand Down Expand Up @@ -140,7 +141,7 @@ public async Task ShouldSendRequestWithFetchVariablesListReceiveResponseAsExpect
RequestTimeout = 5_000L
};
IList<string> variableNames = new List<string> { "foo", "bar", "test" };
TestService.AddRequestHandler(typeof(ActivateJobsRequest), request => CreateExpectedResponse());
TestService.AddRequestHandler<ActivateJobsRequest>(_ => CreateExpectedResponse());

// when
var response = await ZeebeClient.NewActivateJobsCommand()
Expand All @@ -164,4 +165,4 @@ public async Task ShouldSendRequestWithFetchVariablesListReceiveResponseAsExpect
AssertJob(receivedJobs[2], 3);
}
}
}
}
73 changes: 0 additions & 73 deletions Client.UnitTests/BaseZeebeTest.cs

This file was deleted.

10 changes: 7 additions & 3 deletions Client.UnitTests/CancelProcessInstanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GatewayProtocol;
using Grpc.Core;
using NUnit.Framework;
using Zeebe.Client.Helpers;

namespace Zeebe.Client
{
Expand All @@ -18,6 +19,7 @@ public async Task ShouldSendRequestAsExpected()
{
ProcessInstanceKey = 12113
};
TestService.Reset();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ For what these resets have been added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the logic of these tests and share the same server across all. The execution is now way more faster. But I need to reset its state, otherwise the expectation is polluted by previous methods.


// when
await ZeebeClient.NewCancelInstanceCommand(12113).Send();
Expand All @@ -31,12 +33,13 @@ public async Task ShouldSendRequestAsExpected()
public void ShouldTimeoutRequest()
{
// given
TestService.Reset();

// when
var task = ZeebeClient.NewCancelInstanceCommand(12113)
.Send(TimeSpan.Zero);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];
var rpcException = (RpcException) aggregateException.InnerExceptions[0];

// then
Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException.Status.StatusCode);
Expand All @@ -46,15 +49,16 @@ public void ShouldTimeoutRequest()
public void ShouldCancelRequest()
{
// given
TestService.Reset();

// when
var task = ZeebeClient.NewCancelInstanceCommand(12113)
.Send(new CancellationTokenSource(TimeSpan.Zero).Token);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];
var rpcException = (RpcException) aggregateException.InnerExceptions[0];

// then
Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode);
}
}
}
}
4 changes: 2 additions & 2 deletions Client.UnitTests/Client.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Zeebe.Client</RootNamespace>
</PropertyGroup>

Expand Down
12 changes: 9 additions & 3 deletions Client.UnitTests/CompleteJobTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using GatewayProtocol;
using Grpc.Core;
using NUnit.Framework;
using Zeebe.Client.Helpers;

namespace Zeebe.Client
{
Expand All @@ -36,6 +37,7 @@ public async Task ShouldSendRequestAsExpected()
JobKey = jobKey,
Variables = variables
};
TestService.Reset();

// when
await ZeebeClient.NewCompleteJobCommand(jobKey).Variables(variables).Send();
Expand All @@ -52,6 +54,7 @@ public void ShouldTimeoutRequest()
// given
const string variables = "{\"foo\":23}";
const int jobKey = 255;
TestService.Reset();

// when
var task = ZeebeClient.NewCompleteJobCommand(jobKey).Variables(variables).Send(TimeSpan.Zero);
Expand All @@ -68,11 +71,13 @@ public void ShouldCancelRequest()
// given
const string variables = "{\"foo\":23}";
const int jobKey = 255;
TestService.Reset();

// when
var task = ZeebeClient.NewCompleteJobCommand(jobKey).Variables(variables).Send(new CancellationTokenSource(TimeSpan.Zero).Token);
var task = ZeebeClient.NewCompleteJobCommand(jobKey).Variables(variables)
.Send(new CancellationTokenSource(TimeSpan.Zero).Token);
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait());
var rpcException = (RpcException)aggregateException.InnerExceptions[0];
var rpcException = (RpcException) aggregateException.InnerExceptions[0];

// then
Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode);
Expand All @@ -93,6 +98,7 @@ public async Task ShouldUseActivatedJobToComplete()
JobKey = jobKey,
Variables = variables
};
TestService.Reset();

// when
await ZeebeClient.NewCompleteJobCommand(activatedJob).Variables(variables).Send();
Expand All @@ -103,4 +109,4 @@ public async Task ShouldUseActivatedJobToComplete()
Assert.AreEqual(expectedRequest, actualRequest);
}
}
}
}
Loading