diff --git a/.travis.yml b/.travis.yml index 6ba116fb8..3fcbac560 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ env: secure: fKXekuaFWyMO+zEDMaRQ4gQApjunjKDqovNbCPFg/th1oGz7I6xJZB18PgLVN8659gZGREwoIVvijU9MJ6U/Ej+o840D0eosF4QQPDANhQ9kKCNLe22Jv3Co6PK+ENltm9KPP31dsIVRiuhoe3vXGgg5iotYSj+8atVl7cCQl0+j0TirKd/Nfs4Vbe6eiQNGCZK+TPKQMla1fvRurBxUJ/2VeCyThP7lIY93Qbm+PiIok7gTw0bFWvzGHqc6a7VOScCr3b00ruIK0k4CAR0klWw7ICP9n7cPJOzvGW45wAhYVcgON2o9TCxwNqOLotLTeQP4QihIQ5GSFaol3vVD7SsnkyZ03YIF8ZlZiWd5+MpPdShvJ586WPyY9drOaZPP8CnOyuD0le0vlmrLo11kCbNKizRaLYr9XrbM4lDSVHwOw8YS/Nhg24pJp7Bh/e3ULyuyNh2lQ6Q1xdeYHzZRUTUBBIgpU5UL0+4skg06lsD4uJSnlyQqBQk/WbraGPwncf/i03v+AHkSHWctUSI6nSHr641GfQnXqunXcI0KWrH22KI0rlEblzjJHHMP5MLvQyMoWDnPhQZS6Ci6dpZpooaZxibf+7OfrCi45uH2V17kedDOX4TPt6b2by7PPwV+7GwdE8IDPA3eBnAvdK0mYxHTSuxWwJtSUsA/DX5SrwA= script: - "./gradlew --daemon" - - "./gradlew build --parallel --build-cache --info" + - "./gradlew build --parallel --build-cache" - "./gradlew jacocoTestReport" - bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN} after_success: diff --git a/testcontainers/docker/Dockerfile b/testcontainers/docker/Dockerfile index ed0888fb0..5ee73a213 100644 --- a/testcontainers/docker/Dockerfile +++ b/testcontainers/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM hyperledger/iroha:1.0.0_rc4-hotfix1 +FROM hyperledger/iroha:1.0.0_rc5 WORKDIR /opt/iroha_data ENTRYPOINT [""] COPY run-iroha.sh wait-for-it.sh / diff --git a/testcontainers/docker/build_and_push.sh b/testcontainers/docker/build_and_push.sh new file mode 100755 index 000000000..fd2185596 --- /dev/null +++ b/testcontainers/docker/build_and_push.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +export TAG=warchantua/iroha:1.0.0_rc5 + +docker build -t $TAG --compress --squash . +docker push $TAG 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 7f8040f8a..873064af4 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 @@ -8,6 +8,7 @@ import java.net.URI; import java.time.Duration; import jp.co.soramitsu.iroha.java.IrohaAPI; +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; @@ -35,7 +36,7 @@ public class IrohaContainer extends FailureDetectingExternalResource implements public static final String defaultPostgresAlias = "iroha.postgres"; public static final String defaultIrohaAlias = "iroha"; public static final String irohaWorkdir = "/opt/iroha_data"; - public static final String defaultIrohaDockerImage = "warchantua/iroha:1.0.0_rc4-hotfix1"; + public static final String defaultIrohaDockerImage = "warchantua/iroha:1.0.0_rc5"; public static final String defaultPostgresDockerImage = "postgres:11-alpine"; // env vars @@ -44,7 +45,7 @@ public class IrohaContainer extends FailureDetectingExternalResource implements private static final String KEY = "KEY"; private static final String VERBOSITY = "VERBOSITY"; - private Verbosity verbosity = Verbosity.INFO; + private String verbosity = Verbosity.CONFIG_FILE; private String irohaAlias = defaultIrohaAlias; private String irohaDockerImage = defaultIrohaDockerImage; private String postgresAlias = defaultPostgresAlias; @@ -94,7 +95,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())) + .withEnv(VERBOSITY, verbosity) .withNetwork(network) .withExposedPorts(conf.getIrohaConfig().getTorii_port()) .withFileSystemBind(conf.getDir().getAbsolutePath(), irohaWorkdir, READ_ONLY) @@ -125,7 +126,13 @@ public IrohaContainer withPeerConfig(@NonNull PeerConfig conf) { * Setter for irohad verbosity. */ public IrohaContainer withVerbosity(Verbosity verbosity) { - this.verbosity = verbosity; + this.verbosity = verbosity.getLevel(); + return this; + } + + public IrohaContainer withLoggerConfig(LoggerConfig loggerConfig) { + this.verbosity = Verbosity.CONFIG_FILE; + this.conf.getIrohaConfig().setLog(loggerConfig); return this; } diff --git a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/PeerConfig.java b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/PeerConfig.java index 51066c49d..9464a3a79 100644 --- a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/PeerConfig.java +++ b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/PeerConfig.java @@ -2,6 +2,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.protobuf.util.JsonFormat; import iroha.protocol.BlockOuterClass; @@ -14,6 +15,7 @@ import javax.xml.bind.DatatypeConverter; import jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder; import jp.co.soramitsu.iroha.testcontainers.detail.IrohaConfig; +import jp.co.soramitsu.iroha.testcontainers.detail.LoggerConfig; import jp.co.soramitsu.iroha.testcontainers.detail.RuntimeIOException; import lombok.AllArgsConstructor; import lombok.Builder; @@ -33,6 +35,8 @@ public class PeerConfig { public static final String peerKeypairName = "iroha_peer_key"; + private static final ObjectMapper mapper = new ObjectMapper() + .setSerializationInclusion(Include.NON_NULL); @Getter private final Map keyPairMap = new HashMap() {{ @@ -65,6 +69,9 @@ public void finalize() { .addDefaultTransaction() .build(); + @Getter + private LoggerConfig loggerConfig; + private void writeToFile(String filename, String data) throws IOException { File file = new File(dir, filename); PrintWriter writer = new PrintWriter(file); @@ -77,7 +84,6 @@ private void writeKey(String filename, byte[] key) throws IOException { } private void writeJsonConfig() throws IOException { - ObjectMapper mapper = new ObjectMapper(); byte[] data = mapper.writeValueAsBytes(irohaConfig); writeToFile(IrohaConfig.defaultConfigFileName, new String(data, UTF_8)); } @@ -90,6 +96,11 @@ private void writeGenesisBlock() throws IOException { ); } + public void writeLoggerConfig() throws IOException { + byte[] data = mapper.writeValueAsBytes(loggerConfig); + writeToFile(IrohaConfig.defaultConfigFileName, new String(data, UTF_8)); + } + public PeerConfig withPeerKeyPair(KeyPair keyPair) { return withKeyPair(peerKeypairName, keyPair); } diff --git a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/IrohaConfig.java b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/IrohaConfig.java index 8f5379b96..4e3aca2d5 100644 --- a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/IrohaConfig.java +++ b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/IrohaConfig.java @@ -59,6 +59,8 @@ public class IrohaConfig implements Cloneable { @Builder.Default private int stale_stream_max_rounds = 2; + + private LoggerConfig log; @Override public IrohaConfig clone() { diff --git a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/LoggerConfig.java b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/LoggerConfig.java new file mode 100644 index 000000000..217ff06a6 --- /dev/null +++ b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/LoggerConfig.java @@ -0,0 +1,18 @@ +package jp.co.soramitsu.iroha.testcontainers.detail; + +import java.util.Map; +import lombok.Builder; +import lombok.Value; + +@Builder +@Value +public class LoggerConfig { + + @Builder.Default + private Verbosity level = Verbosity.INFO; + + private LoggerPattern patterns; + + private Map children; + +} diff --git a/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/LoggerPattern.java b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/LoggerPattern.java new file mode 100644 index 000000000..84b6f5291 --- /dev/null +++ b/testcontainers/src/main/java/jp/co/soramitsu/iroha/testcontainers/detail/LoggerPattern.java @@ -0,0 +1,17 @@ +package jp.co.soramitsu.iroha.testcontainers.detail; + +import lombok.Builder; +import lombok.Value; + +@Builder +@Value +public class LoggerPattern { + + private String trace; + private String debug; + private String info; + private String warn; + private String error; + private String critical; + +} 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 index 44ac9619d..4f666f8a7 100644 --- 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 @@ -1,18 +1,21 @@ package jp.co.soramitsu.iroha.testcontainers.detail; +import com.fasterxml.jackson.annotation.JsonValue; 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); + TRACE("trace"), + DEBUG("debug"), + INFO("info"), + WARN("warn"), + ERROR("error"), + CRITICAL("critical"); - private final int level; + @JsonValue + private final String level; + + public static final String CONFIG_FILE = "config_file"; } 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 a68c18c13..c85e89d9a 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 @@ -5,9 +5,7 @@ import io.reactivex.observers.TestObserver import iroha.protocol.BlockOuterClass 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 jp.co.soramitsu.iroha.testcontainers.detail.* import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper import spock.lang.Specification @@ -20,6 +18,7 @@ class IrohaContainerTest extends Specification { def mapper = new ObjectMapper() def c = ir.getConf() def d = c.getDir() + println(d) when: "create tmp dir and dump files" ir.configure() @@ -84,4 +83,28 @@ class IrohaContainerTest extends Specification { !ir.postgresDockerContainer.isCreated() !ir.postgresDockerContainer.isRunning() } + + def "tree logger test"() { + given: + def consensusLog = LoggerConfig.builder().level(Verbosity.DEBUG).build() + + def pattern = LoggerPattern.builder() + .info("HEHEHEHEHEHEHEHEHE %v") + .build() + + def lc = LoggerConfig.builder() + .level(Verbosity.INFO) + .patterns(pattern) + .children(Collections.singletonMap("Irohad", consensusLog)) + .build() + + def iroha = new IrohaContainer() + .withLoggerConfig(lc) + + when: + iroha.start() + + then: + noExceptionThrown() + } }