Created
December 16, 2014 16:27
-
-
Save khaf/50809b45ba5645f9f80c to your computer and use it in GitHub Desktop.
ScanAll Test Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"math" | |
"runtime" | |
"time" | |
as "github.com/aerospike/aerospike-client-go" | |
) | |
const ( | |
HOSTNAME = "127.0.0.1" | |
PORT = 3000 | |
NAMESPACE = "test" | |
SET = "" | |
) | |
func panicOnError(err error) { | |
if err != nil { | |
log.Fatalln(err) | |
} | |
} | |
func main() { | |
runtime.GOMAXPROCS(runtime.NumCPU()) | |
client, err := as.NewClient(HOSTNAME, PORT) | |
panicOnError(err) | |
count := 0 | |
for i := 1; i < math.MaxInt16; i *= 2 { | |
for j := count; j < i; j++ { | |
key, _ := as.NewKey(NAMESPACE, SET, j) | |
err := client.PutBins(nil, key, as.NewBin("bin", j)) | |
panicOnError(err) | |
count++ | |
} | |
log.Printf("There are now %d records in the database...\n", i) | |
for j := 0; j < 3; j++ { | |
t := time.Now() | |
scan(client, i) | |
log.Printf("Scanning %d records took: %v\n", i, time.Now().Sub(t)) | |
} | |
} | |
} | |
// scans the database and checks if the number of returned records | |
// is the same as the expected number | |
func scan(client *as.Client, expectedRecordsCount int) { | |
recordset, err := client.ScanAll(nil, NAMESPACE, SET) | |
panicOnError(err) | |
count := 0 | |
L: | |
for { | |
select { | |
case rec := <-recordset.Records: | |
if rec == nil { | |
break L | |
} | |
count++ | |
case err := <-recordset.Errors: | |
panicOnError(err) | |
} | |
} | |
log.Println("Number of records returned by ScanAll:", count) | |
if expectedRecordsCount != count { | |
log.Fatalf("Expected ScanAll to return %d records, but it returned %d.\n", expectedRecordsCount, count) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment