BAEL-20262: Migrate spring-scheduling module to the com.baeldung package
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
package com.baeldung.async;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import com.baeldung.async.config.SpringAsyncConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { SpringAsyncConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class AsyncAnnotationExampleIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private AsyncComponent asyncAnnotationExample;
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public void testAsyncAnnotationForMethodsWithVoidReturnType() {
|
||||
System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName());
|
||||
asyncAnnotationExample.asyncMethodWithVoidReturnType();
|
||||
System.out.println("End - invoking an asynchronous method. ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncAnnotationForMethodsWithReturnType() throws InterruptedException, ExecutionException {
|
||||
System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName());
|
||||
final Future<String> future = asyncAnnotationExample.asyncMethodWithReturnType();
|
||||
|
||||
while (true) {
|
||||
if (future.isDone()) {
|
||||
System.out.println("Result from asynchronous process - " + future.get());
|
||||
break;
|
||||
}
|
||||
System.out.println("Continue doing something else. ");
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncAnnotationForMethodsWithConfiguredExecutor() {
|
||||
System.out.println("Start - invoking an asynchronous method. ");
|
||||
asyncAnnotationExample.asyncMethodWithConfiguredExecutor();
|
||||
System.out.println("End - invoking an asynchronous method. ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncAnnotationForMethodsWithException() throws Exception {
|
||||
System.out.println("Start - invoking an asynchronous method. ");
|
||||
asyncAnnotationExample.asyncMethodWithExceptions();
|
||||
System.out.println("End - invoking an asynchronous method. ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.async;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:springAsync-config.xml")
|
||||
public class AsyncWithXMLIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private AsyncComponent asyncAnnotationExample;
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public void testAsyncAnnotationForMethodsWithVoidReturnType() throws InterruptedException {
|
||||
System.out.println("Start - invoking an asynchronous method. " + Thread.currentThread().getName());
|
||||
asyncAnnotationExample.asyncMethodWithVoidReturnType();
|
||||
Thread.sleep(2000);
|
||||
System.out.println("End - invoking an asynchronous method. ");
|
||||
}
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import com.baeldung.scheduling.SpringSchedulingConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { SpringSchedulingConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class ScheduledAnnotationExampleIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testScheduledAnnotation() throws InterruptedException {
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { SpringSchedulingFixedRateConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { SpringSchedulingConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class ScheduledFixedRateExampleIntegrationTest {
|
||||
|
||||
@Test
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:springScheduled-config.xml")
|
||||
public class SchedulingWithXmlConfigIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testXmlBasedScheduling() throws InterruptedException {
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.springretry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.retry.support.RetryTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
|
||||
public class SpringRetryIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private MyService myService;
|
||||
|
||||
@Autowired
|
||||
private RetryTemplate retryTemplate;
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void givenRetryService_whenCallWithException_thenRetry() {
|
||||
myService.retryService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRetryServiceWithRecovery_whenCallWithException_thenRetryRecover() throws SQLException {
|
||||
myService.retryServiceWithRecovery(null);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void givenTemplateRetryService_whenCallWithException_thenRetry() {
|
||||
retryTemplate.execute(arg0 -> {
|
||||
myService.templateRetryService();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.taskscheduler;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ThreadPoolTaskSchedulerConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class ThreadPoolTaskSchedulerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testThreadPoolTaskSchedulerAnnotation() throws InterruptedException {
|
||||
Thread.sleep(2550);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user