public final class TestKit
extends com.exonum.binding.core.proxy.AbstractCloseableNativeProxy
Only the emulated node has a pool of unconfirmed transactions where a service can submit new
transaction messages through Node.submitTransaction(RawTransaction); or the test
code through createBlockWithTransactions(TransactionMessage...). All transactions
from the pool are committed when a new block is created with createBlock().
When TestKit is created, Exonum blockchain instance is initialized — service instances are initialized and genesis block is committed. Then the public API handlers are created.
| Modifier and Type | Class and Description |
|---|---|
static class |
TestKit.Builder
Builder for the TestKit.
|
| Modifier and Type | Field and Description |
|---|---|
static short |
MAX_VALIDATOR_COUNT_WITH_ENABLED_TIME_SERVICE
The maximum number of validators supported by TestKit when a time oracle is enabled.
|
| Modifier and Type | Method and Description |
|---|---|
<ResultT> ResultT |
applySnapshot(Function<com.exonum.binding.core.storage.database.Snapshot,ResultT> snapshotFunction)
Performs the given function with a snapshot of the current database state (i.e., the one that
corresponds to the latest committed block) and returns a result of its execution.
|
static TestKit.Builder |
builder()
Creates a new builder for the TestKit.
|
com.exonum.binding.core.blockchain.Block |
createBlock()
Creates a block with all in-pool transactions.
|
com.exonum.binding.core.blockchain.Block |
createBlockWithTransactions(Iterable<com.exonum.binding.common.message.TransactionMessage> transactions)
Creates a block with the given transactions.
|
com.exonum.binding.core.blockchain.Block |
createBlockWithTransactions(com.exonum.binding.common.message.TransactionMessage... transactions)
Creates a block with the given transaction(s).
|
protected void |
disposeInternal() |
List<com.exonum.binding.common.message.TransactionMessage> |
findTransactionsInPool(Predicate<com.exonum.binding.common.message.TransactionMessage> predicate)
Returns a list of in-pool transactions that match the given predicate.
|
static TestKit |
forService(Class<? extends com.exonum.binding.core.service.ServiceModule> serviceModule)
Creates a TestKit network with a single validator node for a single service.
|
EmulatedNode |
getEmulatedNode()
Returns the context of the node that the TestKit emulates (i.e., on which it instantiates and
executes services).
|
<T extends com.exonum.binding.core.service.Service> |
getService(short serviceId,
Class<T> serviceClass)
Returns an instance of a service with the given service id and service class.
|
com.exonum.binding.core.storage.database.Snapshot |
getSnapshot()
Returns a snapshot of the current database state (i.e., the one that
corresponds to the latest committed block).
|
List<com.exonum.binding.common.message.TransactionMessage> |
getTransactionPool()
Returns a list of in-pool transactions.
|
void |
withSnapshot(Consumer<com.exonum.binding.core.storage.database.Snapshot> snapshotFunction)
Performs the given function with a snapshot of the current database state (i.e., the one that
corresponds to the latest committed block).
|
public static final short MAX_VALIDATOR_COUNT_WITH_ENABLED_TIME_SERVICE
public static TestKit forService(Class<? extends com.exonum.binding.core.service.ServiceModule> serviceModule)
public <T extends com.exonum.binding.core.service.Service> T getService(short serviceId,
Class<T> serviceClass)
IllegalArgumentException - if the service with given id was not found or could not be
cast to given classpublic com.exonum.binding.core.blockchain.Block createBlockWithTransactions(com.exonum.binding.common.message.TransactionMessage... transactions)
IllegalArgumentException - if transactions are malformed or don't belong to this
servicepublic com.exonum.binding.core.blockchain.Block createBlockWithTransactions(Iterable<com.exonum.binding.common.message.TransactionMessage> transactions)
IllegalArgumentException - if transactions are malformed or don't belong to this
servicepublic com.exonum.binding.core.blockchain.Block createBlock()
public List<com.exonum.binding.common.message.TransactionMessage> getTransactionPool()
public List<com.exonum.binding.common.message.TransactionMessage> findTransactionsInPool(Predicate<com.exonum.binding.common.message.TransactionMessage> predicate)
public void withSnapshot(Consumer<com.exonum.binding.core.storage.database.Snapshot> snapshotFunction)
This method destroys the snapshot once the passed closure completes, compared to
getSnapshot(), which disposes created snapshots only when TestKit is closed.
snapshotFunction - a function to executeapplySnapshot(Function)public <ResultT> ResultT applySnapshot(Function<com.exonum.binding.core.storage.database.Snapshot,ResultT> snapshotFunction)
This method destroys the snapshot once the passed closure completes, compared to
getSnapshot(), which disposes created snapshots only when TestKit is closed.
Consider using withSnapshot(Consumer) when returning the result of given function
is not needed.
ResultT - a type the function returnssnapshotFunction - a function to executepublic com.exonum.binding.core.storage.database.Snapshot getSnapshot()
All created snapshots are deleted when this TestKit is closed. It is forbidden to access the snapshots once the TestKit is closed.
If you need to create a large number (e.g. more than a hundred) of snapshots, it is
recommended to use withSnapshot(Consumer) or applySnapshot(Function), which
destroy the snapshots once the passed closure completes.
public EmulatedNode getEmulatedNode()
protected void disposeInternal()
disposeInternal in class com.exonum.binding.core.proxy.AbstractCloseableNativeProxypublic static TestKit.Builder builder()
Copyright © 2019 Exonum. All rights reserved.