Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Iroha container port #49

Merged
merged 2 commits into from
Aug 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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