Skip to content

Commit

Permalink
ActivateJobsCommand updated to set tenantIds.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnAbshire committed Nov 5, 2023
1 parent 5cd1a1d commit 097450a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
39 changes: 39 additions & 0 deletions Client.UnitTests/ActivateJobTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,44 @@ public async Task ShouldSendRequestWithFetchVariablesListReceiveResponseAsExpect
AssertJob(receivedJobs[1], 2);
AssertJob(receivedJobs[2], 3);
}

[Test]
public async Task ShouldSendRequestWithTenantIdsListReceiveResponseAsExpected()
{
// given
var expectedRequest = new ActivateJobsRequest
{
Type = "foo",
Worker = "jobWorker",
Timeout = 10_000L,
MaxJobsToActivate = 1,
RequestTimeout = 5_000L,
TenantIds = { "1234", "5678" }
};

IList<string> tenantIds = new List<string> { "1234", "5678" };
TestService.AddRequestHandler(typeof(ActivateJobsRequest), _ => CreateExpectedResponse());

// when
var response = await ZeebeClient.NewActivateJobsCommand()
.AddTenantIds(tenantIds)
.JobType("foo")
.MaxJobsToActivate(1)
.Timeout(TimeSpan.FromSeconds(10))
.WorkerName("jobWorker")
.PollingTimeout(TimeSpan.FromSeconds(5))
.Send();

// then
var actualRequest = TestService.Requests[typeof(ActivateJobsRequest)][0];
Assert.AreEqual(expectedRequest, actualRequest);

var receivedJobs = response.Jobs;
Assert.AreEqual(receivedJobs.Count, 3);

AssertJob(receivedJobs[0], 1);
AssertJob(receivedJobs[1], 2);
AssertJob(receivedJobs[2], 3);
}
}
}
4 changes: 2 additions & 2 deletions Client/Api/Commands/IActivateJobsCommandStep1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Zeebe.Client.Api.Commands
{
public interface IActivateJobsCommandStep1
public interface IActivateJobsCommandStep1 : ITenantIdsCommandStep<IActivateJobsCommandStep1>
{
/// <summary>
/// Set the type of jobs to work on.
Expand All @@ -28,7 +28,7 @@ public interface IActivateJobsCommandStep1
IActivateJobsCommandStep2 JobType(string jobType);
}

public interface IActivateJobsCommandStep2
public interface IActivateJobsCommandStep2
{
/// <summary>
/// Set the maximum of jobs to activate. If less jobs are available for activation the
Expand Down
23 changes: 23 additions & 0 deletions Client/Api/Commands/ITenantIdsCommandStep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;

namespace Zeebe.Client.Api.Commands
{
public interface ITenantIdsCommandStep<out T>
{
/// <summary>
/// Set a lit of tenantIds to associate to this resource.
/// </summary>
/// <param name="tenantIds">the tenant to associate to this resource.</param>
/// <returns>The builder for this command. Call <see cref="IFinalCommandStep{T}.Send"/> to complete the command and send it
/// to the broker.</returns>
T AddTenantIds(IList<string> tenantIds);

/// <summary>
/// Set a list of tenantIds to associate to this resource.
/// </summary>
/// <param name="tenantIds">the tenant to associate to this resource.</param>
/// <returns>The builder for this command. Call <see cref="IFinalCommandStep{T}.Send"/> to complete the command and send it
/// to the broker.</returns>
T AddTenantIds(params string[] tenantIds);
}
}
14 changes: 14 additions & 0 deletions Client/Impl/Commands/ActivateJobsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public IActivateJobsCommandStep2 JobType(string jobType)
return this;
}

public IActivateJobsCommandStep1 AddTenantIds(IList<string> tenantIds)
{
Request.TenantIds.AddRange(tenantIds);

return this;
}

public IActivateJobsCommandStep1 AddTenantIds(params string[] tenantIds)
{
Request.TenantIds.AddRange(tenantIds);

return this;
}

public IActivateJobsCommandStep3 MaxJobsToActivate(int maxJobsToActivate)
{
Request.MaxJobsToActivate = maxJobsToActivate;
Expand Down

0 comments on commit 097450a

Please sign in to comment.