@@ -2,7 +2,6 @@ package vitess
2
2
3
3
import (
4
4
"encoding/json"
5
- "fmt"
6
5
"net/http"
7
6
"net/http/httptest"
8
7
"testing"
@@ -16,44 +15,68 @@ func TestParseTablets(t *testing.T) {
16
15
vitessApi := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
17
16
switch r .URL .String () {
18
17
case "/api/keyspace/test/tablets/00" , "/api/keyspace/test/tablets/00?cells=cell2" :
19
- data , _ := json .Marshal ([]Tablet {
18
+ json .NewEncoder ( w ). Encode ([]Tablet {
20
19
{
21
- Alias : & topodata. TabletAlias { Cell : "cell1" },
22
- MysqlHostname : "master" ,
23
- Type : topodata .TabletType_MASTER ,
20
+ // primary (should be ignored)
21
+ Alias : & topodata. TabletAlias { Cell : "cell1" } ,
22
+ Type : topodata .TabletType_MASTER ,
24
23
},
25
24
{
25
+ // replica without realtime tablet stats enabled (assumed to be healthy)
26
26
Alias : & topodata.TabletAlias {Cell : "cell2" },
27
27
MysqlHostname : "replica1" ,
28
28
Type : topodata .TabletType_REPLICA ,
29
29
},
30
30
{
31
+ // replica with healthy realtime tablet stats
31
32
Alias : & topodata.TabletAlias {Cell : "cell3" },
32
33
MysqlHostname : "replica2" ,
33
- Type : topodata .TabletType_REPLICA ,
34
+ Stats : & TabletStats {
35
+ Realtime : & TabletRealtimeStats {},
36
+ },
37
+ Type : topodata .TabletType_REPLICA ,
38
+ },
39
+ {
40
+ // replica with nil realtime stats (should be ignored)
41
+ Alias : & topodata.TabletAlias {Cell : "cell1" },
42
+ MysqlHostname : "replica3" ,
43
+ Stats : & TabletStats {
44
+ Realtime : nil ,
45
+ },
34
46
},
35
47
{
48
+ // replica with realtime tablet stats and 'replication not running' error (should be ignored)
36
49
Alias : & topodata.TabletAlias {Cell : "cell2" },
37
- MysqlHostname : "spare" ,
38
- Type : topodata .TabletType_SPARE ,
50
+ MysqlHostname : "replica4" ,
51
+ Stats : & TabletStats {
52
+ LastError : "vttablet error: replication is not running" ,
53
+ Realtime : & TabletRealtimeStats {
54
+ HealthError : "replication is not running" ,
55
+ },
56
+ },
57
+ Type : topodata .TabletType_REPLICA ,
39
58
},
40
59
{
41
- Alias : & topodata. TabletAlias { Cell : "cell3" },
42
- MysqlHostname : "batch" ,
43
- Type : topodata .TabletType_BATCH ,
60
+ // spare tablet (should be ignored)
61
+ Alias : & topodata. TabletAlias { Cell : "cell2" } ,
62
+ Type : topodata .TabletType_SPARE ,
44
63
},
45
64
{
46
- Alias : & topodata. TabletAlias { Cell : "cell2" },
47
- MysqlHostname : "backup" ,
48
- Type : topodata .TabletType_BACKUP ,
65
+ // batch tablet (should be ignored)
66
+ Alias : & topodata. TabletAlias { Cell : "cell3" } ,
67
+ Type : topodata .TabletType_BATCH ,
49
68
},
50
69
{
51
- Alias : & topodata.TabletAlias {Cell : "cell1" },
52
- MysqlHostname : "restore" ,
53
- Type : topodata .TabletType_RESTORE ,
70
+ // backup tablet (should be ignored)
71
+ Alias : & topodata.TabletAlias {Cell : "cell2" },
72
+ Type : topodata .TabletType_BACKUP ,
73
+ },
74
+ {
75
+ // restore tablet (should be ignored)
76
+ Alias : & topodata.TabletAlias {Cell : "cell1" },
77
+ Type : topodata .TabletType_RESTORE ,
54
78
},
55
79
})
56
- fmt .Fprint (w , string (data ))
57
80
default :
58
81
w .WriteHeader (http .StatusNotFound )
59
82
}
0 commit comments