Skip to content

Commit

Permalink
Fixed Iroha container port (#49)
Browse files Browse the repository at this point in the history
* Fixed Iroha container port

Signed-off-by: Anton Dolgopolov <[email protected]>

* Fixed comments

Signed-off-by: Anton Dolgopolov <[email protected]>
  • Loading branch information
dolgopolovwork authored and Warchant committed Aug 13, 2019
1 parent 3cac393 commit b959d4b
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
import jp.co.soramitsu.iroha.testcontainers.detail.LoggerConfig;
import jp.co.soramitsu.iroha.testcontainers.detail.PostgresConfig;
import jp.co.soramitsu.iroha.testcontainers.detail.Verbosity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.FailureDetectingExternalResource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.*;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.lifecycle.Startable;
Expand Down Expand Up @@ -53,14 +47,16 @@ public class IrohaContainer extends FailureDetectingExternalResource implements

private Logger logger = LoggerFactory.getLogger(IrohaContainer.class);

private Integer fixedIrohaPort;

// use default config
@Getter
private PeerConfig conf = new PeerConfig();

@Getter
private PostgreSQLContainer postgresDockerContainer;
@Getter
private GenericContainer irohaDockerContainer;
private FixedHostPortGenericContainer irohaDockerContainer;
@Getter
private Network network;

Expand Down Expand Up @@ -90,7 +86,7 @@ public IrohaContainer configure() {
.withNetworkAliases(postgresAlias);

// init irohaDockerContainer container
irohaDockerContainer = new GenericContainer<>(irohaDockerImage)
irohaDockerContainer = new FixedHostPortGenericContainer<>(irohaDockerImage)
.withEnv(KEY, PeerConfig.peerKeypairName)
.withEnv(POSTGRES_HOST, postgresAlias)
.withEnv(POSTGRES_USER, postgresDockerContainer.getUsername())
Expand All @@ -105,6 +101,11 @@ public IrohaContainer configure() {
)
.withNetworkAliases(irohaAlias);

// init fixed Iroha port
if (nonNull(fixedIrohaPort)) {
irohaDockerContainer.withFixedExposedPort(fixedIrohaPort, conf.getIrohaConfig().getTorii_port());
}

// init logger
if (nonNull(logger)) {
irohaDockerContainer.withLogConsumer(new Slf4jLogConsumer(logger));
Expand Down Expand Up @@ -181,6 +182,14 @@ public IrohaContainer withIrohaDockerImage(@NonNull String irohaDockerImage) {
return this;
}

public IrohaContainer withFixedPort(int fixedIrohaPort) {
if (fixedIrohaPort < 0 || fixedIrohaPort > 65535) {
throw new IllegalArgumentException("Invalid port " + fixedIrohaPort);
}
this.fixedIrohaPort = fixedIrohaPort;
return this;
}

/**
* Start peer. Method is synchronous -- it is safe to start peer and then access API.
*/
Expand Down

0 comments on commit b959d4b

Please sign in to comment.