mirror of https://github.com/milvus-io/milvus.git
parent
e236a1ccf9
commit
c23236c50e
|
@ -72,17 +72,16 @@ func (lcm *LocalChunkManager) Exist(key string) bool {
|
|||
|
||||
// Read reads the local storage data if exist.
|
||||
func (lcm *LocalChunkManager) Read(key string) ([]byte, error) {
|
||||
path := path.Join(lcm.localPath, key)
|
||||
file, err := os.Open(path)
|
||||
filePath := path.Join(lcm.localPath, key)
|
||||
file, err := os.Open(path.Clean(filePath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
content, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return content, nil
|
||||
return content, file.Close()
|
||||
}
|
||||
|
||||
// ReadAt reads specific position data of local storage if exist.
|
||||
|
|
|
@ -44,7 +44,8 @@ func TestLocalChunkManager_Read(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
|
||||
bin = []byte{1, 2, 3}
|
||||
lcm.Write("1", bin)
|
||||
err = lcm.Write("1", bin)
|
||||
assert.Nil(t, err)
|
||||
res, err := lcm.Read("1")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, len(res), len(bin))
|
||||
|
|
|
@ -39,7 +39,8 @@ func TestMinioChunkManager_ReadAt(t *testing.T) {
|
|||
key := "1"
|
||||
bin := []byte{1, 2, 3}
|
||||
content := make([]byte, 8)
|
||||
minioMgr.minio.Remove(key)
|
||||
err = minioMgr.minio.Remove(key)
|
||||
assert.Nil(t, err)
|
||||
|
||||
n, err := minioMgr.ReadAt(key, content, 0)
|
||||
assert.Equal(t, n, -1)
|
||||
|
|
|
@ -147,8 +147,9 @@ func buildVectorChunkManager(t *testing.T, localPath string, localCacheEnable bo
|
|||
assert.NotNil(t, vcm)
|
||||
|
||||
var allCancel context.CancelFunc = func() {
|
||||
err := minIOKV.RemoveWithPrefix("")
|
||||
assert.Nil(t, err)
|
||||
cancel()
|
||||
minIOKV.RemoveWithPrefix("")
|
||||
}
|
||||
return vcm, allCancel
|
||||
}
|
||||
|
@ -159,7 +160,10 @@ var localPath string = "/tmp/milvus/test_data"
|
|||
func TestMain(m *testing.M) {
|
||||
Params.Init()
|
||||
exitCode := m.Run()
|
||||
os.RemoveAll(localPath)
|
||||
err := os.RemoveAll(localPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
|
@ -177,7 +181,8 @@ func TestVectorChunkManager_GetPath(t *testing.T) {
|
|||
assert.Equal(t, pathGet, pathJoin)
|
||||
|
||||
vcm.localCacheEnable = false
|
||||
vcm.remoteChunkManager.Write(key, []byte{1})
|
||||
err = vcm.remoteChunkManager.Write(key, []byte{1})
|
||||
assert.Nil(t, err)
|
||||
pathGet, err = vcm.GetPath(key)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, pathGet, key)
|
||||
|
@ -219,7 +224,8 @@ func TestVectorChunkManager_Read(t *testing.T) {
|
|||
binlogs := initBinlogFile(meta)
|
||||
assert.NotNil(t, binlogs)
|
||||
for _, binlog := range binlogs {
|
||||
vcm.remoteChunkManager.Write(binlog.Key, binlog.Value)
|
||||
err := vcm.remoteChunkManager.Write(binlog.Key, binlog.Value)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
content, err = vcm.Read("108")
|
||||
|
|
Loading…
Reference in New Issue