如何从 ProcessInstance 中检索执行

How to Retrieve execution from ProcessInstance

刚开始在 camunda 中创建流程并使用流程变量。我可以成功创建这些流程变量,然后在服务任务中读取它们,然后使用 Input/Output 参数输出它们。但是我正在努力再次在实际启动此流程的程序中检索这些参数的更新值。以下是片段:

//测试用例

RuntimeService rs = processEngine().getRuntimeService();
      Map<String, Object> variables = new HashMap<>();
      variables.put("percentageCompletion", "11");
      ProcessInstance processInstance = rs.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);

这个 percentageCompletion 可以通过

在服务任务中访问
Object pc = execution.getVariable("percentageCompletion");// Update and set its new value

现在如何在测试用例中再次获取 percentageCompletion 的更新值?我已经关注过类似的问题

这就是我在 junit 中获取它们的方式

 @Test
  @Deployment(resources = "process.bpmn")
  public void testParsingAndDeployment() {
 }

  @Test
  @Deployment(resources = "process.bpmn")
  public void testHappyPath() {
      RuntimeService rs = processEngine().getRuntimeService();
      Map<String, Object> variables = new HashMap<>();
      variables.put("percentageCompletion", "11");
      ProcessInstance processInstance = rs.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);
      System.out.println(processInstance.isEnded() + ", " + processInstance.isSuspended());
      VariableInstance vi = processEngine().getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).variableName("percentageCompletion").singleResult();
      System.out.println(processInstance.isEnded() + ", " + processInstance.isSuspended());
      System.out.println("********* " + processEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstance.getProcessInstanceId()).count());

      String executionId = processEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstance.getProcessInstanceId()).list().get(0).getExecutionId();
      System.out.println("executionId " + executionId);

      List<HistoricVariableInstance> hvis = processEngine().getHistoryService().createHistoricVariableInstanceQuery().executionIdIn(executionId).list();
      System.out.println("------------ " + hvis.size());

      for (HistoricVariableInstance hi : hvis) {
          System.out.println(hi.getName() + " : "+ hi.getValue());
      }
  }