@Test
public void testSelectAndUpdateExecutionWithSamePriority() 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 submittedFlow1 = submitNewFlow("exectest1", "exec1", currentTime,
      ExecutionOptions.DEFAULT_FLOW_PRIORITY + 3);
  final ExecutableFlow submittedFlow2 = submitNewFlow("exectest1", "exec1", currentTime + 5,
      ExecutionOptions.DEFAULT_FLOW_PRIORITY + 3);
  final ExecutableFlow submittedFlow3 = submitNewFlow("exectest1", "exec1", currentTime + 10,
      ExecutionOptions.DEFAULT_FLOW_PRIORITY + 3);
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected first flow submitted")
      .isEqualTo(submittedFlow1.getExecutionId());
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected second flow submitted")
      .isEqualTo(submittedFlow2.getExecutionId());
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected last flow submitted")
      .isEqualTo(submittedFlow3.getExecutionId());
  // Selecting executions when there are no more submitted flows left
  assertThat(this.executionFlowDao.selectAndUpdateExecution(-1, true))
      .as("Expected no execution selected")
      .isEqualTo(-1);
}