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

Migrate to deploy resource #546

Merged
merged 6 commits into from
Jul 15, 2023
Merged
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
10 changes: 5 additions & 5 deletions Client.IntegrationTests/JobWorkerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public async Task ShouldCompleteProcess()
.JobType("oneTask")
.Handler(async (jobClient, job) =>
{
await jobClient.NewCompleteJobCommand(job).Send();
handledJobs.Add(job);
await jobClient.NewCompleteJobCommand(job).Send();
})
.MaxJobsActive(1)
.Name("csharpWorker")
.Name("ShouldCompleteProcess")
.Timeout(TimeSpan.FromSeconds(10))
.PollInterval(TimeSpan.FromMilliseconds(100))
.PollingTimeout(TimeSpan.FromSeconds(30L))
Expand All @@ -60,7 +60,7 @@ public async Task ShouldCompleteProcess()
.Send();

// then process was completed
Assert.AreEqual(1, handledJobs.Count);
Assert.AreEqual(1, handledJobs.Count, "Jobs handled");

Assert.AreEqual(processInstance.Version, 1);
Assert.AreEqual(processDefinitionKey, processInstance.ProcessDefinitionKey);
Expand All @@ -78,10 +78,10 @@ public async Task ShouldCompleteProcessWithJobAutoCompletion()
// when
using (zeebeClient.NewWorker()
.JobType("oneTask")
.Handler((jobClient, job) => handledJobs.Add(job))
.Handler((_, job) => handledJobs.Add(job))
.MaxJobsActive(1)
.AutoCompletion()
.Name("csharpWorker")
.Name("ShouldCompleteProcessWithJobAutoCompletion")
.Timeout(TimeSpan.FromSeconds(10))
.PollInterval(TimeSpan.FromMilliseconds(100))
.PollingTimeout(TimeSpan.FromSeconds(30L))
Expand Down
10 changes: 5 additions & 5 deletions Client.IntegrationTests/ZeebeIntegrationTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Client.IntegrationTests
{
public class ZeebeIntegrationTestHelper
{
public const string LatestVersion = "1.2.4";
public const string LatestVersion = "8.2.8";

public const ushort ZeebePort = 26500;
private const ushort ZeebePort = 26500;

private ITestcontainersContainer container;
private IContainer container;
private IZeebeClient client;

private readonly string version;
Expand Down Expand Up @@ -61,9 +61,9 @@ public async Task TearDownIntegrationTest()
container = null;
}

private TestcontainersContainer CreateZeebeContainer()
private IContainer CreateZeebeContainer()
{
return new TestcontainersBuilder<TestcontainersContainer>()
return new ContainerBuilder()
.WithImage(new DockerImage("camunda", "zeebe", version))
.WithPortBinding(ZeebePort, true)
.WithEnvironment("ZEEBE_BROKER_CLUSTER_PARTITIONSCOUNT", count.ToString())
Expand Down
167 changes: 106 additions & 61 deletions Client.UnitTests/DeploymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public class DeploymentTest : BaseZeebeTest
public async Task ShouldSendDeployResourceFileAsExpected()
{
// given
var expectedRequest = new DeployProcessRequest
var expectedRequest = new DeployResourceRequest
{
Processes =
Resources =
{
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
}
}
Expand All @@ -35,7 +35,7 @@ public async Task ShouldSendDeployResourceFileAsExpected()
await ZeebeClient.NewDeployCommand().AddResourceFile(_demoProcessPath).Send();

// then
var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];
var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0];

Assert.AreEqual(expectedRequest, actualRequest);
}
Expand Down Expand Up @@ -78,13 +78,13 @@ public void ShouldCancelRequest()
public async Task ShouldSendDeployResourceStringAsExpected()
{
// given
var expectedRequest = new DeployProcessRequest
var expectedRequest = new DeployResourceRequest
{
Processes =
Resources =
{
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
}
}
Expand All @@ -97,7 +97,7 @@ await ZeebeClient.NewDeployCommand()
.Send();

// then
var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];
var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0];

Assert.AreEqual(expectedRequest, actualRequest);
}
Expand All @@ -106,13 +106,13 @@ await ZeebeClient.NewDeployCommand()
public async Task ShouldSendDeployResourceStringUtf8AsExpected()
{
// given
var expectedRequest = new DeployProcessRequest
var expectedRequest = new DeployResourceRequest
{
Processes =
Resources =
{
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
}
}
Expand All @@ -125,7 +125,7 @@ await ZeebeClient.NewDeployCommand()
.Send();

// then
var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];
var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0];

Assert.AreEqual(expectedRequest, actualRequest);
}
Expand All @@ -134,13 +134,13 @@ await ZeebeClient.NewDeployCommand()
public async Task ShouldSendDeployResourceBytesAsExpected()
{
// given
var expectedRequest = new DeployProcessRequest
var expectedRequest = new DeployResourceRequest
{
Processes =
Resources =
{
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
}
}
Expand All @@ -153,7 +153,7 @@ await ZeebeClient.NewDeployCommand()
.Send();

// then
var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];
var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0];

Assert.AreEqual(expectedRequest, actualRequest);
}
Expand All @@ -162,13 +162,13 @@ await ZeebeClient.NewDeployCommand()
public async Task ShouldSendDeployResourceStreamAsExpected()
{
// given
var expectedRequest = new DeployProcessRequest
var expectedRequest = new DeployResourceRequest
{
Processes =
Resources =
{
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
}
}
Expand All @@ -180,7 +180,7 @@ await ZeebeClient.NewDeployCommand()
.Send();

// then
var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];
var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0];

Assert.AreEqual(expectedRequest, actualRequest);
}
Expand All @@ -189,16 +189,25 @@ await ZeebeClient.NewDeployCommand()
public async Task ShouldSendDeployResourceAndGetResponseAsExpected()
{
// given
var expectedResponse = new DeployProcessResponse { Key = 1 };
expectedResponse.Processes.Add(new ProcessMetadata
var expectedResponse = new DeployResourceResponse
{
BpmnProcessId = "process",
ResourceName = _demoProcessPath,
Version = 1,
ProcessDefinitionKey = 2
});
Key = 1,
Deployments =
{
new Deployment
{
Process = new ProcessMetadata
{
BpmnProcessId = "process",
ResourceName = _demoProcessPath,
Version = 1,
ProcessDefinitionKey = 2
}
}
}
};

TestService.AddRequestHandler(typeof(DeployProcessRequest), request => expectedResponse);
TestService.AddRequestHandler(typeof(DeployResourceRequest), request => expectedResponse);

// when
var deployProcessResponse = await ZeebeClient.NewDeployCommand()
Expand All @@ -220,18 +229,18 @@ public async Task ShouldSendDeployResourceAndGetResponseAsExpected()
public async Task ShouldSendMultipleDeployResourceAsExpected()
{
// given
var expectedRequest = new DeployProcessRequest
var expectedRequest = new DeployResourceRequest
{
Processes =
Resources =
{
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
},
new ProcessRequestObject
new Resource
{
Definition = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Content = ByteString.FromStream(File.OpenRead(_demoProcessPath)),
Name = _demoProcessPath,
}
}
Expand All @@ -244,7 +253,7 @@ await ZeebeClient.NewDeployCommand()
.Send();

// then
var actualRequest = TestService.Requests[typeof(DeployProcessRequest)][0];
var actualRequest = TestService.Requests[typeof(DeployResourceRequest)][0];

Assert.AreEqual(expectedRequest, actualRequest);
}
Expand All @@ -253,23 +262,48 @@ await ZeebeClient.NewDeployCommand()
public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected()
{
// given
var expectedResponse = new DeployProcessResponse { Key = 1 };
expectedResponse.Processes.Add(new ProcessMetadata
{
BpmnProcessId = "process",
ResourceName = _demoProcessPath,
Version = 1,
ProcessDefinitionKey = 2
});
expectedResponse.Processes.Add(new ProcessMetadata
var expectedResponse = new DeployResourceResponse
{
BpmnProcessId = "process2",
ResourceName = _demoProcessPath,
Version = 1,
ProcessDefinitionKey = 3
});
Key = 1,
Deployments =
{
new Deployment
{
Process = new ProcessMetadata
{
BpmnProcessId = "process",
ResourceName = _demoProcessPath,
Version = 1,
ProcessDefinitionKey = 2
}
},
new Deployment
{
Decision = new DecisionMetadata
{
DecisionKey = 1,
DecisionRequirementsKey = 2,
Version = 3,
DmnDecisionId = "decisionId",
DmnDecisionName = "decisionName",
DmnDecisionRequirementsId = "idk",
}
},
new Deployment
{
DecisionRequirements = new DecisionRequirementsMetadata
{
Version = 1,
ResourceName = "requirement",
DecisionRequirementsKey = 2,
DmnDecisionRequirementsId = "id",
DmnDecisionRequirementsName = "nameRequirement"
}
}
}
};

TestService.AddRequestHandler(typeof(DeployProcessRequest), request => expectedResponse);
TestService.AddRequestHandler(typeof(DeployResourceRequest), request => expectedResponse);

// when
var fileContent = File.ReadAllText(_demoProcessPath);
Expand All @@ -280,19 +314,30 @@ public async Task ShouldSendMultipleDeployResourceAndGetResponseAsExpected()

// then
Assert.AreEqual(1, deployProcessResponse.Key);
Assert.AreEqual(2, deployProcessResponse.Processes.Count);
Assert.AreEqual(1, deployProcessResponse.Processes.Count);
Assert.AreEqual(1, deployProcessResponse.Decisions.Count);
Assert.AreEqual(1, deployProcessResponse.DecisionRequirements.Count);

var processMetadata = deployProcessResponse.Processes[0];
Assert.AreEqual("process", processMetadata.BpmnProcessId);
Assert.AreEqual(1, processMetadata.Version);
Assert.AreEqual(_demoProcessPath, processMetadata.ResourceName);
Assert.AreEqual(2, processMetadata.ProcessDefinitionKey);

var processMetadata2 = deployProcessResponse.Processes[1];
Assert.AreEqual("process2", processMetadata2.BpmnProcessId);
Assert.AreEqual(1, processMetadata2.Version);
Assert.AreEqual(_demoProcessPath, processMetadata2.ResourceName);
Assert.AreEqual(3, processMetadata2.ProcessDefinitionKey);
var decisionMetadata = deployProcessResponse.Decisions[0];
Assert.AreEqual(1, decisionMetadata.DecisionKey);
Assert.AreEqual(2, decisionMetadata.DecisionRequirementsKey);
Assert.AreEqual(3, decisionMetadata.Version);
Assert.AreEqual("decisionId", decisionMetadata.DmnDecisionId);
Assert.AreEqual("decisionName", decisionMetadata.DmnDecisionName);
Assert.AreEqual("idk", decisionMetadata.DmnDecisionRequirementsId);

var decisionRequirementsMetadata = deployProcessResponse.DecisionRequirements[0];
Assert.AreEqual(2, decisionRequirementsMetadata.DecisionRequirementsKey);
Assert.AreEqual(1, decisionRequirementsMetadata.Version);
Assert.AreEqual("requirement", decisionRequirementsMetadata.ResourceName);
Assert.AreEqual("nameRequirement", decisionRequirementsMetadata.DmnDecisionRequirementsName);
Assert.AreEqual("id", decisionRequirementsMetadata.DmnDecisionRequirementsId);
}
}
}
7 changes: 6 additions & 1 deletion Client.UnitTests/GatewayTestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public GatewayTestService()
typedRequestHandler.Add(typeof(UpdateJobRetriesRequest), request => new UpdateJobRetriesResponse());
typedRequestHandler.Add(typeof(ThrowErrorRequest), request => new ThrowErrorResponse());

typedRequestHandler.Add(typeof(DeployProcessRequest), request => new DeployProcessResponse());
typedRequestHandler.Add(typeof(DeployResourceRequest), request => new DeployResourceResponse());
typedRequestHandler.Add(typeof(CreateProcessInstanceRequest), request => new CreateProcessInstanceResponse());
typedRequestHandler.Add(typeof(CancelProcessInstanceRequest), request => new CancelProcessInstanceResponse());
typedRequestHandler.Add(typeof(SetVariablesRequest), request => new SetVariablesResponse());
Expand Down Expand Up @@ -139,6 +139,11 @@ public override Task<CreateProcessInstanceWithResultResponse> CreateProcessInsta
return Task.FromResult((CreateProcessInstanceWithResultResponse)HandleRequest(request, context));
}

public override Task<DeployResourceResponse> DeployResource(DeployResourceRequest request, ServerCallContext context)
{
return Task.FromResult((DeployResourceResponse)HandleRequest(request, context));
}

public delegate void ConsumeMetadata(Metadata metadata);

public void ConsumeRequestHeaders(ConsumeMetadata consumer)
Expand Down
Loading