From 2171dc8b4c7c9b11a6ee06a86b910036c55d1728 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Wed, 13 Mar 2019 14:04:51 +0200 Subject: [PATCH 1/2] Add verbosity flag Signed-off-by: Bogdan Vaneev --- testcontainers/docker/run-iroha.sh | 7 ++++--- .../iroha/testcontainers/IrohaContainer.java | 12 ++++++++++++ .../iroha/testcontainers/detail/Verbosity.java | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/Verbosity.java diff --git a/testcontainers/docker/run-iroha.sh b/testcontainers/docker/run-iroha.sh index c22198484..b7a12266b 100755 --- a/testcontainers/docker/run-iroha.sh +++ b/testcontainers/docker/run-iroha.sh @@ -9,14 +9,15 @@ BLOCKS_PATH=${BLOCKS_PATH:-`cat ${CONFIG_PATH} | jq -r .block_store_path`} POSTGRES_HOST=${POSTGRES_HOST:-`cat ${CONFIG_PATH} | jq -r .pg_opt | cut -d' ' -f1 | cut -d'=' -f2`} WAIT_TIMEOUT=${WAIT_TIMEOUT:-10} KEY=${KEY} +VERBOSITY=${VERBOSITY:-2} # postgres host is always defined /wait-for-it.sh -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -t ${WAIT_TIMEOUT} -- true -if [ -z "$(ls -A ${BLOCKS_PATH})" ]; then +if [[ -z "$(ls -A ${BLOCKS_PATH})" ]]; then # if ledger is empty then init ledger with genesis_block - irohad --genesis_block ${GENESISBLOCK_PATH} --config ${CONFIG_PATH} --keypair_name ${KEY} + irohad --genesis_block ${GENESISBLOCK_PATH} --config ${CONFIG_PATH} --keypair_name ${KEY} --verbosity ${VERBOSITY} else # else continue to run iroha without genesis_block - irohad --config ${CONFIG_PATH} --keypair_name ${KEY} + irohad --config ${CONFIG_PATH} --keypair_name ${KEY} --verbosity ${VERBOSITY} fi diff --git a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/IrohaContainer.java b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/IrohaContainer.java index 263449915..7f8040f8a 100644 --- a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/IrohaContainer.java +++ b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/IrohaContainer.java @@ -9,6 +9,7 @@ import java.time.Duration; import jp.co.soramitsu.iroha.java.IrohaAPI; 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; @@ -41,7 +42,9 @@ public class IrohaContainer extends FailureDetectingExternalResource implements private static final String POSTGRES_USER = "POSTGRES_USER"; private static final String POSTGRES_HOST = "POSTGRES_HOST"; private static final String KEY = "KEY"; + private static final String VERBOSITY = "VERBOSITY"; + private Verbosity verbosity = Verbosity.INFO; private String irohaAlias = defaultIrohaAlias; private String irohaDockerImage = defaultIrohaDockerImage; private String postgresAlias = defaultPostgresAlias; @@ -91,6 +94,7 @@ public IrohaContainer configure() { .withEnv(POSTGRES_HOST, postgresAlias) .withEnv(POSTGRES_USER, postgresDockerContainer.getUsername()) .withEnv("WAIT_TIMEOUT", "0") // don't wait for postgres + .withEnv(VERBOSITY, String.valueOf(verbosity.getLevel())) .withNetwork(network) .withExposedPorts(conf.getIrohaConfig().getTorii_port()) .withFileSystemBind(conf.getDir().getAbsolutePath(), irohaWorkdir, READ_ONLY) @@ -117,6 +121,14 @@ public IrohaContainer withPeerConfig(@NonNull PeerConfig conf) { return this; } + /** + * Setter for irohad verbosity. + */ + public IrohaContainer withVerbosity(Verbosity verbosity) { + this.verbosity = verbosity; + return this; + } + /** * Technical method to set shared docker network for a network of peers. */ diff --git a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/Verbosity.java b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/Verbosity.java new file mode 100644 index 000000000..44ac9619d --- /dev/null +++ b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/Verbosity.java @@ -0,0 +1,18 @@ +package jp.co.soramitsu.iroha.testcontainers.detail; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Getter +public enum Verbosity { + TRACE(0), + DEBUG(1), + INFO(2), + WARN(3), + ERROR(4), + CRITICAL(5), + OFF(6); + + private final int level; +} From 36b3450b6ba687251e482d476b7053752756a0d0 Mon Sep 17 00:00:00 2001 From: Bogdan Vaneev Date: Wed, 13 Mar 2019 14:06:46 +0200 Subject: [PATCH 2/2] Add test for verbosity Signed-off-by: Bogdan Vaneev --- .../soramitsu/iroha/testcontainers/IrohaContainerTest.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testcontainers/src/test/groovy/jp/co/soramitsu/iroha/testcontainers/IrohaContainerTest.groovy b/testcontainers/src/test/groovy/jp/co/soramitsu/iroha/testcontainers/IrohaContainerTest.groovy index dafeed637..a68c18c13 100644 --- a/testcontainers/src/test/groovy/jp/co/soramitsu/iroha/testcontainers/IrohaContainerTest.groovy +++ b/testcontainers/src/test/groovy/jp/co/soramitsu/iroha/testcontainers/IrohaContainerTest.groovy @@ -7,12 +7,13 @@ import jp.co.soramitsu.iroha.java.IrohaAPI import jp.co.soramitsu.iroha.java.Transaction import jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder import jp.co.soramitsu.iroha.testcontainers.detail.IrohaConfig +import jp.co.soramitsu.iroha.testcontainers.detail.Verbosity import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper import spock.lang.Specification class IrohaContainerTest extends Specification { - IrohaContainer ir = new IrohaContainer() + IrohaContainer ir = new IrohaContainer().withVerbosity(Verbosity.TRACE) def "temp folder is created and files are written"() { given: