Exemple #1
0
// placeVotes votes for votingDuration seconds.
func placeVotes(join chan int) {
	volt, err := voltdb.NewConnection("username", "", "localhost:21212")
	defer volt.Close()
	if err != nil {
		log.Fatalf("Connection error db. %v\n", err)
	}

	timeout := time.After(votingDuration)
	placedVotes := 0

	for {
		select {
		case <-timeout:
			join <- placedVotes
			return
		default:
			// construct a phoneNumber with a valid area code.
			var phoneNumber int64 = (5080000000 + int64(rand.Int31()))
			// pick a contestant at random (contestant ids are 1-based)
			var contestant = (rand.Int() % ttlContestants) + 1
			rsp, err := volt.Call("Vote", phoneNumber, contestant, 100)
			if err != nil {
				log.Fatalf("Error voting. %v\n", err)
			}
			if rsp.Status() == voltdb.SUCCESS {
				placedVotes++
			} else {
				fmt.Printf("Vote failed %#v\n", rsp)
			}
		}
	}
}
Exemple #2
0
func connectOrDie() *voltdb.Conn {
	volt, err := voltdb.NewConnection("username", "", "localhost:21212")
	if err != nil {
		log.Fatalf("Connection error %v\n", err)
	}
	if !volt.TestConnection() {
		log.Fatalf("Connection error: failed to ping VoltDB database.")
	}
	return volt
}
Exemple #3
0
func main() {
	volt, _ := voltdb.NewConnection("username", "", "localhost:21212")
	response, _ := volt.Call("@AdHoc", "select * from store order by Key limit 3;")
	type Row struct {
		Key   string
		Value string
	}
	var row Row
	for response.Table(0).HasNext() {
		response.Table(0).Next(&row)
		fmt.Printf("Row: %v %v\n", row.Key, row.Value)
	}
}