예제 #1
0
파일: ids.go 프로젝트: zbs4ms/ids
func InitProgram() {
	global.CoordinateCenter = coordinate.NewCenterPoolAgent(global.Get("center", "zookeeperAddr"), global.Get("center", "redisAddr"))
	if nil == global.CoordinateCenter {
		fmt.Println("Can not access to coordintor")
		os.Exit(1)
	}
	global.ServeAddr = global.Get("uuidCluster", "serveAddr")

	machineCode := global.Get("uuidCluster", "machineCode")
	global.MachineCode = machineCode

	global.QueCounter = count.NewQueCounter(1, 8191, 1)

	services.InitAuthority(global.CoordinateCenter)
}
예제 #2
0
func TestQueCounter(t *testing.T) {

	queCounter := count.NewQueCounter(1, 100000000, 2)

	chs := make([]chan [1000]string, 100)
	for i := 0; i < 100; i++ {
		chs[i] = make(chan [1000]string)
		go calc(chs[i], queCounter)
	}

	var all map[string]string = make(map[string]string)
	for _, ch := range chs {
		orders := <-ch
		for i := 0; i < 1000; i++ {
			value, ok := all[orders[i]]
			if ok {
				t.Errorf("Failed for create same id: %s", value)
			} else {
				all[orders[i]] = "1"
			}
		}
	}
}