You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
|
2 months ago
|
package logstorage
|
||
|
|
|
||
|
|
import (
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestAuditCapacityRotatesOldestActiveSegment(t *testing.T) {
|
||
|
|
store := openTestStore(t, Options{AuditCapBytes: 1400})
|
||
|
|
for i := 0; i < 5; i++ {
|
||
|
|
if _, err := store.Append(ClassAudit, time.Now().Add(time.Duration(i)*time.Second), map[string]string{"message": strings.Repeat(string(rune('a'+i)), 400)}); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
snapshot, err := store.Snapshot()
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if snapshot.UsageBytes["audit"] > 1400 {
|
||
|
|
t.Fatalf("capacity exceeded: %+v", snapshot)
|
||
|
|
}
|
||
|
|
var messages []string
|
||
|
|
store.mu.Lock()
|
||
|
|
err = store.walkClassLocked(ClassAudit, false, func(event Envelope) error { messages = append(messages, string(event.Payload)); return nil })
|
||
|
|
store.mu.Unlock()
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if len(messages) == 0 || strings.Contains(strings.Join(messages, ""), strings.Repeat("a", 100)) || !strings.Contains(messages[len(messages)-1], strings.Repeat("e", 100)) {
|
||
|
|
t.Fatalf("rotation retained wrong records: %v", messages)
|
||
|
|
}
|
||
|
|
}
|