MCPcopy
hub / github.com/rqlite/rqlite / Test_CDC_SingleNode_PostLoadBoot

Function Test_CDC_SingleNode_PostLoadBoot

system_test/cdc_test.go:173–248  ·  view source on GitHub ↗

Test_CDC_SingleNode_PostLoadBoot verifies that CDC continues to operate after a node is loaded or booted.

(t *testing.T)

Source from the content-addressed store, hash-verified

171// Test_CDC_SingleNode_PostLoadBoot verifies that CDC continues to operate
172// after a node is loaded or booted.
173func Test_CDC_SingleNode_PostLoadBoot(t *testing.T) {
174 node := mustNewLeaderNode("node1")
175 defer node.Deprovision()
176
177 testEndpoint := cdctest.NewHTTPTestServer()
178
179 // Configure CDC before opening the store.
180 cdcCluster := cdc.NewCDCCluster(node.Store, node.Cluster, node.Client)
181 cdcService, err := cdc.NewService(node.ID, node.Dir, cdcCluster, mustCDCConfig(testEndpoint.URL()))
182 if err != nil {
183 t.Fatalf("failed to create CDC service: %s", err.Error())
184 }
185 node.CDC = cdcService
186 node.CDC.Start()
187 node.CDC.SetLeader(true)
188
189 node.Store.EnableCDC(node.CDC.C(), nil, false)
190
191 _, err = node.Execute(`CREATE TABLE foo (id integer not null primary key, name text)`)
192 if err != nil {
193 t.Fatalf("failed to create table: %v", err)
194 }
195 _, err = node.Execute(`INSERT INTO foo (id, name) VALUES (1, 'Alice')`)
196 if err != nil {
197 t.Fatalf("failed to insert data: %v", err)
198 }
199 _, err = node.Execute(`UPDATE foo SET name = 'Alice Updated' WHERE id = 1`)
200 if err != nil {
201 t.Fatalf("failed to update data: %v", err)
202 }
203 _, err = node.Execute(`DELETE FROM foo WHERE id = 1`)
204 if err != nil {
205 t.Fatalf("failed to delete data: %v", err)
206 }
207
208 testEndpoint.Start()
209 defer testEndpoint.Close()
210
211 testPoll(t, func() (bool, error) {
212 // 1 insert, 1 update, 1 delete
213 return testEndpoint.GetMessageCount() == 3, nil
214 }, 100*time.Millisecond, 5*time.Second)
215
216 // Load the node, and ensure CDC continues to work.
217 if _, err := node.Load(filepath.Join("testdata", "auto-restore.sqlite")); err != nil {
218 t.Fatalf("failed to boot node: %s", err.Error())
219 }
220 _, err = node.Execute(`CREATE TABLE qux1 (id integer not null primary key, name text)`)
221 if err != nil {
222 t.Fatalf("failed to create table: %v", err)
223 }
224 _, err = node.Execute(`INSERT INTO qux1 (id, name) VALUES (100, 'Declan')`)
225 if err != nil {
226 t.Fatalf("failed to insert data: %v", err)
227 }
228 testPoll(t, func() (bool, error) {
229 return testEndpoint.GetMessageCount() == 4, nil
230 }, 100*time.Millisecond, 5*time.Second)

Callers

nothing calls this directly

Calls 15

URLMethod · 0.95
StartMethod · 0.95
CloseMethod · 0.95
GetMessageCountMethod · 0.95
NewHTTPTestServerFunction · 0.92
NewCDCClusterFunction · 0.92
NewServiceFunction · 0.92
mustNewLeaderNodeFunction · 0.85
mustCDCConfigFunction · 0.85
EnableCDCMethod · 0.80
CMethod · 0.80
testPollFunction · 0.70

Tested by

no test coverage detected