github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/go-themis/parallel_test.go (about) 1 package themis 2 3 import ( 4 "runtime" 5 "strconv" 6 "sync" 7 8 "github.com/insionng/yougam/libraries/ngaut/log" 9 . "github.com/insionng/yougam/libraries/pingcap/check" 10 "github.com/insionng/yougam/libraries/pingcap/go-hbase" 11 ) 12 13 type ParallelTestSuit struct{} 14 15 var _ = Suite(&ParallelTestSuit{}) 16 17 func (s *ParallelTestSuit) TestParallelHbaseCall(c *C) { 18 runtime.GOMAXPROCS(runtime.NumCPU() / 2) 19 cli, err := createHBaseClient() 20 c.Assert(err, Equals, nil) 21 22 err = createNewTableAndDropOldTable(cli, themisTestTableName, "cf", nil) 23 c.Assert(err, Equals, nil) 24 25 wg := sync.WaitGroup{} 26 for i := 0; i < 10; i++ { 27 wg.Add(1) 28 go func(i int) { 29 defer wg.Done() 30 tx := newTxn(cli, defaultTxnConf) 31 p := hbase.NewPut(getTestRowKey(c)) 32 p.AddValue(cf, q, []byte(strconv.Itoa(i))) 33 tx.Put(themisTestTableName, p) 34 tx.Commit() 35 }(i) 36 } 37 wg.Wait() 38 39 g := hbase.NewGet(getTestRowKey(c)).AddColumn(cf, q) 40 rs, err := cli.Get(themisTestTableName, g) 41 if err != nil { 42 log.Fatal(err) 43 } 44 log.Info(string(rs.SortedColumns[0].Value)) 45 }