org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration源码实例Demo

类org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration源码实例Demo

下面列出了org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void nettyHttpClientDefaults() {
	new ReactiveWebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class,
					MetricsAutoConfiguration.class,
					SimpleMetricsExportAutoConfiguration.class,
					GatewayAutoConfiguration.class))
			.withPropertyValues("debug=true").run(context -> {
				assertThat(context).hasSingleBean(HttpClient.class);
				assertThat(context).hasBean("gatewayHttpClient");
				HttpClient httpClient = context.getBean(HttpClient.class);
				/*
				 * FIXME: 2.1.0 HttpClientOptions options = httpClient.options();
				 *
				 * PoolResources poolResources = options.getPoolResources();
				 * assertThat(poolResources).isNotNull(); //TODO: howto test
				 * PoolResources
				 *
				 * ClientProxyOptions proxyOptions = options.getProxyOptions();
				 * assertThat(proxyOptions).isNull();
				 *
				 * SslContext sslContext = options.sslContext();
				 * assertThat(sslContext).isNull();
				 */
			});
}
 
@Test
public void nettyHttpClientConfigured() {
	new ReactiveWebApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class,
					MetricsAutoConfiguration.class,
					SimpleMetricsExportAutoConfiguration.class,
					GatewayAutoConfiguration.class, HttpClientCustomizedConfig.class))
			.withPropertyValues(
					"spring.cloud.gateway.httpclient.ssl.use-insecure-trust-manager=true",
					"spring.cloud.gateway.httpclient.connect-timeout=10",
					"spring.cloud.gateway.httpclient.response-timeout=10s",
					"spring.cloud.gateway.httpclient.pool.type=fixed",
					// greather than integer max value
					"spring.cloud.gateway.httpclient.max-initial-line-length=2147483647",
					"spring.cloud.gateway.httpclient.proxy.host=myhost",
					"spring.cloud.gateway.httpclient.websocket.max-frame-payload-length=1024")
			.run(context -> {
				assertThat(context).hasSingleBean(HttpClient.class);
				HttpClient httpClient = context.getBean(HttpClient.class);
				HttpClientProperties properties = context
						.getBean(HttpClientProperties.class);
				assertThat(properties.getMaxInitialLineLength().toBytes())
						.isLessThanOrEqualTo(Integer.MAX_VALUE);
				/*
				 * FIXME: 2.1.0 HttpClientOptions options = httpClient.options();
				 *
				 * PoolResources poolResources = options.getPoolResources();
				 * assertThat(poolResources).isNotNull(); //TODO: howto test
				 * PoolResources
				 *
				 * ClientProxyOptions proxyOptions = options.getProxyOptions();
				 * assertThat(proxyOptions).isNotNull();
				 * assertThat(proxyOptions.getAddress().get().getHostName()).isEqualTo
				 * ("myhost");
				 *
				 * SslContext sslContext = options.sslContext();
				 * assertThat(sslContext).isNotNull();
				 */
				// TODO: howto test SslContext
				assertThat(context)
						.hasSingleBean(ReactorNettyRequestUpgradeStrategy.class);
				ReactorNettyRequestUpgradeStrategy upgradeStrategy = context
						.getBean(ReactorNettyRequestUpgradeStrategy.class);
				assertThat(upgradeStrategy.getMaxFramePayloadLength())
						.isEqualTo(1024);
				assertThat(upgradeStrategy.getHandlePing()).isTrue();
				assertThat(context).hasSingleBean(ReactorNettyWebSocketClient.class);
				ReactorNettyWebSocketClient webSocketClient = context
						.getBean(ReactorNettyWebSocketClient.class);
				assertThat(webSocketClient.getMaxFramePayloadLength())
						.isEqualTo(1024);
				HttpClientCustomizedConfig config = context
						.getBean(HttpClientCustomizedConfig.class);
				assertThat(config.called.get()).isTrue();
			});
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类方法
 同包方法