@@ -237,13 +237,8 @@ public void run() {
237
237
AtomicReference <Exception > exceptionReference = new AtomicReference <>();
238
238
String clusterAlias = "test-cluster" ;
239
239
Settings settings = buildRandomSettings (clusterAlias , addresses (seedNode ));
240
- try (
241
- RemoteClusterConnection connection = new RemoteClusterConnection (
242
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
243
- service ,
244
- randomFrom (RemoteClusterCredentialsManager .EMPTY , buildCredentialsManager (clusterAlias ))
245
- )
246
- ) {
240
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , randomBoolean ())) {
241
+
247
242
ActionListener <Void > listener = ActionListener .wrap (x -> {
248
243
listenerCalled .countDown ();
249
244
fail ("expected exception" );
@@ -313,13 +308,7 @@ public void testCloseWhileConcurrentlyConnecting() throws IOException, Interrupt
313
308
service .acceptIncomingRequests ();
314
309
String clusterAlias = "test-cluster" ;
315
310
Settings settings = buildRandomSettings (clusterAlias , seedNodes );
316
- try (
317
- RemoteClusterConnection connection = new RemoteClusterConnection (
318
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
319
- service ,
320
- RemoteClusterCredentialsManager .EMPTY
321
- )
322
- ) {
311
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , false )) {
323
312
int numThreads = randomIntBetween (4 , 10 );
324
313
Thread [] threads = new Thread [numThreads ];
325
314
CyclicBarrier barrier = new CyclicBarrier (numThreads + 1 );
@@ -466,13 +455,7 @@ private void doTestGetConnectionInfo(boolean hasClusterCredentials) throws Excep
466
455
);
467
456
settings = Settings .builder ().put (settings ).setSecureSettings (secureSettings ).build ();
468
457
}
469
- try (
470
- RemoteClusterConnection connection = new RemoteClusterConnection (
471
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
472
- service ,
473
- hasClusterCredentials ? buildCredentialsManager (clusterAlias ) : RemoteClusterCredentialsManager .EMPTY
474
- )
475
- ) {
458
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , hasClusterCredentials )) {
476
459
// test no nodes connected
477
460
RemoteConnectionInfo remoteConnectionInfo = assertSerialization (connection .getConnectionInfo ());
478
461
assertNotNull (remoteConnectionInfo );
@@ -662,13 +645,7 @@ private void doTestCollectNodes(boolean hasClusterCredentials) throws Exception
662
645
settings = Settings .builder ().put (settings ).setSecureSettings (secureSettings ).build ();
663
646
}
664
647
665
- try (
666
- RemoteClusterConnection connection = new RemoteClusterConnection (
667
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
668
- service ,
669
- hasClusterCredentials ? buildCredentialsManager (clusterAlias ) : RemoteClusterCredentialsManager .EMPTY
670
- )
671
- ) {
648
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , hasClusterCredentials )) {
672
649
CountDownLatch responseLatch = new CountDownLatch (1 );
673
650
AtomicReference <Function <String , DiscoveryNode >> reference = new AtomicReference <>();
674
651
AtomicReference <Exception > failReference = new AtomicReference <>();
@@ -718,13 +695,7 @@ public void testNoChannelsExceptREG() throws Exception {
718
695
String clusterAlias = "test-cluster" ;
719
696
Settings settings = buildRandomSettings (clusterAlias , addresses (seedNode ));
720
697
721
- try (
722
- RemoteClusterConnection connection = new RemoteClusterConnection (
723
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
724
- service ,
725
- RemoteClusterCredentialsManager .EMPTY
726
- )
727
- ) {
698
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , false )) {
728
699
PlainActionFuture <Void > plainActionFuture = new PlainActionFuture <>();
729
700
connection .ensureConnected (plainActionFuture );
730
701
plainActionFuture .get (10 , TimeUnit .SECONDS );
@@ -790,13 +761,7 @@ public void testConnectedNodesConcurrentAccess() throws IOException, Interrupted
790
761
791
762
String clusterAlias = "test-cluster" ;
792
763
Settings settings = buildRandomSettings (clusterAlias , seedNodes );
793
- try (
794
- RemoteClusterConnection connection = new RemoteClusterConnection (
795
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
796
- service ,
797
- randomFrom (RemoteClusterCredentialsManager .EMPTY , buildCredentialsManager (clusterAlias ))
798
- )
799
- ) {
764
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , randomBoolean ())) {
800
765
final int numGetThreads = randomIntBetween (4 , 10 );
801
766
final Thread [] getThreads = new Thread [numGetThreads ];
802
767
final int numModifyingThreads = randomIntBetween (4 , 10 );
@@ -890,13 +855,7 @@ public void testGetConnection() throws Exception {
890
855
service .acceptIncomingRequests ();
891
856
String clusterAlias = "test-cluster" ;
892
857
Settings settings = buildRandomSettings (clusterAlias , addresses (seedNode ));
893
- try (
894
- RemoteClusterConnection connection = new RemoteClusterConnection (
895
- RemoteClusterSettings .toConfig (clusterAlias , settings ),
896
- service ,
897
- RemoteClusterCredentialsManager .EMPTY
898
- )
899
- ) {
858
+ try (RemoteClusterConnection connection = createConnection (clusterAlias , settings , service , false )) {
900
859
safeAwait (listener -> connection .ensureConnected (listener .map (x -> null )));
901
860
for (int i = 0 ; i < 10 ; i ++) {
902
861
// always a direct connection as the remote node is already connected
@@ -953,4 +912,18 @@ private static RemoteClusterCredentialsManager buildCredentialsManager(String cl
953
912
builder .setSecureSettings (secureSettings );
954
913
return new RemoteClusterCredentialsManager (builder .build ());
955
914
}
915
+
916
+ private RemoteClusterConnection createConnection (
917
+ String alias ,
918
+ Settings settings ,
919
+ TransportService transportService ,
920
+ boolean hasCredentials
921
+ ) {
922
+ return new RemoteClusterConnection (
923
+ RemoteClusterSettings .toConfig (alias , settings ),
924
+ transportService ,
925
+ hasCredentials ? buildCredentialsManager (alias ) : RemoteClusterCredentialsManager .EMPTY ,
926
+ false
927
+ );
928
+ }
956
929
}
0 commit comments