use of cn.taketoday.context.ConfigurableApplicationContext in project today-infrastructure by TAKETODAY.
the class EnableAsyncTests method withAsyncBeanWithExecutorQualifiedByExpressionOrPlaceholder.
@Test
public void withAsyncBeanWithExecutorQualifiedByExpressionOrPlaceholder() throws Exception {
System.setProperty("myExecutor", "myExecutor1");
System.setProperty("my.app.myExecutor", "myExecutor2");
Class<?> configClass = AsyncWithExecutorQualifiedByExpressionConfig.class;
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(configClass)) {
AsyncBeanWithExecutorQualifiedByExpressionOrPlaceholder asyncBean = context.getBean(AsyncBeanWithExecutorQualifiedByExpressionOrPlaceholder.class);
Future<Thread> workerThread1 = asyncBean.myWork1();
assertThat(workerThread1.get().getName()).startsWith("myExecutor1-");
Future<Thread> workerThread2 = asyncBean.myWork2();
assertThat(workerThread2.get().getName()).startsWith("myExecutor2-");
} finally {
System.clearProperty("myExecutor");
System.clearProperty("my.app.myExecutor");
}
}
use of cn.taketoday.context.ConfigurableApplicationContext in project today-infrastructure by TAKETODAY.
the class AsyncAnnotationBeanPostProcessorTests method invokedAsynchronously.
@Test
public void invokedAsynchronously() {
ConfigurableApplicationContext context = initContext(new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class));
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
Thread mainThread = Thread.currentThread();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
assertThat(asyncThread).isNotSameAs(mainThread);
context.close();
}
use of cn.taketoday.context.ConfigurableApplicationContext in project today-infrastructure by TAKETODAY.
the class AsyncAnnotationBeanPostProcessorTests method handleExceptionWithFuture.
@Test
@SuppressWarnings("resource")
public void handleExceptionWithFuture() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithExceptionHandler.class);
ITestBean testBean = context.getBean("target", ITestBean.class);
TestableAsyncUncaughtExceptionHandler exceptionHandler = context.getBean("exceptionHandler", TestableAsyncUncaughtExceptionHandler.class);
assertThat(exceptionHandler.isCalled()).as("handler should not have been called yet").isFalse();
Future<Object> result = testBean.failWithFuture();
assertFutureWithException(result, exceptionHandler);
}
use of cn.taketoday.context.ConfigurableApplicationContext in project today-infrastructure by TAKETODAY.
the class AsyncAnnotationBeanPostProcessorTests method handleExceptionWithCustomExceptionHandler.
@Test
public void handleExceptionWithCustomExceptionHandler() {
Method m = ReflectionUtils.findMethod(TestBean.class, "failWithVoid");
TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler();
BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
processorDefinition.getPropertyValues().add("exceptionHandler", exceptionHandler);
ConfigurableApplicationContext context = initContext(processorDefinition);
ITestBean testBean = context.getBean("target", ITestBean.class);
assertThat(exceptionHandler.isCalled()).as("Handler should not have been called").isFalse();
testBean.failWithVoid();
exceptionHandler.await(3000);
exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
}
use of cn.taketoday.context.ConfigurableApplicationContext in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentPostProcessorBootstrapContextIntegrationTests method bootstrapsApplicationContext.
@Test
void bootstrapsApplicationContext() {
String args = "--context.config.import=classpath:application-bootstrap-registry-integration-tests.properties";
try (ConfigurableApplicationContext context = application.run(args)) {
LoaderHelper bean = context.getBean(TestConfigDataBootstrap.LoaderHelper.class);
assertThat(bean).isNotNull();
assertThat(bean.getBound()).isEqualTo("igotbound");
assertThat(bean.getProfileBound()).isEqualTo("igotprofilebound");
assertThat(bean.getLocation().getResolverHelper().getLocation()).isEqualTo(ConfigDataLocation.valueOf("testbootstrap:test"));
}
}
Aggregations