@Test public void insert_must_set_relevant_is_last_field() { // only a single task on MAINCOMPONENT_1 -> is_last=true insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS); assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isTrue(); // only a single task on MAINCOMPONENT_2 -> is_last=true insert("TASK_2", REPORT, MAINCOMPONENT_2, SUCCESS); assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue(); // two tasks on MAINCOMPONENT_1, the most recent one is TASK_3 insert("TASK_3", REPORT, MAINCOMPONENT_1, FAILED); assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse(); assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue(); assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue(); // inserting a cancelled task does not change the last task insert("TASK_4", REPORT, MAINCOMPONENT_1, CANCELED); assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse(); assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue(); assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue(); assertThat(underTest.selectByUuid(db.getSession(), "TASK_4").get().getIsLast()).isFalse(); }
public void insert(DbSession dbSession, CeActivityDto dto) { dto.setCreatedAt(system2.now()); dto.setUpdatedAt(system2.now()); dto.setIsLast(dto.getStatus() != CeActivityDto.Status.CANCELED); CeActivityMapper ceActivityMapper = mapper(dbSession); if (dto.getIsLast()) { ceActivityMapper.updateIsLastToFalseForLastKey(dto.getIsLastKey(), dto.getUpdatedAt()); } ceActivityMapper.insert(dto); }
@Test public void test_remove() { CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1")); Optional<CeTask> peek = underTest.peek(WORKER_UUID_1); underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, null, null); // queue is empty assertThat(db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).isPresent()).isFalse(); assertThat(underTest.peek(WORKER_UUID_2).isPresent()).isFalse(); // available in history Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); assertThat(history.isPresent()).isTrue(); assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.SUCCESS); assertThat(history.get().getIsLast()).isTrue(); assertThat(history.get().getAnalysisUuid()).isNull(); }