MCPcopy
hub / github.com/kopia/kopia / TestWriteBufferChunk

Function TestWriteBufferChunk

internal/gather/gather_write_buffer_chunk_test.go:14–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestWriteBufferChunk(t *testing.T) {
15 // reset for testing
16 all := &chunkAllocator{
17 chunkSize: 100,
18 maxFreeListSize: 10,
19 }
20
21 // reset for testing
22 chunk1 := all.allocChunk()
23 _ = append(chunk1, []byte("chunk1")...)
24
25 if got, want := len(chunk1), 0; got != want {
26 t.Errorf("invalid chunk len: %v, want %v", got, want)
27 }
28
29 if got, want := cap(chunk1), all.chunkSize; got != want {
30 t.Errorf("invalid chunk cap: %v, want %v", got, want)
31 }
32
33 if got, want := all.freeListHighWaterMark, 0; got != want {
34 t.Errorf("unexpected high water mark %v, want %v", got, want)
35 }
36
37 chunk2 := all.allocChunk()
38 _ = append(chunk2, []byte("chunk2")...)
39
40 if got, want := all.freeListHighWaterMark, 0; got != want {
41 t.Errorf("unexpected high water mark %v, want %v", got, want)
42 }
43
44 all.releaseChunk(chunk2)
45
46 if got, want := all.freeListHighWaterMark, 1; got != want {
47 t.Errorf("unexpected high water mark %v, want %v", got, want)
48 }
49
50 all.releaseChunk(chunk1)
51
52 if got, want := all.freeListHighWaterMark, 2; got != want {
53 t.Errorf("unexpected high water mark %v, want %v", got, want)
54 }
55
56 // allocate chunk3 - make sure we got the same slice as chunk1 (LIFO)
57 chunk3 := all.allocChunk()
58 if got, want := chunk3[0:6], []byte("chunk1"); !bytes.Equal(got, want) {
59 t.Errorf("got wrong chunk data %q, want %q", string(got), string(want))
60 }
61
62 // allocate chunk4 - make sure we got the same slice as chunk1 (LIFO)
63 chunk4 := all.allocChunk()
64 if got, want := chunk4[0:6], []byte("chunk2"); !bytes.Equal(got, want) {
65 t.Errorf("got wrong chunk data %q, want %q", string(got), string(want))
66 }
67}
68
69func TestContigAllocatorChunkSize(t *testing.T) {
70 // verify that contiguous allocator has chunk size big enough for all splitter results

Callers

nothing calls this directly

Calls 4

allocChunkMethod · 0.95
releaseChunkMethod · 0.95
ErrorfMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected