From 506a5753f24c5abb18dcd03d0b40344da3bf7cc4 Mon Sep 17 00:00:00 2001 From: ShawnAbshire Date: Sun, 5 Nov 2023 14:05:41 -0600 Subject: [PATCH] feat(multitenancy): ActivateJobsCommand updated to set tenantIds. --- Client.UnitTests/ActivateJobTest.cs | 39 +++++++++++++++++++ .../Api/Commands/IActivateJobsCommandStep1.cs | 4 +- Client/Api/Commands/ITenantIdsCommandStep.cs | 23 +++++++++++ Client/Impl/Commands/ActivateJobsCommand.cs | 14 +++++++ 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 Client/Api/Commands/ITenantIdsCommandStep.cs diff --git a/Client.UnitTests/ActivateJobTest.cs b/Client.UnitTests/ActivateJobTest.cs index 3d4ef607..dc1ead8e 100644 --- a/Client.UnitTests/ActivateJobTest.cs +++ b/Client.UnitTests/ActivateJobTest.cs @@ -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 tenantIds = new List { "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); + } } } diff --git a/Client/Api/Commands/IActivateJobsCommandStep1.cs b/Client/Api/Commands/IActivateJobsCommandStep1.cs index b757a993..ce65bfb2 100644 --- a/Client/Api/Commands/IActivateJobsCommandStep1.cs +++ b/Client/Api/Commands/IActivateJobsCommandStep1.cs @@ -18,7 +18,7 @@ namespace Zeebe.Client.Api.Commands { - public interface IActivateJobsCommandStep1 + public interface IActivateJobsCommandStep1 : ITenantIdsCommandStep { /// /// Set the type of jobs to work on. @@ -28,7 +28,7 @@ public interface IActivateJobsCommandStep1 IActivateJobsCommandStep2 JobType(string jobType); } - public interface IActivateJobsCommandStep2 + public interface IActivateJobsCommandStep2 { /// /// Set the maximum of jobs to activate. If less jobs are available for activation the diff --git a/Client/Api/Commands/ITenantIdsCommandStep.cs b/Client/Api/Commands/ITenantIdsCommandStep.cs new file mode 100644 index 00000000..d9407354 --- /dev/null +++ b/Client/Api/Commands/ITenantIdsCommandStep.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace Zeebe.Client.Api.Commands +{ + public interface ITenantIdsCommandStep + { + /// + /// Set a lit of tenantIds to associate to this resource. + /// + /// the tenant to associate to this resource. + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T AddTenantIds(IList tenantIds); + + /// + /// Set a list of tenantIds to associate to this resource. + /// + /// the tenant to associate to this resource. + /// The builder for this command. Call to complete the command and send it + /// to the broker. + T AddTenantIds(params string[] tenantIds); + } +} \ No newline at end of file diff --git a/Client/Impl/Commands/ActivateJobsCommand.cs b/Client/Impl/Commands/ActivateJobsCommand.cs index 3beaf005..976428fa 100644 --- a/Client/Impl/Commands/ActivateJobsCommand.cs +++ b/Client/Impl/Commands/ActivateJobsCommand.cs @@ -29,6 +29,20 @@ public IActivateJobsCommandStep2 JobType(string jobType) return this; } + public IActivateJobsCommandStep1 AddTenantIds(IList 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;