github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/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.Equal(t, defaultInitialAckMapSize, opts.InitialAckMapSize()) 49 require.Equal(t, 123, opts.SetInitialAckMapSize(123).InitialAckMapSize()) 50 51 require.Equal(t, defaultCloseCheckInterval, opts.CloseCheckInterval()) 52 require.Equal(t, time.Second, opts.SetCloseCheckInterval(time.Second).CloseCheckInterval()) 53 54 require.Nil(t, opts.SetInstrumentOptions(nil).InstrumentOptions()) 55 56 require.NotNil(t, opts.MessageRetryNanosFn()) 57 } 58 59 func TestConnectionOptions(t *testing.T) { 60 opts := NewConnectionOptions() 61 62 require.Equal(t, defaultConnectionDialTimeout, opts.DialTimeout()) 63 require.Equal(t, time.Second, opts.SetDialTimeout(time.Second).DialTimeout()) 64 65 require.Equal(t, defaultConnectionWriteTimeout, opts.WriteTimeout()) 66 require.Equal(t, time.Second, opts.SetWriteTimeout(time.Second).WriteTimeout()) 67 68 require.Equal(t, defaultConnectionResetDelay, opts.ResetDelay()) 69 require.Equal(t, time.Second, opts.SetResetDelay(time.Second).ResetDelay()) 70 71 require.Nil(t, opts.SetRetryOptions(nil).RetryOptions()) 72 73 require.Equal(t, defaultConnectionFlushInterval, opts.FlushInterval()) 74 require.Equal(t, 2*time.Second, opts.SetFlushInterval(2*time.Second).FlushInterval()) 75 76 require.Equal(t, defaultConnectionBufferSize, opts.WriteBufferSize()) 77 require.Equal(t, 1, opts.SetWriteBufferSize(1).WriteBufferSize()) 78 79 require.Equal(t, defaultConnectionBufferSize, opts.ReadBufferSize()) 80 require.Equal(t, 1, opts.SetReadBufferSize(1).ReadBufferSize()) 81 82 }