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

fix: Add fetchVariable parameter support in ActivateJobs RPC #1058

Merged
2 commits merged into from
Jan 31, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ and provide you with a set of assertions you can use to verify your process beha

### Dependency

Zeepe Process Test provides you with two dependencies. Which one you need to use is dependent on the
Zeebe Process Test provides you with two dependencies. Which one you need to use is dependent on the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like that you're improving the things you encounter!

Java version you are using.

#### Embedded (JDK 21+)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import io.camunda.zeebe.util.buffer.BufferUtil;
import io.grpc.stub.ServerCallStreamObserver;
import io.grpc.stub.StreamObserver;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -151,6 +152,7 @@ public void activateJobs(
jobBatchRecord.setWorker(request.getWorker());
jobBatchRecord.setTimeout(request.getTimeout());
jobBatchRecord.setMaxJobsToActivate(request.getMaxJobsToActivate());
setJobBatchRecordVariables(jobBatchRecord, request.getFetchVariableList());

writer.writeCommandWithoutKey(jobBatchRecord, recordMetadata);
}
Expand Down Expand Up @@ -601,6 +603,14 @@ public void broadcastSignal(
.intent(SignalIntent.BROADCAST));
}

private void setJobBatchRecordVariables(
final JobBatchRecord jobBatchRecord, final List<String> fetchVariables) {
final ValueArray<StringValue> variables = jobBatchRecord.variables();
fetchVariables.stream()
.map(BufferUtil::wrapString)
.forEach(buffer -> variables.add().wrap(buffer));
}

private ProcessInstanceModificationRecord createProcessInstanceModificationRecord(
final ModifyProcessInstanceRequest request) {
final var record = new ProcessInstanceModificationRecord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,58 @@ void shouldUpdateRetiresOnJob() {
});
}

@Test
void shouldReturnOnlySpecifiedVariablesOnJobActivation() {
// given
zeebeClient
.newDeployResourceCommand()
.addProcessModel(
Bpmn.createExecutableProcess("simpleProcess")
.startEvent()
.serviceTask("task", (task) -> task.zeebeJobType("jobType"))
.endEvent()
.done(),
"simpleProcess.bpmn")
.send()
.join();

zeebeClient
.newCreateInstanceCommand()
.bpmnProcessId("simpleProcess")
.latestVersion()
.variables(
Map.ofEntries(
Map.entry("var_a", "val_a"),
Map.entry("var_b", "val_b"),
Map.entry("var_c", "val_c"),
Map.entry("var_d", "val_d")))
.send()
.join();

Awaitility.await()
.untilAsserted(
() -> {
// when
final ActivateJobsResponse activateJobsResponse =
zeebeClient
.newActivateJobsCommand()
.jobType("jobType")
.maxJobsToActivate(32)
.timeout(Duration.ofMinutes(1))
.workerName("yolo")
.fetchVariables(List.of("var_b", "var_d"))
.send()
.join();

// then
final List<ActivatedJob> jobs = activateJobsResponse.getJobs();
assertThat(jobs)
.first()
.extracting(ActivatedJob::getVariablesAsMap)
.isEqualTo(Map.of("var_b", "val_b", "var_d", "val_d"));
});
}

@Test
void shouldUpdateDeadlineOnJob() {
// given
Expand Down
Loading