Esempio n. 1
0
func main() {
	flag.Parse()
	if flag.NArg() < 2 {
		LOGE.Fatalln("Usage: ./stressclient <user> <numTargets>")
	}

	client, err := tribclient.NewTribClient("localhost", *portnum)
	if err != nil {
		LOGE.Fatalln("FAIL: NewTribClient returned error:", err)
	}

	user := flag.Arg(0)
	userNum, err := strconv.Atoi(user)
	if err != nil {
		LOGE.Fatalf("FAIL: user %s not an integer\n", user)
	}
	numTargets, err := strconv.Atoi(flag.Arg(1))
	if err != nil {
		LOGE.Fatalf("FAIL: numTargets invalid %s\n", flag.Arg(1))
	}

	_, err = client.CreateUser(user)
	if err != nil {
		LOGE.Fatalf("FAIL: error when creating userID '%s': %s\n", user, err)
	}

	tribIndex := 0
	if *seed == 0 {
		rand.Seed(time.Now().UnixNano())
	} else {
		rand.Seed(*seed)
	}

	cmds := make([]int, *numCmds)
	for i := 0; i < *numCmds; i++ {
		cmds[i] = rand.Intn(6)
		switch cmds[i] {
		case GetSubscription:
			gs++
		case AddSubscription:
			as++
		case RemoveSubscription:
			rs++
		case GetTribbles:
			gt++
		case PostTribble:
			pt++
		case GetTribblesBySubscription:
			gtbs++
		}
	}

	if debug {
		// Prints out the total number of operations that will be performed.
		fmt.Println("GetSubscriptions:", gs)
		fmt.Println("AddSubscription:", as)
		fmt.Println("RemoveSubscription:", rs)
		fmt.Println("GetTribbles:", gt)
		fmt.Println("PostTribble:", pt)
		fmt.Println("GetTribblesBySubscription:", gtbs)
	}

	for _, cmd := range cmds {
		switch cmd {
		case GetSubscription:
			subscriptions, status, err := client.GetSubscriptions(user)
			if err != nil {
				LOGE.Fatalf("FAIL: GetSubscriptions returned error '%s'\n", err)
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: GetSubscriptions returned error status '%s'\n", statusMap[status])
			}
			if !validateSubscriptions(&subscriptions) {
				LOGE.Fatalln("FAIL: failed while validating returned subscriptions")
			}
		case AddSubscription:
			target := rand.Intn(numTargets)
			status, err := client.AddSubscription(user, strconv.Itoa(target))
			if err != nil {
				LOGE.Fatalf("FAIL: AddSubscription returned error '%s'\n", err)
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: AddSubscription returned error status '%s'\n", statusMap[status])
			}
		case RemoveSubscription:
			target := rand.Intn(numTargets)
			status, err := client.RemoveSubscription(user, strconv.Itoa(target))
			if err != nil {
				LOGE.Fatalf("FAIL: RemoveSubscription returned error '%s'\n", err)
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: RemoveSubscription returned error status '%s'\n", statusMap[status])
			}
		case GetTribbles:
			target := rand.Intn(numTargets)
			tribbles, status, err := client.GetTribbles(strconv.Itoa(target))
			if err != nil {
				LOGE.Fatalf("FAIL: GetTribbles returned error '%s'\n", err)
			}
			if status == 0 {
				LOGE.Fatalf("FAIL: GetTribbles returned error status '%s'\n", statusMap[status])
			}
			if !validateTribbles(&tribbles, numTargets) {
				LOGE.Fatalln("FAIL: failed while validating returned tribbles")
			}
		case PostTribble:
			tribVal := userNum + tribIndex*numTargets
			msg := fmt.Sprintf("%d;%s", tribVal, *clientId)
			status, err := client.PostTribble(user, msg)
			if err != nil {
				LOGE.Fatalf("FAIL: PostTribble returned error '%s'\n", err)
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: PostTribble returned error status '%s'\n", statusMap[status])
			}
			tribIndex++
		case GetTribblesBySubscription:
			tribbles, status, err := client.GetTribblesBySubscription(user)
			if err != nil {
				LOGE.Fatalf("FAIL: GetTribblesBySubscription returned error '%s'\n", err)
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: GetTribblesBySubscription returned error status '%s'\n", statusMap[status])
			}
			if !validateTribbles(&tribbles, numTargets) {
				LOGE.Fatalln("FAIL: failed while validating returned tribbles")
			}
		}
	}
	fmt.Println("PASS")
	os.Exit(7)
}
Esempio n. 2
0
func main() {
	flag.Parse()
	if flag.NArg() < 2 {
		flag.Usage()
		os.Exit(1)
	}
	cmd := flag.Arg(0)
	client, err := tribclient.NewTribClient("localhost", *port)
	if err != nil {
		log.Fatalln("Failed to create TribClient:", err)
	}

	cmdlist := []cmdInfo{
		{"uc", "TribServer.CreateUser", 1},
		{"sl", "TribServer.GetSubscriptions", 1},
		{"sa", "TribServer.AddSubscription", 2},
		{"sr", "TribServer.RemoveSubscription", 2},
		{"tl", "TribServer.GetTribbles", 1},
		{"tp", "TribServer.AddTribble", 2},
		{"ts", "TribServer.GetTribblesBySubscription", 1},
	}

	cmdmap := make(map[string]cmdInfo)
	for _, j := range cmdlist {
		cmdmap[j.cmdline] = j
	}

	ci, found := cmdmap[cmd]
	if !found {
		flag.Usage()
		os.Exit(1)
	}
	if flag.NArg() < (ci.nargs + 1) {
		flag.Usage()
		os.Exit(1)
	}

	switch cmd {
	case "uc": // user create
		status, err := client.CreateUser(flag.Arg(1))
		printStatus(ci.funcname, status, err)
	case "sl": // subscription list
		subs, status, err := client.GetSubscriptions(flag.Arg(1))
		printStatus(ci.funcname, status, err)
		if err == nil && status == tribrpc.OK {
			fmt.Println(strings.Join(subs, " "))
		}
	case "sa":
		status, err := client.AddSubscription(flag.Arg(1), flag.Arg(2))
		printStatus(ci.funcname, status, err)
	case "sr": // subscription remove
		status, err := client.RemoveSubscription(flag.Arg(1), flag.Arg(2))
		printStatus(ci.funcname, status, err)
	case "tl": // tribble list
		tribbles, status, err := client.GetTribbles(flag.Arg(1))
		printStatus(ci.funcname, status, err)
		if err == nil && status == tribrpc.OK {
			printTribbles(tribbles)
		}
	case "ts": // tribbles by subscription
		tribbles, status, err := client.GetTribblesBySubscription(flag.Arg(1))
		printStatus(ci.funcname, status, err)
		if err == nil && status == tribrpc.OK {
			printTribbles(tribbles)
		}
	case "tp": // tribble post
		status, err := client.PostTribble(flag.Arg(1), flag.Arg(2))
		printStatus(ci.funcname, status, err)
	}
}
Esempio n. 3
0
func main() {
	flag.Parse()
	if flag.NArg() < 2 {
		log.Fatalln("Usage: ./stressclient <user> <numTargets>")
	}

	client, _ := tribclient.NewTribClient("localhost", *portnum)

	user := flag.Arg(0)
	userNum, err := strconv.Atoi(user)
	if err != nil {
		log.Fatalf("FAIL: user %s not an integer\n", user)
	}
	numTargets, err := strconv.Atoi(flag.Arg(1))
	if err != nil {
		log.Fatalf("FAIL: numTargets invalid %s\n", flag.Arg(1))
	}

	client.CreateUser(user)
	if err != nil {
		log.Fatalf("FAIL: error when creating user %s\n", user)
		return
	}

	failed := false
	tribIndex := 0
	if *seed == 0 {
		rand.Seed(time.Now().UnixNano())
	} else {
		rand.Seed(*seed)
	}
	for i := 0; i < *numCmds; i++ {
		funcnum := rand.Intn(6)

		switch funcnum {
		case 0: //client.GetSubscription
			subscriptions, status, err := client.GetSubscriptions(user)
			if err != nil || status == tribrpc.NoSuchUser {
				failTest("error with GetSubscriptions")
			}
			failed = !validateSubscriptions(&subscriptions)
		case 1: //client.AddSubscription
			target := rand.Intn(numTargets)
			status, err := client.AddSubscription(user, strconv.Itoa(target))
			if err != nil || status == tribrpc.NoSuchUser {
				failTest("error with AddSubscription")
			}
		case 2: //client.RemoveSubscription
			target := rand.Intn(numTargets)
			status, err := client.RemoveSubscription(user, strconv.Itoa(target))
			if err != nil || status == tribrpc.NoSuchUser {
				failTest("error with RemoveSubscription")
			}
		case 3: //client.GetTribbles
			target := rand.Intn(numTargets)
			tribbles, _, err := client.GetTribbles(strconv.Itoa(target))
			if err != nil {
				failTest("error with GetTribbles")
			}
			failed = !validateTribbles(&tribbles, numTargets)
		case 4: //client.PostTribble
			tribVal := userNum + tribIndex*numTargets
			msg := fmt.Sprintf("%d;%s", tribVal, *clientId)
			status, err := client.PostTribble(user, msg)
			if err != nil || status == tribrpc.NoSuchUser {
				failTest("error with PostTribble")
			}
			tribIndex++
		case 5: //client.GetTribblesBySubscription
			tribbles, status, err := client.GetTribblesBySubscription(user)
			if err != nil || status == tribrpc.NoSuchUser {
				failTest("error with GetTribblesBySubscription")
			}
			failed = !validateTribbles(&tribbles, numTargets)
		}
		if failed {
			failTest("tribbler output invalid")
		}
	}

	fmt.Println("PASS")
	os.Exit(7)
}
Esempio n. 4
0
func main() {
	flag.Parse()
	if flag.NArg() < 2 {
		LOGE.Fatalln("Usage: ./stressclient <user> <numTargets>")
	}

	client, err := tribclient.NewTribClient("localhost", *portnum)
	if err != nil {
		LOGE.Fatalln("FAIL: NewTribClient returned error:", err)
	}

	user := flag.Arg(0)
	userNum, err := strconv.Atoi(user)
	if err != nil {
		LOGE.Fatalf("FAIL: user %s not an integer\n", user)
	}
	numTargets, err := strconv.Atoi(flag.Arg(1))
	if err != nil {
		LOGE.Fatalf("FAIL: numTargets invalid %s\n", flag.Arg(1))
	}

	_, err = client.CreateUser(user)
	if err != nil {
		LOGE.Fatalf("FAIL: error when creating userID '%s': %s\n", user, err)
	}

	tribIndex := 0
	if *seed == 0 {
		rand.Seed(time.Now().UnixNano())
	} else {
		rand.Seed(*seed)
	}

	cmds := make([]int, *numCmds)
	for i := 0; i < *numCmds; i++ {
		cmds[i] = rand.Intn(6)
		switch cmds[i] {
		case GetSubscription:
			gs++
		case AddSubscription:
			as++
		case RemoveSubscription:
			rs++
		case GetTribbles:
			gt++
		case PostTribble:
			pt++
		case GetTribblesBySubscription:
			gtbs++
		}
	}

	if debug {
		// Prints out the total number of operations that will be performed.
		fmt.Println("GetSubscriptions:", gs)
		fmt.Println("AddSubscription:", as)
		fmt.Println("RemoveSubscription:", rs)
		fmt.Println("GetTribbles:", gt)
		fmt.Println("PostTribble:", pt)
		fmt.Println("GetTribblesBySubscription:", gtbs)
	}
	// file := os.OpenFile("file.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	// multi := io.MultiWriter(file, os.Stdout)
	// var mylog = log.New(multi, "", log.Lshortfile|log.Lmicroseconds)
	file, err := os.OpenFile("file.txt", os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		return
	}
	mylog := log.New(file, "PREFIX: ", log.Ldate|log.Ltime|log.Lshortfile)
	for _, cmd := range cmds {
		switch cmd {
		case GetSubscription:
			mylog.Println("in GetSubscription")
			subscriptions, status, err := client.GetSubscriptions(user)
			if err != nil {
				LOGE.Fatalf("FAIL: GetSubscriptions returned error '%s'\n", err)
				mylog.Println("GetSubscription Error")
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: GetSubscriptions returned error status '%s'\n", statusMap[status])
				mylog.Println("GetSubscription Error")
			}
			if !validateSubscriptions(&subscriptions) {
				LOGE.Fatalln("FAIL: failed while validating returned subscriptions")
				mylog.Println("GetSubscription Error")
			}
		case AddSubscription:
			mylog.Println("in AddSubscription")
			target := rand.Intn(numTargets)
			status, err := client.AddSubscription(user, strconv.Itoa(target))
			if err != nil {
				LOGE.Fatalf("FAIL: AddSubscription returned error '%s'\n", err)
				mylog.Println("AddSubscription Error")
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: AddSubscription returned error status '%s'\n", statusMap[status])
				mylog.Println("AddSubscription Error")
			}
		case RemoveSubscription:
			mylog.Println("in RemoveSubscription")
			target := rand.Intn(numTargets)
			status, err := client.RemoveSubscription(user, strconv.Itoa(target))
			if err != nil {
				LOGE.Fatalf("FAIL: RemoveSubscription returned error '%s'\n", err)
				mylog.Println("RemoveSubscription Error")
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: RemoveSubscription returned error status '%s'\n", statusMap[status])
				mylog.Println("RemoveSubscription Error")
			}
		case GetTribbles:
			mylog.Println("in GetTribbles")
			target := rand.Intn(numTargets)
			tribbles, status, err := client.GetTribbles(strconv.Itoa(target))
			if err != nil {
				LOGE.Fatalf("FAIL: GetTribbles returned error '%s'\n", err)
				mylog.Println("GetTribbles Error")
			}
			if status == 0 {
				LOGE.Fatalf("FAIL: GetTribbles returned error status '%s'\n", statusMap[status])
				mylog.Println("GetTribbles Error")
			}
			if !validateTribbles(&tribbles, numTargets) {
				LOGE.Fatalln("FAIL: failed while validating returned tribbles")
				mylog.Println("GetTribbles Error")
			}
		case PostTribble:
			mylog.Println("in PostTribble")
			tribVal := userNum + tribIndex*numTargets
			msg := fmt.Sprintf("%d;%s", tribVal, *clientId)
			reply, err := client.PostTribble(user, msg)
			if err != nil {
				LOGE.Fatalf("FAIL: PostTribble returned error '%s'\n", err)
				mylog.Println("PostTribble Error")
			}
			if reply.Status == 0 || reply.Status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: PostTribble returned error status '%s'\n", statusMap[reply.Status])
				mylog.Println("PostTribble Error")
			}
			tribIndex++
		case GetTribblesBySubscription:
			mylog.Println("in GetTribblesBySubscription")
			tribbles, status, err := client.GetTribblesBySubscription(user)
			if err != nil {
				LOGE.Fatalf("FAIL: GetTribblesBySubscription returned error '%s'\n", err)
				mylog.Println("GetTribblesBySubscription Error")
			}
			if status == 0 || status == tribrpc.NoSuchUser {
				LOGE.Fatalf("FAIL: GetTribblesBySubscription returned error status '%s'\n", statusMap[status])
				mylog.Println("GetTribblesBySubscription Error")
			}
			if !validateTribbles(&tribbles, numTargets) {
				LOGE.Fatalln("FAIL: failed while validating returned tribbles")
				mylog.Println("GetTribblesBySubscription Error")
			}
		}
	}
	fmt.Println("PASS")
	os.Exit(7)
}