コード例 #1
0
// this tests "RetryBatchGet", which does NOT do intelligent splitting and re-assembling
// of requests and responses
func Test1() {
	b := batch_get_item.NewBatchGetItem()
	tn := "test-godynamo-livetest"
	b.RequestItems[tn] = batch_get_item.NewRequestInstance()
	for i := 1; i <= 200; i++ {
		item := item.NewItem()
		k := fmt.Sprintf("AHashKey%d", i)
		v := fmt.Sprintf("%d", i)
		item["TheHashKey"] = &attributevalue.AttributeValue{S: k}
		item["TheRangeKey"] = &attributevalue.AttributeValue{N: v}
		b.RequestItems[tn].Keys =
			append(b.RequestItems[tn].Keys, item)

	}
	_, jerr := json.Marshal(b)
	if jerr != nil {
		fmt.Printf("%v\n", jerr)
	} else {
		//fmt.Printf("%s\n",string(json))
	}
	bs, _ := batch_get_item.Split(b)
	for _, bsi := range bs {
		body, code, err := bsi.RetryBatchGet(0)
		if err != nil || code != http.StatusOK {
			fmt.Printf("error: %v\n%v\n%v\n", string(body), code, err)
		} else {
			fmt.Printf("worked!: %v\n%v\n%v\n", string(body), code, err)
		}
	}
}
コード例 #2
0
// this tests "DoBatchGet", which breaks up requests that are larger than the limit
// and re-assembles responses
func Test2() {
	b := batch_get_item.NewBatchGetItem()
	tn := "test-godynamo-livetest"
	b.RequestItems[tn] = batch_get_item.NewRequestInstance()
	for i := 1; i <= 300; i++ {
		item := item.NewItem()
		k := fmt.Sprintf("AHashKey%d", i)
		v := fmt.Sprintf("%d", i)
		item["TheHashKey"] = &attributevalue.AttributeValue{S: k}
		item["TheRangeKey"] = &attributevalue.AttributeValue{N: v}
		b.RequestItems[tn].Keys =
			append(b.RequestItems[tn].Keys, item)

	}
	_, jerr := json.Marshal(*b)
	if jerr != nil {
		fmt.Printf("%v\n", jerr)
	} else {
		//fmt.Printf("%s\n",string(json))
	}
	body, code, err := b.DoBatchGet()
	fmt.Printf("%v\n%v\n%v\n", string(body), code, err)
}