func main() { client, err := gobbyclient.NewClient(-1, 0) if err != nil { fmt.Println("wrong") } fmt.Println("Client Put test:1") client.Put("test", "1") fmt.Println("Client Get test") s, err := client.Get("test") if err != nil { fmt.Println("wrong get") fmt.Println(err) } fmt.Println(s) fmt.Println("Client Acquire test") ts, err := client.Acquire("test") fmt.Printf("Client Acquire test, get %s\n", ts) fmt.Println("Client Release test") client.Release("test", ts) client.Watch("test") time.Sleep(2 * time.Second) go client.Put("test", "hahaha") time.Sleep(2 * time.Second) }
func main() { //TODO:need modify NewClient parameter, now is the numNodes client, err := gobbyclient.NewClient(0, 2) if err != nil { fmt.Println("wrong") return } fmt.Println("Client3 Aquire test") ts, err := client.Acquire("test") for err != nil { time.Sleep(time.Second) fmt.Println("Client3 Aquire test") ts, err = client.Acquire("test") } fmt.Println("Client3 Aquires lock " + ts) time.Sleep(10 * time.Second) fmt.Println("Client3 Release lock" + ts) client.Release("test", ts) }
func main() { client, err := gobbyclient.NewClient(numNodes, cid) if err != nil { fmt.Println("can't create gobby client") return } if cid == 0 { fmt.Printf("client %d Put %s:1", cid, key) client.Put(key, "1") } time.Sleep(3 * time.Second) for i := 0; i < 50; i++ { var lstm string var err error for { fmt.Printf("client %d tries to get the lock\n", cid) if lstm, err = client.Acquire(key); err != nil { time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond) continue } fmt.Printf("client %d gets the lock\n", cid) val, _ := client.Get(key) num, _ := strconv.Atoi(val) fmt.Printf("the value is now %d\n", num) newval := strconv.Itoa(num + 1) client.Put(key, newval) fmt.Printf("client %d put %s\n", cid, newval) if err = client.Release(key, lstm); err == nil { fmt.Printf("client %d releases the lock\n", cid) break } else { fmt.Printf("client %d fails to release the lock\n", cid) return } } } }
func main() { //TODO:need modify NewClient parameter, now is the numNodes client, err := gobbyclient.NewClient(0, 0) if err != nil { fmt.Println("wrong") } fmt.Println("Client Put test:1") client.Put("test", "1") fmt.Println("Client Get test") s, err := client.Get("test") if err != nil { fmt.Println("wrong get") fmt.Println(err) } fmt.Println(s) fmt.Println("Client Acquire test") ts, err := client.Acquire("test") fmt.Println("Client Acquire lock " + ts) time.Sleep(15 * time.Second) fmt.Println("Client Release test") client.Release("test", ts) }