This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmulti_elasticsearch_test.go
More file actions
94 lines (78 loc) · 2.43 KB
/
multi_elasticsearch_test.go
File metadata and controls
94 lines (78 loc) · 2.43 KB
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
package kasper
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
elastic "gopkg.in/olivere/elastic.v5"
)
type HeroTenancy struct{}
func (HeroTenancy) TenantIndexAndType(tenant string) (indexName, typeName string) {
indexName = tenant
typeName = "hero"
return
}
func TestMultiElasticsearch(t *testing.T) {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("http://%s:9200", getCIHost())
client, err := elastic.NewClient(
elastic.SetURL(url),
elastic.SetSniff(false),
)
if err != nil {
panic(err)
}
store := NewMultiElasticsearch(config, client, HeroTenancy{})
testMultiStore(t, store)
}
func TestMultiElasticsearch_PutAll_GetAll(t *testing.T) {
config := &Config{
TopicProcessorName: "test",
Logger: &noopLogger{},
MetricsProvider: &NoopMetricsProvider{},
}
url := fmt.Sprintf("http://%s:9200", getCIHost())
client, err := elastic.NewClient(
elastic.SetURL(url),
elastic.SetSniff(false),
)
if err != nil {
panic(err)
}
store := NewMultiElasticsearch(config, client, HeroTenancy{})
spiderman := []byte(`{"name":"Spiderman","power":"webs"}`)
ironman := []byte(`{"name":"Ironman","power":"a kickass powered armor"}`)
batman := []byte(`{"name":"Batman","power":"money and an inflated sense of self"}`)
superman := []byte(`{"name":"Superman","power":"not being recognized by wearing glasses"}`)
err = store.Tenant("marvel").Put("spiderman", spiderman)
assert.Nil(t, err)
err = store.Tenant("dc").Put("batman", batman)
assert.Nil(t, err)
s, err := store.Fetch([]TenantKey{{"marvel", "spiderman"}, {"dc", "batman"}})
assert.Nil(t, err)
hero, _ := s.Tenant("marvel").Get("spiderman")
assert.Equal(t, spiderman, hero)
hero, _ = s.Tenant("dc").Get("batman")
assert.Equal(t, batman, hero)
err = s.Tenant("marvel").Put("ironman", ironman)
assert.Nil(t, err)
err = s.Tenant("dc").Put("superman", superman)
assert.Nil(t, err)
err = store.Push(s)
assert.Nil(t, err)
hero, err = store.Tenant("marvel").Get("ironman")
assert.Nil(t, err)
assert.Equal(t, ironman, hero)
hero, err = store.Tenant("dc").Get("superman")
assert.Nil(t, err)
assert.Equal(t, superman, hero)
}
func init() {
store.client.DeleteIndex("marvel").Do(store.context)
store.client.DeleteIndex("dc").Do(store.context)
store.client.CreateIndex("marvel").Do(store.context)
store.client.CreateIndex("dc").Do(store.context)
}