Lazily start and retain HttpClient once resource factory is running
Closes gh-33093
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 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.
|
||||
@@ -16,17 +16,21 @@
|
||||
|
||||
package org.springframework.http.client.reactive;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ReactorResourceFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sebastien Deleuze
|
||||
* @author Juergen Hoeller
|
||||
* @since 6.1
|
||||
*/
|
||||
class ReactorClientHttpConnectorTests {
|
||||
@@ -41,6 +45,8 @@ class ReactorClientHttpConnectorTests {
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.start();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.stop();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,6 +60,8 @@ class ReactorClientHttpConnectorTests {
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.start();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.stop();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,6 +77,8 @@ class ReactorClientHttpConnectorTests {
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
connector.start();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.stop();
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,6 +94,27 @@ class ReactorClientHttpConnectorTests {
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
connector.start();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.stop();
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void lazyStartWithExternalResourceFactory() throws Exception {
|
||||
ReactorResourceFactory resourceFactory = new ReactorResourceFactory();
|
||||
Function<HttpClient, HttpClient> mapper = Function.identity();
|
||||
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(resourceFactory, mapper);
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
resourceFactory.start();
|
||||
connector.connect(HttpMethod.GET, new URI(""), request -> Mono.empty());
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.stop();
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
connector.connect(HttpMethod.GET, new URI(""), request -> Mono.empty());
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
connector.start();
|
||||
assertThat(connector.isRunning()).isTrue();
|
||||
connector.stop();
|
||||
assertThat(connector.isRunning()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user