github.com/m3db/m3@v1.5.0/src/msg/producer/writer/options_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 writer 22 23 import ( 24 "testing" 25 "time" 26 27 "github.com/stretchr/testify/require" 28 ) 29 30 func TestOptions(t *testing.T) { 31 opts := NewOptions() 32 33 require.Empty(t, opts.TopicName()) 34 require.Equal(t, "topic", opts.SetTopicName("topic").TopicName()) 35 36 require.Equal(t, defaultTopicWatchInitTimeout, opts.TopicWatchInitTimeout()) 37 require.Equal(t, time.Second, opts.SetTopicWatchInitTimeout(time.Second).TopicWatchInitTimeout()) 38 39 require.Equal(t, defaultPlacementWatchInitTimeout, opts.PlacementWatchInitTimeout()) 40 require.Equal(t, time.Second, opts.SetPlacementWatchInitTimeout(time.Second).PlacementWatchInitTimeout()) 41 42 require.Equal(t, defaultMessageQueueNewWritesScanInterval, opts.MessageQueueNewWritesScanInterval()) 43 require.Equal(t, time.Second, opts.SetMessageQueueNewWritesScanInterval(time.Second).MessageQueueNewWritesScanInterval()) 44 45 require.Equal(t, defaultMessageQueueFullScanInterval, opts.MessageQueueFullScanInterval()) 46 require.Equal(t, time.Minute, opts.SetMessageQueueFullScanInterval(time.Minute).MessageQueueFullScanInterval()) 47 48 require.Nil(t, opts.MessagePoolOptions()) 49 50 require.Equal(t, defaultInitialAckMapSize, opts.InitialAckMapSize()) 51 require.Equal(t, 123, opts.SetInitialAckMapSize(123).InitialAckMapSize()) 52 53 require.Equal(t, defaultCloseCheckInterval, opts.CloseCheckInterval()) 54 require.Equal(t, time.Second, opts.SetCloseCheckInterval(time.Second).CloseCheckInterval()) 55 56 require.Nil(t, opts.SetInstrumentOptions(nil).InstrumentOptions()) 57 58 require.NotNil(t, opts.MessageRetryNanosFn()) 59 } 60 61 func TestConnectionOptions(t *testing.T) { 62 opts := NewConnectionOptions() 63 64 require.Equal(t, defaultConnectionDialTimeout, opts.DialTimeout()) 65 require.Equal(t, time.Second, opts.SetDialTimeout(time.Second).DialTimeout()) 66 67 require.Equal(t, defaultConnectionWriteTimeout, opts.WriteTimeout()) 68 require.Equal(t, time.Second, opts.SetWriteTimeout(time.Second).WriteTimeout()) 69 70 require.Equal(t, defaultConnectionResetDelay, opts.ResetDelay()) 71 require.Equal(t, time.Second, opts.SetResetDelay(time.Second).ResetDelay()) 72 73 require.Nil(t, opts.SetRetryOptions(nil).RetryOptions()) 74 75 require.Equal(t, defaultConnectionFlushInterval, opts.FlushInterval()) 76 require.Equal(t, 2*time.Second, opts.SetFlushInterval(2*time.Second).FlushInterval()) 77 78 require.Equal(t, defaultConnectionBufferSize, opts.WriteBufferSize()) 79 require.Equal(t, 1, opts.SetWriteBufferSize(1).WriteBufferSize()) 80 81 require.Equal(t, defaultConnectionBufferSize, opts.ReadBufferSize()) 82 require.Equal(t, 1, opts.SetReadBufferSize(1).ReadBufferSize()) 83 84 }