Skip to content

Commit

Permalink
feat: Lock single job for a project
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar committed Jul 26, 2023
1 parent 1fee819 commit 98489d5
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito
import org.mockito.kotlin.any
import org.mockito.kotlin.argThat
import org.mockito.kotlin.timeout
import org.mockito.kotlin.atLeast
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
Expand Down Expand Up @@ -121,7 +121,7 @@ abstract class AbstractBatchJobsGeneralTest : AbstractSpringTest() {
).process(any(), any(), any(), any())
}

job.waitForCompleted().assert.isEqualTo(BatchJobStatus.SUCCESS)
job.waitForCompleted().status.assert.isEqualTo(BatchJobStatus.SUCCESS)

// 100 progress messages + 1 finish message
websocketHelper.receivedMessages.assert.hasSize(101)
Expand Down Expand Up @@ -292,7 +292,7 @@ abstract class AbstractBatchJobsGeneralTest : AbstractSpringTest() {

val job = runSingleChunkJob(100)

job.waitForCompleted().assert.isEqualTo(BatchJobStatus.SUCCESS)
job.waitForCompleted().status.assert.isEqualTo(BatchJobStatus.SUCCESS)

waitForNotThrowing(pollTime = 1000) {
entityManager.createQuery("""from BatchJobChunkExecution b where b.batchJob.id = :id""")
Expand Down Expand Up @@ -360,9 +360,11 @@ abstract class AbstractBatchJobsGeneralTest : AbstractSpringTest() {

batchJobChunkExecutionQueue.addToQueue(listOf(secondExecution))

// it tries to lock the second job but it can't since the first job is locked
verify(batchJobProjectLockingManager, timeout(1000))
.canRunBatchJobOfExecution(eq(job2.id))
waitForNotThrowing {
// it tries to lock the second job but it can't since the first job is locked
verify(batchJobProjectLockingManager, atLeast(1))
.canRunBatchJobOfExecution(eq(job2.id))
}

// it doesn't run the second execution since the first job is locked
Thread.sleep(1000)
Expand Down

0 comments on commit 98489d5

Please sign in to comment.