42
42
import org .opensearch .client .cluster .RemoteInfoRequest ;
43
43
import org .opensearch .client .indices .CreateIndexRequest ;
44
44
import org .opensearch .common .settings .Settings ;
45
+ import org .opensearch .common .unit .TimeValue ;
45
46
import org .opensearch .common .xcontent .XContentFactory ;
46
47
import org .junit .After ;
47
48
import org .junit .Before ;
48
49
49
50
import java .io .IOException ;
51
+ import java .util .concurrent .TimeUnit ;
50
52
51
53
52
54
public class RemoteClustersIT extends AbstractMultiClusterRemoteTestCase {
@@ -112,7 +114,7 @@ public void testSniffModeConnectionFails() throws IOException {
112
114
assertFalse (rci .isConnected ());
113
115
}
114
116
115
- public void testHAProxyModeConnectionWorks () throws IOException {
117
+ public void testHAProxyModeConnectionWorks () throws Exception {
116
118
String proxyAddress = "haproxy:9600" ;
117
119
logger .info ("Configuring remote cluster [{}]" , proxyAddress );
118
120
ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest ().persistentSettings (Settings .builder ()
@@ -121,12 +123,14 @@ public void testHAProxyModeConnectionWorks() throws IOException {
121
123
.build ());
122
124
assertTrue (cluster1Client ().cluster ().putSettings (request , RequestOptions .DEFAULT ).isAcknowledged ());
123
125
124
- RemoteConnectionInfo rci = cluster1Client ().cluster ().remoteInfo (new RemoteInfoRequest (), RequestOptions .DEFAULT ).getInfos ().get (0 );
125
- logger .info ("Connection info: {}" , rci );
126
- if (!rci .isConnected ()) {
127
- logger .info ("Cluster health: {}" , cluster1Client ().cluster ().health (new ClusterHealthRequest (), RequestOptions .DEFAULT ));
128
- }
129
- assertTrue (rci .isConnected ());
126
+ assertBusy (() -> {
127
+ RemoteConnectionInfo rci = cluster1Client ().cluster ().remoteInfo (new RemoteInfoRequest (), RequestOptions .DEFAULT ).getInfos ().get (0 );
128
+ logger .info ("Connection info: {}" , rci );
129
+ if (!rci .isConnected ()) {
130
+ logger .info ("Cluster health: {}" , cluster1Client ().cluster ().health (new ClusterHealthRequest (), RequestOptions .DEFAULT ));
131
+ }
132
+ assertTrue (rci .isConnected ());
133
+ }, 10 , TimeUnit .SECONDS );
130
134
131
135
assertEquals (2L , cluster1Client ().search (
132
136
new SearchRequest ("haproxynosn:test2" ), RequestOptions .DEFAULT ).getHits ().getTotalHits ().value );
0 commit comments