Skip to content

Commit

Permalink
#29479 Applying sonarlint feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Sep 27, 2024
1 parent ec99927 commit 0952bd7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ public class PostgresJobQueue implements JobQueue {
* Jackson mapper configuration and lazy initialized instance.
*/
private final Lazy<ObjectMapper> objectMapper = Lazy.of(() -> {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.registerModule(new Jdk8Module());
objectMapper.registerModule(new GuavaModule());
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new VersioningModule());
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return objectMapper;
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new GuavaModule());
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new VersioningModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return mapper;
});

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,11 @@ void test_CancelJob() throws Exception {
Map<String, Object> parameters = new HashMap<>();
String jobId = jobQueueManagerAPI.createJob("cancellableQueue", parameters);

// Wait for the job to start
Thread.sleep(1000);
Awaitility.await().atMost(5, TimeUnit.SECONDS)
.until(() -> {
Job job = jobQueueManagerAPI.getJob(jobId);
return job.state() == JobState.RUNNING;
});

// Cancel the job
jobQueueManagerAPI.cancelJob(jobId);
Expand Down Expand Up @@ -385,7 +388,7 @@ void test_CombinedScenarios() throws Exception {
});

// Wait a bit before cancelling the job
Thread.sleep(500);
Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).until(() -> true);
jobQueueManagerAPI.cancelJob(cancelJobId);

// Wait for all jobs to complete (or timeout after 30 seconds)
Expand Down Expand Up @@ -430,12 +433,9 @@ public void process(Job job) {
for (int i = 0; i <= 10; i++) {
float progress = i / 10.0f;
tracker.updateProgress(progress);
try {
Thread.sleep(500); // Simulate work being done
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}

// Simulate work being done
Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).until(() -> true);
}
}

Expand Down Expand Up @@ -495,20 +495,12 @@ private static class CancellableJobProcessor implements JobProcessor, Cancellabl

@Override
public void process(Job job) {
while (!canceled.get()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Awaitility.await().atMost(10, TimeUnit.SECONDS)
.until(canceled::get);

// Simulate some additional work after cancellation
Awaitility.await().pollDelay(1, TimeUnit.SECONDS).until(() -> true);
}

@Override
Expand All @@ -532,11 +524,7 @@ private static class TestJobProcessor implements JobProcessor {
@Override
public void process(Job job) {
// Simulate some work
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Awaitility.await().pollDelay(1, TimeUnit.SECONDS).until(() -> true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -206,7 +208,10 @@ void test_nextJob() throws Exception {
assertEquals(JobState.PENDING, nextJob.state());

// Simulate some processing time
Thread.sleep(1000);
Awaitility.await().atMost(5, TimeUnit.SECONDS)
.pollInterval(100, TimeUnit.MILLISECONDS).until(() -> {
return true;
});

// Mark job as completed
Job completedJob = nextJob.markAsCompleted(null);
Expand Down Expand Up @@ -324,9 +329,13 @@ void test_getUpdatedJobsSince() throws JobQueueException, InterruptedException {
String job1Id = jobQueue.createJob(queueName, new HashMap<>());
String job2Id = jobQueue.createJob(queueName, new HashMap<>());

Thread.sleep(100); // Ensure some time passes
Awaitility.await().atMost(1, TimeUnit.SECONDS)
.pollInterval(50, TimeUnit.MILLISECONDS)
.until(() -> true);// Ensure some time passes
LocalDateTime checkpointTime = LocalDateTime.now();
Thread.sleep(100); // Ensure some more time passes
Awaitility.await().atMost(1, TimeUnit.SECONDS)
.pollInterval(50, TimeUnit.MILLISECONDS)
.until(() -> true);// Ensure some more time passes

// Update job1 and create a new job after the checkpoint
Job job1 = jobQueue.getJob(job1Id);
Expand Down

0 comments on commit 0952bd7

Please sign in to comment.