From 1c81b8aaa08bb6a37b3c635505b7cb2fb5fadbae Mon Sep 17 00:00:00 2001 From: Ashwin <ashwin2007ray@gmail.com> Date: Thu, 4 Feb 2016 07:45:21 +0000 Subject: [PATCH] unit test for uidassigner --- server/uidassigner/main_test.go | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 server/uidassigner/main_test.go diff --git a/server/uidassigner/main_test.go b/server/uidassigner/main_test.go new file mode 100644 index 00000000..91fb6537 --- /dev/null +++ b/server/uidassigner/main_test.go @@ -0,0 +1,53 @@ +package main + +import ( + "io/ioutil" + "math" + "os" + "testing" + + "github.com/Sirupsen/logrus" + "github.com/dgraph-io/dgraph/commit" + "github.com/dgraph-io/dgraph/posting" + "github.com/dgraph-io/dgraph/rdf" + "github.com/dgraph-io/dgraph/store" + "github.com/dgryski/go-farm" +) + +func TestQuery(t *testing.T) { + var instanceIdx uint64 = 0 + var numInstances uint64 = 2 + + var mod uint64 = math.MaxUint64 / numInstances + var minIdx uint64 = instanceIdx * mod + + logrus.SetLevel(logrus.DebugLevel) + + dir, err := ioutil.TempDir("", "storetest_") + if err != nil { + t.Error(err) + return + } + defer os.RemoveAll(dir) + ps := new(store.Store) + ps.Init(dir) + clog := commit.NewLogger(dir, "mutations", 50<<20) + clog.Init() + defer clog.Close() + + posting.Init(ps, clog) + + list := []string{"alice", "bob", "mallory", "ash", "man", "dgraph"} + + for _, str := range list { + if farm.Fingerprint64([]byte(str))%numInstances != instanceIdx { + continue + } else { + uid, err := rdf.GetUid(str, instanceIdx, numInstances) + if uid < minIdx || uid > minIdx+mod-1 { + t.Error("Not the correct UID", err) + } + t.Logf("Correct UID") + } + } +} -- GitLab