[BAEL-4639] Running background jobs in Spring with JobRunr (#10089)

* [BAEL-4639] Running background jobs in Spring with JobRunr

* [BAEL-4639] Background jobs in Spring with JobRunr - update dependencies and readme

* [BAEL-4639] Background jobs in Spring with JobRunr - add required newline to application.properties

* [BAEL-4639] Background jobs in Spring with JobRunr - Make sure link is correct

* [BAEL-4639] Background jobs in Spring with JobRunr - Cleanup and LiveTest added

* [BAEL-4639] - Feedback

* [BAEL-4639] Update test with feedback
This commit is contained in:
Ronald Dehuysser
2020-09-26 23:14:11 +02:00
committed by GitHub
parent 7c8b656a7d
commit 70203a988b
8 changed files with 218 additions and 0 deletions
@@ -0,0 +1,46 @@
package com.baeldung.jobrunr;
import org.awaitility.Awaitility;
import org.jobrunr.jobs.states.StateName;
import org.jobrunr.storage.StorageProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = DEFINED_PORT, classes = JobRunrSpringBootApp.class)
public class JobRunrLiveTest {
@Autowired
TestRestTemplate restTemplate;
@Autowired
StorageProvider storageProvider;
@Test
public void givenEndpoint_whenJobEnqueued_thenJobIsProcessedWithin30Seconds() {
String response = enqueueJobViaRest("some-input");
assertEquals("job enqueued successfully", response);
await().atMost(30, TimeUnit.SECONDS).until(() -> storageProvider.countJobs(StateName.SUCCEEDED) == 1);
}
private String enqueueJobViaRest(String input) {
try {
return restTemplate.getForObject(new URI("http://localhost:8080/jobrunr/enqueue/" + input), String.class);
} catch (Exception ignored) {
ignored.printStackTrace();
}
return null;
}
}