Exemplo n.º 1
0
func TestPartDownloadWorker(t *testing.T) {
	return
	url := "http://releases.ubuntu.com/14.04.2/ubuntu-14.04.2-server-amd64.list"
	c, _ := httpclient.GetSize(url)
	c = c / 2
	f, _ := iotools.CreateSafeFile("g_ubuntu-14.04.2-server-amd64.list")
	defer f.Close()
	log.Println(f.Truncate(c))
	dow := httpclient.CreatePartialDownloader(url, f, 0, 0, c)
	mv := monitor.MonitoredWorker{Itw: dow}
	log.Println(mv.Start())
	log.Println(mv.Start())
	time.Sleep(time.Second * 1)
	log.Println(mv.Stop())
	time.Sleep(time.Second * 5)
	log.Println(mv.Start())
	log.Println(mv.Start())
	time.Sleep(time.Second * 5)
	log.Println(mv.Stop())
}
Exemplo n.º 2
0
func TestMultiPartDownloadWorker(t *testing.T) {
	partcount := 10
	pc := int64(partcount)
	url := "http://releases.ubuntu.com/14.04.2/ubuntu-14.04.2-server-amd64.list"
	c, _ := httpclient.GetSize(url)
	f, _ := iotools.CreateSafeFile("gm_ubuntu-14.04.2-server-amd64.list")
	defer f.Close()
	f.Truncate(c)
	ps := c / pc
	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}
		mv.Start()
	}
	lastseg := c - (ps * (pc - 1))
	dow := httpclient.CreatePartialDownloader(url, f, lastseg, lastseg, c)
	mv := monitor.MonitoredWorker{Itw: dow}
	mv.Start()

	time.Sleep(time.Second * 15)

}
Exemplo n.º 3
0
func TestWorker(t *testing.T) {
	tes := new(monitor.MonitoredWorker)
	itw := &TestWork{From: 1, To: 8, sleep: 300}
	tes.Itw = itw
	tes.Start()
	log.Println(tes.Start())
	time.Sleep(time.Second * 1)
	if tes.GetState() != 1 {
		t.Error("Expected Running(1)")
		return
	}
	tes.Stop()
	if tes.GetState() != 0 {
		t.Error("Expected Stoped(0)")
		return
	}
	tes.Start()
	time.Sleep(time.Second * 9)
	if tes.GetState() != 3 {
		t.Error("Expected Comlete(3)")
		return
	}

	tes.Start()
	time.Sleep(time.Second * 1)
	if tes.GetState() != 3 {
		t.Error("Expected Failed(3)")
		return
	}
}