-
Notifications
You must be signed in to change notification settings - Fork 207
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @001mertiya could you clarify please what exactly you are trying to achieve here? The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reta There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @playLeo , if it was deprecated and is not working anymore, we should make sure our API does switch to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here http5client commit link! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, my point is: we have class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the detailed explanation. I understand. I have a question before I start working. It seems that you can configure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @playLeo , since the timeout properties from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think I did not explain it clearly. If we create a I also know that for If there are two ways to configure this, wouldn’t that be confusing? Are you saying it’s fine as long as it’s documented properly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, so the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please take a look at the updated |
||
.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.