public void create(final long key, final JobRecord record) { final DirectBuffer type = record.getType(); zeebeDb.batch(() -> createJob(key, record, type)); }
public void create(final long key, final JobRecord record) { final DirectBuffer type = record.getType(); zeebeDb.batch(() -> createJob(key, record, type)); }
public void resolve(long key, final JobRecord updatedValue) { final DirectBuffer type = updatedValue.getType(); zeebeDb.batch( () -> { updateJobRecord(key, updatedValue); updateJobState(State.ACTIVATABLE); makeJobActivatable(type); }); }
public void resolve(long key, final JobRecord updatedValue) { final DirectBuffer type = updatedValue.getType(); zeebeDb.batch( () -> { updateJobRecord(key, updatedValue); updateJobState(State.ACTIVATABLE); makeJobActivatable(type); }); }
@Test public void shouldNotOverwritePreviousRecord() { // given final long key = 1L; final JobRecord writtenRecord = newJobRecord(); // when jobState.create(key, writtenRecord); writtenRecord.setType("foo"); // then final JobRecord readRecord = jobState.getJob(key); assertThat(readRecord.getType()).isNotEqualTo(writtenRecord.getType()); assertThat(readRecord.getType()).isEqualTo(BufferUtil.wrapString("test")); assertThat(writtenRecord.getType()).isEqualTo(BufferUtil.wrapString("foo")); }
@Test public void shouldNotOverwritePreviousRecord() { // given final long key = 1L; final JobRecord writtenRecord = newJobRecord(); // when jobState.create(key, writtenRecord); writtenRecord.setType("foo"); // then final JobRecord readRecord = jobState.getJob(key); assertThat(readRecord.getType()).isNotEqualTo(writtenRecord.getType()); assertThat(readRecord.getType()).isEqualTo(BufferUtil.wrapString("test")); assertThat(writtenRecord.getType()).isEqualTo(BufferUtil.wrapString("foo")); }
public void timeout(final long key, final JobRecord record) { final DirectBuffer type = record.getType(); final long deadline = record.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { createJob(key, record, type); removeJobDeadline(deadline); }); }
private void assertJobRecordIsEqualTo(final JobRecord jobRecord, final JobRecord expected) { assertThat(jobRecord.getDeadline()).isEqualTo(expected.getDeadline()); assertThat(jobRecord.getWorker()).isEqualTo(expected.getWorker()); assertThat(jobRecord.getRetries()).isEqualTo(expected.getRetries()); assertThat(jobRecord.getType()).isEqualTo(expected.getType()); assertThat(jobRecord.getCustomHeaders()).isEqualTo(expected.getCustomHeaders()); assertThat(jobRecord.getPayload()).isEqualTo(expected.getPayload()); }
public void timeout(final long key, final JobRecord record) { final DirectBuffer type = record.getType(); final long deadline = record.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { createJob(key, record, type); removeJobDeadline(deadline); }); }
private void assertJobRecordIsEqualTo(final JobRecord jobRecord, final JobRecord expected) { assertThat(jobRecord.getDeadline()).isEqualTo(expected.getDeadline()); assertThat(jobRecord.getWorker()).isEqualTo(expected.getWorker()); assertThat(jobRecord.getRetries()).isEqualTo(expected.getRetries()); assertThat(jobRecord.getType()).isEqualTo(expected.getType()); assertThat(jobRecord.getCustomHeaders()).isEqualTo(expected.getCustomHeaders()); assertThat(jobRecord.getPayload()).isEqualTo(expected.getPayload()); }
public void delete(long key, JobRecord record) { final DirectBuffer type = record.getType(); final long deadline = record.getDeadline(); zeebeDb.batch( () -> { jobKey.wrapLong(key); jobsColumnFamily.delete(jobKey); statesJobColumnFamily.delete(jobKey); makeJobNotActivatable(type); removeJobDeadline(deadline); }); }
public void delete(long key, JobRecord record) { final DirectBuffer type = record.getType(); final long deadline = record.getDeadline(); zeebeDb.batch( () -> { jobKey.wrapLong(key); jobsColumnFamily.delete(jobKey); statesJobColumnFamily.delete(jobKey); makeJobNotActivatable(type); removeJobDeadline(deadline); }); }
public void activate(final long key, final JobRecord record) { final DirectBuffer type = record.getType(); final long deadline = record.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { updateJobRecord(key, record); updateJobState(State.ACTIVATED); makeJobNotActivatable(type); deadlineKey.wrapLong(deadline); deadlinesColumnFamily.put(deadlineJobKey, DbNil.INSTANCE); }); }
public void activate(final long key, final JobRecord record) { final DirectBuffer type = record.getType(); final long deadline = record.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { updateJobRecord(key, record); updateJobState(State.ACTIVATED); makeJobNotActivatable(type); deadlineKey.wrapLong(deadline); deadlinesColumnFamily.put(deadlineJobKey, DbNil.INSTANCE); }); }
public void fail(long key, JobRecord updatedValue) { final DirectBuffer type = updatedValue.getType(); final long deadline = updatedValue.getDeadline(); validateParameters(type, deadline); zeebeDb.batch( () -> { updateJobRecord(key, updatedValue); final State newState = updatedValue.getRetries() > 0 ? State.ACTIVATABLE : State.FAILED; updateJobState(newState); if (newState == State.ACTIVATABLE) { makeJobActivatable(type); } removeJobDeadline(deadline); }); }
@Test public void shouldDeleteActivatableJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); jobState.delete(key, jobRecord); // then assertThat(jobState.exists(key)).isFalse(); assertThat(jobState.isInState(key, State.NOT_FOUND)).isTrue(); assertThat(jobState.getJob(key)).isNull(); refuteListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldReturnCorrectJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord().setType("test"); // when jobState.create(key, jobRecord); jobState.create(key + 1, newJobRecord().setType("other")); // then final JobRecord savedJob = jobState.getJob(key); assertJobRecordIsEqualTo(savedJob, jobRecord); assertThat(BufferUtil.bufferAsString(savedJob.getType())).isEqualTo("test"); }
@Test public void shouldReturnCorrectJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord().setType("test"); // when jobState.create(key, jobRecord); jobState.create(key + 1, newJobRecord().setType("other")); // then final JobRecord savedJob = jobState.getJob(key); assertJobRecordIsEqualTo(savedJob, jobRecord); assertThat(BufferUtil.bufferAsString(savedJob.getType())).isEqualTo("test"); }
@Test public void shouldCreateJobEntry() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.ACTIVATABLE); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); assertListedAsActivatable(key, jobRecord.getType()); refuteListedAsTimedOut(key, jobRecord.getDeadline() + 1); }
@Test public void shouldActivateJob() { // given final long key = 1L; final JobRecord jobRecord = newJobRecord(); // when jobState.create(key, jobRecord); jobState.activate(key, jobRecord); // then assertThat(jobState.exists(key)).isTrue(); assertJobState(key, State.ACTIVATED); assertJobRecordIsEqualTo(jobState.getJob(key), jobRecord); refuteListedAsActivatable(key, jobRecord.getType()); assertListedAsTimedOut(key, jobRecord.getDeadline() + 1); }