How to use getConfig method of cmd Package

Best K6 code snippet using cmd.getConfig

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "bcXwallet/client"4 "bcXwallet/common"5 "bcXwallet/rpc"6 rpcserver "common/rpc/lib/server"7 "fmt"8 "github.com/spf13/cobra"9 "github.com/tendermint/go-amino"10 cmn "github.com/tendermint/tmlibs/common"11 "net/http"12 "os"13 "strconv"14 "strings"15)16const (17 usage = "bcbXwallet_rpc's url"18)19func main() {20 err := common.InitAll()21 if err != nil {22 panic(err)23 }24 if version() == "" {25 err = rpc.InitDB()26 if err != nil {27 panic(err)28 }29 rpcLogger := common.GetLogger()30 coreCodec := amino.NewCodec()31 mux := http.NewServeMux()32 rpcserver.RegisterRPCFuncs(mux, rpc.Routes, coreCodec, rpcLogger)33 if common.GetConfig().UseHttps {34 crtPath, keyPath := common.OutCertFileIsExist()35 _, err = rpcserver.StartHTTPAndTLSServer(serverAddr(common.GetConfig().ServerAddr, false), mux, crtPath, keyPath, rpcLogger)36 if err != nil {37 cmn.Exit(err.Error())38 }39 } else {40 _, err = rpcserver.StartHTTPServer(serverAddr(common.GetConfig().ServerAddr, false), mux, rpcLogger)41 if err != nil {42 cmn.Exit(err.Error())43 }44 }45 }46 err = Execute()47 if err != nil {48 fmt.Print(err)49 os.Exit(1)50 }51}52func serverAddr(address string, bRequest bool) string {53 splitAddr := strings.Split(address, ":")54 if len(splitAddr) != 3 {55 fmt.Println("invalid serverAddr=" + address)56 return ""57 }58 port, err := strconv.Atoi(splitAddr[2])59 if err != nil {60 fmt.Println("invalid serverAddr=" + address)61 return ""62 }63 if bRequest {64 if common.GetConfig().UseHttps {65 return fmt.Sprintf("https://127.0.0.1:%d", port)66 } else {67 return fmt.Sprintf("http://127.0.0.1:%d", port)68 }69 } else {70 return address71 }72}73func version() string {74 params := map[string]interface{}{}75 result := new(rpc.VersionResult)76 err := common.DoHttpRequestAndParseEx([]string{serverAddr(common.GetConfig().ServerAddr, true)}, "bcb_version", params, result)77 if err != nil {78 return ""79 }80 return result.Version81}82// flags83var (84 // global flags85 flagRpcUrl string86 // block flag87 flagHeight int6488 // transaction flag89 flagTxHash string90 // address flag91 flagAddress string92 flagTokenAddress string93 flagTokenName string94 // commitTx flag95 flagTx string96 // wallet flag97 flagName string98 flagPassword string99 flagAccessKey string100 flagEncPrivateKey string101 flagSmcAddress string102 flagGasLimit string103 flagNote string104 flagNonce string105 flagTo string106 flagValue string107 flagPlainText string108 flagPageNum uint64109)110var RootCmd = &cobra.Command{111 Use: "bcbXwallet",112 Short: "bcb exchange wallet console",113 Long: "bcbXwallet client that it can perform the wallet operation, query chain information and so on.",114}115func Execute() error {116 addFlags()117 addCommands()118 return RootCmd.Execute()119}120func addFlags() {121 addWalletCreateFlag()122 addWalletExportFlag()123 addWalletImportFlag()124 addWalletListFlag()125 addTransferFlag()126 addTransferOfflineFlag()127 addBlockHeightFlag()128 addBlockFlag()129 addTransactionFlag()130 addBalanceFlag()131 addBalanceOfTokenFlag()132 addAllBalanceFlag()133 addNonceFlag()134 addCommitTxFlag()135}136func addCommands() {137 RootCmd.AddCommand(walletCreateCmd)138 RootCmd.AddCommand(walletExportCmd)139 RootCmd.AddCommand(walletImportCmd)140 RootCmd.AddCommand(walletListCmd)141 RootCmd.AddCommand(transferCmd)142 RootCmd.AddCommand(transferOfflineCmd)143 RootCmd.AddCommand(blockHeightCmd)144 RootCmd.AddCommand(blockCmd)145 RootCmd.AddCommand(transactionCmd)146 RootCmd.AddCommand(balanceCmd)147 RootCmd.AddCommand(balanceOfTokenCmd)148 RootCmd.AddCommand(allBalanceCmd)149 RootCmd.AddCommand(nonceCmd)150 RootCmd.AddCommand(commitTxCmd)151}152var walletCreateCmd = &cobra.Command{153 Use: "walletCreate",154 Short: "Create wallet",155 Long: "Create a new wallet",156 Args: cobra.ExactArgs(0),157 RunE: func(cmd *cobra.Command, args []string) error {158 return client.WalletCreate(flagName, flagPassword, flagRpcUrl)159 },160}161func addWalletCreateFlag() {162 walletCreateCmd.PersistentFlags().StringVarP(&flagName, "name", "n", "", "wallet name")163 walletCreateCmd.PersistentFlags().StringVarP(&flagPassword, "password", "p", "", "wallet password")164 walletCreateCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)165}166var walletExportCmd = &cobra.Command{167 Use: "walletExport",168 Short: "Export wallet",169 Long: "Export the private key and walletAddr of wallet",170 Args: cobra.ExactArgs(0),171 RunE: func(cmd *cobra.Command, args []string) error {172 return client.WalletExport(flagName, flagPassword, flagAccessKey, flagRpcUrl, flagPlainText)173 },174}175func addWalletExportFlag() {176 walletExportCmd.PersistentFlags().StringVarP(&flagName, "name", "n", "", "wallet name")177 walletExportCmd.PersistentFlags().StringVarP(&flagPassword, "password", "p", "", "wallet password")178 walletExportCmd.PersistentFlags().StringVarP(&flagAccessKey, "accessKey", "a", "", "wallet accessKey")179 walletExportCmd.PersistentFlags().StringVarP(&flagPlainText, "plainText", "t", "", "export plain text(default false)")180 walletExportCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)181}182var walletImportCmd = &cobra.Command{183 Use: "walletImport",184 Short: "Import wallet",185 Long: "Import the private key to a new wallet",186 Args: cobra.ExactArgs(0),187 RunE: func(cmd *cobra.Command, args []string) error {188 return client.WalletImport(flagName, flagEncPrivateKey, flagPassword, flagAccessKey, flagRpcUrl, flagPlainText)189 },190}191func addWalletImportFlag() {192 walletImportCmd.PersistentFlags().StringVarP(&flagName, "name", "n", "", "wallet name")193 walletImportCmd.PersistentFlags().StringVarP(&flagEncPrivateKey, "privateKey", "k", "", "wallet privateKey")194 walletImportCmd.PersistentFlags().StringVarP(&flagPassword, "password", "p", "", "wallet password")195 walletImportCmd.PersistentFlags().StringVarP(&flagAccessKey, "accessKey", "a", "", "wallet accessKey")196 walletImportCmd.PersistentFlags().StringVarP(&flagPlainText, "plainText", "t", "", "import plain text(default false)")197 walletImportCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)198}199var walletListCmd = &cobra.Command{200 Use: "walletList",201 Short: "Wallet list",202 Long: "Query all wallet names and walletAddrs",203 Args: cobra.ExactArgs(0),204 RunE: func(cmd *cobra.Command, args []string) error {205 return client.WalletList(flagPageNum, flagRpcUrl)206 },207}208func addWalletListFlag() {209 walletListCmd.PersistentFlags().Uint64VarP(&flagPageNum, "pageNum", "p", 1, "page index, default first page")210 walletListCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)211}212var transferCmd = &cobra.Command{213 Use: "transfer",214 Short: "Transfer token",215 Long: "Transfer token to someone with value",216 Args: cobra.ExactArgs(0),217 RunE: func(cmd *cobra.Command, args []string) error {218 return client.Transfer(flagName, flagAccessKey, flagSmcAddress, flagGasLimit, flagNote, flagTo, flagValue, flagRpcUrl)219 },220}221func addTransferFlag() {222 transferCmd.PersistentFlags().StringVarP(&flagName, "name", "n", "", "wallet name")223 transferCmd.PersistentFlags().StringVarP(&flagAccessKey, "accessKey", "a", "", "wallet accessKey")224 transferCmd.PersistentFlags().StringVarP(&flagSmcAddress, "smcAddress", "s", "", "smart contract address")225 transferCmd.PersistentFlags().StringVarP(&flagGasLimit, "gasLimit", "g", "5000", "gas limit ")226 transferCmd.PersistentFlags().StringVarP(&flagNote, "note", "o", "", "note")227 transferCmd.PersistentFlags().StringVarP(&flagTo, "to", "t", "", "to address")228 transferCmd.PersistentFlags().StringVarP(&flagValue, "value", "v", "", "transfer value")229 transferCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)230}231var transferOfflineCmd = &cobra.Command{232 Use: "transferOffline",233 Short: "Offline transaction",234 Long: "Offline pack and sign transfer transaction",235 Args: cobra.ExactArgs(0),236 RunE: func(cmd *cobra.Command, args []string) error {237 return client.TransferOffline(flagName, flagAccessKey, flagSmcAddress, flagGasLimit, flagNote, flagTo, flagValue, flagNonce, flagRpcUrl)238 },239}240func addTransferOfflineFlag() {241 transferOfflineCmd.PersistentFlags().StringVarP(&flagName, "name", "n", "", "wallet name")242 transferOfflineCmd.PersistentFlags().StringVarP(&flagAccessKey, "accessKey", "a", "", "wallet accessKey")243 transferOfflineCmd.PersistentFlags().StringVarP(&flagSmcAddress, "smcAddress", "s", "", "smart contract address")244 transferOfflineCmd.PersistentFlags().StringVarP(&flagGasLimit, "gasLimit", "g", "5000", "gas limit ")245 transferOfflineCmd.PersistentFlags().StringVarP(&flagNonce, "nonce", "c", "", "nonce")246 transferOfflineCmd.PersistentFlags().StringVarP(&flagNote, "note", "o", "", "note")247 transferOfflineCmd.PersistentFlags().StringVarP(&flagTo, "to", "t", "", "to address")248 transferOfflineCmd.PersistentFlags().StringVarP(&flagValue, "value", "v", "", "transfer value")249 transferOfflineCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)250}251var blockHeightCmd = &cobra.Command{252 Use: "blockHeight",253 Short: "Get current block height",254 Long: "Get BlockChain current block height",255 Args: cobra.ExactArgs(0),256 RunE: func(cmd *cobra.Command, args []string) error {257 return client.BlockHeight(flagRpcUrl)258 },259}260func addBlockHeightFlag() {261 blockHeightCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)262}263var blockCmd = &cobra.Command{264 Use: "block",265 Short: "Get block information",266 Long: "Get block information with height, must great than zero",267 Args: cobra.ExactArgs(0),268 RunE: func(cmd *cobra.Command, args []string) error {269 return client.Block(flagHeight, flagRpcUrl)270 },271}272func addBlockFlag() {273 blockCmd.PersistentFlags().Int64VarP(&flagHeight, "height", "t", 0, "block height")274 blockCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)275}276var transactionCmd = &cobra.Command{277 Use: "transaction",278 Short: "Get transaction information",279 Long: "Get transaction information with txHash and cannot be empty",280 Args: cobra.ExactArgs(0),281 RunE: func(cmd *cobra.Command, args []string) error {282 return client.Transaction(flagTxHash, flagRpcUrl)283 },284}285func addTransactionFlag() {286 transactionCmd.PersistentFlags().StringVarP(&flagTxHash, "txHash", "t", "", "transaction's hash")287 transactionCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)288}289var balanceCmd = &cobra.Command{290 Use: "balance",291 Short: "Get balance information",292 Long: "Get balance of BCB token for specific address",293 Args: cobra.ExactArgs(0),294 RunE: func(cmd *cobra.Command, args []string) error {295 return client.Balance(flagAddress, flagRpcUrl)296 },297}298func addBalanceFlag() {299 balanceCmd.PersistentFlags().StringVarP(&flagAddress, "address", "a", "", "account's address")300 balanceCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)301}302var balanceOfTokenCmd = &cobra.Command{303 Use: "balanceOfToken",304 Short: "Get balance information of address",305 Long: "Get balance of specific token for specific address",306 Args: cobra.ExactArgs(0),307 RunE: func(cmd *cobra.Command, args []string) error {308 return client.BalanceOfToken(flagAddress, flagTokenAddress, flagTokenName, flagRpcUrl)309 },310}311func addBalanceOfTokenFlag() {312 balanceOfTokenCmd.PersistentFlags().StringVarP(&flagAddress, "address", "a", "", "account's address")313 balanceOfTokenCmd.PersistentFlags().StringVarP(&flagTokenAddress, "tokenAddress", "t", "", "token's address")314 balanceOfTokenCmd.PersistentFlags().StringVarP(&flagTokenName, "tokenName", "n", "", "token's address")315 balanceOfTokenCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)316}317var allBalanceCmd = &cobra.Command{318 Use: "allBalance",319 Short: "Get all balance information",320 Long: "Get balance of all tokens for specific address",321 Args: cobra.ExactArgs(0),322 RunE: func(cmd *cobra.Command, args []string) error {323 return client.AllBalance(flagAddress, flagRpcUrl)324 },325}326func addAllBalanceFlag() {327 allBalanceCmd.PersistentFlags().StringVarP(&flagAddress, "address", "a", "", "account's address")328 allBalanceCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)329}330var nonceCmd = &cobra.Command{331 Use: "nonce",332 Short: "Get account nonce",333 Long: "Get the next usable nonce for specific address",334 Args: cobra.ExactArgs(0),335 RunE: func(cmd *cobra.Command, args []string) error {336 return client.Nonce(flagAddress, flagRpcUrl)337 },338}339func addNonceFlag() {340 nonceCmd.PersistentFlags().StringVarP(&flagAddress, "address", "a", "", "account's address")341 nonceCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)342}343var commitTxCmd = &cobra.Command{344 Use: "commitTx",345 Short: "Commit transaction",346 Long: "Commit transaction with tx's data",347 Args: cobra.ExactArgs(0),348 RunE: func(cmd *cobra.Command, args []string) error {349 return client.CommitTx(flagTx, flagRpcUrl)350 },351}352func addCommitTxFlag() {353 commitTxCmd.PersistentFlags().StringVarP(&flagTx, "tx", "t", "", "packed and signed transaction's data")354 commitTxCmd.PersistentFlags().StringVarP(&flagRpcUrl, "url", "u", serverAddr(common.GetConfig().ServerAddr, true), usage)355}...

Full Screen

Full Screen

system_test.go

Source:system_test.go Github

copy

Full Screen

1package our_tests2import (3 "testing"4 "time"5 "fmt"6 "github.com/stretchr/testify/assert"7)8func TestLeaderDropAndRestart(t *testing.T) {9 // leader drops out, no nodes have any log entries10 cluster, err := NewRaftCluster(t, DoubleElectionTimeoutConfig())11 if err != nil {12 t.Errorf(err.Error())13 return14 }15 SetDebug(false)16 cluster.strictTests = false17 cluster.config.VerboseLog = true18 // election19 time.Sleep(cluster.GetConfig().ElectionTimeout * 4)20 // start client, execute some command21 client, _ := cluster.ClusterCmdClientRegister(nil)22 cluster.ClusterCmdClientCmdInit(client, "hello")23 cluster.ClusterCmdClientCmdHash(client)24 time.Sleep(cluster.GetConfig().ElectionTimeout * 4)25 leader, _ := cluster.GetSimpleLeader()26 cluster.ClusterCmdNodeShutdown(leader)27 Out.Printf("SHUTTING DOWN %v", leader)28 // re-election29 time.Sleep(time.Second * 5)30 Out.Printf("NEW LEADER ELECTED\n")31 // client needs to reconnect32 client, _ = cluster.ClusterCmdClientRegister(nil)33 time.Sleep(time.Second)34 Out.Printf("CLIENT CONNECTED\n")35 // send sequence of hashes w/o init and it should work36 for i := 0; i < 3; i++ {37 cluster.ClusterCmdClientCmdHash(client)38 }39 Out.Printf("CLIENT HASHES COMPLETED\n")40 time.Sleep(2)41}42func TestLeaderDropWithLargeLog(t *testing.T) {43 run := false44 if run {45 conf := SystemTestingConfig()46 conf.ClusterSize = 547 cluster, err := NewRaftCluster(t, conf)48 cluster.strictTests = false49 if err != nil {50 t.Errorf(err.Error())51 return52 }53 time.Sleep(cluster.GetConfig().ElectionTimeout * 10)54 leader, exists := cluster.GetLeader()55 if !exists {56 t.Errorf("No leader!")57 return58 }59 cluster.ClusterCmdClientStart()60 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)61 // some NON-LEADER nodes shutdown62 nonLeaders := make([]*RaftNode, 0)63 cluster.mutex.Lock()64 for _, node := range cluster.nodes {65 if node.State != LEADER_STATE {66 nonLeaders = append(nonLeaders, node)67 }68 }69 cluster.mutex.Unlock()70 cluster.ClusterCmdNodeShutdown(nonLeaders[0])71 cluster.ClusterCmdNodeShutdown(nonLeaders[1])72 cluster.ClusterCmdNodeShutdown(nonLeaders[2])73 time.Sleep(cluster.GetConfig().ElectionTimeout * 10)74 go cluster.ClusterCmdClientCmdHash(nil)75 go cluster.ClusterCmdClientCmdHash(nil)76 go cluster.ClusterCmdClientCmdHash(nil)77 time.Sleep(cluster.GetConfig().ElectionTimeout * 10)78 // leader drops, has uncommitted log entries b/c cannot commit to a majority of nodes79 cluster.ClusterCmdNodeShutdown(leader)80 // nodes elect new leader and receive commits81 time.Sleep(cluster.GetConfig().ElectionTimeout * 10)82 cluster.ClusterCmdNodeRestart(nonLeaders[0])83 cluster.ClusterCmdNodeRestart(nonLeaders[1])84 cluster.ClusterCmdNodeRestart(nonLeaders[2])85 time.Sleep(cluster.GetConfig().ElectionTimeout * 10)86 go cluster.ClusterCmdClientStart()87 go cluster.ClusterCmdClientCmdHash(nil)88 go cluster.ClusterCmdClientCmdHash(nil)89 // old leader starts up again and its log is truncated to be up to date with the new leader90 cluster.ClusterCmdNodeRestart(leader)91 // stable running resumes92 time.Sleep(cluster.GetConfig().ElectionTimeout * 10)93 cluster.assertLeaderState()94 // DESCRIBED IN DETAIL IN README95 }96}97func TestSplitVotes(t *testing.T) {98 // all nodes start as followers99 // all nodes timeout AT THE SAME TIME100 // every candidate should timeout and become a follower again101 // leader should elect normally102 cluster, _ := NewRaftCluster(t, DoubleElectionTimeoutConfig())103 for _, node := range cluster.nodes {104 cluster.initNode(node)105 }106 time.Sleep(time.Second * 2)107 // waits for all functions to be waiting on the lock and releases them all simultaneously108 Out.Printf("RELEASING ALL NODES INTO CANDIDATE STATE")109 cluster.debugCond.L.Lock()110 cluster.debugCond.Broadcast()111 cluster.debugCond.L.Unlock()112 // re-election113 time.Sleep(time.Second * 10)114 // must be able to find a leader115 leader, _ := cluster.GetSimpleLeader()116 Out.Printf("Cluster elected %v as leader", leader.Id)117}118func TestLeaderUpdatesFollowerWithPrevTerm(t *testing.T) {119 cluster, _ := NewRaftCluster(t, DefaultConfig())120 cluster.strictTests = false121 // election takes place122 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)123 leader, _ := cluster.GetSimpleLeader()124 // followers both drop out125 for _, node := range cluster.nodes {126 if node.Id != leader.Id {127 cluster.ClusterCmdNodeShutdown(node)128 }129 }130 time.Sleep(time.Second * 3)131 // leader keeps going, increments term132 // adds entries to its log via client requests133 go cluster.ClusterCmdClientRegister(leader)134 time.Sleep(time.Second)135 go cluster.ClusterCmdClientRegister(leader)136 time.Sleep(time.Second)137 go cluster.ClusterCmdClientRegister(leader)138 time.Sleep(time.Second)139 lastTerm := leader.getLogEntry(leader.getLastLogIndex()).GetTermId()140 lastIndex := leader.getLastLogIndex()141 // followers restart and are updated to match leader's log142 for _, node := range cluster.nodes {143 if node.Id != leader.Id {144 cluster.ClusterCmdNodeRestart(node)145 }146 }147 time.Sleep(time.Second * 5)148 // check that all logs are consistent149 for _, node := range cluster.nodes {150 if node.Id != leader.Id {151 if node.getLogEntry(node.getLastLogIndex()).GetTermId() != lastTerm {152 t.Errorf("Last terms inconsistent")153 }154 if node.getLastLogIndex() != lastIndex {155 t.Errorf("Last index inconsistent")156 }157 }158 }159}160func TestLeaderUpdatesFollowerNextTermExtraEntries(t *testing.T) {161 conf := SystemTestingConfig()162 cluster, err := NewRaftCluster(t, conf)163 cluster.strictTests = false164 if err != nil {165 t.Errorf(err.Error())166 return167 }168 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)169 // A follower, B leader with term 1170 B, isLeader := cluster.GetLeader()171 if !isLeader {172 fmt.Errorf("No leader!")173 }174 // B crashes and new election occurs175 cluster.ClusterCmdNodeShutdown(B)176 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)177 // B restarts, all nodes in term 2178 cluster.ClusterCmdNodeRestart(B)179 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)180 // A is leader, receives two request and crashes immediately w/o duplication181 A, isLeader := cluster.GetLeader()182 if !isLeader {183 fmt.Errorf("No leader!")184 }185 cl, err := cluster.ClusterCmdClientRegister(A)186 if err != nil {187 fmt.Errorf("Client failure!")188 }189 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)190 aLogLen := A.getLastLogIndex() + 1191 go cluster.ClusterCmdClientCmdHash(cl)192 go cluster.ClusterCmdClientCmdHash(cl)193 go cluster.ClusterCmdClientCmdHash(cl)194 go cluster.ClusterCmdClientCmdHash(cl)195 for A.getLastLogIndex()+1 < aLogLen {196 }197 cluster.ClusterCmdNodeShutdown(A)198 // B is elected leader, in term 3199 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)200 // A restarts, is now a follower with entries that are not in B's log201 cluster.ClusterCmdNodeRestart(A)202 // A should update correctly and B should remain leader203 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)204 assert.Equal(t, LEADER_STATE, B.State)205}206// PARTITION TESTS207func TestSoloNodePartition(t *testing.T) {208 cluster, err := NewRaftCluster(t, SystemTestingConfig())209 cluster.strictTests = false210 if err != nil {211 t.Errorf(err.Error())212 return213 }214 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)215 // single node breaks off into partition and keeps running, continuously going into the candidate state216 // and incrementing its turn217 rightSideNodes, leftSideNodes := cluster.ClusterCmdRandPartitionSplit(1)218 time.Sleep(cluster.GetConfig().ElectionTimeout * 30)219 // the right side's single node's term should be larger than everyone's220 // on the left at this point221 rightIncrementerTerm := rightSideNodes[0].GetCurrentTerm()222 for _, node := range leftSideNodes {223 assert.True(t, rightIncrementerTerm > node.GetCurrentTerm(),224 "rightIncrementerTerm=%d, curTerm=%d, node=%v", rightIncrementerTerm, node.GetCurrentTerm(), node)225 }226 // when partition is healed, all other nodes will have lower term but nobody will vote for the solo node227 // because log is out of date228 // all other nodes will be brought to the term of the solo node and solo node will become follower229 // THIS ALSO TESTS THAT OUT OF DATE LOGS CANNOT BE ELECTED230 cluster.ClusterCmdResolvePartition()231 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)232 // everyone's should be equal now233 rightIncrementerTerm = rightSideNodes[0].GetCurrentTerm()234 for _, node := range leftSideNodes {235 assert.Equal(t, rightIncrementerTerm, node.GetCurrentTerm())236 }237 // NOTE: look at assertLogEntries and assertLeaderState for how these are tested238}239func TestTwoLeaderPartition(t *testing.T) {240 // RAFT HAS 5 NODES IN THIS TEST - A,B,C,D,E241 conf := SystemTestingConfig()242 conf.ClusterSize = 5243 cluster, err := NewRaftCluster(t, conf)244 cluster.strictTests = false245 if err != nil {246 t.Errorf(err.Error())247 return248 }249 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)250 // A (without loss of generality) is elected leader, partition is setup between A,B|C,D,E251 rightSideNodes, leftSideNodes := cluster.ClusterCmdRandPartitionSplit(2)252 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)253 // A stays leader of its side of the partition, C,D,E reelect and become a greater term254 // We have two leaders on both sides of the partition255 var A = new(RaftNode)256 for _, node := range rightSideNodes {257 if node.State == LEADER_STATE {258 A = node259 }260 }261 if A == nil {262 t.Errorf("No leader election on side of A!")263 } else {264 // Add another client to the new side of the partition and update both sides with a different call265 leftClientEntry := cluster.GetRandomNodeFrom(leftSideNodes)266 cl, err := cluster.ClusterCmdClientRegister(leftClientEntry)267 if err != nil {268 t.Errorf("Couldn't create client on CDE side")269 return270 }271 cluster.ClusterCmdClientCmdInit(cl, "cats")272 cluster.ClusterCmdClientCmdHash(cl)273 cluster.ClusterCmdClientCmdHash(cl)274 cluster.ClusterCmdClientCmdHash(cl)275 cluster.ClusterCmdClientCmdHash(cl)276 cluster.ClusterCmdClientCmdHash(cl)277 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)278 // Remove partition, A should step down (as it has no committed entries) and match C,D,E's log279 cluster.ClusterCmdResolvePartition()280 time.Sleep(cluster.GetConfig().ElectionTimeout * 5)281 assert.True(t, A.State != LEADER_STATE)282 }283}...

Full Screen

Full Screen

cmd.go

Source:cmd.go Github

copy

Full Screen

1package x_gob_explorer2import (3 "aioz.io/go-aioz/x_gob_explorer/config"4 database "aioz.io/go-aioz/x_gob_explorer/domain/db"5 "aioz.io/go-aioz/x_gob_explorer/utils"6 "github.com/spf13/cobra"7 "github.com/spf13/viper"8 tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"9 "github.com/tendermint/tendermint/libs/cli"10)11const (12 flagResetDB = "resetDB"13 flagResetNode = "resetData"14 flagWithTendermint = "with-tendermint"15 flagAddress = "address"16 flagTraceStore = "trace-store"17 flagPruning = "pruning"18 flagCPUProfile = "cpu-profile"19 FlagMinGasPrices = "minimum-gas-prices"20)21func GobCmd(start func() error) *cobra.Command {22 host := config.GetConfig().GetString("database.host")23 port := config.GetConfig().GetString("database.port")24 user := config.GetConfig().GetString("database.user")25 pwd := config.GetConfig().GetString("database.passwd")26 dbname := config.GetConfig().GetString("database.dbname")27 sslmode := config.GetConfig().GetString("database.sslmode")28 sslrootcert := config.GetConfig().GetString("database.sslrootcert")29 sslkey := config.GetConfig().GetString("database.sslkey")30 sslcert := config.GetConfig().GetString("database.sslcert")31 schema := config.GetConfig().GetString("database.schema")32 cmd := &cobra.Command{33 Use: "gob",34 Short: "Run the full node with indexing",35 RunE: func(cmd *cobra.Command, args []string) error {36 resetDB := viper.GetBool(flagResetDB)37 resetNode := viper.GetBool(flagResetNode)38 if resetDB {39 db := database.NewCockroachDB(user, pwd, host, port,40 dbname, sslmode, sslrootcert, sslkey, sslcert)41 db.Reset(schema)42 return nil43 }44 if resetNode {45 homeDir := viper.GetString(cli.HomeFlag)46 if err := utils.ResetNodeDB(homeDir); err != nil {47 return err48 }49 return nil50 }51 return start()52 },53 }54 // core flags for the ABCI application55 cmd.Flags().Bool(flagResetDB, false, "Reset cockroach database")56 cmd.Flags().Bool(flagResetNode, false, "Delete node directory")57 cmd.Flags().Bool(flagWithTendermint, true, "Run abci app embedded in-process with tendermint")58 cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address")59 cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file")60 cmd.Flags().String(flagPruning, "syncable", "Pruning strategy: syncable, nothing, everything")61 cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file")62 cmd.Flags().String(FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.0001stake)")63 // add support for all Tendermint-specific command line options64 tcmd.AddNodeFlags(cmd)65 return cmd66}...

Full Screen

Full Screen

getConfig

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 cmd := cmd{}4 fmt.Println(cmd.getConfig())5}6import "fmt"7func main() {8 cmd := cmd{}9 fmt.Println(cmd.getConfig())10}11import "fmt"12func main() {13 cmd := cmd{}14 fmt.Println(cmd.getConfig())15}16import "fmt"17func main() {18 cmd := cmd{}19 fmt.Println(cmd.getConfig())20}21import "fmt"22func main() {23 cmd := cmd{}24 fmt.Println(cmd.getConfig())25}26import "fmt"27func main() {28 cmd := cmd{}29 fmt.Println(cmd.getConfig())30}31import "fmt"32func main() {33 cmd := cmd{}34 fmt.Println(cmd.getConfig())35}36import "fmt"37func main() {38 cmd := cmd{}39 fmt.Println(cmd.getConfig())40}41import "fmt"42func main() {43 cmd := cmd{}44 fmt.Println(cmd.getConfig())45}46import "fmt"47func main() {48 cmd := cmd{}49 fmt.Println(cmd.getConfig())50}51import "fmt"52func main() {53 cmd := cmd{}54 fmt.Println(cmd.getConfig())55}56import "fmt"57func main() {58 cmd := cmd{}59 fmt.Println(cmd.getConfig())60}61import "fmt"62func main() {63 cmd := cmd{}

Full Screen

Full Screen

getConfig

Using AI Code Generation

copy

Full Screen

1func main() {2 cmd := Cmd{Config: getConfig()}3 cmd.Run()4}5func main() {6 cmd := Cmd{Config: getConfig()}7 cmd.Run()8}9func main() {10 cmd := Cmd{Config: getConfig()}11 cmd.Run()12}13func main() {14 cmd := Cmd{Config: getConfig()}15 cmd.Run()16}17func main() {18 cmd := Cmd{Config: getConfig()}19 cmd.Run()20}21func main() {22 cmd := Cmd{Config: getConfig()}23 cmd.Run()24}25func main() {26 cmd := Cmd{Config: getConfig()}27 cmd.Run()28}29func main() {30 cmd := Cmd{Config: getConfig()}31 cmd.Run()32}33func main() {34 cmd := Cmd{Config: getConfig()}35 cmd.Run()36}37func main() {38 cmd := Cmd{Config: getConfig()}39 cmd.Run()40}41func main() {42 cmd := Cmd{Config: getConfig()}43 cmd.Run()44}45func main() {46 cmd := Cmd{Config: getConfig()}47 cmd.Run()48}49func main() {50 cmd := Cmd{Config: getConfig()}51 cmd.Run()52}53func main() {54 cmd := Cmd{Config: getConfig()}55 cmd.Run()56}57func main() {

Full Screen

Full Screen

getConfig

Using AI Code Generation

copy

Full Screen

1import (2type Command struct {3}4func (cmd *Command) getConfig() string {5}6func main() {7 cmd := Command{}8 fmt.Println(cmd.getConfig())9}10import (11func main() {12 cmd := Command{}13 fmt.Println(cmd.getConfig())14}15import (16type Command struct {17}18func (cmd *Command) getConfig() string {19}20func main() {21 cmd := Command{}22 fmt.Println(cmd.getConfig())23}24import (25func main() {26 cmd := Command{}27 fmt.Println(cmd.getConfig())28}29import (30type Command struct {31}32func (cmd *Command) getConfig() string {33}34func main() {35 cmd := Command{}36 fmt.Println(cmd.getConfig())37}38import (39func main() {40 cmd := Command{}41 fmt.Println(cmd.getConfig())42}43import (44type Command struct {45}46func (cmd *Command) getConfig() string {47}48func main() {49 cmd := Command{}50 fmt.Println(cmd.getConfig())51}52import (53func main() {54 cmd := Command{}55 fmt.Println(cmd.getConfig())56}57import (58type Command struct {59}60func (cmd *Command) getConfig() string {61}62func main() {63 cmd := Command{}64 fmt.Println(cmd.getConfig())65}66import (67func main() {68 cmd := Command{}69 fmt.Println(cmd.getConfig())70}71import (72type Command struct {73}74func (cmd *Command) getConfig() string {75}76func main() {77 cmd := Command{}78 fmt.Println(cmd.getConfig())79}80import (

Full Screen

Full Screen

getConfig

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 configObj.getConfig()4}5import "fmt"6func main() {7 configObj.getConfig()8}9import "fmt"10func main() {11 configObj.getConfig()12}13import "fmt"14func main() {15 configObj.getConfig()16}17import "fmt"18func main() {19 configObj.getConfig()20}21import "fmt"22func main() {23 configObj.getConfig()24}25import "fmt"26func main() {27 configObj.getConfig()28}29import "fmt"30func main() {31 configObj.getConfig()32}33import "fmt"34func main() {35 configObj.getConfig()36}37import "fmt"38func main() {39 configObj.getConfig()40}41import "fmt"42func main() {43 configObj.getConfig()44}45import "fmt"46func main() {47 configObj.getConfig()48}49import "fmt"50func main() {

Full Screen

Full Screen

getConfig

Using AI Code Generation

copy

Full Screen

1cmd := exec.Command("go", "run", "1.go")2cmd.Env = os.Environ()3cmd.Env = append(cmd.Env, "GOPATH=/home/abhishek/Desktop/GoLang")4err := cmd.Run()5if err != nil {6 fmt.Println(fmt.Sprint(err) + ": " + stderr.String())7}8fmt.Println("Result: " + out.String())9cmd := exec.Command("go", "run", "1.go")10cmd.Env = os.Environ()11cmd.Env = append(cmd.Env, "GOPATH=/home/abhishek/Desktop/GoLang")12err := cmd.Run()13if err != nil {14 fmt.Println(fmt.Sprint(err) + ": " + stderr.String())15}16fmt.Println("Result: " + out.String())17cmd := exec.Command("go", "run", "1.go")18cmd.Env = os.Environ()19cmd.Env = append(cmd.Env, "GOPATH=/home/abhishek/Desktop/GoLang")20err := cmd.Run()21if err != nil {22 fmt.Println(fmt.Sprint(err) + ": " + stderr.String())23}24fmt.Println("Result: " + out.String())25cmd := exec.Command("go", "run", "1.go")26cmd.Env = os.Environ()27cmd.Env = append(cmd.Env, "GOPATH=/home/abhishek/Desktop/GoLang")28err := cmd.Run()29if err != nil {30 fmt.Println(fmt.Sprint(err)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful