@@ -25,6 +25,7 @@ import (
25
25
"testing"
26
26
"time"
27
27
28
+ "github.com/apache/incubator-pegasus/go-client/admin"
28
29
"github.com/apache/incubator-pegasus/go-client/idl/replication"
29
30
"github.com/apache/incubator-pegasus/go-client/pegasus"
30
31
"github.com/stretchr/testify/assert"
@@ -43,6 +44,22 @@ func defaultConfig() Config {
43
44
}
44
45
}
45
46
47
+ func defaultReplicaServers () []string {
48
+ return []string {"0.0.0.0:34801" , "0.0.0.0:34802" , "0.0.0.0:34803" }
49
+ }
50
+
51
+ func timeoutConfig () Config {
52
+ return Config {
53
+ MetaServers : []string {"0.0.0.0:123456" },
54
+ Timeout : 500 * time .Millisecond ,
55
+ }
56
+ }
57
+
58
+ func testAdmin_Timeout (t * testing.T , exec func (c * admin.Client ) error ) {
59
+ c := NewClient (timeoutConfig ())
60
+ assert .Equal (t , context .DeadlineExceeded , exec (c ))
61
+ }
62
+
46
63
func TestAdmin_Table (t * testing.T ) {
47
64
c := NewClient (defaultConfig ())
48
65
@@ -75,13 +92,9 @@ func TestAdmin_Table(t *testing.T) {
75
92
}
76
93
77
94
func TestAdmin_ListTablesTimeout (t * testing.T ) {
78
- c := NewClient (Config {
79
- MetaServers : []string {"0.0.0.0:123456" },
80
- Timeout : 500 * time .Millisecond ,
95
+ testAdmin_Timeout (t , func (c * admin.Client ) (err , error ) {
96
+ _ , err := c .ListTables ()
81
97
})
82
-
83
- _ , err := c .ListTables ()
84
- assert .Equal (t , err , context .DeadlineExceeded )
85
98
}
86
99
87
100
// Ensures after the call `CreateTable` ends, the table must be right available to access.
@@ -145,3 +158,31 @@ func TestAdmin_GetAppEnvs(t *testing.T) {
145
158
assert .Empty (t , tb .Envs )
146
159
}
147
160
}
161
+
162
+ func TestAdmin_ListNodes (t * testing.T ) {
163
+ c := NewClient (defaultConfig ())
164
+
165
+ nodes , err := c .ListNodes ()
166
+ assert .Nil (t , err )
167
+
168
+ expectedReplicaServers := defaultReplicaServers ()
169
+
170
+ // Compare slice length.
171
+ assert .Equal (t , len (expectedReplicaServers ), len (nodes ))
172
+
173
+ actualReplicaServers := make ([]int , len (nodes ))
174
+ for _ , node := range nodes {
175
+ // Each node should be alive.
176
+ assert .Equal (t , admin .NodeStatus_NS_ALIVE , node .Status )
177
+ actualReplicaServers [i ] = node .Address .GetAddress ()
178
+ }
179
+
180
+ // Match elements without extra ordering.
181
+ assert .ElementsMatch (t , expectedReplicaServers , actualReplicaServers )
182
+ }
183
+
184
+ func TestAdmin_ListNodesTimeout (t * testing.T ) {
185
+ testAdmin_Timeout (t , func (c * admin.Client ) (err , error ) {
186
+ _ , err := c .ListNodes ()
187
+ })
188
+ }
0 commit comments