Skip to content

Commit

Permalink
Remove references to AsyncConfigurerSupport
Browse files Browse the repository at this point in the history
Closes gh-27812
  • Loading branch information
snicoll committed Dec 14, 2021
1 parent 8422d9d commit b06d267
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,19 +28,13 @@
* {@link AsyncUncaughtExceptionHandler} instance used to process exception thrown from
* async method with {@code void} return type.
*
* <p>Consider using {@link AsyncConfigurerSupport} providing default implementations for
* both methods if only one element needs to be customized. Furthermore, backward compatibility
* of this interface will be insured in case new customization options are introduced
* in the future.
*
* <p>See @{@link EnableAsync} for usage examples.
*
* @author Chris Beams
* @author Stephane Nicoll
* @since 3.1
* @see AbstractAsyncConfiguration
* @see EnableAsync
* @see AsyncConfigurerSupport
*/
public interface AsyncConfigurer {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -218,8 +218,8 @@ public void handleExceptionWithListenableFuture() {
private void assertFutureWithException(Future<Object> result,
TestableAsyncUncaughtExceptionHandler exceptionHandler) {
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
result::get)
.withCauseExactlyInstanceOf(UnsupportedOperationException.class);
result::get)
.withCauseExactlyInstanceOf(UnsupportedOperationException.class);
assertThat(exceptionHandler.isCalled()).as("handler should never be called with Future return type").isFalse();
}

Expand Down Expand Up @@ -343,7 +343,7 @@ public void execute(Runnable r) {

@Configuration
@EnableAsync
static class ConfigWithExceptionHandler extends AsyncConfigurerSupport {
static class ConfigWithExceptionHandler implements AsyncConfigurer {

@Bean
public ITestBean target() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -73,13 +73,17 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
private static final CountDownLatch countDownLatch = new CountDownLatch(1);

private final TestContextManager testContextManager = new TestContextManager(ExampleTestCase.class);

private final TestContext testContext = testContextManager.getTestContext();

// Note that the following invocation of getApplicationContext() forces eager
// loading of the test's ApplicationContext which consequently results in the
// publication of all test execution events. Otherwise, TestContext#publishEvent
// would never fire any events for ExampleTestCase.
private final TestExecutionListener listener = testContext.getApplicationContext().getBean(TestExecutionListener.class);

private final Object testInstance = new ExampleTestCase();

private final Method traceableTestMethod = ReflectionUtils.findMethod(ExampleTestCase.class, "traceableTest");


Expand Down Expand Up @@ -127,8 +131,8 @@ public void beforeTestMethodAnnotationWithFailingCondition() throws Exception {
public void beforeTestMethodAnnotationWithFailingEventListener() throws Exception {
Method method = ReflectionUtils.findMethod(ExampleTestCase.class, "testWithFailingEventListener");
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
testContextManager.beforeTestMethod(testInstance, method))
.withMessageContaining("Boom!");
testContextManager.beforeTestMethod(testInstance, method))
.withMessageContaining("Boom!");
verify(listener, only()).beforeTestMethod(testContext);
}

Expand All @@ -149,7 +153,7 @@ public void beforeTestMethodAnnotationWithFailingAsyncEventListener() throws Exc

verify(listener, only()).beforeTestMethod(testContext);
assertThat(TrackingAsyncUncaughtExceptionHandler.asyncException.getMessage())
.startsWith("Asynchronous exception for test method [" + methodName + "] in thread [" + THREAD_NAME_PREFIX);
.startsWith("Asynchronous exception for test method [" + methodName + "] in thread [" + THREAD_NAME_PREFIX);
}

@Test
Expand Down Expand Up @@ -211,7 +215,7 @@ public void testWithFailingAsyncEventListener() {

@Configuration
@EnableAsync(proxyTargetClass = true)
static class TestEventListenerConfiguration extends AsyncConfigurerSupport {
static class TestEventListenerConfiguration implements AsyncConfigurer {

@Override
public Executor getAsyncExecutor() {
Expand Down Expand Up @@ -306,7 +310,7 @@ static class AsyncTestEventComponent {
public void beforeTestMethodWithAsyncFailure(BeforeTestMethodEvent event) throws Exception {
this.listener.beforeTestMethod(event.getSource());
throw new RuntimeException(String.format("Asynchronous exception for test method [%s] in thread [%s]",
event.getTestContext().getTestMethod().getName(), Thread.currentThread().getName()));
event.getTestContext().getTestMethod().getName(), Thread.currentThread().getName()));
}

}
Expand Down

0 comments on commit b06d267

Please sign in to comment.