@Test
public void testSelectAndUpdateExecutionWithPriority() throws Exception {

  // Selecting executions when DB is empty
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected no execution selected")
      .isEqualTo(-1);
  final long currentTime = System.currentTimeMillis();
  final ExecutableFlow lowPriorityFlow1 = submitNewFlow("exectest1", "exec1", currentTime,
      ExecutionOptions.DEFAULT_FLOW_PRIORITY);
  final ExecutableFlow highPriorityFlow = submitNewFlow("exectest1", "exec1", currentTime + 5,
      ExecutionOptions.DEFAULT_FLOW_PRIORITY + 5);
  final ExecutableFlow lowPriorityFlow2 = submitNewFlow("exectest1", "exec1", currentTime + 10,
      ExecutionOptions.DEFAULT_FLOW_PRIORITY + 3);
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected flow with highest priority")
      .isEqualTo(highPriorityFlow.getExecutionId());
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected second flow with highest priority")
      .isEqualTo(lowPriorityFlow2.getExecutionId());
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected flow with lowest priority")
      .isEqualTo(lowPriorityFlow1.getExecutionId());
  // Selecting executions when there are no more submitted flows left
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected no execution selected")
      .isEqualTo(-1);
}