Class TestKit.Builder

java.lang.Object
com.exonum.binding.testkit.TestKit.Builder
Enclosing class:
TestKit

public static final class TestKit.Builder
extends Object
Builder for the TestKit.
  • Method Details

    • withNodeType

      public TestKit.Builder withNodeType​(EmulatedNodeType nodeType)
      Sets the type of the main TestKit node - either validator or auditor. Note that Service.afterCommit(BlockCommittedEvent) logic will only be called on the main TestKit node of this type
    • withValidators

      public TestKit.Builder withValidators​(short validatorCount)
      Sets number of validator nodes in the TestKit network, should be positive. Note that regardless of the configured number of validators, only a single service will be instantiated. Equal to one by default.

      Note that validator count should be 3 or less if time service is enabled.

      Throws:
      IllegalArgumentException - if validatorCount is less than one
    • withDeployedArtifact

      public TestKit.Builder withDeployedArtifact​(ServiceArtifactId serviceArtifactId, String artifactFilename)
      Adds a service artifact which would be deployed by the TestKit. Several service artifacts can be added.

      Once the service artifact is deployed, the service instances can be added with withService(ServiceArtifactId, String, int, MessageLite).

    • withArtifactsDirectory

      public TestKit.Builder withArtifactsDirectory​(Path artifactsDirectory)
      Sets artifact directory.
      Parameters:
      artifactsDirectory - the directory from which the service runtime loads service artifacts
    • withService

      public TestKit.Builder withService​(ServiceArtifactId serviceArtifactId, String serviceName, int serviceId, com.google.protobuf.MessageLite configuration)
      Adds a service specification with which the TestKit would create the corresponding service instance. Several service specifications can be added. All services are started and configured before the genesis block.

      Note that the corresponding service artifact with equal serviceArtifactId should be deployed with withDeployedArtifact(ServiceArtifactId, String).

      Parameters:
      serviceArtifactId - the id of the artifact
      serviceName - the name of the service
      serviceId - the id of the service, must be in range [0; 1023]
      configuration - the service configuration parameters
      Throws:
      IllegalArgumentException - if serviceId is not in range [0; 1023]
      IllegalArgumentException - if service artifact with equal serviceArtifactId was not deployed
    • withService

      public TestKit.Builder withService​(ServiceArtifactId serviceArtifactId, String serviceName, int serviceId)
      Adds a service specification with which the TestKit would create the corresponding service instance with no configuration. Several service specifications can be added. All services are started and configured before the genesis block.

      Note that the corresponding service artifact with equal serviceArtifactId should be deployed with withDeployedArtifact(ServiceArtifactId, String).

      Parameters:
      serviceArtifactId - the id of the artifact
      serviceName - the name of the service
      serviceId - the id of the service, must be in range [0; 1023]
      Throws:
      IllegalArgumentException - if serviceId is not in range [0; 1023]
      IllegalArgumentException - if service artifact with equal serviceArtifactId was not deployed
    • withTimeService

      public TestKit.Builder withTimeService​(String serviceName, int serviceId, TimeProvider timeProvider)
      Adds a time service specification with which the TestKit would create the corresponding time service instance. Only a single time service specification can be added.

      Note that validator count should be 3 or less if time service is enabled.

    • build

      public TestKit build()
      Creates the TestKit instance.
      Throws:
      IllegalArgumentException - if validator count is invalid
      IllegalArgumentException - if service number is invalid
      IllegalArgumentException - if service artifacts were deployed, but no service instances with same service artifact id were created