Skip to content

Commit

Permalink
satellite/metabasetest: order RawSegments by streamID and position
Browse files Browse the repository at this point in the history
Change-Id: I669c0c2361c2c7989c8e946eb1fbf2f52074ce0e
  • Loading branch information
Fadila82 committed Feb 25, 2022
1 parent 2d4760f commit 332e6af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 0 additions & 5 deletions satellite/metabase/copy_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,6 @@ func TestFinishCopyObject(t *testing.T) {
numberOfSegments := 10
copyStream := metabasetest.RandObjectStream()

// make sure segments are ordered as expected when checking database
if copyStream.StreamID.Less(obj.StreamID) {
obj, copyStream = copyStream, obj
}

originalObj := metabasetest.CreateTestObject{
CommitObject: &metabase.CommitObject{
ObjectStream: obj,
Expand Down
11 changes: 7 additions & 4 deletions satellite/metabase/metabasetest/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,28 @@ func (step Verify) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB

func sortObjects(objects []metabase.Object) {
sort.Slice(objects, func(i, j int) bool {
return bytes.Compare(objects[i].StreamID[:], objects[j].StreamID[:]) < 0
return objects[i].StreamID.Less(objects[j].StreamID)
})
}

func sortRawObjects(objects []metabase.RawObject) {
sort.Slice(objects, func(i, j int) bool {
return bytes.Compare(objects[i].StreamID[:], objects[j].StreamID[:]) < 0
return objects[i].StreamID.Less(objects[j].StreamID)
})
}

func sortRawSegments(segments []metabase.RawSegment) {
sort.Slice(segments, func(i, j int) bool {
return bytes.Compare(segments[i].StreamID[:], segments[j].StreamID[:]) < 0
if segments[i].StreamID == segments[j].StreamID {
return segments[i].Position.Less(segments[j].Position)
}
return segments[i].StreamID.Less(segments[j].StreamID)
})
}

func sortRawCopies(copies []metabase.RawCopy) {
sort.Slice(copies, func(i, j int) bool {
return bytes.Compare(copies[i].StreamID[:], copies[j].StreamID[:]) < 0
return copies[i].StreamID.Less(copies[j].StreamID)
})
}

Expand Down

0 comments on commit 332e6af

Please sign in to comment.