-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from camunda-community-hub/zell-fix-activation
Fix job worker activation and handling
- Loading branch information
Showing
10 changed files
with
179 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Zeebe.Client; | ||
using Zeebe.Client.Api.Responses; | ||
|
||
namespace Client.IntegrationTests | ||
{ | ||
[TestFixture] | ||
public class JobWorkerMultiPartitionTest | ||
{ | ||
private static readonly string DemoProcessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "oneTaskProcess.bpmn"); | ||
|
||
private readonly ZeebeIntegrationTestHelper testHelper = ZeebeIntegrationTestHelper.Latest().withPartitionCount(3); | ||
private IZeebeClient zeebeClient; | ||
private long processDefinitionKey; | ||
|
||
[OneTimeSetUp] | ||
public async Task Setup() | ||
{ | ||
zeebeClient = await testHelper.SetupIntegrationTest(); | ||
var deployResponse = await zeebeClient.NewDeployCommand() | ||
.AddResourceFile(DemoProcessPath) | ||
.Send(); | ||
processDefinitionKey = deployResponse.Processes[0].ProcessDefinitionKey; | ||
} | ||
|
||
[OneTimeTearDown] | ||
public async Task Stop() | ||
{ | ||
await testHelper.TearDownIntegrationTest(); | ||
} | ||
|
||
[Test] | ||
public async Task ShouldHandleAllJobs() | ||
{ | ||
// given | ||
var handledJobs = new List<IJob>(); | ||
foreach (int i in Enumerable.Range(1, 3)) | ||
{ | ||
await zeebeClient.NewCreateProcessInstanceCommand() | ||
.ProcessDefinitionKey(processDefinitionKey) | ||
.Send(); | ||
} | ||
|
||
// when | ||
using (var signal = new EventWaitHandle(false, EventResetMode.AutoReset)) | ||
{ | ||
using (zeebeClient.NewWorker() | ||
.JobType("oneTask") | ||
.Handler(async (jobClient, job) => | ||
{ | ||
await jobClient.NewCompleteJobCommand(job).Send(); | ||
handledJobs.Add(job); | ||
if (handledJobs.Count >= 3) | ||
{ | ||
signal.Set(); | ||
} | ||
}) | ||
.MaxJobsActive(5) | ||
.Name("csharpWorker") | ||
.Timeout(TimeSpan.FromHours(10)) | ||
.PollInterval(TimeSpan.FromSeconds(5)) | ||
.Open()) | ||
{ | ||
signal.WaitOne(TimeSpan.FromSeconds(5)); | ||
} | ||
} | ||
|
||
Assert.AreEqual(3, handledJobs.Count); | ||
} | ||
|
||
|
||
[Test] | ||
public async Task ShouldActivateAllJobs() | ||
{ | ||
// given | ||
foreach (int i in Enumerable.Range(1, 3)) | ||
{ | ||
await zeebeClient.NewCreateProcessInstanceCommand() | ||
.ProcessDefinitionKey(processDefinitionKey) | ||
.Send(); | ||
} | ||
|
||
// when | ||
var activateJobsResponse = await zeebeClient.NewActivateJobsCommand() | ||
.JobType("oneTask") | ||
.MaxJobsToActivate(5) | ||
.WorkerName("csharpWorker") | ||
.Timeout(TimeSpan.FromHours(10)) | ||
.Send(); | ||
|
||
Assert.AreEqual(3, activateJobsResponse.Jobs.Count); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,4 @@ public async Task ShouldCompleteProcessWithJobAutoCompletion() | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.