feat: enforce tiered storage reservations
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWholeCommandEvictionOrderingAndAge_HP_STORE_06(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
now := time.Unix(2_000_000, 0)
|
||||
first := retentionUUID(1)
|
||||
second := retentionUUID(2)
|
||||
third := retentionUUID(3)
|
||||
active := retentionUUID(4)
|
||||
candidates := []RetentionCandidate{
|
||||
{IssueUUID: third, IssueTime: now.Add(-time.Hour), TerminalTime: now.Add(-31 * 24 * time.Hour), ChargedBytes: 30, Terminal: true},
|
||||
{IssueUUID: active, IssueTime: now.Add(-100 * 24 * time.Hour), ChargedBytes: 1000},
|
||||
{IssueUUID: second, IssueTime: now.Add(-2 * time.Hour), TerminalTime: now.Add(-time.Hour), ChargedBytes: 20, Terminal: true},
|
||||
{IssueUUID: first, IssueTime: now.Add(-2 * time.Hour), TerminalTime: now.Add(-time.Hour), ChargedBytes: 10, Terminal: true},
|
||||
}
|
||||
selection := SelectWholeCommandEvictions(now, 30*24*time.Hour, 45, candidates)
|
||||
want := [][16]byte{third, first, second}
|
||||
if !reflect.DeepEqual(selection.IssueUUIDs, want) || selection.ReleasedBytes != 60 {
|
||||
t.Fatalf("selection = %+v, want IDs %v and 60 bytes", selection, want)
|
||||
}
|
||||
selection = SelectWholeCommandEvictions(now, 0, 0, candidates)
|
||||
if len(selection.IssueUUIDs) != 0 {
|
||||
t.Fatalf("disabled age/no pressure selected %v", selection.IssueUUIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputRotationProtectsActiveSegmentAndFIFO_BH_STORE_07(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
selected := SelectOutputRotation(130, 100, []OutputSegmentCandidate{
|
||||
{Ordinal: 2, ChargedBytes: 50, Sealed: true},
|
||||
{Ordinal: 0, ChargedBytes: 20, Sealed: true},
|
||||
{Ordinal: 1, ChargedBytes: 20, Sealed: false},
|
||||
})
|
||||
if !reflect.DeepEqual(selected, []uint32{0, 2}) {
|
||||
t.Fatalf("rotation = %v", selected)
|
||||
}
|
||||
if got := FIFOEntriesToRemove(1_000_001, 1_000_000); got != 1 {
|
||||
t.Fatalf("FIFO removal = %d", got)
|
||||
}
|
||||
if got := FIFOEntriesToRemove(10, 10); got != 0 {
|
||||
t.Fatalf("FIFO boundary removal = %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func retentionUUID(last byte) [16]byte {
|
||||
var result [16]byte
|
||||
result[15] = last
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user