github.com/m3db/m3@v1.5.0/src/dbnode/client/config_test.go (about)

     1  // Copyright (c) 2017 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package client
    22  
    23  import (
    24  	"io/ioutil"
    25  	"os"
    26  	"testing"
    27  	"time"
    28  
    29  	"github.com/m3db/m3/src/dbnode/encoding"
    30  	"github.com/m3db/m3/src/dbnode/topology"
    31  	xconfig "github.com/m3db/m3/src/x/config"
    32  	"github.com/m3db/m3/src/x/retry"
    33  
    34  	"github.com/stretchr/testify/assert"
    35  	"github.com/stretchr/testify/require"
    36  )
    37  
    38  func TestConfiguration(t *testing.T) {
    39  	in := `
    40  writeConsistencyLevel: majority
    41  readConsistencyLevel: unstrict_majority
    42  iterateEqualTimestampStrategy: iterate_lowest_value
    43  connectConsistencyLevel: any
    44  writeTimeout: 10s
    45  fetchTimeout: 15s
    46  connectTimeout: 20s
    47  writeRetry:
    48      initialBackoff: 500ms
    49      backoffFactor: 3
    50      maxRetries: 2
    51      jitter: true
    52  fetchRetry:
    53      initialBackoff: 500ms
    54      backoffFactor: 2
    55      maxRetries: 3
    56      jitter: true
    57  backgroundHealthCheckFailLimit: 4
    58  backgroundHealthCheckFailThrottleFactor: 0.5
    59  hashing:
    60    seed: 42
    61  proto:
    62    enabled: false
    63    schema_registry:
    64      "ns1:2d":
    65        schemaFilePath: "/path/to/schema"
    66        messageName: "ns1_msg_name"
    67      ns2:
    68        schemaDeployID: "deployID-345"
    69        messageName: "ns2_msg_name"
    70  `
    71  
    72  	fd, err := ioutil.TempFile("", "config.yaml")
    73  	require.NoError(t, err)
    74  	defer func() {
    75  		assert.NoError(t, fd.Close())
    76  		assert.NoError(t, os.Remove(fd.Name()))
    77  	}()
    78  
    79  	_, err = fd.Write([]byte(in))
    80  	require.NoError(t, err)
    81  
    82  	var cfg Configuration
    83  	err = xconfig.LoadFile(&cfg, fd.Name(), xconfig.Options{})
    84  	require.NoError(t, err)
    85  
    86  	var (
    87  		levelMajority        = topology.ConsistencyLevelMajority
    88  		readUnstrictMajority = topology.ReadConsistencyLevelUnstrictMajority
    89  		iterateLowestValue   = encoding.IterateLowestValue
    90  		connectAny           = topology.ConnectConsistencyLevelAny
    91  		second10             = 10 * time.Second
    92  		second15             = 15 * time.Second
    93  		second20             = 20 * time.Second
    94  		num4                 = 4
    95  		numHalf              = 0.5
    96  		boolTrue             = true
    97  	)
    98  
    99  	expected := Configuration{
   100  		WriteConsistencyLevel:         &levelMajority,
   101  		ReadConsistencyLevel:          &readUnstrictMajority,
   102  		IterateEqualTimestampStrategy: &iterateLowestValue,
   103  		ConnectConsistencyLevel:       &connectAny,
   104  		WriteTimeout:                  &second10,
   105  		FetchTimeout:                  &second15,
   106  		ConnectTimeout:                &second20,
   107  		WriteRetry: &retry.Configuration{
   108  			InitialBackoff: 500 * time.Millisecond,
   109  			BackoffFactor:  3,
   110  			MaxRetries:     2,
   111  			Jitter:         &boolTrue,
   112  		},
   113  		FetchRetry: &retry.Configuration{
   114  			InitialBackoff: 500 * time.Millisecond,
   115  			BackoffFactor:  2,
   116  			MaxRetries:     3,
   117  			Jitter:         &boolTrue,
   118  		},
   119  		BackgroundHealthCheckFailLimit:          &num4,
   120  		BackgroundHealthCheckFailThrottleFactor: &numHalf,
   121  		HashingConfiguration: &HashingConfiguration{
   122  			Seed: 42,
   123  		},
   124  		Proto: &ProtoConfiguration{
   125  			Enabled: false,
   126  			SchemaRegistry: map[string]NamespaceProtoSchema{
   127  				"ns1:2d": {SchemaFilePath: "/path/to/schema", MessageName: "ns1_msg_name"},
   128  				"ns2":    {SchemaDeployID: "deployID-345", MessageName: "ns2_msg_name"},
   129  			},
   130  		},
   131  	}
   132  
   133  	assert.Equal(t, expected, cfg)
   134  }