-
Notifications
You must be signed in to change notification settings - Fork 30
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 #45 from AMalininHere/fetch-and-lock-request-provider
Add FetchAndLockRequestProvider
- Loading branch information
Showing
13 changed files
with
186 additions
and
54 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
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
12 changes: 12 additions & 0 deletions
12
src/Camunda.Worker/Execution/IFetchAndLockRequestProvider.cs
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,12 @@ | ||
using Camunda.Worker.Client; | ||
|
||
namespace Camunda.Worker.Execution | ||
{ | ||
public interface IFetchAndLockRequestProvider | ||
{ | ||
/// <summary> | ||
/// This method is called in the worker before each "fetch and lock" operation | ||
/// </summary> | ||
FetchAndLockRequest GetRequest(); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/Camunda.Worker/Execution/LegacyFetchAndLockRequestProvider.cs
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,34 @@ | ||
using Camunda.Worker.Client; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Camunda.Worker.Execution | ||
{ | ||
internal class LegacyFetchAndLockRequestProvider : IFetchAndLockRequestProvider | ||
{ | ||
private readonly ITopicsProvider _topicsProvider; | ||
private readonly FetchAndLockOptions _options; | ||
|
||
internal LegacyFetchAndLockRequestProvider( | ||
ITopicsProvider topicsProvider, | ||
IOptions<FetchAndLockOptions> options | ||
) | ||
{ | ||
_topicsProvider = topicsProvider; | ||
_options = options.Value; | ||
} | ||
|
||
public FetchAndLockRequest GetRequest() | ||
{ | ||
var topics = _topicsProvider.GetTopics(); | ||
|
||
var fetchAndLockRequest = new FetchAndLockRequest(_options.WorkerId, _options.MaxTasks) | ||
{ | ||
UsePriority = _options.UsePriority, | ||
AsyncResponseTimeout = _options.AsyncResponseTimeout, | ||
Topics = topics | ||
}; | ||
|
||
return fetchAndLockRequest; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Generic; | ||
using Camunda.Worker.Execution; | ||
|
||
namespace Camunda.Worker | ||
{ | ||
public class WorkerServiceOptions | ||
{ | ||
internal WorkerServiceOptions(string workerId, IEnumerable<HandlerDescriptor> handlerDescriptors) | ||
{ | ||
WorkerId = Guard.NotNull(workerId, nameof(workerId)); | ||
HandlerDescriptors = Guard.NotNull(handlerDescriptors, nameof(handlerDescriptors)); | ||
} | ||
|
||
public string WorkerId { get; } | ||
|
||
public IEnumerable<HandlerDescriptor> HandlerDescriptors { get; } | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
test/Camunda.Worker.Tests/Execution/LegacyFetchAndLockRequestProviderTests.cs
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,46 @@ | ||
using System.Linq; | ||
using Bogus; | ||
using Camunda.Worker.Client; | ||
using Microsoft.Extensions.Options; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Camunda.Worker.Execution | ||
{ | ||
public class LegacyFetchAndLockRequestProviderTests | ||
{ | ||
[Fact] | ||
public void GetRequest_ShouldReturnsRequest() | ||
{ | ||
// Arrange | ||
var fetchAndLockOptions = new Faker<FetchAndLockOptions>() | ||
.RuleFor(o => o.WorkerId, f => f.Lorem.Word()) | ||
.RuleFor(o => o.MaxTasks, f => f.Random.Int(1, 10)) | ||
.RuleFor(o => o.AsyncResponseTimeout, f => f.Random.Int(100, 10000)) | ||
.RuleFor(o => o.UsePriority, f => f.Random.Bool()) | ||
.Generate(); | ||
|
||
var topics = new Faker<FetchAndLockRequest.Topic>() | ||
.CustomInstantiator(f => new FetchAndLockRequest.Topic(f.Random.Hash(), f.Random.Int(1000, 10000))) | ||
.GenerateLazy(5) | ||
.ToList(); | ||
var topicsProviderMock = new Mock<ITopicsProvider>(); | ||
topicsProviderMock.Setup(p => p.GetTopics()).Returns(topics); | ||
|
||
var sut = new LegacyFetchAndLockRequestProvider( | ||
topicsProviderMock.Object, | ||
Options.Create(fetchAndLockOptions) | ||
); | ||
|
||
// Act | ||
var request = sut.GetRequest(); | ||
|
||
// Assert | ||
Assert.Same(topics, request.Topics); | ||
Assert.Equal(fetchAndLockOptions.WorkerId, request.WorkerId); | ||
Assert.Equal(fetchAndLockOptions.MaxTasks, request.MaxTasks); | ||
Assert.Equal(fetchAndLockOptions.AsyncResponseTimeout, request.AsyncResponseTimeout); | ||
Assert.Equal(fetchAndLockOptions.UsePriority, request.UsePriority); | ||
} | ||
} | ||
} |
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