Configure quiet period for shutting down Reactor resources
This commit adds two new properties to the `ReactorResourceFactory`. This allows to configure the quiet and timeout periods when shutting down Reactor resources. While we'll retain Reactor Netty's default for production use, this option is useful for tests and developement environments when developers want to avoid long waiting times when shutting down resources. Fixes gh-24538
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.http.client.reactive;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -23,6 +24,7 @@ import reactor.netty.resources.ConnectionProvider;
|
||||
import reactor.netty.resources.LoopResources;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -41,7 +43,7 @@ public class ReactorResourceFactoryTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void globalResources() throws Exception {
|
||||
void globalResources() throws Exception {
|
||||
|
||||
this.resourceFactory.setUseGlobalResources(true);
|
||||
this.resourceFactory.afterPropertiesSet();
|
||||
@@ -57,7 +59,7 @@ public class ReactorResourceFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void globalResourcesWithConsumer() throws Exception {
|
||||
void globalResourcesWithConsumer() throws Exception {
|
||||
|
||||
AtomicBoolean invoked = new AtomicBoolean(false);
|
||||
|
||||
@@ -69,7 +71,7 @@ public class ReactorResourceFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localResources() throws Exception {
|
||||
void localResources() throws Exception {
|
||||
|
||||
this.resourceFactory.setUseGlobalResources(false);
|
||||
this.resourceFactory.afterPropertiesSet();
|
||||
@@ -91,7 +93,7 @@ public class ReactorResourceFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localResourcesViaSupplier() throws Exception {
|
||||
void localResourcesViaSupplier() throws Exception {
|
||||
|
||||
this.resourceFactory.setUseGlobalResources(false);
|
||||
this.resourceFactory.setConnectionProviderSupplier(() -> this.connectionProvider);
|
||||
@@ -110,12 +112,29 @@ public class ReactorResourceFactoryTests {
|
||||
|
||||
// Managed (destroy disposes)..
|
||||
verify(this.connectionProvider).disposeLater();
|
||||
verify(this.loopResources).disposeLater();
|
||||
verify(this.loopResources).disposeLater(eq(Duration.ofSeconds(LoopResources.DEFAULT_SHUTDOWN_QUIET_PERIOD)), eq(Duration.ofSeconds(LoopResources.DEFAULT_SHUTDOWN_TIMEOUT)));
|
||||
verifyNoMoreInteractions(this.connectionProvider, this.loopResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalResources() throws Exception {
|
||||
void customShutdownDurations() throws Exception {
|
||||
Duration quietPeriod = Duration.ofMillis(500);
|
||||
Duration shutdownTimeout = Duration.ofSeconds(1);
|
||||
this.resourceFactory.setUseGlobalResources(false);
|
||||
this.resourceFactory.setConnectionProviderSupplier(() -> this.connectionProvider);
|
||||
this.resourceFactory.setLoopResourcesSupplier(() -> this.loopResources);
|
||||
this.resourceFactory.setShutdownQuietPeriod(quietPeriod);
|
||||
this.resourceFactory.setShutdownTimeout(shutdownTimeout);
|
||||
this.resourceFactory.afterPropertiesSet();
|
||||
this.resourceFactory.destroy();
|
||||
|
||||
verify(this.connectionProvider).disposeLater();
|
||||
verify(this.loopResources).disposeLater(eq(quietPeriod), eq(shutdownTimeout));
|
||||
verifyNoMoreInteractions(this.connectionProvider, this.loopResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
void externalResources() throws Exception {
|
||||
|
||||
this.resourceFactory.setUseGlobalResources(false);
|
||||
this.resourceFactory.setConnectionProvider(this.connectionProvider);
|
||||
|
||||
Reference in New Issue
Block a user