-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate_list_test.go
59 lines (54 loc) · 1.13 KB
/
generate_list_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package rankdb
// Copyright 2019 Vivino. All rights reserved
//
// See LICENSE file for license details
import (
"bufio"
"fmt"
"math/rand"
"os"
"testing"
"github.com/Vivino/rankdb/api/app"
"github.com/ugorji/go/codec"
)
func TestGenerateList(t *testing.T) {
t.SkipNow()
var (
mh codec.MsgpackHandle
h = &mh // or mh to use msgpack
elements = int(20 * 1e6)
)
f, err := os.Create(fmt.Sprintf("../%d-elements.msgp", elements))
if err != nil {
t.Fatal(err)
}
defer f.Close()
lst := app.RankList{
ID: fmt.Sprintf("list-%d-elements", elements),
LoadIndex: false,
Metadata: map[string]string{
"country": "dk",
"game": "2",
},
MergeSize: 500,
SplitSize: 2000,
Populate: make([]*app.Element, elements),
Set: "storage-set",
}
rng := rand.New(rand.NewSource(0x1984))
w := bufio.NewWriter(f)
defer w.Flush()
for i := 0; i < elements; i++ {
tb := rng.Uint32()
lst.Populate[i] = &app.Element{
ID: rng.Uint64(),
Score: uint64(elements - i),
TieBreaker: &tb,
}
}
enc := codec.NewEncoder(w, h)
err = enc.Encode(lst)
if err != nil {
t.Fatal(err)
}
}