Skip to content

Commit

Permalink
#29479 Add JobQueue getter to JobQueueManagerAPI
Browse files Browse the repository at this point in the history
Implemented a public getter method for JobQueue in JobQueueManagerAPI. Updated corresponding tests to include assertions for the new method. This enhances testability and ensures the JobQueue dependency is correctly injected.
  • Loading branch information
jgambarios committed Sep 20, 2024
1 parent 2a64551 commit fd872ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.dotcms.jobs.business.job.Job;
import com.dotcms.jobs.business.job.JobPaginatedResult;
import com.dotcms.jobs.business.processor.JobProcessor;
import com.dotcms.jobs.business.queue.JobQueue;
import com.dotmarketing.exception.DotDataException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -116,6 +117,11 @@ String createJob(String queueName, Map<String, Object> parameters)
*/
CircuitBreaker getCircuitBreaker();

/**
* @return The JobQueue instance
*/
JobQueue getJobQueue();

/**
* @return The size of the thread pool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ public CircuitBreaker getCircuitBreaker() {
return this.circuitBreaker;
}

@Override
@VisibleForTesting
public JobQueue getJobQueue() {
return this.jobQueue;
}

@Override
@VisibleForTesting
public int getThreadPoolSize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dotcms.jobs.business.api;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;

Expand All @@ -15,7 +17,6 @@
import org.jboss.weld.junit5.WeldInitiator;
import org.jboss.weld.junit5.WeldJunit5Extension;
import org.jboss.weld.junit5.WeldSetup;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

Expand Down Expand Up @@ -66,7 +67,7 @@ void test_SingletonBehavior() {
@Test
void test_CDIInjection() {
assertNotNull(jobQueueManagerAPI, "JobQueueManagerAPI should be injected");
Assertions.assertInstanceOf(JobQueueManagerAPIImpl.class, jobQueueManagerAPI,
assertInstanceOf(JobQueueManagerAPIImpl.class, jobQueueManagerAPI,
"JobQueueManagerAPI should be an instance of JobQueueManagerAPIImpl");
}

Expand All @@ -78,14 +79,18 @@ void test_CDIInjection() {
@Test
void test_JobQueueManagerAPIFields() {

assertNotNull(jobQueueManagerAPI.getJobQueue(), "JobQueue should be injected");
assertInstanceOf(JobQueue.class, jobQueueManagerAPI.getJobQueue(),
"Injected object should implement JobQueue interface");

assertNotNull(jobQueueManagerAPI.getCircuitBreaker(),
"CircuitBreaker should be injected");
assertNotNull(jobQueueManagerAPI.getDefaultRetryStrategy(),
"Retry strategy should be injected");

Assertions.assertEquals(10, jobQueueManagerAPI.getThreadPoolSize(),
assertEquals(10, jobQueueManagerAPI.getThreadPoolSize(),
"ThreadPoolSize should be greater than 0");
Assertions.assertInstanceOf(ExponentialBackoffRetryStrategy.class,
assertInstanceOf(ExponentialBackoffRetryStrategy.class,
jobQueueManagerAPI.getDefaultRetryStrategy(),
"Retry strategy should be an instance of ExponentialBackoffRetryStrategy");
}
Expand Down

0 comments on commit fd872ba

Please sign in to comment.