Skip to content

Commit

Permalink
Merge pull request #16 from hyperledger/feature/verbosity
Browse files Browse the repository at this point in the history
Feature/verbosity
  • Loading branch information
Warchant authored Mar 13, 2019
2 parents 00e8a71 + 36b3450 commit 9b16b75
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
7 changes: 4 additions & 3 deletions testcontainers/docker/run-iroha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9b16b75

Please sign in to comment.