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