Skip to content
Snippets Groups Projects
main_test.go 1.25 KiB
Newer Older
  • Learn to ignore specific revisions
  • Ashwin's avatar
    Ashwin committed
    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 numInstances uint64 = 2
    
    Ashwin's avatar
    Ashwin committed
    	mod := math.MaxUint64 / numInstances
    	minIdx0 := 0 * mod
    	minIdx1 := 1 * mod
    
    Ashwin's avatar
    Ashwin committed
    
    	logrus.SetLevel(logrus.DebugLevel)
    	dir, err := ioutil.TempDir("", "storetest_")
    	if err != nil {
    		t.Error(err)
    		return
    	}
    	defer os.RemoveAll(dir)
    
    Ashwin's avatar
    Ashwin committed
    
    
    Ashwin's avatar
    Ashwin committed
    	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 == 0 {
    			uid, err := rdf.GetUid(str, 0, numInstances)
    			if uid < minIdx0 || uid > minIdx0+mod-1 {
    				t.Error("Not the correct UID", err)
    			}
    
    Ashwin's avatar
    Ashwin committed
    			t.Logf("Instance-0", str, uid)
    
    			t.Logf("Correct UID")
    
    Ashwin's avatar
    Ashwin committed
    
    
    Ashwin's avatar
    Ashwin committed
    		} else {
    
    			uid, err := rdf.GetUid(str, 1, numInstances)
    			if uid < minIdx1 || uid > minIdx1+mod-1 {
    
    Ashwin's avatar
    Ashwin committed
    				t.Error("Not the correct UID", err)
    			}
    
    Ashwin's avatar
    Ashwin committed
    			t.Logf("Instance-1", str, uid)
    
    Ashwin's avatar
    Ashwin committed
    			t.Logf("Correct UID")
    		}
    	}
    }