* 测试ChubbyGo的功能是否ok. */
()
| 12 | /* 测试ChubbyGo的功能是否ok. */ |
| 13 | |
| 14 | func main() { |
| 15 | GoroutinueNumber := 1 |
| 16 | // 可选的,SyncMap或者ConcurrentMap |
| 17 | entry := BaseServer.NewChubbyGoMap(BaseServer.SyncMap) |
| 18 | |
| 19 | |
| 20 | wg := sync.WaitGroup{} |
| 21 | wg.Add(GoroutinueNumber) |
| 22 | var ErrorNumber uint32 = 0 |
| 23 | |
| 24 | for j := 0; j < GoroutinueNumber; j++ { |
| 25 | go func(number int) { |
| 26 | for i := 0; i < 10; i++ { |
| 27 | if i&1 == 0 { |
| 28 | temp := "x " + strconv.Itoa(number) + " " + strconv.Itoa(i) + " y" |
| 29 | entry.ChubbyGoMapSet(strconv.Itoa(number), temp) |
| 30 | } else { |
| 31 | res, ok := entry.ChubbyGoMapGet(strconv.Itoa(number)) |
| 32 | temp := "x " + strconv.Itoa(number) + " " + strconv.Itoa(i-1) + " y" |
| 33 | if ok && res != temp{ |
| 34 | log.Printf("Error : res(%s) expected(%s).\n", res, temp) |
| 35 | atomic.AddUint32(&ErrorNumber, 1) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | wg.Done() |
| 40 | }(j) |
| 41 | } |
| 42 | |
| 43 | wg.Wait() |
| 44 | |
| 45 | if atomic.LoadUint32(&ErrorNumber) == 0{ |
| 46 | fmt.Println("PASS.") |
| 47 | } else { |
| 48 | fmt.Println("Not Pass.") |
| 49 | } |
| 50 | } |
nothing calls this directly
no test coverage detected