restores http2 termination tests

This commit is contained in:
spencergibb
2021-09-23 11:44:15 -04:00
parent c1eb83cd38
commit f5f23ce61f
4 changed files with 28 additions and 26 deletions

View File

@@ -38,10 +38,8 @@ import org.springframework.web.bind.annotation.RestController;
@SpringBootConfiguration
@EnableAutoConfiguration
@RestController
@LoadBalancerClients({
@LoadBalancerClient(name = "myservice", configuration = Http2Application.MyServiceConf.class),
@LoadBalancerClient(name = "nossl", configuration = Http2Application.NosslServiceConf.class)
})
@LoadBalancerClients({ @LoadBalancerClient(name = "myservice", configuration = Http2Application.MyServiceConf.class),
@LoadBalancerClient(name = "nossl", configuration = Http2Application.NosslServiceConf.class) })
public class Http2Application {
@GetMapping("hello")

View File

@@ -63,16 +63,13 @@ public class Http2ApplicationTests {
Assertions.assertThat(output).contains("Negotiated application-level protocol [h2]", "PRI * HTTP/2.0");
}
public static void assertResponse(String uri, String expected ) {
Flux<HttpClientResponse> responseFlux = getHttpClient().request(HttpMethod.GET)
.uri(uri)
.send(Mono.empty())
public static void assertResponse(String uri, String expected) {
Flux<HttpClientResponse> responseFlux = getHttpClient().request(HttpMethod.GET).uri(uri).send(Mono.empty())
.response((res, byteBufFlux) -> {
assertThat(res.status()).isEqualTo(HttpResponseStatus.OK);
NettyDataBufferFactory bufferFactory = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT);
return DataBufferUtils.join(byteBufFlux.map(bufferFactory::wrap))
.map(dataBuffer -> dataBuffer.toString(StandardCharsets.UTF_8))
.map(s -> {
.map(dataBuffer -> dataBuffer.toString(StandardCharsets.UTF_8)).map(s -> {
assertThat(s).isEqualTo(expected);
return res;
});
@@ -82,14 +79,12 @@ public class Http2ApplicationTests {
}
static HttpClient getHttpClient() {
return HttpClient.create(ConnectionProvider.builder("test").maxConnections(100)
.pendingAcquireTimeout(Duration.ofMillis(0))
.pendingAcquireMaxCount(-1).build())
.protocol(HttpProtocol.HTTP11, HttpProtocol.H2)
.secure(sslContextSpec -> {
Http2SslContextSpec clientSslCtxt =
Http2SslContextSpec.forClient()
.configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
return HttpClient
.create(ConnectionProvider.builder("test").maxConnections(100)
.pendingAcquireTimeout(Duration.ofMillis(0)).pendingAcquireMaxCount(-1).build())
.protocol(HttpProtocol.HTTP11, HttpProtocol.H2).secure(sslContextSpec -> {
Http2SslContextSpec clientSslCtxt = Http2SslContextSpec.forClient()
.configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
sslContextSpec.sslContext(clientSslCtxt);
});
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.gateway.tests.http2.config;
package org.springframework.cloud.gateway.tests.http2.nossl;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
@@ -30,4 +30,5 @@ public class NosslConfiguration {
public String home() {
return "nossl";
}
}

View File

@@ -14,19 +14,22 @@
* limitations under the License.
*/
package org.springframework.cloud.gateway.tests.http2.config;
package org.springframework.cloud.gateway.tests.http2.nossl;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import reactor.core.publisher.Hooks;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.gateway.tests.http2.Http2Application;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.SocketUtils;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -54,12 +57,17 @@ public class NosslTests {
}
@Test
public void http2Works(CapturedOutput output) {
String uri = "https://localhost:" + port + "/myprefix/hello";
String expected = "Hello";
assertResponse(uri, expected);
Assertions.assertThat(output).contains("Negotiated application-level protocol [h2]", "PRI * HTTP/2.0");
public void http2TerminationWorks(CapturedOutput output) {
int nosslPort = Integer.parseInt(System.getProperty("nossl.port"));
System.err.println("nossl.port = " + nosslPort);
Hooks.onOperatorDebug();
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(NosslConfiguration.class)
.properties("server.port=" + nosslPort).profiles("nossl").run()) {
String uri = "https://localhost:" + port + "/nossl";
String expected = "nossl";
assertResponse(uri, expected);
Assertions.assertThat(output).doesNotContain("PRI * HTTP/2.0");
}
}
}