1
1
package org .testcontainers .containers ;
2
2
3
3
import com .github .dockerjava .api .command .InspectContainerResponse ;
4
- import io .tarantool .driver .exceptions .TarantoolConnectionException ;
5
4
6
5
import org .testcontainers .containers .exceptions .CartridgeTopologyException ;
7
6
import org .testcontainers .images .builder .ImageFromDockerfile ;
12
11
import java .util .HashMap ;
13
12
import java .util .List ;
14
13
import java .util .Map ;
15
- import java .util .concurrent .CompletableFuture ;
16
14
import java .util .concurrent .ExecutionException ;
17
15
import java .util .concurrent .TimeoutException ;
18
16
import java .util .function .Supplier ;
82
80
* specified in the http_port options, will be exposed.
83
81
*
84
82
* @author Alexey Kuzin
83
+ * @authorm Artyom Dubinin
84
+ * @author Ivan Dneprov
85
+ *
85
86
*/
86
87
public class TarantoolCartridgeContainer extends GenericContainer <TarantoolCartridgeContainer >
87
88
implements TarantoolContainerOperations <TarantoolCartridgeContainer > {
@@ -119,6 +120,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
119
120
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY ;
120
121
private String instanceDir = INSTANCE_DIR ;
121
122
private String topologyConfigurationFile ;
123
+ private SslContext sslContext ;
122
124
123
125
/**
124
126
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -333,6 +335,11 @@ public String getInstanceDir() {
333
335
return instanceDir ;
334
336
}
335
337
338
+ @ Override
339
+ public int getInternalPort () {
340
+ return routerPort ;
341
+ }
342
+
336
343
/**
337
344
* Get Cartridge router HTTP API hostname
338
345
*
@@ -480,7 +487,7 @@ private boolean setupTopology() {
480
487
.substring (topologyConfigurationFile .lastIndexOf ('/' ) + 1 );
481
488
482
489
try {
483
- Container . ExecResult result = execInContainer ("cartridge" ,
490
+ ExecResult result = execInContainer ("cartridge" ,
484
491
"replicasets" ,
485
492
"--run-dir=" + TARANTOOL_RUN_DIR ,
486
493
"--file=" + replicasetsFileName , "setup" , "--bootstrap-vshard" );
@@ -494,7 +501,7 @@ private boolean setupTopology() {
494
501
495
502
} else {
496
503
try {
497
- List <?> res = executeScript (topologyConfigurationFile ). get ( );
504
+ List <?> res = executeScriptDecoded (topologyConfigurationFile );
498
505
if (res .size () >= 2 && res .get (1 ) != null && res .get (1 ) instanceof Map ) {
499
506
HashMap <?, ?> error = ((HashMap <?, ?>) res .get (1 ));
500
507
// that means topology already exists
@@ -506,10 +513,6 @@ private boolean setupTopology() {
506
513
if (e .getCause () instanceof TimeoutException ) {
507
514
return true ;
508
515
// Do nothing, the cluster is reloading
509
- } else if (e .getCause () instanceof TarantoolConnectionException ) {
510
- // Probably cluster is not ready
511
- logger ().error ("Failed to setup topology: {}" , e .getMessage ());
512
- return false ;
513
516
}
514
517
} else {
515
518
throw new CartridgeTopologyException (e );
@@ -535,7 +538,7 @@ private void retryingSetupTopology() {
535
538
536
539
private void bootstrapVshard () {
537
540
try {
538
- executeCommand (VSHARD_BOOTSTRAP_COMMAND ). get () ;
541
+ executeCommand (VSHARD_BOOTSTRAP_COMMAND );
539
542
} catch (Exception e ) {
540
543
logger ().error ("Failed to bootstrap vshard cluster" , e );
541
544
throw new RuntimeException (e );
@@ -583,10 +586,10 @@ private void waitUntilTrue(int secondsToWait, Supplier<Boolean> waitFunc) {
583
586
584
587
private boolean routerIsUp () {
585
588
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
586
- " return assert( cartridge ~= nil) " ;
589
+ " return cartridge ~= nil" ;
587
590
try {
588
- List <?> result = executeCommand (healthyCmd ). get ( );
589
- return (Boolean ) result .get (0 );
591
+ List <?> result = executeCommandDecoded (healthyCmd );
592
+ return result . get ( 0 ). getClass () == Boolean . class && (Boolean ) result .get (0 );
590
593
} catch (Exception e ) {
591
594
logger ().warn ("Error while waiting for router instance to be up: " + e .getMessage ());
592
595
return false ;
@@ -595,23 +598,33 @@ private boolean routerIsUp() {
595
598
596
599
private boolean isCartridgeHealthy () {
597
600
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
598
- " return assert( cartridge) and assert( cartridge.is_healthy() )" ;
601
+ " return cartridge ~= nil and cartridge.is_healthy()" ;
599
602
try {
600
- List <?> result = executeCommand (healthyCmd ). get ( );
601
- return (Boolean ) result .get (0 );
603
+ List <?> result = executeCommandDecoded (healthyCmd );
604
+ return result . get ( 0 ). getClass () == Boolean . class && (Boolean ) result .get (0 );
602
605
} catch (Exception e ) {
603
606
logger ().warn ("Error while waiting for cartridge healthy state: " + e .getMessage ());
604
607
return false ;
605
608
}
606
609
}
607
610
608
611
@ Override
609
- public CompletableFuture <List <?>> executeScript (String scriptResourcePath ) throws Exception {
610
- return clientHelper .executeScript (scriptResourcePath );
612
+ public ExecResult executeScript (String scriptResourcePath ) throws Exception {
613
+ return clientHelper .executeScript (scriptResourcePath , this .sslContext );
614
+ }
615
+
616
+ @ Override
617
+ public <T > T executeScriptDecoded (String scriptResourcePath ) throws Exception {
618
+ return clientHelper .executeScriptDecoded (scriptResourcePath , this .sslContext );
619
+ }
620
+
621
+ @ Override
622
+ public ExecResult executeCommand (String command ) throws Exception {
623
+ return clientHelper .executeCommand (command , this .sslContext );
611
624
}
612
625
613
626
@ Override
614
- public CompletableFuture < List <?>> executeCommand (String command , Object ... arguments ) throws Exception {
615
- return clientHelper .executeCommand (command , arguments );
627
+ public < T > T executeCommandDecoded (String command ) throws Exception {
628
+ return clientHelper .executeCommandDecoded (command , this . sslContext );
616
629
}
617
630
}
0 commit comments