Ejemplo n.º 1
0
func (p *Visitor) VisitFile(file string, fi os.FileInfo) {

	var (
		conf CaseInfo
	)
	log.Info("loading ", file, "...")
	if err := config.LoadEx(&conf, file); err != nil {
		log.Error("load err :", file, err)
		os.Exit(1)
	}
	if conf.Enable == true {
		if _, ok := p.cases[conf.Name]; ok || conf.Name == "" {
			log.Error("name err or duplicate: ", file, conf.Name, conf.Type)
			os.Exit(-1)
		}
		fun, ok := Cases[conf.Type]
		if !ok {
			log.Error("no such type :", conf.Type, conf.Name)
			os.Exit(1)
		}
		caseEntry := fun()
		err := caseEntry.Init(file, p.Env, p.DataPath)
		if err != nil {
			log.Error("init err :", conf.Name, conf.Type, err)
			os.Exit(1)
		}
		p.cases[conf.Name] = caseEntry
		log.Info("loaded", conf.Name, conf.Type)
	}
}
Ejemplo n.º 2
0
func main() {
	var (
		conf Config
	)
	confDir, _ := cc.GetConfigDir("qbox.me")
	var confName *string = flag.String("f", confDir+"/qboxtest.conf", "the config file")
	flag.Parse()
	log.Info("Use the config file of " + *confName)
	if err := config.LoadEx(&conf, *confName); err != nil {
		log.Error(err)
		return
	}

	runtime.GOMAXPROCS(conf.MaxProcs)

	cases := make(map[string]Interface)
	conf.Include = filepath1.Join(confDir, conf.Include)
	conf.DataPath = filepath1.Join(confDir, conf.DataPath)
	conf.Env = filepath1.Join(confDir, conf.Env)
	filepath.Walk(conf.Include, &Visitor{&conf, cases}, nil)

	check := func() bool {
		msg := fmt.Sprintf("begin check ...\n")
		errCount := 0
		count := 0
		for k, v := range cases {
			count++
			log.Info("begin check", k, "...")
			msg += fmt.Sprintf("[%v/%v]process %v <<<\n", count, len(cases), k)
			info, err := v.Test()
			log.Info("check done :\n", info, k, err)
			msg += info
			msg += "\n"
			if err != nil {
				msg += fmt.Sprintf("!!!!!!!!!!mon case [%v] err!!![%v]\n", k, errors.Detail(err))
				errCount++
			} else {
				msg += fmt.Sprintf("[no err]%v done <<<\n", k)
			}
		}
		msg += fmt.Sprintf("all cases finish[%v/%v] <<<\n", len(cases)-errCount, len(cases))
		fmt.Println("----------------- result ------------------")
		fmt.Println(msg)
		fmt.Println("-------------------------------------------")
		return errCount == 0
	}

	b := check()
	if b {
		os.Exit(0)
	} else {
		os.Exit(1)
	}
}
Ejemplo n.º 3
0
func (self *UpResuPut) doTestPut() (msg string, err error) {

	DataFile := self.DataFile
	entry := self.Bucket + ":" + self.Key
	self.EntryURI = entry
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	host := self.Env.Hosts["up"]
	ip := self.Env.Ips["up"]
	upservice, _ := up.NewService(host, ip, self.BlockBits, self.ChunkSize, self.PutRetryTimes, dt, 1, 1)
	log.Info(upservice)

	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.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestPut", begin, end, duration)
	if err != nil || code != 200 {
		return
	}
	return
}
Ejemplo n.º 4
0
func main() {

	flag.Parse()

	var conf config
	if err := qconfig.LoadEx(&conf, *confName); err != nil {
		return
	}

	log.SetOutputLevel(conf.DebugLevel)

	logName := logPrefix + strconv.Itoa(conf.LogIndex)
	logFile, err := os.Open(logName)
	if err != nil {
		log.Fatal("open ", logName, " fail: ", err)
	}
	defer func() {
		logFile.Close()
	}()

	defer save(&conf)
	go interruptSave(&conf)
	go successiveSave(&conf)

	var reader *bufio.Reader
	reader, conf.Off = getReader(logFile, conf.Off)

	line := make([]byte, 0, 128)
	now := time.Now()
	last := now
	for {
		now = time.Now()
		sleep(now, last, conf.IntervalNS)
		last = now

		// assume isPrefix nerver be true
		b, _, err := reader.ReadLine()
		line = append(line, b...)

		if err != nil {
			if !conf.Follow {
				break
			}

			newFile := reOpen(logFile, conf.MaxLogSize)
			if newFile == nil {
				continue
			}

			if logFile.Name() != newFile.Name() {
				conf.RW.Lock()
				conf.Off = 0
				conf.LogIndex = getLogIndex(newFile.Name())
				conf.RW.Unlock()
				log.Info("reOpen ", newFile.Name())
			}
			logFile.Close()
			logFile = newFile

			reader, conf.Off = getReader(logFile, conf.Off)

			continue
		}

		atomic.AddInt64(&conf.Off, int64(len(line))+1)

		if uri, ok := parseLine(string(line), conf.Uids, conf.ImageSuffixs); ok {
			preOp(conf.IODomain, string(uri), conf.Params, conf.Save)
		}

		line = line[:0]
	}
}