Merge pull request #765 from steveyen/more-TestIndexRollback-fixes
fix for TestIndexRollback unit tests
This commit is contained in:
commit
8a7990427f
|
@ -31,10 +31,9 @@ func (r *RollbackPoint) GetInternal(key []byte) []byte {
|
||||||
return r.meta[string(key)]
|
return r.meta[string(key)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollbackPoints returns an array of rollback points available
|
// RollbackPoints returns an array of rollback points available for
|
||||||
// for the application to make a decision on where to rollback
|
// the application to rollback to, with more recent rollback points
|
||||||
// to. A nil return value indicates that there are no available
|
// (higher epochs) coming first.
|
||||||
// rollback points.
|
|
||||||
func (s *Scorch) RollbackPoints() ([]*RollbackPoint, error) {
|
func (s *Scorch) RollbackPoints() ([]*RollbackPoint, error) {
|
||||||
if s.rootBolt == nil {
|
if s.rootBolt == nil {
|
||||||
return nil, fmt.Errorf("RollbackPoints: root is nil")
|
return nil, fmt.Errorf("RollbackPoints: root is nil")
|
||||||
|
@ -54,7 +53,7 @@ func (s *Scorch) RollbackPoints() ([]*RollbackPoint, error) {
|
||||||
|
|
||||||
snapshots := tx.Bucket(boltSnapshotsBucket)
|
snapshots := tx.Bucket(boltSnapshotsBucket)
|
||||||
if snapshots == nil {
|
if snapshots == nil {
|
||||||
return nil, fmt.Errorf("RollbackPoints: no snapshots available")
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rollbackPoints := []*RollbackPoint{}
|
rollbackPoints := []*RollbackPoint{}
|
||||||
|
|
|
@ -62,6 +62,15 @@ func TestIndexRollback(t *testing.T) {
|
||||||
go sh.mainLoop()
|
go sh.mainLoop()
|
||||||
go sh.persisterLoop()
|
go sh.persisterLoop()
|
||||||
|
|
||||||
|
// should have no rollback points initially
|
||||||
|
rollbackPoints, err := sh.RollbackPoints()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no err, got: %v, %d", err, len(rollbackPoints))
|
||||||
|
}
|
||||||
|
if len(rollbackPoints) != 0 {
|
||||||
|
t.Fatalf("expected no rollbackPoints, got %d", len(rollbackPoints))
|
||||||
|
}
|
||||||
|
|
||||||
// create a batch, insert 2 new documents
|
// create a batch, insert 2 new documents
|
||||||
batch := index.NewBatch()
|
batch := index.NewBatch()
|
||||||
doc := document.NewDocument("1")
|
doc := document.NewDocument("1")
|
||||||
|
@ -84,10 +93,13 @@ func TestIndexRollback(t *testing.T) {
|
||||||
_ = readerSlow.Close()
|
_ = readerSlow.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// fetch rollback points available as of here
|
// fetch rollback points after first batch
|
||||||
rollbackPoints, err := sh.RollbackPoints()
|
rollbackPoints, err = sh.RollbackPoints()
|
||||||
if err != nil || len(rollbackPoints) != 1 {
|
if err != nil {
|
||||||
t.Fatal(err, len(rollbackPoints))
|
t.Fatalf("expected no err, got: %v, %d", err, len(rollbackPoints))
|
||||||
|
}
|
||||||
|
if len(rollbackPoints) == 0 {
|
||||||
|
t.Fatalf("expected some rollbackPoints, got none")
|
||||||
}
|
}
|
||||||
|
|
||||||
// set this as a rollback point for the future
|
// set this as a rollback point for the future
|
||||||
|
@ -109,8 +121,8 @@ func TestIndexRollback(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rollbackPointsB, err := sh.RollbackPoints()
|
rollbackPointsB, err := sh.RollbackPoints()
|
||||||
if err != nil || len(rollbackPointsB) != 3 {
|
if err != nil || len(rollbackPointsB) <= len(rollbackPoints) {
|
||||||
t.Fatal(err, len(rollbackPointsB))
|
t.Fatalf("expected no err, got: %v, %d", err, len(rollbackPointsB))
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
|
|
Loading…
Reference in New Issue