public static void makeInProgress(DbSession dbSession, String workerUuid, long now, CeQueueDto... ceQueueDtos) { Stream.of(ceQueueDtos).forEach(ceQueueDto -> { CeQueueMapper mapper = dbSession.getMapper(CeQueueMapper.class); int touchedRows = mapper.updateIf(ceQueueDto.getUuid(), new UpdateIf.NewProperties(IN_PROGRESS, workerUuid, now, now), new UpdateIf.OldProperties(PENDING)); assertThat(touchedRows).isEqualTo(1); }); }
public static void reset(DbSession dbSession, long now, CeQueueDto... ceQueueDtos) { Stream.of(ceQueueDtos).forEach(ceQueueDto -> { checkArgument(ceQueueDto.getStatus() == IN_PROGRESS); checkArgument(ceQueueDto.getWorkerUuid() != null); CeQueueMapper mapper = dbSession.getMapper(CeQueueMapper.class); int touchedRows = mapper.updateIf(ceQueueDto.getUuid(), new UpdateIf.NewProperties(PENDING, ceQueueDto.getUuid(), now, now), new UpdateIf.OldProperties(IN_PROGRESS)); assertThat(touchedRows).isEqualTo(1); }); } }
private Optional<CeQueueDto> tryToPeek(DbSession session, String eligibleTaskUuid, String workerUuid) { long now = system2.now(); int touchedRows = mapper(session).updateIf(eligibleTaskUuid, new UpdateIf.NewProperties(IN_PROGRESS, workerUuid, now, now), new UpdateIf.OldProperties(PENDING)); if (touchedRows != 1) { return Optional.empty(); } CeQueueDto result = mapper(session).selectByUuid(eligibleTaskUuid); session.commit(); return Optional.ofNullable(result); }
@Test public void newProperties_constructor_IAE_if_workerUuid_is_41_chars() { String str_41_chars = STR_40_CHARS + "a"; expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("worker uuid is too long: " + str_41_chars); new UpdateIf.NewProperties(CeQueueDto.Status.PENDING, str_41_chars, 123, 345); } }
@Test public void newProperties_constructor_fails_with_NPE_if_status_is_null() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("status can't be null"); new UpdateIf.NewProperties(null, "foo", 123, 456); }
@Test public void newProperties_constructor_accepts_null_workerUuid() { UpdateIf.NewProperties newProperties = new UpdateIf.NewProperties(CeQueueDto.Status.PENDING, null, 123, 456); assertThat(newProperties.getWorkerUuid()).isNull(); }
@Test public void newProperties_constructor_fails_with_IAE_if_workerUuid_is_41_or_more() { String workerUuid = RandomStringUtils.randomAlphanumeric(41 + new Random().nextInt(5)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("worker uuid is too long: " + workerUuid); new UpdateIf.NewProperties(CeQueueDto.Status.PENDING, workerUuid, 123, 456); }
@Test @UseDataProvider("workerUuidValidValues") public void newProperties_constructor_accepts_null_empty_and_string_40_chars_or_less(String workerUuid) { new UpdateIf.NewProperties(CeQueueDto.Status.PENDING, workerUuid, 123, 345); }