github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/tools/LTE/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 import "github.com/spf13/viper" 10 11 // chainInitOp is a type that an experiment uses to specify how the chains 12 // should be initialized at the beginning of the experiment. See below the 13 // enum values for this type 14 type chainInitOp uint8 15 16 const ( 17 // ChainInitOpCreate indicates that the chains should be creates afresh 18 ChainInitOpCreate chainInitOp = iota + 1 19 // ChainInitOpOpen indicates that the existing chains should be opened 20 ChainInitOpOpen 21 ) 22 23 // TestEnv is a high level struct that the experiments are expeted to use as a starting point. 24 // See one of the Benchmark tests for the intended usage 25 type TestEnv struct { 26 mgr *chainsMgr 27 } 28 29 // InitTestEnv initialize TestEnv with given configurations. The initialization cuases 30 // creation (or openning of existing) chains and the block creation and commit go routines 31 // for each of the chains. For configurations options, see comments on specific configuration type 32 func InitTestEnv(mgrConf *ChainMgrConf, batchConf *BatchConf, initOperation chainInitOp) *TestEnv { 33 viper.Set("peer.fileSystemPath", mgrConf.DataDir) 34 mgr := newChainsMgr(mgrConf, batchConf, initOperation) 35 chains := mgr.createOrOpenChains() 36 for _, chain := range chains { 37 chain.startBlockPollingAndCommit() 38 } 39 return &TestEnv{mgr} 40 } 41 42 // Chains returns handle to all the chains 43 func (env TestEnv) Chains() []*Chain { 44 return env.mgr.chains() 45 } 46 47 // WaitForTestCompletion waits till all the transactions are committed 48 // An experiment after launching all the goroutine should call this 49 // so that the process is alive till all the goroutines complete 50 func (env TestEnv) WaitForTestCompletion() { 51 env.mgr.waitForChainsToExhaustAllBlocks() 52 }