forked from tsuna/gohbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_state_test.go
116 lines (98 loc) · 3.1 KB
/
debug_state_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
111
112
113
114
115
116
package gohbase
import (
"encoding/json"
"log/slog"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"github.com/tsuna/gohbase/hrpc"
"github.com/tsuna/gohbase/region"
)
func TestDebugStateSanity(t *testing.T) {
client := newClient("~invalid.quorum~") // We shouldn't connect to ZK.
ctrl := gomock.NewController(t)
defer ctrl.Finish()
regClientAddr := "regionserver:1"
regClient := region.NewClient(
regClientAddr,
region.RegionClient,
defaultRPCQueueSize,
defaultFlushInterval,
defaultEffectiveUser,
region.DefaultReadTimeout,
client.compressionCodec,
nil,
slog.Default(),
)
newClientFn := func() hrpc.RegionClient {
return regClient
}
// Inject 3 entries in the cache.
region1 := region.NewInfo(
1,
nil,
[]byte("test"),
[]byte("test,,1234567890042.56f833d5569a27c7a43fbf547b4924a4."),
[]byte(""),
[]byte("foo"),
)
if os, replaced := client.regions.put(region1); !replaced {
t.Errorf("Expected to put new region into cache, got: %v", os)
} else if len(os) != 0 {
t.Errorf("Didn't expect any overlaps, got: %v", os)
}
region1.SetClient(regClient)
client.clients.put("regionserver:1", region1, newClientFn)
region2 := region.NewInfo(
2,
nil,
[]byte("test"),
[]byte("test,foo,1234567890042.56f833d5569a27c7a43fbf547b4924a4."),
[]byte("foo"),
[]byte("gohbase"),
)
if os, replaced := client.regions.put(region2); !replaced {
t.Errorf("Expected to put new region into cache, got: %v", os)
} else if len(os) != 0 {
t.Errorf("Didn't expect any overlaps, got: %v", os)
}
region2.SetClient(regClient)
client.clients.put("regionserver:1", region2, newClientFn)
region3 := region.NewInfo(
3,
nil,
[]byte("test"),
[]byte("test,gohbase,1234567890042.56f833d5569a27c7a43fbf547b4924a4."),
[]byte("gohbase"),
[]byte(""),
)
if os, replaced := client.regions.put(region3); !replaced {
t.Errorf("Expected to put new region into cache, got: %v", os)
} else if len(os) != 0 {
t.Errorf("Didn't expect any overlaps, got: %v", os)
}
region3.SetClient(regClient)
client.clients.put("regionserver:1", region3, newClientFn)
jsonVal, err := DebugState(client)
if err != nil {
t.Fatalf("DebugInfo should not have an error: %v", err)
}
var jsonUnMarshal map[string]interface{}
err = json.Unmarshal(jsonVal, &jsonUnMarshal)
if err != nil {
t.Fatalf("Encoutered eror when Unmarshalling: %v", err)
}
clientRegionMap := jsonUnMarshal["ClientRegionMap"]
clientType := jsonUnMarshal["ClientType"]
regionInfoMap := jsonUnMarshal["RegionInfoMap"]
keyRegionCache := jsonUnMarshal["KeyRegionCache"]
clientRegionCache := jsonUnMarshal["ClientRegionCache"]
expectedClientRegionSize := 1
regionInfoMapSize := 3
assert.Equal(t, clientType.(string), string(region.RegionClient))
assert.Equal(t, expectedClientRegionSize, len(clientRegionMap.(map[string]interface{})))
assert.Equal(t, regionInfoMapSize, len(regionInfoMap.(map[string]interface{})))
assert.Equal(t, 3, len(keyRegionCache.(map[string]interface{})))
assert.Equal(t, len(clientRegionCache.(map[string]interface{})), 1) // only have one client
assert.Equal(t, true, json.Valid(jsonVal))
}