Skip to content

Commit 43a87ea

Browse files
committed
fix: spring properties for connection timeout
Signed-off-by: weiping-code <[email protected]>
1 parent dbf69f7 commit 43a87ea

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/core/OpenGeminiPropertiesConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public HttpClientConfig toHttpClientConfig(OpenGeminiProperties.Http http) {
8383
HttpClientConfig.Builder builder = new HttpClientConfig.Builder();
8484
builder.engine(http.getEngine());
8585
builder.timeout(http.getTimeout());
86-
builder.timeout(http.getTimeout());
86+
builder.connectTimeout(http.getConnectTimeout());
8787
Optional.ofNullable(http.getSsl()).map(this::toTlsConfig).ifPresent(builder::tlsConfig);
8888
Optional.ofNullable(http.getOkHttp()).map(this::toOkHttpConfig).ifPresent(builder::okHttpConfig);
8989
return builder.build();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 openGemini Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.opengemini.client.spring.data.core;
18+
19+
import io.github.openfacade.http.HttpClientConfig;
20+
import io.github.openfacade.http.HttpClientEngine;
21+
import io.opengemini.client.api.Configuration;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.Test;
24+
import org.springframework.beans.factory.ObjectProvider;
25+
import org.springframework.beans.factory.support.StaticListableBeanFactory;
26+
27+
import java.time.Duration;
28+
29+
class OpenGeminiPropertiesConverterTest {
30+
31+
@Test
32+
void toConfiguration_should_right_for_convert_http_config() {
33+
OpenGeminiProperties.Http http = new OpenGeminiProperties.Http();
34+
http.setEngine(HttpClientEngine.OkHttp);
35+
http.setTimeout(Duration.ofSeconds(30));
36+
http.setConnectTimeout(Duration.ofSeconds(10));
37+
38+
OpenGeminiProperties properties = new OpenGeminiProperties();
39+
properties.setHttp(http);
40+
41+
ObjectProvider<ClientConfigurationBuilderCustomizer> provider =
42+
new StaticListableBeanFactory().getBeanProvider(ClientConfigurationBuilderCustomizer.class);
43+
OpenGeminiPropertiesConverter converter = new OpenGeminiPropertiesConverter(properties, provider);
44+
45+
Configuration configuration = converter.toConfiguration();
46+
HttpClientConfig httpConfig = configuration.getHttpConfig();
47+
48+
Assertions.assertEquals(http.getEngine(), httpConfig.engine());
49+
Assertions.assertEquals(http.getTimeout(), httpConfig.timeout());
50+
Assertions.assertEquals(http.getConnectTimeout(), httpConfig.connectTimeout());
51+
}
52+
}

0 commit comments

Comments
 (0)