/
multi_cluster_test.go
84 lines (71 loc) · 1.63 KB
/
multi_cluster_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
package esmc_test
import (
"encoding/json"
"github.com/bernerdschaefer/esmc"
es "github.com/peterbourgon/elasticsearch"
"reflect"
"testing"
"time"
)
func TestMultiClusterSearch(t *testing.T) {
expected := es.SearchResponse{Took: 134}
cluster1 := newServer(func(e *json.Encoder) {
e.Encode(expected)
})
defer cluster1.Close()
cluster2 := newServer(func(e *json.Encoder) {
time.Sleep(10 * time.Millisecond)
e.Encode(es.SearchResponse{Took: 1340})
})
defer cluster2.Close()
mc := esmc.MultiCluster{
newCluster(clusterSpec(cluster1.URL, "cluster1", "on")),
newCluster(clusterSpec(cluster2.URL, "cluster2", "on")),
}
defer func() {
for _, c := range mc {
c.Shutdown()
}
}()
got, err := mc.Search(es.SearchRequest{
es.SearchParams{},
es.MatchAllQuery(),
})
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(expected, got) {
t.Fatal("got != epxected")
}
}
func TestMultiClusterSearchDarkMode(t *testing.T) {
expected := es.SearchResponse{Took: 134}
cluster1 := newServer(func(e *json.Encoder) {
time.Sleep(10 * time.Millisecond)
e.Encode(expected)
})
defer cluster1.Close()
cluster2 := newServer(func(e *json.Encoder) {
e.Encode(es.SearchResponse{Took: 1340})
})
defer cluster2.Close()
mc := esmc.MultiCluster{
newCluster(clusterSpec(cluster1.URL, "cluster1", "on")),
newCluster(clusterSpec(cluster2.URL, "cluster2", "dark")),
}
defer func() {
for _, c := range mc {
c.Shutdown()
}
}()
got, err := mc.Search(es.SearchRequest{
es.SearchParams{},
es.MatchAllQuery(),
})
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(expected, got) {
t.Fatal("got != epxected")
}
}