Exemplo n.º 1
0
func TestStorageWrite(t *testing.T) {
	skipIfClientNil(t)
	es := []string{}

	toolkit.Printf("Writing Data:\n")
	for i := 0; i < 200; i++ {
		dataku := toolkit.RandInt(1000)
		totalInt += dataku
		//toolkit.Printf("%d ", dataku)

		in := toolkit.M{}.Set("key", fmt.Sprintf("public.dataku.%d", i)).Set("data", toolkit.ToBytes(dataku, ""))
		writeResult := client.Call("set", in)
		if writeResult.Status != toolkit.Status_OK {
			es = append(es, toolkit.Sprintf("Fail to write data %d : %d => %s", i, dataku, writeResult.Message))
		}
	}

	if len(es) > 0 {
		errorTxt := ""
		if len(es) <= 10 {
			errorTxt = strings.Join(es, "\n")
		} else {
			errorTxt = strings.Join(es[:10], "\n") + "\n... And others ..."
		}
		t.Errorf("Write data fail.\n%s", errorTxt)
	}
}
Exemplo n.º 2
0
func TestClient(t *testing.T) {
	checkTestSkip(t)
	client = new(pecelclient.Client)
	e := client.Connect(server.Address, serverSecret, "ariefdarmawan")
	//e := client.Connect(server.Address, serverSecret+"_10", "ariefdarmawan")
	if e != nil {
		t.Error(e.Error())
		return
	}

	var result *toolkit.Result
	result = client.Call("ping", toolkit.M{})
	checkResult(result, t)
}
Exemplo n.º 3
0
func TestStorageGet(t *testing.T) {
	skipIfClientNil(t)

	in := toolkit.M{}
	in.Set("key", "dataku")
	getResult := client.Call("get", in)
	if getResult.Status != toolkit.Status_OK {
		t.Errorf(getResult.Message)
		return
	}

	data := []int{}
	e := toolkit.FromBytes(getResult.Data.([]byte), "", &data)
	if e != nil {
		t.Errorf("Unable to decode: " + e.Error())
	}
	fmt.Println("Result received: %s \n", toolkit.JsonString(data))

	total := int(crowd.From(data).Sum(nil))

	if total != totalInt {
		t.Errorf("Wrong summation expecting %d got %d", totalInt, total)
	}
}
Exemplo n.º 4
0
func TestClientHi(t *testing.T) {
	checkTestSkip(t)
	r := client.Call("hi", toolkit.M{}.Set("name", "Arief Darmawan"))
	checkResult(r, t)
}