forked from startreedata/pinot-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableAwareBrokerSelector_test.go
40 lines (35 loc) · 1.14 KB
/
tableAwareBrokerSelector_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
package pinot
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExtractTableName(t *testing.T) {
assert.Equal(t, "table", extractTableName("table_OFFLINE"))
assert.Equal(t, "table", extractTableName("table_REALTIME"))
assert.Equal(t, "table", extractTableName("table"))
}
func TestSelectBroker(t *testing.T) {
selector := &tableAwareBrokerSelector{
tableBrokerMap: map[string]([]string){"myTable": []string{"localhost:8000"}},
allBrokerList: []string{"localhost:8000"},
}
broker, err := selector.selectBroker("")
assert.Equal(t, "localhost:8000", broker)
assert.Nil(t, err)
broker, err = selector.selectBroker("myTable")
assert.Equal(t, "localhost:8000", broker)
assert.Nil(t, err)
_, err = selector.selectBroker("unexistTable")
assert.NotNil(t, err)
}
func TestErrorSelectBroker(t *testing.T) {
emptySelector := &tableAwareBrokerSelector{
tableBrokerMap: map[string]([]string){"myTable": []string{}},
}
_, err := emptySelector.selectBroker("")
assert.NotNil(t, err)
_, err = emptySelector.selectBroker("myTable")
assert.NotNil(t, err)
_, err = emptySelector.selectBroker("unexistTable")
assert.NotNil(t, err)
}