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 ;
13
12
import java .util .HashMap ;
14
13
import java .util .List ;
15
14
import java .util .Map ;
16
- import java .util .concurrent .CompletableFuture ;
17
15
import java .util .concurrent .ExecutionException ;
18
16
import java .util .concurrent .TimeoutException ;
19
17
import java .util .function .Supplier ;
83
81
* specified in the http_port options, will be exposed.
84
82
*
85
83
* @author Alexey Kuzin
84
+ * @author Artyom Dubinin
85
+ * @author Ivan Dneprov
86
+ *
86
87
*/
87
88
public class TarantoolCartridgeContainer extends GenericContainer <TarantoolCartridgeContainer >
88
89
implements TarantoolContainerOperations <TarantoolCartridgeContainer > {
@@ -120,6 +121,7 @@ public class TarantoolCartridgeContainer extends GenericContainer<TarantoolCartr
120
121
private String directoryResourcePath = SCRIPT_RESOURCE_DIRECTORY ;
121
122
private String instanceDir = INSTANCE_DIR ;
122
123
private String topologyConfigurationFile ;
124
+ private SslContext sslContext ;
123
125
124
126
/**
125
127
* Create a container with default image and specified instances file from the classpath resources. Assumes that
@@ -344,6 +346,11 @@ public String getInstanceDir() {
344
346
return instanceDir ;
345
347
}
346
348
349
+ @ Override
350
+ public int getInternalPort () {
351
+ return routerPort ;
352
+ }
353
+
347
354
/**
348
355
* Get Cartridge router HTTP API hostname
349
356
*
@@ -491,7 +498,7 @@ private boolean setupTopology() {
491
498
.substring (topologyConfigurationFile .lastIndexOf ('/' ) + 1 );
492
499
493
500
try {
494
- Container . ExecResult result = execInContainer ("cartridge" ,
501
+ ExecResult result = execInContainer ("cartridge" ,
495
502
"replicasets" ,
496
503
"--run-dir=" + TARANTOOL_RUN_DIR ,
497
504
"--file=" + replicasetsFileName , "setup" , "--bootstrap-vshard" );
@@ -505,7 +512,7 @@ private boolean setupTopology() {
505
512
506
513
} else {
507
514
try {
508
- List <?> res = executeScript (topologyConfigurationFile ). get ( );
515
+ List <?> res = executeScriptDecoded (topologyConfigurationFile );
509
516
if (res .size () >= 2 && res .get (1 ) != null && res .get (1 ) instanceof Map ) {
510
517
HashMap <?, ?> error = ((HashMap <?, ?>) res .get (1 ));
511
518
// that means topology already exists
@@ -517,10 +524,6 @@ private boolean setupTopology() {
517
524
if (e .getCause () instanceof TimeoutException ) {
518
525
return true ;
519
526
// Do nothing, the cluster is reloading
520
- } else if (e .getCause () instanceof TarantoolConnectionException ) {
521
- // Probably cluster is not ready
522
- logger ().error ("Failed to setup topology: {}" , e .getMessage ());
523
- return false ;
524
527
}
525
528
} else {
526
529
throw new CartridgeTopologyException (e );
@@ -546,7 +549,7 @@ private void retryingSetupTopology() {
546
549
547
550
private void bootstrapVshard () {
548
551
try {
549
- executeCommand (VSHARD_BOOTSTRAP_COMMAND ). get () ;
552
+ executeCommand (VSHARD_BOOTSTRAP_COMMAND );
550
553
} catch (Exception e ) {
551
554
logger ().error ("Failed to bootstrap vshard cluster" , e );
552
555
throw new RuntimeException (e );
@@ -594,10 +597,10 @@ private void waitUntilTrue(int secondsToWait, Supplier<Boolean> waitFunc) {
594
597
595
598
private boolean routerIsUp () {
596
599
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
597
- " return assert( cartridge ~= nil) " ;
600
+ " return cartridge ~= nil" ;
598
601
try {
599
- List <?> result = executeCommand (healthyCmd ). get ( );
600
- return (Boolean ) result .get (0 );
602
+ List <?> result = executeCommandDecoded (healthyCmd );
603
+ return result . get ( 0 ). getClass () == Boolean . class && (Boolean ) result .get (0 );
601
604
} catch (Exception e ) {
602
605
logger ().warn ("Error while waiting for router instance to be up: " + e .getMessage ());
603
606
return false ;
@@ -606,23 +609,33 @@ private boolean routerIsUp() {
606
609
607
610
private boolean isCartridgeHealthy () {
608
611
String healthyCmd = " local cartridge = package.loaded['cartridge']" +
609
- " return assert( cartridge) and assert( cartridge.is_healthy() )" ;
612
+ " return cartridge ~= nil and cartridge.is_healthy()" ;
610
613
try {
611
- List <?> result = executeCommand (healthyCmd ). get ( );
612
- return (Boolean ) result .get (0 );
614
+ List <?> result = executeCommandDecoded (healthyCmd );
615
+ return result . get ( 0 ). getClass () == Boolean . class && (Boolean ) result .get (0 );
613
616
} catch (Exception e ) {
614
617
logger ().warn ("Error while waiting for cartridge healthy state: " + e .getMessage ());
615
618
return false ;
616
619
}
617
620
}
618
621
619
622
@ Override
620
- public CompletableFuture <List <?>> executeScript (String scriptResourcePath ) throws Exception {
621
- return clientHelper .executeScript (scriptResourcePath );
623
+ public ExecResult executeScript (String scriptResourcePath ) throws Exception {
624
+ return clientHelper .executeScript (scriptResourcePath , this .sslContext );
625
+ }
626
+
627
+ @ Override
628
+ public <T > T executeScriptDecoded (String scriptResourcePath ) throws Exception {
629
+ return clientHelper .executeScriptDecoded (scriptResourcePath , this .sslContext );
630
+ }
631
+
632
+ @ Override
633
+ public ExecResult executeCommand (String command ) throws Exception {
634
+ return clientHelper .executeCommand (command , this .sslContext );
622
635
}
623
636
624
637
@ Override
625
- public CompletableFuture < List <?>> executeCommand (String command , Object ... arguments ) throws Exception {
626
- return clientHelper .executeCommand (command , arguments );
638
+ public < T > T executeCommandDecoded (String command ) throws Exception {
639
+ return clientHelper .executeCommandDecoded (command , this . sslContext );
627
640
}
628
641
}
0 commit comments