Exemplo n.º 1
0
func TestMultiPartDownloadPool(t *testing.T) {
	partcount := 10
	pc := int64(partcount)
	url := "http://mirror.yandex.ru/ubuntu-releases/15.04/ubuntu-15.04-snappy-amd64%2bgeneric.img.xz"
	c, _ := httpclient.GetSize(url)
	f, _ := iotools.CreateSafeFile("ubuntu-15.04-snappy-amd64+generic.img.xz ")
	defer f.Close()
	f.Truncate(c)
	ps := c / pc
	wp := monitor.WorkerPool{}
	for i := int64(0); i < pc-1; i++ {
		//log.Println(ps*i, ps*i+ps)
		d := httpclient.CreatePartialDownloader(url, f, ps*i, ps*i, ps*i+ps)
		mv := monitor.MonitoredWorker{Itw: d}
		wp.AppendWork(&mv)
	}
	lastseg := c - (ps * (pc - 1))
	dow := httpclient.CreatePartialDownloader(url, f, lastseg, lastseg, c)
	mv := monitor.MonitoredWorker{Itw: dow}
	wp.AppendWork(&mv)
	wp.StartAll()
	time.Sleep(time.Second * 10000)

}
Exemplo n.º 2
0
func TestWorkerPool(t *testing.T) {
	wp := monitor.WorkerPool{}
	for i := 0; i < 20; i++ {
		mw := &monitor.MonitoredWorker{Itw: &TestWorkPool{From: 0, To: 20, id: rand.Int31()}}
		wp.AppendWork(mw)
	}
	wp.StartAll()
	time.Sleep(time.Second)
	log.Println("------------------Work Started------------------")
	log.Println(wp.GetAllProgress())
	log.Println("------------------Get All Progress--------------")
	time.Sleep(time.Second)
	wp.StopAll()
	log.Println("------------------Work Stop-------------------")

	time.Sleep(time.Second)
	wp.StartAll()
	time.Sleep(time.Second * 5)
	wp.StopAll()
	wp.StartAll()
	wp.StopAll()
}