11
11
import jp .co .soramitsu .iroha .testcontainers .detail .LoggerConfig ;
12
12
import jp .co .soramitsu .iroha .testcontainers .detail .PostgresConfig ;
13
13
import 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 .*;
18
15
import org .slf4j .Logger ;
19
16
import 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 .*;
24
18
import org .testcontainers .containers .output .Slf4jLogConsumer ;
25
19
import org .testcontainers .containers .wait .strategy .Wait ;
26
20
import org .testcontainers .lifecycle .Startable ;
@@ -53,14 +47,16 @@ public class IrohaContainer extends FailureDetectingExternalResource implements
53
47
54
48
private Logger logger = LoggerFactory .getLogger (IrohaContainer .class );
55
49
50
+ private Integer fixedIrohaPort ;
51
+
56
52
// use default config
57
53
@ Getter
58
54
private PeerConfig conf = new PeerConfig ();
59
55
60
56
@ Getter
61
57
private PostgreSQLContainer postgresDockerContainer ;
62
58
@ Getter
63
- private GenericContainer irohaDockerContainer ;
59
+ private FixedHostPortGenericContainer irohaDockerContainer ;
64
60
@ Getter
65
61
private Network network ;
66
62
@@ -90,7 +86,7 @@ public IrohaContainer configure() {
90
86
.withNetworkAliases (postgresAlias );
91
87
92
88
// init irohaDockerContainer container
93
- irohaDockerContainer = new GenericContainer <>(irohaDockerImage )
89
+ irohaDockerContainer = new FixedHostPortGenericContainer <>(irohaDockerImage )
94
90
.withEnv (KEY , PeerConfig .peerKeypairName )
95
91
.withEnv (POSTGRES_HOST , postgresAlias )
96
92
.withEnv (POSTGRES_USER , postgresDockerContainer .getUsername ())
@@ -105,6 +101,11 @@ public IrohaContainer configure() {
105
101
)
106
102
.withNetworkAliases (irohaAlias );
107
103
104
+ // init fixed Iroha port
105
+ if (nonNull (fixedIrohaPort )) {
106
+ irohaDockerContainer .withFixedExposedPort (fixedIrohaPort , conf .getIrohaConfig ().getTorii_port ());
107
+ }
108
+
108
109
// init logger
109
110
if (nonNull (logger )) {
110
111
irohaDockerContainer .withLogConsumer (new Slf4jLogConsumer (logger ));
@@ -181,6 +182,14 @@ public IrohaContainer withIrohaDockerImage(@NonNull String irohaDockerImage) {
181
182
return this ;
182
183
}
183
184
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
+
184
193
/**
185
194
* Start peer. Method is synchronous -- it is safe to start peer and then access API.
186
195
*/
0 commit comments