MongoJobRepository extends AbstractMongoRepository<String, JobInfo> implements JobRepository { @Override public void appendMessage(final String jobId, final JobMessage jobMessage) { collectionWithWriteTimeout(mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS).updateOne(eq(ID, jobId), combine(push(JobStructure.MESSAGES.key(), encodeJobMessage(jobMessage)), set(JobStructure.LAST_UPDATED.key(), Date.from(jobMessage.getTimestamp().toInstant())))); } MongoJobRepository(final MongoDatabase mongoDatabase,
                              final String jobInfoCollectionName,
                              final MongoProperties mongoProperties); @Override JobStatus findStatus(final String jobId); @Override void removeIfStopped(final String id); @Override void appendMessage(final String jobId, final JobMessage jobMessage); @Override void setJobStatus(final String jobId, final JobStatus jobStatus); @Override void setLastUpdate(final String jobId, final OffsetDateTime lastUpdate); @Override List<JobInfo> findLatest(final int maxCount); @Override List<JobInfo> findLatestJobsDistinct(); List<String> findAllJobIdsDistinct(); @Override List<JobInfo> findLatestBy(final String type, final int maxCount); @Override List<JobInfo> findByType(final String type); @Override List<JobInfo> findRunningWithoutUpdateSince(final OffsetDateTime timeOffset); @Override List<JobInfo> findAllJobInfoWithoutMessages(); @Override void keepJobMessagesWithinMaximumSize(String jobId); static final String ID; }
@Test public void shouldAppendMessageToJob() throws Exception { final String jobId = "http: final JobInfo jobInfo = jobInfo(jobId, "T_FOO"); repo.createOrUpdate(jobInfo); final JobMessage jobMessage = jobMessage(Level.INFO, "Schön ist es auf der Welt zu sein, sagt der Igel zu dem Stachelschwein", now()); repo.appendMessage(jobId, jobMessage); final JobInfo jobInfoFromDB = repo.findOne(jobId).orElse(null); assertThat(jobInfoFromDB.getMessages(), hasSize(3)); assertThat(jobInfoFromDB.getMessages().get(2), is(jobMessage)); assertThat(jobInfoFromDB.getStatus(), is(OK)); }