@Test
public void testHostRoleScheduled() throws InterruptedException, AmbariException {

  populateActionDB(db, hostName, requestId, stageId);
  Stage stage = db.getStage(StageUtils.getActionId(requestId, stageId));
  assertEquals(HostRoleStatus.PENDING, stage.getHostRoleStatus(hostName, Role.HBASE_MASTER.toString()));
  List<HostRoleCommandEntity> entities=
      hostRoleCommandDAO.findByHostRole(hostName, requestId, stageId, Role.HBASE_MASTER.toString());
  assertEquals(HostRoleStatus.PENDING, entities.get(0).getStatus());
  stage.setHostRoleStatus(hostName, Role.HBASE_MASTER.toString(), HostRoleStatus.QUEUED);
  entities = hostRoleCommandDAO.findByHostRole(hostName, requestId, stageId, Role.HBASE_MASTER.toString());
  assertEquals(HostRoleStatus.QUEUED, stage.getHostRoleStatus(hostName, Role.HBASE_MASTER.toString()));
  assertEquals(HostRoleStatus.PENDING, entities.get(0).getStatus());
  db.hostRoleScheduled(stage, hostName, Role.HBASE_MASTER.toString());
  entities = hostRoleCommandDAO.findByHostRole(hostName, requestId, stageId, Role.HBASE_MASTER.toString());
  assertEquals(HostRoleStatus.QUEUED, entities.get(0).getStatus());
  Thread thread = new Thread(){
    @Override
    public void run() {
      Stage stage1 = db.getStage("23-31");
      stage1.setHostRoleStatus(hostName, Role.HBASE_MASTER.toString(), HostRoleStatus.COMPLETED);
      db.hostRoleScheduled(stage1, hostName, Role.HBASE_MASTER.toString());
      injector.getInstance(EntityManager.class).clear();
    }
  };
  thread.start();
  thread.join();
  injector.getInstance(EntityManager.class).clear();
  entities = hostRoleCommandDAO.findByHostRole(hostName, requestId, stageId, Role.HBASE_MASTER.toString());
  assertEquals("Concurrent update failed", HostRoleStatus.COMPLETED, entities.get(0).getStatus());
}