2021-09-02 22:18:10 +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.
|
|
|
|
|
|
|
|
package paramtable
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-09-20 22:01:27 +08:00
|
|
|
"time"
|
2021-09-02 22:18:10 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-04-06 19:14:32 +08:00
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/pkg/config"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
2021-09-02 22:18:10 +08:00
|
|
|
)
|
|
|
|
|
2022-02-08 20:57:47 +08:00
|
|
|
func TestServiceParam(t *testing.T) {
|
|
|
|
var SParams ServiceParam
|
2023-09-05 10:31:48 +08:00
|
|
|
bt := NewBaseTable(SkipRemote(true))
|
|
|
|
SParams.init(bt)
|
2022-02-07 10:09:45 +08:00
|
|
|
t.Run("test etcdConfig", func(t *testing.T) {
|
2022-11-17 18:59:09 +08:00
|
|
|
Params := &SParams.EtcdCfg
|
2021-09-02 22:18:10 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotZero(t, len(Params.Endpoints.GetAsStrings()))
|
|
|
|
t.Logf("etcd endpoints = %s", Params.Endpoints.GetAsStrings())
|
2021-09-02 22:18:10 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
assert.NotEqual(t, Params.MetaRootPath, "")
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Logf("meta root path = %s", Params.MetaRootPath.GetValue())
|
2021-09-02 22:18:10 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
assert.NotEqual(t, Params.KvRootPath, "")
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Logf("kv root path = %s", Params.KvRootPath.GetValue())
|
2021-09-02 22:18:10 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotNil(t, Params.EtcdUseSSL.GetAsBool())
|
|
|
|
t.Logf("use ssl = %t", Params.EtcdUseSSL.GetAsBool())
|
2022-05-20 12:29:19 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEmpty(t, Params.EtcdTLSKey.GetValue())
|
|
|
|
t.Logf("tls key = %s", Params.EtcdTLSKey.GetValue())
|
2022-05-20 12:29:19 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEmpty(t, Params.EtcdTLSCACert.GetValue())
|
|
|
|
t.Logf("tls CACert = %s", Params.EtcdTLSCACert.GetValue())
|
2022-05-20 12:29:19 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEmpty(t, Params.EtcdTLSCert.GetValue())
|
|
|
|
t.Logf("tls cert = %s", Params.EtcdTLSCert.GetValue())
|
2022-05-20 12:29:19 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEmpty(t, Params.EtcdTLSMinVersion.GetValue())
|
|
|
|
t.Logf("tls minVersion = %s", Params.EtcdTLSMinVersion.GetValue())
|
2022-05-20 12:29:19 +08:00
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
// test UseEmbedEtcd
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Setenv("etcd.use.embed", "true")
|
2022-10-11 18:43:23 +08:00
|
|
|
t.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.ClusterDeployMode)
|
2023-09-05 10:31:48 +08:00
|
|
|
assert.Panics(t, func() {
|
|
|
|
NewBaseTable()
|
|
|
|
})
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-10-11 18:43:23 +08:00
|
|
|
t.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.StandaloneDeployMode)
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Setenv("etcd.use.embed", "false")
|
2023-09-05 10:31:48 +08:00
|
|
|
SParams.init(bt)
|
2022-02-07 10:09:45 +08:00
|
|
|
})
|
|
|
|
|
2023-09-07 07:25:14 +08:00
|
|
|
t.Run("test tikvConfig", func(t *testing.T) {
|
|
|
|
Params := &SParams.TiKVCfg
|
|
|
|
|
|
|
|
assert.NotZero(t, len(Params.Endpoints.GetAsStrings()))
|
|
|
|
t.Logf("tikv endpoints = %s", Params.Endpoints.GetAsStrings())
|
|
|
|
|
|
|
|
assert.NotEqual(t, Params.MetaRootPath, "")
|
|
|
|
t.Logf("meta root path = %s", Params.MetaRootPath.GetValue())
|
|
|
|
|
|
|
|
assert.NotEqual(t, Params.KvRootPath, "")
|
|
|
|
t.Logf("kv root path = %s", Params.KvRootPath.GetValue())
|
|
|
|
|
|
|
|
t.Setenv(metricsinfo.DeployModeEnvKey, metricsinfo.StandaloneDeployMode)
|
|
|
|
SParams.init(bt)
|
|
|
|
})
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
t.Run("test pulsarConfig", func(t *testing.T) {
|
2022-11-21 17:49:12 +08:00
|
|
|
// test default value
|
|
|
|
{
|
|
|
|
pc := &PulsarConfig{}
|
2024-01-11 13:48:49 +08:00
|
|
|
base := &BaseTable{mgr: config.NewManager()}
|
2022-11-21 17:49:12 +08:00
|
|
|
pc.Init(base)
|
|
|
|
assert.Empty(t, pc.Address.GetValue())
|
|
|
|
}
|
2022-08-02 21:26:33 +08:00
|
|
|
{
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEqual(t, SParams.PulsarCfg.Address.GetValue(), "")
|
|
|
|
t.Logf("pulsar address = %s", SParams.PulsarCfg.Address.GetValue())
|
|
|
|
assert.Equal(t, SParams.PulsarCfg.MaxMessageSize.GetAsInt(), SuggestPulsarMaxMessageSize)
|
2022-08-02 21:26:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
address := "pulsar://localhost:6650"
|
|
|
|
{
|
2023-09-05 10:31:48 +08:00
|
|
|
bt.Save("pulsar.address", address)
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, SParams.PulsarCfg.Address.GetValue(), address)
|
2022-08-02 21:26:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-09-05 10:31:48 +08:00
|
|
|
bt.Save("pulsar.address", "localhost")
|
|
|
|
bt.Save("pulsar.port", "6650")
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, SParams.PulsarCfg.Address.GetValue(), address)
|
2022-08-02 21:26:33 +08:00
|
|
|
}
|
|
|
|
})
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-08-02 21:26:33 +08:00
|
|
|
t.Run("test pulsar web config", func(t *testing.T) {
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEqual(t, SParams.PulsarCfg.Address.GetValue(), "")
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-08-02 21:26:33 +08:00
|
|
|
{
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEqual(t, SParams.PulsarCfg.WebAddress.GetValue(), "")
|
2022-08-02 21:26:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-09-05 10:31:48 +08:00
|
|
|
bt.Save(SParams.PulsarCfg.Address.Key, "u\\invalid")
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, SParams.PulsarCfg.WebAddress.GetValue(), "")
|
2022-08-02 21:26:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-09-05 10:31:48 +08:00
|
|
|
bt.Save(SParams.PulsarCfg.Address.Key, "")
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, SParams.PulsarCfg.WebAddress.GetValue(), "")
|
2022-08-02 21:26:33 +08:00
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
})
|
|
|
|
|
2022-11-11 10:55:05 +08:00
|
|
|
t.Run("test pulsar auth config", func(t *testing.T) {
|
2023-08-23 20:46:23 +08:00
|
|
|
Params := &SParams.PulsarCfg
|
2022-11-11 10:55:05 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, "", Params.AuthPlugin.GetValue())
|
2023-01-03 10:11:34 +08:00
|
|
|
assert.Equal(t, "{}", Params.AuthParams.GetValue())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test pulsar auth config formatter", func(t *testing.T) {
|
2023-08-23 20:46:23 +08:00
|
|
|
Params := &SParams.PulsarCfg
|
2023-01-03 10:11:34 +08:00
|
|
|
|
|
|
|
assert.Equal(t, "{}", Params.AuthParams.Formatter(""))
|
|
|
|
assert.Equal(t, "{\"a\":\"b\"}", Params.AuthParams.Formatter("a:b"))
|
2022-11-11 10:55:05 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test pulsar tenant/namespace config", func(t *testing.T) {
|
2023-08-23 20:46:23 +08:00
|
|
|
Params := &SParams.PulsarCfg
|
2022-11-11 10:55:05 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, "public", Params.Tenant.GetValue())
|
|
|
|
assert.Equal(t, "default", Params.Namespace.GetValue())
|
2022-11-11 10:55:05 +08:00
|
|
|
})
|
|
|
|
|
2023-08-23 20:46:23 +08:00
|
|
|
t.Run("pulsar_operation_timeout", func(t *testing.T) {
|
|
|
|
Params := &SParams.PulsarCfg
|
|
|
|
|
|
|
|
assert.Equal(t, "60", Params.RequestTimeout.GetValue())
|
|
|
|
})
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
t.Run("test rocksmqConfig", func(t *testing.T) {
|
2022-11-17 18:59:09 +08:00
|
|
|
Params := &SParams.RocksmqCfg
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.NotEqual(t, Params.Path.GetValue(), "")
|
|
|
|
t.Logf("rocksmq path = %s", Params.Path.GetValue())
|
2022-02-07 10:09:45 +08:00
|
|
|
})
|
|
|
|
|
2022-11-21 17:49:12 +08:00
|
|
|
t.Run("test kafkaConfig", func(t *testing.T) {
|
|
|
|
// test default value
|
|
|
|
{
|
|
|
|
kc := &KafkaConfig{}
|
2024-01-11 13:48:49 +08:00
|
|
|
base := &BaseTable{mgr: config.NewManager()}
|
2022-11-21 17:49:12 +08:00
|
|
|
kc.Init(base)
|
|
|
|
assert.Empty(t, kc.Address.GetValue())
|
2024-03-01 18:17:03 +08:00
|
|
|
assert.Empty(t, kc.SaslMechanisms.GetValue())
|
|
|
|
assert.Empty(t, kc.SecurityProtocol.GetValue())
|
2023-09-20 22:01:27 +08:00
|
|
|
assert.Equal(t, kc.ReadTimeout.GetAsDuration(time.Second), 10*time.Second)
|
2024-02-28 18:43:07 +08:00
|
|
|
assert.Equal(t, kc.KafkaUseSSL.GetAsBool(), false)
|
|
|
|
assert.Empty(t, kc.KafkaTLSCACert.GetValue())
|
|
|
|
assert.Empty(t, kc.KafkaTLSCert.GetValue())
|
|
|
|
assert.Empty(t, kc.KafkaTLSKey.GetValue())
|
|
|
|
assert.Empty(t, kc.KafkaTLSKeyPassword.GetValue())
|
2022-11-21 17:49:12 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
t.Run("test minioConfig", func(t *testing.T) {
|
2022-11-17 18:59:09 +08:00
|
|
|
Params := &SParams.MinioCfg
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
addr := Params.Address.GetValue()
|
2022-02-07 10:09:45 +08:00
|
|
|
equal := addr == "localhost:9000" || addr == "minio:9000"
|
|
|
|
assert.Equal(t, equal, true)
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Logf("minio address = %s", Params.Address.GetValue())
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, Params.AccessKeyID.GetValue(), "minioadmin")
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, Params.SecretAccessKey.GetValue(), "minioadmin")
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, Params.UseSSL.GetAsBool(), false)
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2024-03-21 11:15:20 +08:00
|
|
|
assert.NotEmpty(t, Params.SslCACert.GetValue())
|
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, Params.UseIAM.GetAsBool(), false)
|
2022-06-02 19:42:03 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, Params.CloudProvider.GetValue(), "aws")
|
2022-11-01 11:07:35 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
assert.Equal(t, Params.IAMEndpoint.GetValue(), "")
|
2022-06-02 19:42:03 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Logf("Minio BucketName = %s", Params.BucketName.GetValue())
|
2022-02-07 10:09:45 +08:00
|
|
|
|
2022-11-17 18:59:09 +08:00
|
|
|
t.Logf("Minio rootpath = %s", Params.RootPath.GetValue())
|
2022-02-07 10:09:45 +08:00
|
|
|
})
|
2021-09-02 22:18:10 +08:00
|
|
|
}
|