1111import jp .co .soramitsu .iroha .testcontainers .detail .LoggerConfig ;
1212import jp .co .soramitsu .iroha .testcontainers .detail .PostgresConfig ;
1313import jp .co .soramitsu .iroha .testcontainers .detail .Verbosity ;
14- import lombok .Getter ;
15- import lombok .NoArgsConstructor ;
16- import lombok .NonNull ;
17- import lombok .SneakyThrows ;
14+ import lombok .*;
1815import org .slf4j .Logger ;
1916import org .slf4j .LoggerFactory ;
20- import org .testcontainers .containers .FailureDetectingExternalResource ;
21- import org .testcontainers .containers .GenericContainer ;
22- import org .testcontainers .containers .Network ;
23- import org .testcontainers .containers .PostgreSQLContainer ;
17+ import org .testcontainers .containers .*;
2418import org .testcontainers .containers .output .Slf4jLogConsumer ;
2519import org .testcontainers .containers .wait .strategy .Wait ;
2620import org .testcontainers .lifecycle .Startable ;
@@ -53,14 +47,16 @@ public class IrohaContainer extends FailureDetectingExternalResource implements
5347
5448 private Logger logger = LoggerFactory .getLogger (IrohaContainer .class );
5549
50+ private Integer fixedIrohaPort ;
51+
5652 // use default config
5753 @ Getter
5854 private PeerConfig conf = new PeerConfig ();
5955
6056 @ Getter
6157 private PostgreSQLContainer postgresDockerContainer ;
6258 @ Getter
63- private GenericContainer irohaDockerContainer ;
59+ private FixedHostPortGenericContainer irohaDockerContainer ;
6460 @ Getter
6561 private Network network ;
6662
@@ -90,7 +86,7 @@ public IrohaContainer configure() {
9086 .withNetworkAliases (postgresAlias );
9187
9288 // init irohaDockerContainer container
93- irohaDockerContainer = new GenericContainer <>(irohaDockerImage )
89+ irohaDockerContainer = new FixedHostPortGenericContainer <>(irohaDockerImage )
9490 .withEnv (KEY , PeerConfig .peerKeypairName )
9591 .withEnv (POSTGRES_HOST , postgresAlias )
9692 .withEnv (POSTGRES_USER , postgresDockerContainer .getUsername ())
@@ -105,6 +101,11 @@ public IrohaContainer configure() {
105101 )
106102 .withNetworkAliases (irohaAlias );
107103
104+ // init fixed Iroha port
105+ if (nonNull (fixedIrohaPort )) {
106+ irohaDockerContainer .withFixedExposedPort (fixedIrohaPort , conf .getIrohaConfig ().getTorii_port ());
107+ }
108+
108109 // init logger
109110 if (nonNull (logger )) {
110111 irohaDockerContainer .withLogConsumer (new Slf4jLogConsumer (logger ));
@@ -181,6 +182,14 @@ public IrohaContainer withIrohaDockerImage(@NonNull String irohaDockerImage) {
181182 return this ;
182183 }
183184
185+ public IrohaContainer withFixedPort (int fixedIrohaPort ) {
186+ if (fixedIrohaPort < 0 || fixedIrohaPort > 65535 ) {
187+ throw new IllegalArgumentException ("Invalid port " + fixedIrohaPort );
188+ }
189+ this .fixedIrohaPort = fixedIrohaPort ;
190+ return this ;
191+ }
192+
184193 /**
185194 * Start peer. Method is synchronous -- it is safe to start peer and then access API.
186195 */
0 commit comments