public JobRecordStream withType(final String type) { return valueFilter(v -> type.equals(v.getType())); }
public JobRecordStream withType(final String type) { return valueFilter(v -> type.equals(v.getType())); }
/** * Verifies that the actual JobRecordValue's type is equal to the given one. * @param type the given type to compare the actual JobRecordValue's type to. * @return this assertion object. * @throws AssertionError - if the actual JobRecordValue's type is not equal to the given one. */ public S hasType(String type) { // 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 type of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // null safe check String actualType = actual.getType(); if (!Objects.areEqual(actualType, type)) { failWithMessage(assertjErrorMessage, actual, type, actualType); } // return the current assertion for method chaining return myself; }
@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 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 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 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 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); }