Ejemplo n.º 1
0
func testInmemVoteFetcher() ([]FetchResult, error) {
	entries := make([]FetchResult, ENTRY_PER_FETCH)
	i := 0
	if len(estimates) > 0 {
		sampleEntries := estimates[len(estimates)-1]
		//log.Printf("sampleEntries: %v", sampleEntries)
		for ; i < int(float64(1-NEWLY_ADD_RATE)*ENTRY_PER_FETCH); i++ {
			//add score to existing entry
			sample := sampleEntries.results[rand.Int31n(int32(len(sampleEntries.results)))]
			up, down := int32(rand.Int31n(50)+1), int32(rand.Int31n(50)+1)
			entries[i] = FetchResult{
				id:     sample.id,
				score:  up - down,
				parent: sample.parent,
				vote:   uint32(up + down),
			}
		}
	}
	//make clock backward to assure all generated ids have timestamp before current getClock()
	genClock := getClock().Add(-1 * time.Second)
	for ; i < ENTRY_PER_FETCH; i++ {
		//add new entry
		up, down := int32(rand.Int31n(50)+1), int32(rand.Int31n(50)+1)
		entries[i] = FetchResult{
			id:     proto.UUID(node.GenUUID(genClock)),
			score:  up - down,
			parent: proto.UUID(rand.Int31n(50) + 1),
			vote:   uint32(up + down),
		}
		//parentMap[entries[i].id] = entries[i].parent
	}
	log.Printf("testInmemVoteFetcher: %v", entries)
	estimates = append(estimates, fetchCache{
		fetchAt: getClock(),
		results: entries,
	})
	return entries, nil
}
Ejemplo n.º 2
0
func (dbm *Database) UUID() proto.UUID {
	//var uuid UUID
	//err := DBM().Db.QueryRow("select experimental_unique_int()").Scan(&uuid)
	//return uuid, err
	return proto.UUID(yue.NewId())
}