Package com.exonum.binding.testkit
Class TestKit.Builder
java.lang.Object
com.exonum.binding.testkit.TestKit.Builder
- Enclosing class:
- TestKit
public static final class TestKit.Builder
extends java.lang.Object
Builder for the TestKit.
-
Method Summary
Modifier and Type Method Description TestKit
build()
Creates the TestKit instance.TestKit.Builder
withArtifactsDirectory(java.nio.file.Path artifactsDirectory)
Sets artifact directory.TestKit.Builder
withDeployedArtifact(ServiceArtifactId serviceArtifactId, java.lang.String artifactFilename)
Adds a service artifact which would be deployed by the TestKit.TestKit.Builder
withNodeType(EmulatedNodeType nodeType)
Sets the type of the main TestKit node - either validator or auditor.TestKit.Builder
withService(ServiceArtifactId serviceArtifactId, java.lang.String serviceName, int serviceId)
Adds a service specification with which the TestKit would create the corresponding service instance with no configuration.TestKit.Builder
withService(ServiceArtifactId serviceArtifactId, java.lang.String serviceName, int serviceId, com.google.protobuf.MessageLite configuration)
Adds a service specification with which the TestKit would create the corresponding service instance.TestKit.Builder
withTimeService(java.lang.String serviceName, int serviceId, TimeProvider timeProvider)
Adds a time service specification with which the TestKit would create the corresponding time service instance.TestKit.Builder
withValidators(short validatorCount)
Sets number of validator nodes in the TestKit network, should be positive.
-
Method Details
-
withNodeType
Sets the type of the main TestKit node - either validator or auditor. Note thatService.afterCommit(BlockCommittedEvent)
logic will only be called on the main TestKit node of this type -
withValidators
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:
java.lang.IllegalArgumentException
- if validatorCount is less than one
-
withDeployedArtifact
public TestKit.Builder withDeployedArtifact(ServiceArtifactId serviceArtifactId, java.lang.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
Sets artifact directory.- Parameters:
artifactsDirectory
- the directory from which the service runtime loads service artifacts
-
withService
public TestKit.Builder withService(ServiceArtifactId serviceArtifactId, java.lang.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 artifactserviceName
- the name of the serviceserviceId
- the id of the service, must be in range [0; 1023]configuration
- the service configuration parameters- Throws:
java.lang.IllegalArgumentException
- if serviceId is not in range [0; 1023]java.lang.IllegalArgumentException
- if service artifact with equal serviceArtifactId was not deployed
-
withService
public TestKit.Builder withService(ServiceArtifactId serviceArtifactId, java.lang.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 artifactserviceName
- the name of the serviceserviceId
- the id of the service, must be in range [0; 1023]- Throws:
java.lang.IllegalArgumentException
- if serviceId is not in range [0; 1023]java.lang.IllegalArgumentException
- if service artifact with equal serviceArtifactId was not deployed
-
withTimeService
public TestKit.Builder withTimeService(java.lang.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
Creates the TestKit instance.- Throws:
java.lang.IllegalArgumentException
- if validator count is invalidjava.lang.IllegalArgumentException
- if service number is invalidjava.lang.IllegalArgumentException
- if service artifacts were deployed, but no service instances with same service artifact id were created
-