Skip to content

Commit

Permalink
Merge dce4ebb into f9a23fb
Browse files Browse the repository at this point in the history
  • Loading branch information
sreekanth-cb committed Mar 17, 2020
2 parents f9a23fb + dce4ebb commit 5725194
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions index/scorch/scorch.go
Expand Up @@ -223,6 +223,7 @@ func (s *Scorch) openBolt() error {
s.introducerNotifier = make(chan *epochWatcher, 1)
s.revertToSnapshots = make(chan *snapshotReversion)
s.persisterNotifier = make(chan *epochWatcher, 1)
s.closeCh = make(chan struct{})

if !s.readOnly && s.path != "" {
err := s.removeOldZapFiles() // Before persister or merger create any new files.
Expand Down
110 changes: 110 additions & 0 deletions index/scorch/scorch_test.go
Expand Up @@ -163,6 +163,116 @@ func TestIndexOpenReopen(t *testing.T) {
}
}

func TestIndexOpenReopenWithInsert(t *testing.T) {
cfg := CreateConfig("TestIndexOpenReopen")
err := InitTest(cfg)
if err != nil {
t.Fatal(err)
}
defer func() {
err := DestroyTest(cfg)
if err != nil {
t.Log(err)
}
}()

analysisQueue := index.NewAnalysisQueue(1)
idx, err := NewScorch(Name, cfg, analysisQueue)
if err != nil {
t.Fatal(err)
}
err = idx.Open()
if err != nil {
t.Errorf("error opening index: %v", err)
}

var expectedCount uint64
reader, err := idx.Reader()
if err != nil {
t.Fatal(err)
}
docCount, err := reader.DocCount()
if err != nil {
t.Error(err)
}
if docCount != expectedCount {
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
}
err = reader.Close()
if err != nil {
t.Fatal(err)
}

// insert a doc
doc := document.NewDocument("1")
doc.AddField(document.NewTextField("name", []uint64{}, []byte("test")))
err = idx.Update(doc)
if err != nil {
t.Errorf("Error updating index: %v", err)
}
expectedCount++

reader, err = idx.Reader()
if err != nil {
t.Fatal(err)
}
docCount, err = reader.DocCount()
if err != nil {
t.Error(err)
}
if docCount != expectedCount {
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
}
err = reader.Close()
if err != nil {
t.Fatal(err)
}

// now close it
err = idx.Close()
if err != nil {
t.Fatal(err)
}

// try to open the index and insert data
err = idx.Open()
if err != nil {
t.Errorf("error opening index: %v", err)
}

// insert a doc
doc = document.NewDocument("2")
doc.AddField(document.NewTextField("name", []uint64{}, []byte("test2")))
err = idx.Update(doc)
if err != nil {
t.Errorf("Error updating index: %v", err)
}
expectedCount++

// check the doc count again after reopening it
reader, err = idx.Reader()
if err != nil {
t.Fatal(err)
}
docCount, err = reader.DocCount()
if err != nil {
t.Error(err)
}
if docCount != expectedCount {
t.Errorf("Expected document count to be %d got %d", expectedCount, docCount)
}
err = reader.Close()
if err != nil {
t.Fatal(err)
}

// now close it
err = idx.Close()
if err != nil {
t.Fatal(err)
}
}

func TestIndexInsert(t *testing.T) {
cfg := CreateConfig("TestIndexInsert")
err := InitTest(cfg)
Expand Down

0 comments on commit 5725194

Please sign in to comment.