github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/kvledger/benchmark/chainmgmt/testenv.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package chainmgmt 8 9 // chainInitOp is a type that an experiment uses to specify how the chains 10 // should be initialized at the beginning of the experiment. See below the 11 // enum values for this type 12 type chainInitOp uint8 13 14 const ( 15 // ChainInitOpCreate indicates that the chains should be creates afresh 16 ChainInitOpCreate chainInitOp = iota + 1 17 // ChainInitOpOpen indicates that the existing chains should be opened 18 ChainInitOpOpen 19 ) 20 21 // TestEnv is a high level struct that the experiments are expeted to use as a starting point. 22 // See one of the Benchmark tests for the intended usage 23 type TestEnv struct { 24 mgr *chainsMgr 25 } 26 27 // InitTestEnv initialize TestEnv with given configurations. The initialization cuases 28 // creation (or openning of existing) chains and the block creation and commit go routines 29 // for each of the chains. For configurations options, see comments on specific configuration type 30 func InitTestEnv(mgrConf *ChainMgrConf, batchConf *BatchConf, initOperation chainInitOp) *TestEnv { 31 mgr := newChainsMgr(mgrConf, batchConf, initOperation) 32 chains := mgr.createOrOpenChains() 33 for _, chain := range chains { 34 chain.startBlockPollingAndCommit() 35 } 36 return &TestEnv{mgr} 37 } 38 39 // Chains returns handle to all the chains 40 func (env TestEnv) Chains() []*Chain { 41 return env.mgr.chains() 42 } 43 44 // WaitForTestCompletion waits till all the transactions are committed 45 // An experiment after launching all the goroutine should call this 46 // so that the process is alive till all the goroutines complete 47 func (env TestEnv) WaitForTestCompletion() { 48 env.mgr.waitForChainsToExhaustAllBlocks() 49 }