Skip to content

Commit

Permalink
JPAReactiveJobServiceManagementRepository updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedvede committed Sep 4, 2024
1 parent dda0d8c commit 8ac4db7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public Uni<JobServiceManagementInfo> heartbeat(JobServiceManagementInfo info) {
return Uni.createFrom().completionStage(this.reactiveRepositoryHelper.runAsync(() -> this.doHeartbeat(info)));
}

@Override
public Uni<Boolean> release(JobServiceManagementInfo info) {
return Uni.createFrom().completionStage(this.reactiveRepositoryHelper.runAsync(() -> this.doRelease(info)));
}

private JobServiceManagementEntity findById(String id) {
return repository.findById(id);
}
Expand All @@ -124,6 +129,17 @@ private JobServiceManagementInfo doHeartbeat(JobServiceManagementInfo info) {
return from(jobService);
}

private Boolean doRelease(JobServiceManagementInfo info) {
JobServiceManagementEntity jobService = findByIdAndToken(info);
if (jobService == null) {
return false;
}
jobService.setToken(null);
jobService.setLastHeartBeat(null);
repository.persist(jobService);
return true;
}

JobServiceManagementInfo from(JobServiceManagementEntity jobService) {
if (Objects.isNull(jobService)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,24 @@ void testConflictHeartbeat() {
JobServiceManagementInfo updated = tested.heartbeat(new JobServiceManagementInfo(id, "differentToken", null)).await().indefinitely();
assertThat(updated).isNull();
}

@Test
void testRelease() {
String id = "instance-id-5";
String token = "token5";
JobServiceManagementInfo created = create(id, token);

Boolean released = tested.release(created).await().indefinitely();
assertThat(released).isTrue();
}

@Test
void testReleaseNotExisting() {
String id = "instance-id-6";
String token = "token6";
JobServiceManagementInfo notExisting = new JobServiceManagementInfo(id, token, OffsetDateTime.now());

Boolean released = tested.release(notExisting).await().indefinitely();
assertThat(released).isFalse();
}
}

0 comments on commit 8ac4db7

Please sign in to comment.