Exemplo n.º 1
0
func (self *UpResuPut) doTestDownload() (msg string, err error) {
	h := sha1.New()
	begin := time.Now()
	var req *http.Request
	if req, err = http.NewRequest("GET", self.Url, nil); err != nil {
		return
	}
	var resp *http.Response
	if resp, err = http.DefaultClient.Do(req); err != nil {
		return
	}
	defer resp.Body.Close()
	if _, err = io.Copy(h, resp.Body); err != nil {
		return
	}
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("UP    "+self.Env.Id+"_"+self.Name+"_doTestDownload", begin, end, duration)

	hash := hex.EncodeToString(h.Sum(nil))
	if hash != self.DataSha1 {
		err = errors.New("check shal failed!")
		return
	}
	return
}
Exemplo n.º 2
0
func (self *FopImgInfo) doTestGetImgInfo(downloadUrl string) (msg string, err error) {
	begin := time.Now()
	url := downloadUrl + "?imageInfo"
	netBuf, err := util.DoHttpGet(url)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("Fp    "+self.Env.Id+"_"+self.Name+"_doTestGetImgInfo", begin, end, duration)
	if err != nil {
		return
	}

	var serImgInfo ImageInfo
	json.Unmarshal(netBuf.Bytes(), &serImgInfo)
	locImgInfo := self.TargetImgInfo

	if err = CheckImgInfo(serImgInfo, locImgInfo); err != nil {
		return
	}
	return
}
Exemplo n.º 3
0
func (self *UpResuPut) doTestRSGet() (msg string, err error) {
	var ret rss.GetRet

	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rss.NewRS(&self.Conf, dt)
	if err != nil {
		return
	}
	begin := time.Now()
	ret, code, err := rsservice.Get(self.EntryURI, "", "", 3600)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("UP    "+self.Env.Id+"_"+self.Name+"_doTestRsGet", begin, end, duration)

	if err != nil || code != 200 {
		return
	}
	self.Url = ret.URL
	return
}
Exemplo n.º 4
0
func (self *FopImgOp) doTestImgOp(downloadUrl string) (msg string, err error) {
	begin := time.Now()
	url := downloadUrl + "?" + self.Op
	netBuf, err := util.DoHttpGet(url)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("Fp    "+self.Env.Id+"_"+self.Name+"_doTestImgOp", begin, end, duration)
	if err != nil {
		return
	}
	targetFile, err := os.Open(self.TargetImg)
	if err != nil {
		return
	}
	_, err = util.CheckImg(netBuf, targetFile)
	if err != nil {
		return
	}

	return
}
Exemplo n.º 5
0
func (self *UpResuPut) doTestPut() (msg string, err error) {
	var conf service.Config
	// load config
	self.buildConfig(&conf)
	self.Conf = conf
	DataFile := self.DataFile
	entry := self.Bucket + ":" + self.Key
	self.EntryURI = entry
	dt := digest.NewTransport(conf.AccessKey, conf.SecretKey, nil)
	upservice, _ := up.NewService(&conf, dt, 1, 1)

	f, err := os.Open(DataFile)
	if err != nil {
		return
	}
	defer f.Close()
	fi, err := f.Stat()
	blockCnt := upservice.BlockCount(fi.Size())

	var (
		checksums []string           = make([]string, blockCnt)
		progs     []up.BlockProgress = make([]up.BlockProgress, blockCnt)
		ret       up.PutRet
		code      int
	)
	begin := time.Now()
	code, err = upservice.Put(f, fi.Size(), checksums, progs, func(int, string) {}, func(int, *up.BlockProgress) {})

	if err != nil || code != 200 {
		return
	}
	code, err = upservice.Mkfile(&ret, "/rs-mkfile/", entry, fi.Size(), "", "", checksums)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("UP    "+self.Env.Id+"_"+self.Name+"_doTestPut", begin, end, duration)
	if err != nil || code != 200 {
		return
	}
	return
}