From 65094b7079a885114deb80b09738ffed5005d96d Mon Sep 17 00:00:00 2001 From: Ashwin <ashwin2007ray@gmail.com> Date: Tue, 23 Feb 2016 18:29:19 +1100 Subject: [PATCH] added preliminary loader test --- server/loader/main_test.go | 38 +++++++++----------------------------- server/loader/test_input | 7 +++++++ 2 files changed, 16 insertions(+), 29 deletions(-) create mode 100644 server/loader/test_input diff --git a/server/loader/main_test.go b/server/loader/main_test.go index 1ccaa530..a348b441 100644 --- a/server/loader/main_test.go +++ b/server/loader/main_test.go @@ -1,8 +1,8 @@ package main import ( + "bufio" "io/ioutil" - "math" "os" "testing" @@ -12,16 +12,10 @@ import ( "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_") @@ -46,30 +40,16 @@ func TestQuery(t *testing.T) { uid.Init(ps) loader.Init(ps, ps1) - list := []x.DirectedEdge{ - {1, "friend", 2}, - {2, "frined", 3}, - {1, "friend", 3}, - } + f, err := os.Open("test_input") + r := bufio.NewReader(f) + count, err := loader.HandleRdfReader(r, 1, 2) + t.Logf("count", count) - 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) + posting.MergeLists(100) - } 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) + if farm.Fingerprint64([]byte("follows"))%2 == 1 { + if count != 4 { + t.Error("loader assignment not as expected") } } } diff --git a/server/loader/test_input b/server/loader/test_input new file mode 100644 index 00000000..642eec7f --- /dev/null +++ b/server/loader/test_input @@ -0,0 +1,7 @@ +`_:alice1 <follows> _:bob0 .` +`_:alice2 <follows> _:bob1 .` +`_:alice3 <follows> _:bob2 .` +`_:alice4 <follows> _:bob3 .` +`_:alice1 <friend1> _:bob5 .` +`_:alice2 <friend1> _:bob6 .` +`_:alice3 <friend1> _:bob7 .` -- GitLab