2023-11-30 14:30:28 +08:00
|
|
|
package io
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/samber/lo"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2024-06-06 14:33:52 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2023-11-30 14:30:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const binlogIOTestDir = "/tmp/milvus_test/binlog_io"
|
|
|
|
|
|
|
|
func TestBinlogIO(t *testing.T) {
|
|
|
|
suite.Run(t, new(BinlogIOSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type BinlogIOSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
cm storage.ChunkManager
|
|
|
|
b BinlogIO
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BinlogIOSuite) SetupTest() {
|
2024-06-06 14:33:52 +08:00
|
|
|
paramtable.Init()
|
2023-11-30 14:30:28 +08:00
|
|
|
s.cm = storage.NewLocalChunkManager(storage.RootPath(binlogIOTestDir))
|
|
|
|
|
2024-06-06 14:33:52 +08:00
|
|
|
s.b = NewBinlogIO(s.cm)
|
2023-11-30 14:30:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BinlogIOSuite) TeardownTest() {
|
|
|
|
ctx := context.Background()
|
|
|
|
s.cm.RemoveWithPrefix(ctx, s.cm.RootPath())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BinlogIOSuite) TestUploadDownload() {
|
|
|
|
kvs := map[string][]byte{
|
|
|
|
path.Join(binlogIOTestDir, "a/b/c"): {1, 255, 255},
|
|
|
|
path.Join(binlogIOTestDir, "a/b/d"): {1, 255, 255},
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
err := s.b.Upload(ctx, kvs)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
vs, err := s.b.Download(ctx, lo.Keys(kvs))
|
|
|
|
s.NoError(err)
|
|
|
|
s.ElementsMatch(lo.Values(kvs), vs)
|
|
|
|
}
|