func (self *UpRPut) doTestGet() (msg string, err error) { begin := time.Now() entryURI := self.Bucket + ":" + self.Key ret, code, err := self.Rscli.Get(entryURI, "", "", 3600) end := time.Now() duration := end.Sub(begin) msg = util.GenLog("UP "+self.Env.Id+"_"+self.Name+"_doTestGet", begin, end, duration) if err != nil || code/100 != 2 { if err == nil { err = errors.New("Invalid response code") } err = errors.Info(err, "download failed", entryURI) return } resp, err := http.Get(ret.URL) if err != nil { err = errors.Info(err, "download failed", entryURI, ret.URL) return } defer resp.Body.Close() h := sha1.New() io.Copy(h, resp.Body) hash := hex.EncodeToString(h.Sum(nil)) if hash != self.DataSha1 { err = errors.Info(errors.New("Invalid data sha1"), self.DataSha1, hash) return } return }
func (p *Pub) doTestDownload() (msg string, err error) { var ( url string ) if p.isNormalDomain { url = "http://" + p.Domain + "/" + p.Key } else { url = "http://" + p.DomainIp + "/" + p.Key } req, err := http.NewRequest("GET", url, nil) if err != nil { err = errors.Info(err, "Download failed:", url) return } if !p.isNormalDomain { req.Host = p.Domain } begin := time.Now() resp, err := http.DefaultClient.Do(req) end := time.Now() duration := end.Sub(begin) msg = util.GenLogEx("Fp "+p.Env.Id+"_"+p.Name+"_doTestDownload", begin, end, duration) if err != nil { err = errors.Info(err, "Download failed:", url) return } defer resp.Body.Close() if resp.StatusCode/100 != 2 { err = errors.New("download status code is not 20x!") err = errors.Info(err, url, resp.StatusCode) return } if ct, ok := resp.Header["Content-Type"]; !ok || len(ct) != 1 || ct[0] != p.dataType { err = errors.New("Invalid content type") return } h := sha1.New() if _, err = io.Copy(h, resp.Body); err != nil { err = errors.Info(err, "check sha1 failed") return } if p.DataSha1 != hex.EncodeToString(h.Sum(nil)) { err = errors.New("Invalid data sha1") err = errors.Info(err, p.DataSha1, hex.EncodeToString(h.Sum(nil))) return } return }
func (p *PubImage) doTestUnimage() (msg string, err error) { code, err := p.Pubcli.Unimage(p.Bucket) if err != nil || code/100 != 2 { if err == nil { err = errors.New("doTestUnimage failed") } err = errors.Info(err, code, p.Bucket) return } return }
func (p *PubImage) doTestImage() (msg string, err error) { from := []string{p.FromDomain} code, err := p.Pubcli.Image(p.Bucket, from, p.SrcHost, 0) if err != nil || code/100 != 2 { if err == nil { err = errors.New("doTestImage failed") } err = errors.Info(err, code, p.SrcHost, p.FromDomain) return } url := "http://" + p.Env.Hosts["io"] + "/" + p.SrcKey _, err = httputil.DownloadEx(url, p.FromDomain) if err != nil { err = errors.Info(err, "doTestImage failed", url) return } return }
func (self *UpRPut) doTestRPut() (msg string, err error) { f, err := os.Open(self.DataFile) if err != nil { err = errors.Info(err, "Resumable put failed") return } defer f.Close() fi, _ := f.Stat() entryURI := self.Bucket + ":" + self.Key blockcnt := self.Up2cli.BlockCount(fi.Size()) progs := make([]up2.BlockputProgress, blockcnt) chunkNotify := func(idx int, p *up2.BlockputProgress) { if rand.Intn(blockcnt)/3 == 0 { p1 := *p progs[idx] = p1 } } blockNotify := func(idx int, p *up2.BlockputProgress) { } t1 := self.Up2cli.NewRPtask(entryURI, "", "", "", "", f, fi.Size(), nil) t1.ChunkNotify = chunkNotify t1.BlockNotify = blockNotify begin := time.Now() for i := 0; i < blockcnt; i++ { t1.PutBlock(i) } t1.Progress = progs code, err := t1.Run(10, 10, nil, nil) end := time.Now() duration := end.Sub(begin) msg = util.GenLog("UP "+self.Env.Id+"_"+self.Name+"_doTestRPut", begin, end, duration) if err != nil || code/100 != 2 { err = errors.Info(errors.New("Resumable put failed"), entryURI, err, code) return } return }