Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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
}