Skip to content
Snippets Groups Projects
Commit f9dddbf9 authored by Manish R Jain's avatar Manish R Jain
Browse files

All tests pass with rocksdb store.

parent a05ecf4a
No related branches found
No related tags found
No related merge requests found
......@@ -124,6 +124,7 @@ func (l *Logger) Close() {
if err := l.curFile.Close(); err != nil {
glog.WithError(err).Error("While closing current file.")
}
l.curFile = nil
}
}
......@@ -162,6 +163,10 @@ func (l *Logger) handleFile(path string, info os.FileInfo, err error) error {
lf.endTs = ts
lf.path = path
l.list = append(l.list, lf)
if l.lastLogTs < lf.endTs {
l.lastLogTs = lf.endTs
}
return nil
}
......
......@@ -116,6 +116,10 @@ func mergeInterfaces(i1 interface{}, i2 interface{}) interface{} {
}
func postTraverse(g *SubGraph) (result map[uint64]interface{}, rerr error) {
if len(g.query) == 0 {
return result, nil
}
result = make(map[uint64]interface{})
// Get results from all children first.
cResult := make(map[uint64]interface{})
......
......@@ -29,10 +29,6 @@ import (
"github.com/dgraph-io/dgraph/store"
)
func NewStore() (string, error) {
return ioutil.TempDir("", "storetest_")
}
var q0 = `
{
user(_xid_:alice) {
......@@ -46,41 +42,49 @@ var q0 = `
}
`
func prepare() error {
dir, err := ioutil.TempDir("", "storetest_")
func prepare() (dir1, dir2 string, clog *commit.Logger, rerr error) {
var err error
dir1, err = ioutil.TempDir("", "storetest_")
if err != nil {
return err
return "", "", nil, err
}
defer os.RemoveAll(dir)
ps := new(store.Store)
ps.Init(dir)
ps.Init(dir1)
clog := commit.NewLogger(dir, "mutations", 50<<20)
dir2, err = ioutil.TempDir("", "storemuts_")
if err != nil {
return dir1, "", nil, err
}
clog = commit.NewLogger(dir2, "mutations", 50<<20)
clog.Init()
defer clog.Close()
posting.Init(ps, clog)
f, err := os.Open("testdata.nq")
if err != nil {
return err
return dir1, dir2, clog, err
}
defer f.Close()
_, err = handleRdfReader(f)
if err != nil {
return err
return dir1, dir2, clog, err
}
return nil
// Even though all files would be closed and the directory deleted,
// postings would still be present in memory.
return dir1, dir2, clog, nil
}
func closeAll(dir1, dir2 string, clog *commit.Logger) {
clog.Close()
os.RemoveAll(dir2)
os.RemoveAll(dir1)
}
func TestQuery(t *testing.T) {
if err := prepare(); err != nil {
dir1, dir2, clog, err := prepare()
if err != nil {
t.Error(err)
return
}
defer closeAll(dir1, dir2, clog)
// Parse GQL into internal query representation.
g, err := gql.Parse(q0)
......@@ -163,10 +167,12 @@ var q1 = `
`
func BenchmarkQuery(b *testing.B) {
if err := prepare(); err != nil {
dir1, dir2, clog, err := prepare()
if err != nil {
b.Error(err)
return
}
defer closeAll(dir1, dir2, clog)
b.ResetTimer()
for i := 0; i < b.N; i++ {
......
......@@ -17,6 +17,8 @@
package store
import (
"fmt"
"github.com/dgraph-io/dgraph/store/rocksdb"
"github.com/dgraph-io/dgraph/x"
)
......@@ -47,14 +49,12 @@ func (s *Store) Init(filepath string) {
}
}
/*
func (s *Store) IsNew(id uint64) bool {
return false
}
*/
func (s *Store) Get(key []byte) (val []byte, rerr error) {
return s.db.Get(s.ropt, key)
val, rerr = s.db.Get(s.ropt, key)
if rerr == nil && val == nil {
return []byte(""), fmt.Errorf("E_KEY_NOT_FOUND")
}
return val, rerr
}
func (s *Store) SetOne(k []byte, val []byte) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment