Newer
Older
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"io/ioutil"
"math"
"os"
"testing"
"github.com/Sirupsen/logrus"
"github.com/dgraph-io/dgraph/commit"
"github.com/dgraph-io/dgraph/loader"
"github.com/dgraph-io/dgraph/posting"
"github.com/dgraph-io/dgraph/store"
"github.com/dgraph-io/dgraph/uid"
"github.com/dgraph-io/dgraph/x"
"github.com/dgryski/go-farm"
)
func TestQuery(t *testing.T) {
var numInstances uint64 = 2
mod := math.MaxUint64 / numInstances
minIdx0 := 0 * mod
minIdx1 := 1 * mod
logrus.SetLevel(logrus.DebugLevel)
dir, err := ioutil.TempDir("", "storetest_")
dir1, err1 := ioutil.TempDir("", "storetest1_")
if err != nil || err1 != nil {
t.Error(err)
return
}
defer os.RemoveAll(dir)
defer os.RemoveAll(dir1)
ps := new(store.Store)
ps.Init(dir)
ps1 := new(store.Store)
ps1.Init(dir1)
clog := commit.NewLogger(dir, "mutations", 50<<20)
clog.Init()
defer clog.Close()
posting.Init(clog)
uid.Init(ps)
loader.Init(ps, ps1)
list := []x.DirectedEdge{
{1, "friend", 2},
{2, "frined", 3},
{1, "friend", 3},
}
for _, obj := range list {
if farm.Fingerprint64([]byte(obj.Attribute))%numInstances == 0 {
key := posting.Key(edge.Entity, edge.Attribute)
plist := posting.GetOrCreate(key, ps1)
plist.AddMutation(edge, posting.Set)
if uid < minIdx0 || uid > minIdx0+mod-1 {
t.Error("Not the correct UID", err)
}
t.Logf("Instance-0 Correct UID", str, uid)
} else {
key := posting.Key(edge.Entity, edge.Attribute)
plist := posting.GetOrCreate(key, ps1)
plist.AddMutation(edge, posting.Set)
if uid < minIdx1 || uid > minIdx1+mod-1 {
t.Error("Not the correct UID", err)
}
t.Logf("Instance-1 Correct UID", str, uid)
}
}
}