@@ -4,80 +4,107 @@ import (
4
4
"testing"
5
5
"time"
6
6
7
+ "crypto/rand"
8
+
9
+ "github.com/oklog/ulid/v2"
7
10
"github.com/stretchr/testify/require"
8
11
9
12
"github.com/cortexproject/cortex/pkg/storage/tsdb"
10
13
)
11
14
12
15
func TestShouldConvertBlockToParquet (t * testing.T ) {
13
16
for _ , tc := range []struct {
14
- name string
15
- mint , maxt int64
16
- durations tsdb.DurationList
17
- expected bool
18
- noCompactMarkExist bool
17
+ name string
18
+ mint , maxt int64
19
+ durations tsdb.DurationList
20
+ expected bool
21
+ checkFunc NoCompactMarkCheckFunc
19
22
}{
20
23
{
21
24
name : "2h block. Don't convert" ,
22
25
mint : 0 ,
23
26
maxt : 2 * time .Hour .Milliseconds (),
24
27
durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
25
28
expected : false ,
29
+ checkFunc : func (bId ulid.ULID ) bool {
30
+ return false
31
+ },
26
32
},
27
33
{
28
34
name : "1h block. Don't convert" ,
29
35
mint : 0 ,
30
36
maxt : 1 * time .Hour .Milliseconds (),
31
37
durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
32
38
expected : false ,
39
+ checkFunc : func (bId ulid.ULID ) bool {
40
+ return false
41
+ },
33
42
},
34
43
{
35
- name : "2h block. Exist NoCompactMark. Convert" ,
36
- mint : 0 ,
37
- maxt : 2 * time .Hour .Milliseconds (),
38
- durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
39
- expected : true ,
40
- noCompactMarkExist : true ,
44
+ name : "2h block. Exist NoCompactMark. Convert" ,
45
+ mint : 0 ,
46
+ maxt : 2 * time .Hour .Milliseconds (),
47
+ durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
48
+ expected : true ,
49
+ checkFunc : func (bId ulid.ULID ) bool {
50
+ return true
51
+ },
41
52
},
42
53
{
43
- name : "1h block. Exist NoCompactMark. Convert" ,
44
- mint : 0 ,
45
- maxt : 1 * time .Hour .Milliseconds (),
46
- durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
47
- expected : true ,
48
- noCompactMarkExist : true ,
54
+ name : "1h block. Exist NoCompactMark. Convert" ,
55
+ mint : 0 ,
56
+ maxt : 1 * time .Hour .Milliseconds (),
57
+ durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
58
+ expected : true ,
59
+ checkFunc : func (bId ulid.ULID ) bool {
60
+ return true
61
+ },
49
62
},
50
63
{
51
64
name : "3h block. Convert" ,
52
65
mint : 0 ,
53
66
maxt : 3 * time .Hour .Milliseconds (),
54
67
durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
55
68
expected : true ,
69
+ checkFunc : func (bId ulid.ULID ) bool {
70
+ return false
71
+ },
56
72
},
57
73
{
58
74
name : "12h block. Convert" ,
59
75
mint : 0 ,
60
76
maxt : 12 * time .Hour .Milliseconds (),
61
77
durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
62
78
expected : true ,
79
+ checkFunc : func (bId ulid.ULID ) bool {
80
+ return false
81
+ },
63
82
},
64
83
{
65
84
name : "12h block with 1h offset. Convert" ,
66
85
mint : time .Hour .Milliseconds (),
67
86
maxt : 13 * time .Hour .Milliseconds (),
68
87
durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
69
88
expected : true ,
89
+ checkFunc : func (bId ulid.ULID ) bool {
90
+ return false
91
+ },
70
92
},
71
93
{
72
94
name : "24h block. Convert" ,
73
95
mint : 0 ,
74
96
maxt : 24 * time .Hour .Milliseconds (),
75
97
durations : tsdb.DurationList {2 * time .Hour , 12 * time .Hour },
76
98
expected : true ,
99
+ checkFunc : func (bId ulid.ULID ) bool {
100
+ return false
101
+ },
77
102
},
78
103
} {
79
104
t .Run (tc .name , func (t * testing.T ) {
80
- res := ShouldConvertBlockToParquet (tc .mint , tc .maxt , (& tc .durations ).ToMilliseconds (), tc .noCompactMarkExist )
105
+ id , err := ulid .New (ulid .Now (), rand .Reader )
106
+ require .NoError (t , err )
107
+ res := ShouldConvertBlockToParquet (tc .mint , tc .maxt , (& tc .durations ).ToMilliseconds (), id , tc .checkFunc )
81
108
require .Equal (t , tc .expected , res )
82
109
})
83
110
}
0 commit comments