Example #1
0
func (table *SDBTable) put(id string, values map[string]string) error {
	var attrs sdb.PutAttrs
	for k, v := range values {
		attrs.Replace(k, v)
	}

	item := table.domain.Item(id)

	var err error
	for retry := 0; retry < maxRetries; retry++ {
		_, err := item.PutAttrs(&attrs)
		if err == nil {
			return nil
		}

		// Wait a bit before trying again with exponential backoff.
		ms := int(rand.Float64() * math.Pow(4, float64(retry)) * 100)
		log.Printf("sdb retry: %d, %d", retry, ms)
		time.Sleep(time.Duration(ms) * time.Millisecond)
	}
	return err
}
Example #2
0
func (s *S) TestPutAttrsOK(c *C) {
	testServer.Response(200, nil, TestPutAttrsXmlOK)

	domain := s.sdb.Domain("MyDomain")
	item := domain.Item("Item123")

	putAttrs := new(sdb.PutAttrs)
	putAttrs.Add("FirstName", "john")
	putAttrs.Add("LastName", "smith")
	putAttrs.Replace("MiddleName", "jacob")

	putAttrs.IfValue("FirstName", "john")
	putAttrs.IfMissing("FirstName")

	resp, err := item.PutAttrs(putAttrs)
	req := testServer.WaitRequest()
	c.Assert(req.Method, Equals, "GET")
	c.Assert(req.URL.Path, Equals, "/")
	c.Assert(req.Form["Action"], DeepEquals, []string{"PutAttributes"})
	c.Assert(req.Form["ItemName"], DeepEquals, []string{"Item123"})
	c.Assert(req.Form["DomainName"], DeepEquals, []string{"MyDomain"})
	c.Assert(req.Form["Attribute.1.Name"], DeepEquals, []string{"FirstName"})
	c.Assert(req.Form["Attribute.1.Value"], DeepEquals, []string{"john"})
	c.Assert(req.Form["Attribute.2.Name"], DeepEquals, []string{"LastName"})
	c.Assert(req.Form["Attribute.2.Value"], DeepEquals, []string{"smith"})
	c.Assert(req.Form["Attribute.3.Name"], DeepEquals, []string{"MiddleName"})
	c.Assert(req.Form["Attribute.3.Value"], DeepEquals, []string{"jacob"})
	c.Assert(req.Form["Attribute.3.Replace"], DeepEquals, []string{"true"})

	c.Assert(req.Form["Expected.1.Name"], DeepEquals, []string{"FirstName"})
	c.Assert(req.Form["Expected.1.Value"], DeepEquals, []string{"john"})
	c.Assert(req.Form["Expected.1.Exists"], DeepEquals, []string{"false"})

	c.Assert(err, IsNil)
	c.Assert(resp.ResponseMetadata.RequestId, Equals, "490206ce-8292-456c-a00f-61b335eb202b")
	c.Assert(resp.ResponseMetadata.BoxUsage, Equals, 0.0000219907)

}