func initFilePath() (string, error) { cfg := kaiju.GetConfig() path := filepath.Join(kaiju.ConfigFileDir(), cfg.DataDir) if err := os.MkdirAll(path, os.ModePerm); err != nil { return "", err } else { return path, nil } }
func TestScanKeys(t *testing.T) { cfg := kaiju.GetConfig() path := filepath.Join(kaiju.ConfigFileDir(), cfg.DataDir) f := openFile(t, path, cfg.KdbFileName) wa := openFile(t, path, cfg.KdbWAFileName) db, err := Load(f, wa) if err != nil { t.Errorf("Failed load db %s", err) } r, g, err := db.enumerate(nil) if err != nil { t.Errorf("Failed to scan keys: %s", err) } t.Logf("KDB scanKeys %d %d", r, g) }
func _TestRebuild(t *testing.T) { cfg := kaiju.GetConfig() path := filepath.Join(kaiju.ConfigFileDir(), cfg.DataDir) f := openFile(t, path, cfg.KdbFileName) wa := openFile(t, path, cfg.KdbWAFileName) rebf := createFile(t, path, cfg.KdbFileName+".reb") rebwa := createFile(t, path, cfg.KdbWAFileName+".reb") db, err := Load(f, wa) if err != nil { t.Errorf("Failed to load db %s", err) } db2, err := db.Rebuild(cfg.KDBCapacity, rebf, rebwa) if err != nil { t.Errorf("Failed to rebuild db %s", err) } r, g, err := db2.enumerate(nil) if err != nil { t.Errorf("Failed to scan keys: %s", err) } t.Logf("KDB scanKeys %d %d", r, g) }
func TestKDB(t *testing.T) { cfg := kaiju.GetConfig() path := filepath.Join(kaiju.ConfigFileDir(), cfg.TempDataDir) os.MkdirAll(path, os.ModePerm) f := createFile(t, path, "testkdb.dat") wa := createFile(t, path, "testkdb.wa") capacity := uint32(1000) db, dberr := New(capacity, f, wa) if dberr != nil { t.Errorf("Failed to create KDB: %s", dberr) } for i := uint32(0); i < capacity/2; i++ { writeUint32(t, db, uint32(i), uint32(i)) } commit(t, db, 1) for i := uint32(0); i < capacity/2; i += 3 { removeUint32(t, db, uint32(i), uint32(i)) } commit(t, db, 2) for i := uint32(0); i < capacity/2; i += 3 { writeUint32(t, db, uint32(i), uint32(i)) } commit(t, db, 3) for i := capacity / 2; i < capacity; i++ { writeUint32(t, db, uint32(i), uint32(i)) } commit(t, db, 4) for i := uint32(0); i < capacity; i++ { testUint32(t, db, uint32(i), uint32(i)) } for i := uint32(0); i < capacity/10000; i++ { removeUint32(t, db, uint32(i), uint32(i)) } for i := uint32(0); i < capacity/10000; i++ { testNotUint32(t, db, uint32(i), uint32(i)) } for i := uint32(0); i < capacity/10000; i++ { writeUint32(t, db, uint32(i), uint32(i)) } for i := uint32(0); i < capacity; i++ { testUint32(t, db, uint32(i), uint32(i)) } r, g, err := db.enumerate(nil) if dberr != nil { t.Errorf("Failed to scan keys: %s", err) } t.Logf("KDB:keys %d %d", r, g) f.Seek(0, 0) wa.Seek(0, 0) db, dberr = Load(f, wa) if dberr != nil { t.Errorf("Failed to load KDB: %s", dberr) } else { for i := uint32(0); i < capacity; i++ { testUint32(t, db, uint32(i), uint32(i)) } } r, g, err = db.enumerate(nil) if dberr != nil { t.Errorf("Failed to scan keys: %s", err) } t.Logf("KDB:keys %d %d", r, g) if closeErr := f.Close(); closeErr != nil { t.Errorf("Error closing file: %s", closeErr) } }