-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathmockshift.go
More file actions
114 lines (96 loc) · 2.56 KB
/
mockshift.go
File metadata and controls
114 lines (96 loc) · 2.56 KB
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
111
112
113
114
/*
* Radon
*
* Copyright 2018-2020 The Radon Authors.
* Code is licensed under the GPLv3.
*
*/
package shiftmanager
import (
"fmt"
"github.com/radondb/shift/shift"
"github.com/xelabs/go-mysqlstack/xlog"
)
// MockShiftInfo used to mock a shift info
var MockShiftInfo = &ShiftInfo{
From: "src",
FromUser: "test",
FromPassword: "test",
FromDatabase: "testdb",
FromTable: "tbl",
To: "dst",
ToUser: "user",
ToPassword: "user",
ToDatabase: "todb",
ToTable: "totbl",
Cleanup: false,
Checksum: true,
MysqlDump: "mysqldump",
Threads: 128,
PosBehinds: 2048,
WaitTimeBeforeChecksum: 10,
RadonURL: "",
}
// MockShift used to mock a shift for test
type MockShift struct {
log *xlog.Log
err chan struct{}
allDone chan struct{}
stopSignal chan struct{}
}
// NewMockShift used to new a mockshift
func NewMockShift(log *xlog.Log) shift.ShiftHandler {
return &MockShift{
log: log,
err: make(chan struct{}),
allDone: make(chan struct{}),
stopSignal: make(chan struct{}),
}
}
// Start used to start a shift work.
func (mockShift *MockShift) Start() error {
return nil
}
// WaitFinish used to wait success or fail signal to finish.
func (mockShift *MockShift) WaitFinish() error {
log := mockShift.log
select {
case <-mockShift.getAllDoneCh():
log.Info("mockshift.table.OK")
return nil
case <-mockShift.getErrorCh():
log.Error("mockshift.table.get.error")
return fmt.Errorf("mockshift.table.get.error")
case <-mockShift.getStopSignal():
log.Info("mockshift.table.get.stop.signal")
return fmt.Errorf("mockshift.table.get.stop.signal")
}
}
// ChecksumTable used to checksum data src tbl and dst tbl.
func (mockShift *MockShift) ChecksumTable() error {
return nil
}
// SetStopSignal used set a stop signal to stop a shift work.
func (mockShift *MockShift) SetStopSignal() {
close(mockShift.stopSignal)
}
// setAllDoneSignal used to set allDone signal
func (mockShift MockShift) setAllDoneSignal() {
close(mockShift.allDone)
}
// setErrSignal used to set allDone signal
func (mockShift MockShift) setErrSignal() {
close(mockShift.err)
}
// getAllDoneCh used to get success signal
func (mockShift *MockShift) getAllDoneCh() <-chan struct{} {
return mockShift.allDone
}
// getErrorCh used to get error signal
func (mockShift *MockShift) getErrorCh() <-chan struct{} {
return mockShift.err
}
// getStopSignal used to get stop signal
func (mockShift *MockShift) getStopSignal() <-chan struct{} {
return mockShift.stopSignal
}