milvus/internal/kv/minio/minio_stats_wacher_test.go
sunby 1d7195e036 Add minio and etcd stats watcher
Our system needs to watch the performance of etcd and minio. For now I just add the creation stats.

Signed-off-by: sunby <bingyi.sun@zilliz.com>
2021-04-08 14:14:43 +08:00

54 lines
1.2 KiB
Go

package miniokv
import (
"context"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zilliztech/milvus-distributed/internal/util/paramtable"
)
func TestMinioStats(t *testing.T) {
var p paramtable.BaseTable
p.Init()
endPoint, _ := p.Load("_MinioAddress")
accessKeyID, _ := p.Load("minio.accessKeyID")
secretAccessKey, _ := p.Load("minio.secretAccessKey")
useSSLStr, _ := p.Load("minio.useSSL")
useSSL, _ := strconv.ParseBool(useSSLStr)
option := &Option{
Address: endPoint,
AccessKeyID: accessKeyID,
SecretAccessKeyID: secretAccessKey,
UseSSL: useSSL,
BucketName: "teststats",
CreateBucket: true,
}
cli, err := NewMinIOKV(context.TODO(), option)
assert.Nil(t, err)
startCh := make(chan struct{})
receiveCh := make(chan struct{})
w := NewMinioStatsWatcher(cli.minioClient, "teststats")
w.helper.eventAfterStartWatch = func() {
var e struct{}
startCh <- e
}
w.helper.eventAfterNotify = func() {
var e struct{}
receiveCh <- e
}
go w.StartBackground(context.TODO())
<-startCh
err = cli.Save("a", string([]byte{65, 65, 65, 65, 65}))
assert.Nil(t, err)
<-receiveCh
size := w.GetObjectCreateSize()
assert.EqualValues(t, 5, size)
}