github.com/matrixorigin/matrixone@v1.2.0/pkg/tests/service/options_test.go (about)

     1  // Copyright 2021 - 2022 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 service
    16  
    17  import (
    18  	"testing"
    19  	"time"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/tnservice"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestDefaultOptons(t *testing.T) {
    26  	opt := DefaultOptions()
    27  	opt.validate()
    28  	require.Equal(t, opt.rootDataDir, defaultRootDataDir)
    29  }
    30  
    31  func TestWithTNServiceNum(t *testing.T) {
    32  	num := 4
    33  	opt := Options{}.WithTNServiceNum(num)
    34  	require.Equal(t, num, opt.initial.tnServiceNum)
    35  }
    36  
    37  func TestWithLogServiceNum(t *testing.T) {
    38  	num := 5
    39  	opt := Options{}.WithLogServiceNum(num)
    40  	require.Equal(t, num, opt.initial.logServiceNum)
    41  }
    42  
    43  func TestWithLogShardNum(t *testing.T) {
    44  	num := uint64(4)
    45  	opt := Options{}.WithLogShardNum(num)
    46  	require.Equal(t, num, opt.initial.logShardNum)
    47  }
    48  
    49  func TestWithTnShartnum(t *testing.T) {
    50  	num := uint64(5)
    51  	opt := Options{}.WithTNShardNum(num)
    52  	require.Equal(t, num, opt.initial.tnShardNum)
    53  }
    54  
    55  func TestWithLogReplicaNum(t *testing.T) {
    56  	num := uint64(4)
    57  	opt := Options{}.WithLogReplicaNum(num)
    58  	require.Equal(t, num, opt.initial.logReplicaNum)
    59  }
    60  
    61  func TestWithRootDataDir(t *testing.T) {
    62  	root := "/tmp/tests"
    63  	opt := Options{}.WithRootDataDir(root)
    64  	require.Equal(t, root, opt.rootDataDir)
    65  }
    66  
    67  func TestWithStorage(t *testing.T) {
    68  	opt := Options{}.WithTNUseMEMStorage()
    69  	require.Equal(t, tnservice.StorageMEM, opt.storage.tnStorage)
    70  }
    71  
    72  func TestWithHostAddress(t *testing.T) {
    73  	host := "127.0.0.1"
    74  	opt := Options{}.WithHostAddress(host)
    75  	opt.validate()
    76  	require.Equal(t, host, opt.hostAddr)
    77  }
    78  
    79  func TestWithHKTickPerSecond(t *testing.T) {
    80  	opt := DefaultOptions()
    81  	opt.validate()
    82  	require.Equal(t, defaultTickPerSecond, opt.hakeeper.tickPerSecond)
    83  
    84  	tick := 11
    85  	opt = opt.WithHKTickPerSecond(tick)
    86  	require.Equal(t, tick, opt.hakeeper.tickPerSecond)
    87  }
    88  
    89  func TestWithHKLogStoreTimeout(t *testing.T) {
    90  	opt := DefaultOptions()
    91  	opt.validate()
    92  	require.Equal(t, defaultLogStoreTimeout, opt.hakeeper.logStoreTimeout)
    93  
    94  	timeout := 20 * time.Second
    95  	opt = opt.WithHKLogStoreTimeout(timeout)
    96  	require.Equal(t, timeout, opt.hakeeper.logStoreTimeout)
    97  }
    98  
    99  func TestWithHKTNStoreTimeout(t *testing.T) {
   100  	opt := DefaultOptions()
   101  	opt.validate()
   102  	require.Equal(t, defaultTNStoreTimeout, opt.hakeeper.tnStoreTimeout)
   103  
   104  	timeout := 21 * time.Second
   105  	opt = opt.WithHKTNStoreTimeout(timeout)
   106  	require.Equal(t, timeout, opt.hakeeper.tnStoreTimeout)
   107  }
   108  
   109  func TestWithHKCNStoreTimeout(t *testing.T) {
   110  	opt := DefaultOptions()
   111  	opt.validate()
   112  	require.Equal(t, defaultCNStoreTimeout, opt.hakeeper.cnStoreTimeout)
   113  
   114  	timeout := 20 * time.Second
   115  	opt = opt.WithHKCNStoreTimeout(timeout)
   116  	require.Equal(t, timeout, opt.hakeeper.cnStoreTimeout)
   117  }
   118  
   119  func TestWithTNHeartbeatInterval(t *testing.T) {
   120  	opt := DefaultOptions()
   121  	opt.validate()
   122  	require.Equal(t, defaultTNHeartbeatInterval, opt.heartbeat.tn)
   123  
   124  	interval := 21 * time.Second
   125  	opt = opt.WithTNHeartbeatInterval(interval)
   126  	require.Equal(t, interval, opt.heartbeat.tn)
   127  }
   128  
   129  func TestWithLogHeartbeatInterval(t *testing.T) {
   130  	opt := DefaultOptions()
   131  	opt.validate()
   132  	require.Equal(t, defaultLogHeartbeatInterval, opt.heartbeat.log)
   133  
   134  	interval := 22 * time.Second
   135  	opt = opt.WithLogHeartbeatInterval(interval)
   136  	require.Equal(t, interval, opt.heartbeat.log)
   137  }
   138  
   139  func TestWithHKCheckInterval(t *testing.T) {
   140  	opt := DefaultOptions()
   141  	opt.validate()
   142  	require.Equal(t, defaultCheckInterval, opt.hakeeper.checkInterval)
   143  
   144  	interval := 23 * time.Second
   145  	opt = opt.WithHKCheckInterval(interval)
   146  	require.Equal(t, interval, opt.hakeeper.checkInterval)
   147  }
   148  
   149  func TestGossipSeedNum(t *testing.T) {
   150  	require.Equal(t, 1, gossipSeedNum(1))
   151  	require.Equal(t, 2, gossipSeedNum(2))
   152  }
   153  
   154  func TestHaKeeperNum(t *testing.T) {
   155  	require.Equal(t, 1, haKeeperNum(1))
   156  	require.Equal(t, 2, haKeeperNum(2))
   157  }
   158  
   159  func TestBuildHAKeeperConfig(t *testing.T) {
   160  	opt := DefaultOptions()
   161  	opt.validate()
   162  	cfg := opt.BuildHAKeeperConfig()
   163  	require.Equal(t, opt.hakeeper.tickPerSecond, cfg.TickPerSecond)
   164  	require.Equal(t, opt.hakeeper.logStoreTimeout, cfg.LogStoreTimeout)
   165  	require.Equal(t, opt.hakeeper.tnStoreTimeout, cfg.TNStoreTimeout)
   166  }