github.com/m3db/m3@v1.5.0/src/msg/producer/config/writer_test.go (about) 1 // Copyright (c) 2018 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 config 22 23 import ( 24 "testing" 25 "time" 26 27 "github.com/golang/mock/gomock" 28 "github.com/stretchr/testify/require" 29 yaml "gopkg.in/yaml.v2" 30 31 "github.com/m3db/m3/src/cluster/client" 32 "github.com/m3db/m3/src/cluster/kv" 33 "github.com/m3db/m3/src/cluster/services" 34 "github.com/m3db/m3/src/x/instrument" 35 xio "github.com/m3db/m3/src/x/io" 36 ) 37 38 func TestConnectionConfiguration(t *testing.T) { 39 str := ` 40 dialTimeout: 3s 41 writeTimeout: 2s 42 keepAlivePeriod: 20s 43 resetDelay: 1s 44 retry: 45 initialBackoff: 1ms 46 maxBackoff: 2ms 47 flushInterval: 2s 48 writeBufferSize: 100 49 readBufferSize: 200 50 ` 51 52 var cfg ConnectionConfiguration 53 require.NoError(t, yaml.Unmarshal([]byte(str), &cfg)) 54 55 cOpts := cfg.NewOptions(instrument.NewOptions()) 56 require.Equal(t, 3*time.Second, cOpts.DialTimeout()) 57 require.Equal(t, 2*time.Second, cOpts.WriteTimeout()) 58 require.Equal(t, 20*time.Second, cOpts.KeepAlivePeriod()) 59 require.Equal(t, time.Second, cOpts.ResetDelay()) 60 require.Equal(t, time.Millisecond, cOpts.RetryOptions().InitialBackoff()) 61 require.Equal(t, 2*time.Millisecond, cOpts.RetryOptions().MaxBackoff()) 62 require.Equal(t, 2*time.Second, cOpts.FlushInterval()) 63 require.Equal(t, 100, cOpts.WriteBufferSize()) 64 require.Equal(t, 200, cOpts.ReadBufferSize()) 65 } 66 67 func TestWriterConfiguration(t *testing.T) { 68 str := ` 69 topicName: testTopic 70 topicServiceOverride: 71 zone: z1 72 namespace: n1 73 topicWatchInitTimeout: 1s 74 placementServiceOverride: 75 namespaces: 76 placement: n2 77 placementWatchInitTimeout: 2s 78 messagePool: 79 size: 5 80 messageRetry: 81 initialBackoff: 1ms 82 messageQueueNewWritesScanInterval: 200ms 83 messageQueueFullScanInterval: 10s 84 messageQueueScanBatchSize: 1024 85 initialAckMapSize: 1024 86 closeCheckInterval: 2s 87 ackErrorRetry: 88 initialBackoff: 2ms 89 connection: 90 dialTimeout: 5s 91 encoder: 92 maxMessageSize: 100 93 decoder: 94 maxMessageSize: 200 95 ` 96 var cfg WriterConfiguration 97 require.NoError(t, yaml.Unmarshal([]byte(str), &cfg)) 98 99 ctrl := gomock.NewController(t) 100 defer ctrl.Finish() 101 102 cs := client.NewMockClient(ctrl) 103 cs.EXPECT().Store(kv.NewOverrideOptions().SetZone("z1").SetNamespace("n1")).Return(nil, nil) 104 cs.EXPECT().Services( 105 services.NewOverrideOptions().SetNamespaceOptions( 106 services.NewNamespaceOptions().SetPlacementNamespace("n2"), 107 ), 108 ).Return(nil, nil) 109 110 wOpts, err := cfg.NewOptions(cs, instrument.NewOptions(), xio.NewOptions()) 111 require.NoError(t, err) 112 require.Equal(t, "testTopic", wOpts.TopicName()) 113 require.Equal(t, time.Second, wOpts.TopicWatchInitTimeout()) 114 require.Equal(t, 2*time.Second, wOpts.PlacementWatchInitTimeout()) 115 require.Equal(t, 5, wOpts.MessagePoolOptions().Size()) 116 require.NotNil(t, wOpts.MessageRetryNanosFn()) 117 require.Equal(t, 200*time.Millisecond, wOpts.MessageQueueNewWritesScanInterval()) 118 require.Equal(t, 10*time.Second, wOpts.MessageQueueFullScanInterval()) 119 require.Equal(t, 1024, wOpts.MessageQueueScanBatchSize()) 120 require.Equal(t, 1024, wOpts.InitialAckMapSize()) 121 require.Equal(t, 2*time.Second, wOpts.CloseCheckInterval()) 122 require.Equal(t, 2*time.Millisecond, wOpts.AckErrorRetryOptions().InitialBackoff()) 123 require.Equal(t, 5*time.Second, wOpts.ConnectionOptions().DialTimeout()) 124 require.Equal(t, 100, wOpts.EncoderOptions().MaxMessageSize()) 125 require.Equal(t, 200, wOpts.DecoderOptions().MaxMessageSize()) 126 }