TestChunkWriter_ReadAfterWrite ensures that chunk segment are cut at the set segment size and that the resulted segments includes the expected chunks data.
(t *testing.T)
| 3031 | // TestChunkWriter_ReadAfterWrite ensures that chunk segment are cut at the set segment size and |
| 3032 | // that the resulted segments includes the expected chunks data. |
| 3033 | func TestChunkWriter_ReadAfterWrite(t *testing.T) { |
| 3034 | chk1 := assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 1, nil, nil}}) |
| 3035 | chk2 := assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 2, nil, nil}}) |
| 3036 | chk3 := assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 3, nil, nil}}) |
| 3037 | chk4 := assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 4, nil, nil}}) |
| 3038 | chk5 := assureChunkFromSamples(t, []chunks.Sample{sample{0, 1, 5, nil, nil}}) |
| 3039 | chunkSize := len(chk1.Chunk.Bytes()) + chunks.MaxChunkLengthFieldSize + chunks.ChunkEncodingSize + crc32.Size |
| 3040 | |
| 3041 | tests := []struct { |
| 3042 | chks [][]chunks.Meta |
| 3043 | segmentSize, |
| 3044 | expSegmentsCount int |
| 3045 | expSegmentSizes []int |
| 3046 | }{ |
| 3047 | // 0:Last chunk ends at the segment boundary so |
| 3048 | // all chunks should fit in a single segment. |
| 3049 | { |
| 3050 | chks: [][]chunks.Meta{ |
| 3051 | { |
| 3052 | chk1, |
| 3053 | chk2, |
| 3054 | chk3, |
| 3055 | }, |
| 3056 | }, |
| 3057 | segmentSize: 3 * chunkSize, |
| 3058 | expSegmentSizes: []int{3 * chunkSize}, |
| 3059 | expSegmentsCount: 1, |
| 3060 | }, |
| 3061 | // 1:Two chunks can fit in a single segment so the last one should result in a new segment. |
| 3062 | { |
| 3063 | chks: [][]chunks.Meta{ |
| 3064 | { |
| 3065 | chk1, |
| 3066 | chk2, |
| 3067 | chk3, |
| 3068 | chk4, |
| 3069 | chk5, |
| 3070 | }, |
| 3071 | }, |
| 3072 | segmentSize: 2 * chunkSize, |
| 3073 | expSegmentSizes: []int{2 * chunkSize, 2 * chunkSize, chunkSize}, |
| 3074 | expSegmentsCount: 3, |
| 3075 | }, |
| 3076 | // 2:When the segment size is smaller than the size of 2 chunks |
| 3077 | // the last segment should still create a new segment. |
| 3078 | { |
| 3079 | chks: [][]chunks.Meta{ |
| 3080 | { |
| 3081 | chk1, |
| 3082 | chk2, |
| 3083 | chk3, |
| 3084 | }, |
| 3085 | }, |
| 3086 | segmentSize: 2*chunkSize - 1, |
| 3087 | expSegmentSizes: []int{chunkSize, chunkSize, chunkSize}, |
| 3088 | expSegmentsCount: 3, |
| 3089 | }, |
| 3090 | // 3:When the segment is smaller than a single chunk |
nothing calls this directly
no test coverage detected
searching dependent graphs…