Example #1
0
func main() {
	var attrs client.Attributes
	var objs chan client.Attributes
	var errs chan client.Error
	_ = attrs
	_ = objs
	_ = errs
	var c *client.Client
	var err client.Error
	port, _ := strconv.Atoi(os.Args[2])
	c, er, _ := client.NewClient(os.Args[1], port)
	if er != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	attrs, err = c.Get("kv", "k")
	if err.Status != client.NOTFOUND {
		fmt.Printf("bad status: %d (should be NOTFOUND)\n", err)
	}
	err = c.Put("kv", "k", client.Attributes{"v": "v1"})
	if err.Status != client.SUCCESS {
		os.Exit(1)
	}
	attrs, err = c.Get("kv", "k")
	if err.Status != client.SUCCESS {
		fmt.Printf("bad status: %d (should be SUCCESS)\n", err.Status)
	}
	if !sloppyEqualAttributes(attrs, client.Attributes{"v": "v1"}) {
		fmt.Printf("%s %s\n", attrs, client.Map{"v": "v1"})
		panic("objects not equal")
	}
	err = c.CondPut("kv", "k", []client.Predicate{{"v", "v2", client.EQUALS}}, client.Attributes{"v": "v3"})
	if err.Status != client.CMPFAIL {
		os.Exit(1)
	}
	attrs, err = c.Get("kv", "k")
	if err.Status != client.SUCCESS {
		fmt.Printf("bad status: %d (should be SUCCESS)\n", err.Status)
	}
	if !sloppyEqualAttributes(attrs, client.Attributes{"v": "v1"}) {
		fmt.Printf("%s %s\n", attrs, client.Map{"v": "v1"})
		panic("objects not equal")
	}
	err = c.CondPut("kv", "k", []client.Predicate{{"v", "v1", client.EQUALS}}, client.Attributes{"v": "v3"})
	if err.Status != client.SUCCESS {
		os.Exit(1)
	}
	attrs, err = c.Get("kv", "k")
	if err.Status != client.SUCCESS {
		fmt.Printf("bad status: %d (should be SUCCESS)\n", err.Status)
	}
	if !sloppyEqualAttributes(attrs, client.Attributes{"v": "v3"}) {
		fmt.Printf("%s %s\n", attrs, client.Map{"v": "v3"})
		panic("objects not equal")
	}
	os.Exit(0)
}
Example #2
0
func main() {
	var attrs client.Attributes
	var objs chan client.Attributes
	var errs chan client.Error
	_ = attrs
	_ = objs
	_ = errs
	var c *client.Client
	var err client.Error
	port, _ := strconv.Atoi(os.Args[2])
	c, er, _ := client.NewClient(os.Args[1], port)
	if er != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	err = c.Put("kv", "k", client.Attributes{})
	if err.Status != client.SUCCESS {
		os.Exit(1)
	}
	attrs, err = c.Get("kv", "k")
	if err.Status != client.SUCCESS {
		fmt.Printf("bad status: %d (should be SUCCESS)\n", err.Status)
	}
	if !sloppyEqualAttributes(attrs, client.Attributes{"v": float64(0.0)}) {
		fmt.Printf("%s %s\n", attrs, client.Map{"v": float64(0.0)})
		panic("objects not equal")
	}
	err = c.Put("kv", "k", client.Attributes{"v": float64(3.14)})
	if err.Status != client.SUCCESS {
		os.Exit(1)
	}
	attrs, err = c.Get("kv", "k")
	if err.Status != client.SUCCESS {
		fmt.Printf("bad status: %d (should be SUCCESS)\n", err.Status)
	}
	if !sloppyEqualAttributes(attrs, client.Attributes{"v": float64(3.14)}) {
		fmt.Printf("%s %s\n", attrs, client.Map{"v": float64(3.14)})
		panic("objects not equal")
	}
	os.Exit(0)
}