-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathchangefeed_processors_test.go
110 lines (107 loc) · 3.56 KB
/
changefeed_processors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2024 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
package changefeedccl
import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/stretchr/testify/require"
"testing"
)
// TestSetupSpansAndFrontier tests that the setupSpansAndFrontier function
// correctly sets up frontier for the changefeed aggregator frontier.
func TestSetupSpansAndFrontier(t *testing.T) {
for _, tc := range []struct {
name string
expectedFrontier hlc.Timestamp
watches []execinfrapb.ChangeAggregatorSpec_Watch
}{
{
name: "new initial scan",
expectedFrontier: hlc.Timestamp{},
watches: []execinfrapb.ChangeAggregatorSpec_Watch{
{
Span: roachpb.Span{Key: roachpb.Key("a"), EndKey: roachpb.Key("b")},
InitialResolved: hlc.Timestamp{},
},
{
Span: roachpb.Span{Key: roachpb.Key("b"), EndKey: roachpb.Key("c")},
InitialResolved: hlc.Timestamp{},
},
{
Span: roachpb.Span{Key: roachpb.Key("c"), EndKey: roachpb.Key("d")},
InitialResolved: hlc.Timestamp{},
},
},
},
{
name: "incomplete initial scan with non-empty initial resolved in the end",
expectedFrontier: hlc.Timestamp{},
watches: []execinfrapb.ChangeAggregatorSpec_Watch{
{
Span: roachpb.Span{Key: roachpb.Key("a"), EndKey: roachpb.Key("b")},
InitialResolved: hlc.Timestamp{WallTime: 5},
},
{
Span: roachpb.Span{Key: roachpb.Key("b"), EndKey: roachpb.Key("c")},
InitialResolved: hlc.Timestamp{},
},
{
Span: roachpb.Span{Key: roachpb.Key("c"), EndKey: roachpb.Key("d")},
InitialResolved: hlc.Timestamp{WallTime: 20},
},
},
},
{
name: "incomplete initial scan with empty initial resolved in the end",
expectedFrontier: hlc.Timestamp{},
watches: []execinfrapb.ChangeAggregatorSpec_Watch{
{
Span: roachpb.Span{Key: roachpb.Key("a"), EndKey: roachpb.Key("b")},
InitialResolved: hlc.Timestamp{WallTime: 10},
},
{
Span: roachpb.Span{Key: roachpb.Key("b"), EndKey: roachpb.Key("c")},
InitialResolved: hlc.Timestamp{WallTime: 20},
},
{
Span: roachpb.Span{Key: roachpb.Key("c"), EndKey: roachpb.Key("d")},
InitialResolved: hlc.Timestamp{},
},
},
},
{
name: "complete initial scan",
expectedFrontier: hlc.Timestamp{WallTime: 5},
watches: []execinfrapb.ChangeAggregatorSpec_Watch{
{
Span: roachpb.Span{Key: roachpb.Key("a"), EndKey: roachpb.Key("b")},
InitialResolved: hlc.Timestamp{WallTime: 10},
},
{
Span: roachpb.Span{Key: roachpb.Key("b"), EndKey: roachpb.Key("c")},
InitialResolved: hlc.Timestamp{WallTime: 20},
},
{
Span: roachpb.Span{Key: roachpb.Key("c"), EndKey: roachpb.Key("d")},
InitialResolved: hlc.Timestamp{WallTime: 5},
},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
ca := &changeAggregator{}
ca.spec = execinfrapb.ChangeAggregatorSpec{
Watches: tc.watches,
}
_, err := ca.setupSpansAndFrontier()
require.NoError(t, err)
require.Equal(t, tc.expectedFrontier, ca.frontier.Frontier())
})
}
}