github.com/matrixorigin/matrixone@v1.2.0/pkg/proxy/bootstrap_test.go (about)

     1  // Copyright 2021 - 2023 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package proxy
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  	"time"
    21  
    22  	"github.com/matrixorigin/matrixone/pkg/common/runtime"
    23  	"github.com/matrixorigin/matrixone/pkg/common/stopper"
    24  	db_holder "github.com/matrixorigin/matrixone/pkg/util/export/etl/db"
    25  	"github.com/matrixorigin/matrixone/pkg/util/toml"
    26  	"github.com/stretchr/testify/require"
    27  )
    28  
    29  func TestBootstrap(t *testing.T) {
    30  	ctx, cancel := context.WithCancel(context.Background())
    31  	defer cancel()
    32  	rt := runtime.DefaultRuntime()
    33  	runtime.SetupProcessLevelRuntime(rt)
    34  	c := mockHAKeeperClient{}
    35  	st := stopper.NewStopper("test-proxy", stopper.WithLogger(rt.Logger().RawLogger()))
    36  	cfg := Config{
    37  		RebalanceInterval: toml.Duration{Duration: time.Second},
    38  	}
    39  	cfg.Cluster.RefreshInterval = toml.Duration{Duration: defaultRefreshInterval}
    40  	h, err := newProxyHandler(ctx, rt, cfg, st, nil, &c)
    41  	require.NoError(t, err)
    42  	h.bootstrap(ctx)
    43  
    44  	u, err := db_holder.GetSQLWriterDBUser()
    45  	require.NoError(t, err)
    46  	require.Equal(t, db_holder.MOLoggerUser, u.UserName)
    47  	f := db_holder.GetSQLWriterDBAddressFunc()
    48  	require.NotNil(t, f)
    49  	addr, err := f(ctx, true)
    50  	require.Error(t, err)
    51  	require.Equal(t, "", addr)
    52  }