-
Notifications
You must be signed in to change notification settings - Fork 211
Fix default connectTimeout of transportBuilder #1633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
22690eb
6313ab8
62cf14f
f469469
1109526
3b0cb76
aff280f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.opensearch.client.transport.httpclient5; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.hc.client5.http.ConnectTimeoutException; | ||
import org.apache.hc.client5.http.config.ConnectionConfig; | ||
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager; | ||
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; | ||
import org.apache.hc.core5.http.HttpHost; | ||
import org.apache.hc.core5.util.Timeout; | ||
import org.junit.Test; | ||
import org.opensearch.client.opensearch.OpenSearchClient; | ||
import org.opensearch.client.opensearch.core.SearchRequest; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ApacheHttpClient5TransportBuilderTest { | ||
|
||
@Test | ||
public void timeOutTest() { | ||
|
||
int expectTime = 10; | ||
String expectMessage = expectTime + " MILLISECONDS"; | ||
|
||
ApacheHttpClient5Transport apacheHttpClient5Transport = ApacheHttpClient5TransportBuilder.builder(new HttpHost("10.255.255.1", 9200)) | ||
.setHttpClientConfigCallback(httpClientBuilder -> { | ||
|
||
ConnectionConfig connectionConfig = ConnectionConfig.custom() | ||
.setConnectTimeout(Timeout.ofMilliseconds(expectTime)) | ||
.build(); | ||
|
||
PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder | ||
.create() | ||
.setDefaultConnectionConfig(connectionConfig) | ||
|
||
.build(); | ||
|
||
return httpClientBuilder.setConnectionManager(connectionManager); | ||
}).build(); | ||
|
||
OpenSearchClient osClient = new OpenSearchClient(apacheHttpClient5Transport); | ||
|
||
ConnectTimeoutException exception = assertThrows(ConnectTimeoutException.class, () -> osClient.search(SearchRequest.of(sb -> sb.index("index")), JsonNode.class)); | ||
|
||
assertTrue("Expected timeout value not found in message", exception.getMessage().contains(expectMessage)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s remove
DEFAULT_CONNECT_TIMEOUT_MILLIS
from this class since we don’t need it here now.