@ -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" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -15,6 +15,7 @@
* /
* /
package org.springframework.http.client.reactive ;
package org.springframework.http.client.reactive ;
import java.time.Duration ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.concurrent.atomic.AtomicBoolean ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.Test ;
@ -23,6 +24,7 @@ import reactor.netty.resources.ConnectionProvider;
import reactor.netty.resources.LoopResources ;
import reactor.netty.resources.LoopResources ;
import static org.assertj.core.api.Assertions.assertThat ;
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.mock ;
import static org.mockito.Mockito.verify ;
import static org.mockito.Mockito.verify ;
import static org.mockito.Mockito.verifyNoMoreInteractions ;
import static org.mockito.Mockito.verifyNoMoreInteractions ;
@ -41,7 +43,7 @@ public class ReactorResourceFactoryTests {
@Test
@Test
public void globalResources ( ) throws Exception {
void globalResources ( ) throws Exception {
this . resourceFactory . setUseGlobalResources ( true ) ;
this . resourceFactory . setUseGlobalResources ( true ) ;
this . resourceFactory . afterPropertiesSet ( ) ;
this . resourceFactory . afterPropertiesSet ( ) ;
@ -57,7 +59,7 @@ public class ReactorResourceFactoryTests {
}
}
@Test
@Test
public void globalResourcesWithConsumer ( ) throws Exception {
void globalResourcesWithConsumer ( ) throws Exception {
AtomicBoolean invoked = new AtomicBoolean ( false ) ;
AtomicBoolean invoked = new AtomicBoolean ( false ) ;
@ -69,7 +71,7 @@ public class ReactorResourceFactoryTests {
}
}
@Test
@Test
public void localResources ( ) throws Exception {
void localResources ( ) throws Exception {
this . resourceFactory . setUseGlobalResources ( false ) ;
this . resourceFactory . setUseGlobalResources ( false ) ;
this . resourceFactory . afterPropertiesSet ( ) ;
this . resourceFactory . afterPropertiesSet ( ) ;
@ -91,7 +93,7 @@ public class ReactorResourceFactoryTests {
}
}
@Test
@Test
public void localResourcesViaSupplier ( ) throws Exception {
void localResourcesViaSupplier ( ) throws Exception {
this . resourceFactory . setUseGlobalResources ( false ) ;
this . resourceFactory . setUseGlobalResources ( false ) ;
this . resourceFactory . setConnectionProviderSupplier ( ( ) - > this . connectionProvider ) ;
this . resourceFactory . setConnectionProviderSupplier ( ( ) - > this . connectionProvider ) ;
@ -110,12 +112,29 @@ public class ReactorResourceFactoryTests {
// Managed (destroy disposes)..
// Managed (destroy disposes)..
verify ( this . connectionProvider ) . disposeLater ( ) ;
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 ) ;
verifyNoMoreInteractions ( this . connectionProvider , this . loopResources ) ;
}
}
@Test
@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 . setUseGlobalResources ( false ) ;
this . resourceFactory . setConnectionProvider ( this . connectionProvider ) ;
this . resourceFactory . setConnectionProvider ( this . connectionProvider ) ;