JobState { public void create(final long key, final JobRecord record) { final DirectBuffer type = record.getTypeBuffer(); createJob(key, record, type); metrics.jobCreated(record.getType()); } JobState(
      final ZeebeDb<ZbColumnFamilies> zeebeDb, final DbContext dbContext, final int partitionId); void create(final long key, final JobRecord record); void activate(final long key, final JobRecord record); void timeout(final long key, final JobRecord record); void complete(final long key, final JobRecord record); void cancel(final long key, final JobRecord record); void disable(final long key, final JobRecord record); void throwError(final long key, final JobRecord updatedValue); void delete(final long key, final JobRecord record); void fail(final long key, final JobRecord updatedValue); void resolve(final long key, final JobRecord updatedValue); void forEachTimedOutEntry(
      final long upperBound, final BiFunction<Long, JobRecord, Boolean> callback); boolean exists(final long jobKey); State getState(final long key); boolean isInState(final long key, final State state); void forEachActivatableJobs(
      final DirectBuffer type, final BiFunction<Long, JobRecord, Boolean> callback); JobRecord updateJobRetries(final long jobKey, final int retries); JobRecord getJob(final long key); void setJobsAvailableCallback(final Consumer<String> onJobsAvailableCallback);  }
@Test public void shouldListTimedOutEntriesInOrder() { createAndActivateJobRecord(1, newJobRecord().setDeadline(1L)); createAndActivateJobRecord(2, newJobRecord().setDeadline(256L)); jobState.create(5, newJobRecord().setDeadline(512L)); createAndActivateJobRecord(3, newJobRecord().setDeadline(65536L)); createAndActivateJobRecord(4, newJobRecord().setDeadline(4294967296L)); final List<Long> jobKeys = getTimedOutKeys(32768L); assertThat(jobKeys).hasSize(2); assertThat(jobKeys).containsExactly(1L, 2L); }
@Test public void shouldDoNothingIfNotTimedOutJobs() { jobState.create(5, newJobRecord().setDeadline(512L)); createAndActivateJobRecord(4, newJobRecord().setDeadline(4294967296L)); final List<Long> jobKeys = getTimedOutKeys(32768L); assertThat(jobKeys).isEmpty(); }
@Test public void shouldListActivatableJobsForTypeInOrder() { final DirectBuffer type = wrapString("test"); jobState.create(1, newJobRecord().setType("tes")); jobState.create(256L, newJobRecord().setType(type)); createAndActivateJobRecord(512, newJobRecord().setType(type)); jobState.create(65536L, newJobRecord().setType(type)); jobState.create(4294967296L, newJobRecord().setType("test-other")); final List<Long> jobKeys = getActivatableKeys(type); assertThat(jobKeys).hasSize(2); assertThat(jobKeys).containsExactly(256L, 65536L); }
@Test public void shouldNotDoAnythingIfNoActivatableJobs() { final DirectBuffer type = wrapString("test"); createAndActivateJobRecord(1, newJobRecord().setType(type)); jobState.create(256L, newJobRecord().setType("other")); final List<Long> jobKeys = getActivatableKeys(type); assertThat(jobKeys).isEmpty(); }