forked from Juniper/contrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_db.go
41 lines (32 loc) · 946 Bytes
/
cache_db.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
package integration
import (
"context"
"github.com/Juniper/contrail/pkg/cache"
"github.com/Juniper/contrail/pkg/etcd"
asfetcd "github.com/Juniper/asf/pkg/etcd"
integrationetcd "github.com/Juniper/contrail/pkg/testutil/integration/etcd"
)
const (
maxHistory = 100000
)
// RunCacheDB runs DB Cache with etcd event producer.
func RunCacheDB() (*cache.DB, func() error, error) {
setViper(map[string]interface{}{
"cache.timeout": "10s",
asfetcd.ETCDEndpointsVK: []string{integrationetcd.Endpoint},
})
cacheDB := cache.NewDB(maxHistory)
processor, err := etcd.NewEventProducer(cacheDB, "integration-cache-db")
if err != nil {
return nil, func() error { return nil }, err
}
ctx, cancelEtcdEventProducer := context.WithCancel(context.Background())
errChan := make(chan error)
go func() {
errChan <- processor.Start(ctx)
}()
return cacheDB, func() error {
cancelEtcdEventProducer()
return <-errChan
}, nil
}