Exemple #1
0
func TestDefault(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	err := AddDefault2("mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local")
	if err != nil {
		t.Error(err.Error())
		return
	}
	err = AddDefault2("mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local")
	if err != nil {
		t.Error(err.Error())
		return
	}
	if Db() == nil {
		t.Error("error")
		return
	}
	// time.Sleep(5 * time.Second)
	wg := &sync.WaitGroup{}
	rundb := func() {
		iv, err := dbutil.DbQueryInt(Db(), "select 1")
		if err != nil {
			t.Error(err.Error())
		}
		wg.Done()
		fmt.Println(iv)
	}
	wg.Add(3)
	for i := 0; i < 3; i++ {
		go rundb()
	}
	wg.Wait()
}
Exemple #2
0
func tmgo() {
	runtime.GOMAXPROCS(util.CPU())
	dbm.ShowLog = true
	// for {
	// 	ss, err := xmgo.Dial("cny:[email protected]:27017/cny")
	// 	fmt.Println(ss, err)
	// 	if err == nil {
	// 		time.Sleep(1000 * time.Second)
	// 	}
	// }
	// err := mgo.AddDefault("cny:[email protected]:27017/cny", "cny")
	// if err != nil {
	// 	fmt.Println(err.Error())
	// 	return
	// }
	// time.Sleep(500 * time.Second)
	mgo.AddDefault2("cny:[email protected]:27017/cny*8")
	fmt.Println("add done...")
	time.Sleep(10000 * time.Second)
	rundb := func(v int) {
		fmt.Println("running->", v)
		err := mgo.C("abc").Insert(bson.M{"a": 1, "b": 2})
		if err != nil {
			panic(err.Error())
		}
		fmt.Println("done->", v)
	}
	for {
		for i := 0; i < 5; i++ {
			go rundb(i)
		}
		time.Sleep(100 * time.Millisecond)
	}
	fmt.Println("all done...")
}
Exemple #3
0
func tsql() {
	runtime.GOMAXPROCS(util.CPU())
	err := sql.AddDefault("mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local", 5, 8)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	// time.Sleep(500 * time.Second)
	err = sql.AddDefault("mysql", "cny:123@tcp(127.0.0.1:3306)/test?charset=utf8&loc=Local", 5, 8)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Println("add done...")
	rundb := func(v int) {
		fmt.Println("running->", v)
		iv, err := dbutil.DbQueryI(sql.Db(), "select 1")
		if err != nil {
			panic(err.Error())
		}
		fmt.Println("done->", iv, v)
	}
	for {
		for i := 0; i < 5; i++ {
			go rundb(i)
		}
		time.Sleep(3 * time.Second)
	}
	fmt.Println("all done...")
}
Exemple #4
0
func TestDefault(t *testing.T) {
	dbm.ShowLog = true
	time.Sleep(time.Second)
	runtime.GOMAXPROCS(util.CPU())
	Default = dbm.NewMDbs2()
	err := AddDefault("cny:[email protected]:27017/cny", "cny")
	if err != nil {
		t.Error(err.Error())
		return
	}
	err = AddDefault("cny:[email protected]:27017/cny", "cny")
	if err != nil {
		t.Error(err.Error())
		return
	}
	if Db() == nil {
		t.Error("error")
		return
	}
	Db().C("abc").DropCollection()
	//
	err = ChkIdx(C, Indexes)
	if err != nil {
		t.Error(err.Error())
		return
	}
	err = ChkIdx(C, Indexes2)
	if err != nil {
		t.Error(err.Error())
		return
	}
	// time.Sleep(5 * time.Second)
	wg := &sync.WaitGroup{}
	rundb := func() {
		err := C("abc").Insert(bson.M{"a": 1, "b": 2})
		if err != nil {
			t.Error(err.Error())
		}
		wg.Done()
	}
	wg.Add(3)
	for i := 0; i < 3; i++ {
		go rundb()
	}
	wg.Wait()
	// Default.SelMDb().Close()
	// Default.SelMDb().Close()
	// C("abc").Insert(bson.M{"a": 1, "b": 2})
	time.Sleep(2 * time.Second)
}
Exemple #5
0
func TestPerformance(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	dbm.ShowLog = true
	err := AddDefault2("mysql", "cny:123@tcp(192.168.2.57:3306)/test?charset=utf8&loc=Local")
	if err != nil {
		t.Error(err.Error())
		return
	}
	used, err := tutil.DoPerf(5000, "", func(i int) {
		_, err = dbutil.DbQueryF(Db(), "select 1")
		if err != nil {
			t.Error(err.Error())
		}
	})
	fmt.Println(used, err)
}
Exemple #6
0
func main() {
	runtime.GOMAXPROCS(util.CPU())
	netw.ShowLog = true
	//netw.ShowLog_C = true
	//impl.ShowLog = true
	dnh := netw.NewDoNotH()
	dnh.ShowLog = true
	rcs = rc.NewRC_Listener_m_j(pool.BP, ":13424", dnh)
	rcs.AddToken3("abc", 1)
	rcs.AddHFunc("args_s", Args_s)
	rcs.AddHFunc("args_m", Args_m)
	rcs.AddHFunc("call_c", CallC)
	var err = rcs.Run()
	fmt.Println(err)
	http.ListenAndServe(":13425", nil)
}
Exemple #7
0
func TestDbL(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	Default = dbm.NewMDbs2()
	err := AddDbL("a1", "cny:[email protected]:27017/cny", "cny")
	if err != nil {
		t.Error(err.Error())
		return
	}
	err = AddDbL("a2", "cny:[email protected]:27017/cny", "cny")
	if err != nil {
		t.Error(err.Error())
		return
	}
	if DbBy("a1") == nil {
		t.Error("error")
		return
	}
	if DbBy("a2") == nil {
		t.Error("error")
		return
	}
	// time.Sleep(5 * time.Second)
	wg := &sync.WaitGroup{}
	rundb := func() {
		err = CBy("a1", "abc").Insert(bson.M{"a": 1, "b": 2})
		if err != nil {
			t.Error(err.Error())
		}
		err = CBy("a2", "abc").Insert(bson.M{"a": 1, "b": 2})
		if err != nil {
			t.Error(err.Error())
		}
		wg.Done()
	}
	wg.Add(3)
	for i := 0; i < 3; i++ {
		go rundb()
	}
	wg.Wait()
	time.Sleep(2 * time.Second)
	fmt.Println("all done")
}
Exemple #8
0
func TestMdbs(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	mdbs, _ := NewMDbs(&MockDb{})
	mdb, _ := NewMDb(&MockDb{})
	mdbs.Add(mdb)
	if mdbs.Db() == nil {
		t.Error("error")
		return
	}
	rundb := func() {
		if mdbs.Db() == nil {
			t.Error("error")
		}
	}
	go func() {
		for {
			for i := 0; i < 3; i++ {
				go rundb()
			}
			time.Sleep(2 * time.Second)
		}
	}()
	time.Sleep(15 * time.Second)
}
Exemple #9
0
func AddDbL2(key, driver, url string) error {
	return AddDbL(key, driver, url, util.CPU(), util.CPU()*2)
}
Exemple #10
0
func AddDefault2(driver, url string) error {
	return AddDefault(driver, url, util.CPU(), util.CPU()*2)
}
Exemple #11
0
func TestPerformance(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	Default = dbm.NewMDbs2()
	err := AddDefault("cny:[email protected]:27017/cny", "cny")
	if err != nil {
		t.Error(err.Error())
		return
	}
	fmt.Println("xxxx->")
	var added = map[int64]bool{}
	var lck = sync.RWMutex{}
	C(Sequence).RemoveAll(nil)
	fmt.Println(Next2("abc", 1))
	fmt.Println(Next2("abc", 10))
	used, err := tutil.DoPerf(2000, "", func(i int) {
		err := C("abc").Insert(bson.M{"a": 1, "b": 2})
		if err != nil {
			t.Error(err.Error())
			return
		}
		_, nv, err := Next2("abc", 1)
		if err != nil {
			t.Error(err.Error())
			return
		}
		_, nv2, err := Next(Sequence, "abc", 1)
		if err != nil {
			t.Error(err.Error())
			return
		}
		lck.Lock()
		if added[nv] {
			panic("exit")
		}
		if added[nv2] {
			panic("exit")
		}
		added[nv] = true
		added[nv2] = true
		lck.Unlock()
	})
	fmt.Println("used->", used, err)
	fmt.Println(Next2("abc", 0))
	//
	// added = map[int64]bool{}
	used, err = tutil.DoPerf(20000, "", func(i int) {
		nv := WaitNext("abc")
		if err != nil {
			t.Error(err.Error())
			return
		}
		nv2 := WaitNext("abc")
		if err != nil {
			t.Error(err.Error())
			return
		}
		lck.Lock()
		if added[nv] {
			fmt.Println(nv)
			fmt.Println(pool)
			panic("exists")
		}
		if added[nv2] {
			fmt.Println(nv2)
			panic("exists")
		}
		added[nv] = true
		added[nv2] = true
		lck.Unlock()
	})
	fmt.Println("used->", used, err)
	fmt.Println(Next2("abc", 0))
}
Exemple #12
0
func TestFFCM(t *testing.T) {
	runtime.GOMAXPROCS(util.CPU())
	//
	//
	//
	util.Exec("rm", "-f", "xx_*")
	var fcfg_s = util.NewFcfg3()
	fcfg_s.InitWithFilePath2("ffcm_s.properties", true)

	var sh = &dtcm_s_h{cw: make(chan int, 100)}
	var err error
	go func() {
		err := InitDtcmS(fcfg_s, dtm.MemDbc, sh)
		if err != nil {
			t.Error(err.Error())
			return
		}
		err = RunFFCM_S_V(fcfg_s)
		if err != nil {
			t.Error(err.Error())
			return
		}
	}()
	fmt.Println("xxx->")
	time.Sleep(1 * time.Second)
	go RunFFCM_C("ffcm_c.properties")
	time.Sleep(1 * time.Second)
	fmt.Println("xxxx--->a")
	err = SRV.AddTask("xx.mp4", "xx.mp4")
	if err != nil {
		t.Error(err.Error())
		return
	}
	fmt.Println("xxxx--->b")
	fmt.Println("xxxx--->c")
	<-sh.cw
	<-sh.cw
	util.Exec("rm", "-f", "xx_*")
	at_ts := httptest.NewServer(SRV.AddTaskH)
	res, err := at_ts.G2("/addTask?args=%v,%v", "xx.mp4", "xx_x")
	if res.IntVal("code") != 0 {
		t.Error("error")
		return
	}
	<-sh.cw
	<-sh.cw
	var vproc = SRV.AbsL[0].(*AbsV)
	if _, _, _, err = vproc.Build(SRV, "xkkd", nil, "xdds"); err == nil {
		t.Error("error")
		return
	}
	ts := httptest.NewServer2(NewVideoProc(CLIENT))
	ts.PostN("?tid=%v", "text/plain", bytes.NewBufferString(`
		`), "xxx")
	ts.PostN("?tid=%v&duration=1111", "text/plain", bytes.NewBufferString(`
		xx=
		progress=end
		`), "xxx")
	fmt.Println("xxxx--->d")
	//
	util.Exec("cp", "xx.mp4", "xx_mm")
	SRV.AddTask("xx_mm")
	SRV.AddTask("ffcm.sh")
	//
	// RunFFCM_S("ffcm_s.properties", dtm.MemDbc, sh)
	// RunFFCM_S_V(nil, dtm.MemDbc, sh)
	RunFFCM_C("ffcm_c.properties")
	//
	// StopFFCM_C()
	// StopFFCM_S()
	time.Sleep(2 * time.Second)
	//
	// StopFFCM_C()
	// StopFFCM_S()
	//
	res, err = at_ts.G2("/addTask?src=%v", "sfsd")
	if res.IntVal("code") == 0 {
		t.Error("error")
		return
	}
	CLIENT.Stop()
	SRV.Close()
	SRV = nil
	CLIENT = nil
	RunFFCM_S_V(nil)
	//
	//

	util.Exec("rm", "-f", "xx_*")
}
Exemple #13
0
func main() {
	var f, s string
	var base, token, name, alias string
	var log bool = false
	var hb int = 30
	olen := len(os.Args)
	for i := 1; i < olen; i++ {
		switch os.Args[i] {
		case "-f":
			if i < olen-1 {
				f = os.Args[i+1]
			}
		case "-s":
			if i < olen-1 {
				s = os.Args[i+1]
				i++
			}
		case "-base":
			if i < olen-1 {
				base = os.Args[i+1]
				i++
			}
		case "-token":
			if i < olen-1 {
				token = os.Args[i+1]
				i++
			}
		case "-name":
			if i < olen-1 {
				name = os.Args[i+1]
				i++
			}
		case "-alias":
			if i < olen-1 {
				alias = os.Args[i+1]
				i++
			}
		case "-hb":
			if i < olen-1 {
				t, err := strconv.ParseInt(os.Args[i+1], 10, 32)
				if err != nil {
					fmt.Println(err.Error())
					ef(1)
					return
				}
				hb = int(t)
				i++
			}
		case "-l":
			log = true
		case "-h":
			usage()
			ef(1)
			return
		}
	}
	runtime.GOMAXPROCS(util.CPU())
	if len(s) > 0 {
		RunHrvC(s, base, token, name, alias, log, hb)
	} else if len(f) > 0 {
		RunHrvS(f)
	} else {
		usage()
	}
}