2020-11-14 11:24:49 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2020-11-16 21:10:43 +08:00
|
|
|
package paramtable
|
2020-11-14 11:24:49 +08:00
|
|
|
|
|
|
|
import (
|
2020-12-08 14:41:04 +08:00
|
|
|
"os"
|
2022-08-25 11:02:53 +08:00
|
|
|
"strings"
|
2020-11-14 11:24:49 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-04-06 19:14:32 +08:00
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/pkg/config"
|
2020-11-14 11:24:49 +08:00
|
|
|
)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
var baseParams = BaseTable{}
|
2020-11-16 21:10:43 +08:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-01-19 14:53:44 +08:00
|
|
|
baseParams.init(0)
|
2020-12-08 14:41:04 +08:00
|
|
|
code := m.Run()
|
|
|
|
os.Exit(code)
|
2020-11-16 21:10:43 +08:00
|
|
|
}
|
|
|
|
|
2023-01-06 09:55:36 +08:00
|
|
|
func TestBaseTable_DuplicateValues(t *testing.T) {
|
|
|
|
baseParams.Save("rootcoord.dmlchannelnum", "10")
|
|
|
|
baseParams.Save("rootcoorddmlchannelnum", "11")
|
|
|
|
|
|
|
|
prefix := "rootcoord."
|
|
|
|
configs := baseParams.mgr.GetConfigs()
|
|
|
|
|
|
|
|
configsWithPrefix := make(map[string]string)
|
|
|
|
for k, v := range configs {
|
|
|
|
if strings.HasPrefix(k, prefix) {
|
|
|
|
configsWithPrefix[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rootconfigs := baseParams.mgr.GetBy(config.WithPrefix(prefix))
|
|
|
|
|
|
|
|
assert.Equal(t, len(rootconfigs), len(configsWithPrefix))
|
|
|
|
assert.Equal(t, "11", rootconfigs["rootcoord.dmlchannelnum"])
|
|
|
|
}
|
|
|
|
|
2021-09-07 15:20:40 +08:00
|
|
|
func TestBaseTable_SaveAndLoad(t *testing.T) {
|
2021-06-18 15:20:08 +08:00
|
|
|
err1 := baseParams.Save("int", "10")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err1)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err2 := baseParams.Save("string", "testSaveAndLoad")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err2)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err3 := baseParams.Save("float", "1.234")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err3)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
r1, _ := baseParams.Load("int")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Equal(t, "10", r1)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
r2, _ := baseParams.Load("string")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Equal(t, "testSaveAndLoad", r2)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
r3, _ := baseParams.Load("float")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Equal(t, "1.234", r3)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err4 := baseParams.Remove("int")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err4)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err5 := baseParams.Remove("string")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err5)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err6 := baseParams.Remove("float")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err6)
|
|
|
|
}
|
|
|
|
|
2021-09-07 15:20:40 +08:00
|
|
|
func TestBaseTable_Remove(t *testing.T) {
|
2021-06-18 15:20:08 +08:00
|
|
|
err1 := baseParams.Save("RemoveInt", "10")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err1)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err2 := baseParams.Save("RemoveString", "testRemove")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err2)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err3 := baseParams.Save("RemoveFloat", "1.234")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err3)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err4 := baseParams.Remove("RemoveInt")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err4)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err5 := baseParams.Remove("RemoveString")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err5)
|
|
|
|
|
2021-06-18 15:20:08 +08:00
|
|
|
err6 := baseParams.Remove("RemoveFloat")
|
2020-11-14 11:24:49 +08:00
|
|
|
assert.Nil(t, err6)
|
|
|
|
}
|
|
|
|
|
2022-04-12 19:47:33 +08:00
|
|
|
func TestBaseTable_Get(t *testing.T) {
|
|
|
|
err := baseParams.Save("key", "10")
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-04-12 19:47:33 +08:00
|
|
|
|
|
|
|
v := baseParams.Get("key")
|
|
|
|
assert.Equal(t, "10", v)
|
|
|
|
|
|
|
|
v2 := baseParams.Get("none")
|
|
|
|
assert.Equal(t, "", v2)
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:28:11 +08:00
|
|
|
func TestBaseTable_Pulsar(t *testing.T) {
|
|
|
|
//test PULSAR ADDRESS
|
2022-10-11 18:43:23 +08:00
|
|
|
t.Setenv("PULSAR_ADDRESS", "pulsar://localhost:6650")
|
2023-01-19 14:53:44 +08:00
|
|
|
baseParams.init(0)
|
2022-06-16 17:28:11 +08:00
|
|
|
|
2022-08-02 21:26:33 +08:00
|
|
|
address := baseParams.Get("pulsar.address")
|
2022-06-16 17:28:11 +08:00
|
|
|
assert.Equal(t, "pulsar://localhost:6650", address)
|
2022-08-02 21:26:33 +08:00
|
|
|
|
|
|
|
port := baseParams.Get("pulsar.port")
|
|
|
|
assert.NotEqual(t, "", port)
|
2022-06-16 17:28:11 +08:00
|
|
|
}
|
|
|
|
|
2021-11-10 14:27:37 +08:00
|
|
|
func TestBaseTable_Env(t *testing.T) {
|
2022-10-11 18:43:23 +08:00
|
|
|
t.Setenv("milvus.test", "test")
|
|
|
|
t.Setenv("milvus.test.test2", "test2")
|
2021-11-10 14:27:37 +08:00
|
|
|
|
2023-01-19 14:53:44 +08:00
|
|
|
baseParams.init(0)
|
2021-11-10 14:27:37 +08:00
|
|
|
result, _ := baseParams.Load("test")
|
|
|
|
assert.Equal(t, result, "test")
|
|
|
|
|
|
|
|
result, _ = baseParams.Load("test.test2")
|
|
|
|
assert.Equal(t, result, "test2")
|
|
|
|
|
2022-10-11 18:43:23 +08:00
|
|
|
t.Setenv("milvus.invalid", "xxx=test")
|
2021-11-10 14:27:37 +08:00
|
|
|
|
2023-01-19 14:53:44 +08:00
|
|
|
baseParams.init(0)
|
2021-11-10 14:27:37 +08:00
|
|
|
result, _ = baseParams.Load("invalid")
|
|
|
|
assert.Equal(t, result, "xxx=test")
|
|
|
|
}
|
|
|
|
|
2022-10-12 11:37:23 +08:00
|
|
|
func TestNewBaseTableFromYamlOnly(t *testing.T) {
|
|
|
|
var yaml string
|
|
|
|
var gp *BaseTable
|
|
|
|
yaml = "not_exist.yaml"
|
|
|
|
gp = NewBaseTableFromYamlOnly(yaml)
|
|
|
|
assert.Empty(t, gp.Get("key"))
|
|
|
|
}
|