public JobRecordStream withDeadline(final long deadline) { return valueFilter(v -> Instant.ofEpochMilli(deadline).equals(v.getDeadline())); } }
public JobRecordStream withDeadline(final long deadline) { return valueFilter(v -> Instant.ofEpochMilli(deadline).equals(v.getDeadline())); } }
public JobRecordStream withDeadline(final Instant deadline) { return valueFilter(v -> deadline.equals(v.getDeadline())); }
public JobRecordStream withDeadline(final Instant deadline) { return valueFilter(v -> deadline.equals(v.getDeadline())); }
/** * Verifies that the actual JobRecordValue's deadline is equal to the given one. * @param deadline the given deadline to compare the actual JobRecordValue's deadline to. * @return this assertion object. * @throws AssertionError - if the actual JobRecordValue's deadline is not equal to the given one. */ public S hasDeadline(java.time.Instant deadline) { // check that actual JobRecordValue we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting deadline of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // null safe check java.time.Instant actualDeadline = actual.getDeadline(); if (!Objects.areEqual(actualDeadline, deadline)) { failWithMessage(assertjErrorMessage, actual, deadline, actualDeadline); } // return the current assertion for method chaining return myself; }
@Test public void shouldUpdateRetries() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(JobIntent.ACTIVATED); client.failJob(jobEvent.getKey(), 0); // when final ExecuteCommandResponse response = client.updateJobRetries(jobEvent.getKey(), NEW_RETRIES); // then assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(JobIntent.RETRIES_UPDATED); assertThat(response.getKey()).isEqualTo(jobEvent.getKey()); final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", 20L), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = client.receiveFirstJobEvent(JobIntent.RETRIES_UPDATED); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldFail() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(ACTIVATED); final int retries = 23; // when final ExecuteCommandResponse response = client.failJob(jobEvent.getKey(), retries); // then final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(FAILED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) retries), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(FAILED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldFailWithMessage() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(ACTIVATED); final int retries = 23; // when final ExecuteCommandResponse response = client.failJobWithMessage(jobEvent.getKey(), retries, "failed job"); // then final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(FAILED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) retries), entry("deadline", jobEventValue.getDeadline().toEpochMilli()), entry("errorMessage", "failed job")); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(FAILED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); assertThat(loggedEvent.getValue().getErrorMessage()).isEqualTo("failed job"); }
@Test public void shouldUpdateRetries() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(JobIntent.ACTIVATED); client.failJob(jobEvent.getKey(), 0); // when final ExecuteCommandResponse response = client.updateJobRetries(jobEvent.getKey(), NEW_RETRIES); // then assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(JobIntent.RETRIES_UPDATED); assertThat(response.getKey()).isEqualTo(jobEvent.getKey()); final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", 20L), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = client.receiveFirstJobEvent(JobIntent.RETRIES_UPDATED); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldFail() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(ACTIVATED); final int retries = 23; // when final ExecuteCommandResponse response = client.failJob(jobEvent.getKey(), retries); // then final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(FAILED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) retries), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(FAILED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldFailWithMessage() { // given client.createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = client.receiveFirstJobEvent(ACTIVATED); final int retries = 23; // when final ExecuteCommandResponse response = client.failJobWithMessage(jobEvent.getKey(), retries, "failed job"); // then final JobRecordValue jobEventValue = jobEvent.getValue(); assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(FAILED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) retries), entry("deadline", jobEventValue.getDeadline().toEpochMilli()), entry("errorMessage", "failed job")); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(FAILED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); assertThat(loggedEvent.getValue().getErrorMessage()).isEqualTo("failed job"); }
@Test public void shouldCompleteJob() { // given createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = receiveSingleJobEvent(); // when final JobRecordValue jobEventValue = jobEvent.getValue(); final ExecuteCommandResponse response = testClient.completeJob(jobEvent.getKey(), jobEventValue.getPayload()); // then assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(JobIntent.COMPLETED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) jobEventValue.getRetries()), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(JobIntent.COMPLETED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }
@Test public void shouldCompleteJob() { // given createJob(JOB_TYPE); apiRule.activateJobs(JOB_TYPE).await(); final Record<JobRecordValue> jobEvent = receiveSingleJobEvent(); // when final JobRecordValue jobEventValue = jobEvent.getValue(); final ExecuteCommandResponse response = testClient.completeJob(jobEvent.getKey(), jobEventValue.getPayload()); // then assertThat(response.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(response.getIntent()).isEqualTo(JobIntent.COMPLETED); assertThat(response.getValue()) .contains( entry("worker", jobEventValue.getWorker()), entry("type", jobEventValue.getType()), entry("retries", (long) jobEventValue.getRetries()), entry("deadline", jobEventValue.getDeadline().toEpochMilli())); final Record<JobRecordValue> loggedEvent = RecordingExporter.jobRecords(JobIntent.COMPLETED).getFirst(); assertThat(loggedEvent.getValue().getType()).isEqualTo(JOB_TYPE); }