Prevent ReactorResourceFactory from participating in pause scenarios

Prior to this commit, ReactorResourceFactory was not restarted properly
when the ApplicationContext was resumed by the TestContext Framework
after a context pause. The reason is that the managed LoopResources
were disposed when ConfigurableApplicationContext.pause() was invoked
and reacquired when ConfigurableApplicationContext.restart() was
invoked.

To address that, this commit overrides isPauseable() in
ReactorResourceFactory to return false, thereby avoiding participation
in pause scenarios.

Closes gh-35585
This commit is contained in:
Sam Brannen
2025-10-08 15:28:24 +02:00
parent e0b8cb4fe2
commit d404fdafa0
2 changed files with 53 additions and 7 deletions
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @author Sam Brannen
*/
class ReactorResourceFactoryTests {
@@ -157,7 +158,7 @@ class ReactorResourceFactoryTests {
}
@Test
void restartWithGlobalResources() {
void stopAndStartWithGlobalResources() {
this.resourceFactory.setUseGlobalResources(true);
this.resourceFactory.start();
this.resourceFactory.stop();
@@ -174,7 +175,7 @@ class ReactorResourceFactoryTests {
}
@Test
void restartWithLocalResources() {
void stopAndStartWithLocalResources() {
this.resourceFactory.setUseGlobalResources(false);
this.resourceFactory.start();
this.resourceFactory.stop();
@@ -197,7 +198,7 @@ class ReactorResourceFactoryTests {
}
@Test
void restartWithExternalResources() {
void stopAndStartWithExternalResources() {
this.resourceFactory.setUseGlobalResources(false);
this.resourceFactory.setConnectionProvider(this.connectionProvider);
this.resourceFactory.setLoopResources(this.loopResources);
@@ -220,7 +221,7 @@ class ReactorResourceFactoryTests {
}
@Test
void restartWithinApplicationContext() {
void stopAndStartWithinApplicationContext() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBean(ReactorResourceFactory.class);
context.refresh();
@@ -241,9 +242,42 @@ class ReactorResourceFactoryTests {
assertThat(resourceFactory.getConnectionProvider()).isSameAs(globalResources);
assertThat(resourceFactory.getLoopResources()).isSameAs(globalResources);
assertThat(globalResources.isDisposed()).isFalse();
context.close();
assertThat(resourceFactory.isRunning()).isFalse();
assertThat(globalResources.isDisposed()).isTrue();
}
@Test // gh-35585
void pauseAndRestartWithinApplicationContext() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBean(ReactorResourceFactory.class);
context.refresh();
ReactorResourceFactory resourceFactory = context.getBean(ReactorResourceFactory.class);
assertThat(resourceFactory.isRunning()).isTrue();
HttpResources globalResources = HttpResources.get();
assertThat(resourceFactory.getConnectionProvider()).isSameAs(globalResources);
assertThat(resourceFactory.getLoopResources()).isSameAs(globalResources);
assertThat(globalResources.isDisposed()).isFalse();
context.pause();
globalResources = HttpResources.get();
assertThat(resourceFactory.isRunning()).isTrue();
assertThat(resourceFactory.getConnectionProvider()).isSameAs(globalResources);
assertThat(resourceFactory.getLoopResources()).isSameAs(globalResources);
assertThat(globalResources.isDisposed()).isFalse();
context.restart();
globalResources = HttpResources.get();
assertThat(resourceFactory.isRunning()).isTrue();
assertThat(resourceFactory.getConnectionProvider()).isSameAs(globalResources);
assertThat(resourceFactory.getLoopResources()).isSameAs(globalResources);
assertThat(globalResources.isDisposed()).isFalse();
context.close();
assertThat(resourceFactory.isRunning()).isFalse();
assertThat(globalResources.isDisposed()).isTrue();
}