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"
|
|
|
|
|
|
|
|
"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
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test pulsarConfig", func(t *testing.T) {
|
2022-11-21 17:49:12 +08:00
|
|
|
// test default value
|
|
|
|
{
|
|
|
|
pc := &PulsarConfig{}
|
|
|
|
base := &BaseTable{mgr: &config.Manager{}}
|
|
|
|
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{}
|
|
|
|
base := &BaseTable{mgr: &config.Manager{}}
|
|
|
|
kc.Init(base)
|
|
|
|
assert.Empty(t, kc.Address.GetValue())
|
|
|
|
assert.Equal(t, kc.SaslMechanisms.GetValue(), "PLAIN")
|
|
|
|
assert.Equal(t, kc.SecurityProtocol.GetValue(), "SASL_SSL")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|