From 2ca6db647a51c1a8689db99994485354118b6fa1 Mon Sep 17 00:00:00 2001 From: Riya Tyagi Date: Wed, 23 Apr 2025 09:58:04 +0530 Subject: [PATCH 1/4] Added unit tests for encoding package under dbnode along with new mocks --- src/dbnode/encoding/encoder_pool_test.go | 20 + src/dbnode/encoding/encoding_test.go | 25 + src/dbnode/encoding/iterator_pool_test.go | 49 ++ .../multi_reader_iterator_array_pool_test.go | 48 ++ src/dbnode/encoding/null_test.go | 64 ++ src/dbnode/encoding/options_test.go | 65 ++ .../encoding/proto/parse_schema_test.go | 67 ++ .../encoding/series_iterator_pool_test.go | 24 + src/dbnode/encoding/series_iterators_test.go | 50 ++ src/dbnode/generated/mocks/generate.go | 3 + src/dbnode/ratelimit/options_test.go | 22 + src/dbnode/sharding/shardset_mock.go | 171 +++++ src/dbnode/storage/limits/limits_mock.go | 502 +++++++++++++ src/dbnode/x/m3em/node/node_mock.go | 687 ++++++++++++++++++ .../writer/keep_alivable_mock_test.go | 8 +- 15 files changed, 1801 insertions(+), 4 deletions(-) create mode 100644 src/dbnode/encoding/encoder_pool_test.go create mode 100644 src/dbnode/encoding/iterator_pool_test.go create mode 100644 src/dbnode/encoding/multi_reader_iterator_array_pool_test.go create mode 100644 src/dbnode/encoding/null_test.go create mode 100644 src/dbnode/encoding/options_test.go create mode 100644 src/dbnode/encoding/proto/parse_schema_test.go create mode 100644 src/dbnode/encoding/series_iterator_pool_test.go create mode 100644 src/dbnode/encoding/series_iterators_test.go create mode 100644 src/dbnode/ratelimit/options_test.go create mode 100644 src/dbnode/sharding/shardset_mock.go create mode 100644 src/dbnode/storage/limits/limits_mock.go create mode 100644 src/dbnode/x/m3em/node/node_mock.go diff --git a/src/dbnode/encoding/encoder_pool_test.go b/src/dbnode/encoding/encoder_pool_test.go new file mode 100644 index 0000000000..e4e4f0852a --- /dev/null +++ b/src/dbnode/encoding/encoder_pool_test.go @@ -0,0 +1,20 @@ +package encoding + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/m3db/m3/src/x/pool" +) + +func TestEncoderPool(t *testing.T) { + pOpts := pool.NewObjectPoolOptions().SetSize(1) + p := NewEncoderPool(pOpts) + p.Init(NewNullEncoder) + + encoder := p.Get() + assert.NotNil(t, encoder) + + p.Put(encoder) +} diff --git a/src/dbnode/encoding/encoding_test.go b/src/dbnode/encoding/encoding_test.go index a81a86ae08..98be96767d 100644 --- a/src/dbnode/encoding/encoding_test.go +++ b/src/dbnode/encoding/encoding_test.go @@ -22,6 +22,7 @@ package encoding import ( "math" + "math/bits" "testing" "github.com/stretchr/testify/require" @@ -35,3 +36,27 @@ func TestNumSig(t *testing.T) { require.Equal(t, uint8(64), NumSig(uint64(math.MaxUint64))) require.Equal(t, uint8(64), NumSig(uint64(math.MaxUint64-1))) } + +func TestLeadingAndTrailingZeros(t *testing.T) { + tests := []struct { + name string + input uint64 + expectedLZ int + expectedTZ int + }{ + {"Zero case", 0, 64, 0}, + {"All ones", ^uint64(0), 0, 0}, + {"Single bit (LSB)", 1, 63, 0}, + {"Single bit (MSB)", 1 << 63, 0, 63}, + {"Multiple bits", 0b0000110000000000, 52, 10}, + {"Random number", 0xF0F00000000000F, bits.LeadingZeros64(0xF0F00000000000F), bits.TrailingZeros64(0xF0F00000000000F)}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + leading, trailing := LeadingAndTrailingZeros(tt.input) + require.Equal(t, tt.expectedLZ, leading) + require.Equal(t, tt.expectedTZ, trailing) + }) + } +} diff --git a/src/dbnode/encoding/iterator_pool_test.go b/src/dbnode/encoding/iterator_pool_test.go new file mode 100644 index 0000000000..e08284ef4f --- /dev/null +++ b/src/dbnode/encoding/iterator_pool_test.go @@ -0,0 +1,49 @@ +package encoding + +import ( + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + + "github.com/m3db/m3/src/dbnode/namespace" + "github.com/m3db/m3/src/dbnode/x/xio" + "github.com/m3db/m3/src/x/pool" +) + +// Mocked allocation function +func mockReaderIteratorAllocate(_ xio.Reader64, _ namespace.SchemaDescr) ReaderIterator { + ctrl := gomock.NewController(nil) + defer ctrl.Finish() + return NewMockReaderIterator(ctrl) +} + +func TestReaderIteratorPool(t *testing.T) { + opts := pool.NewObjectPoolOptions() + pool := NewReaderIteratorPool(opts) + + // Initialize pool with mock allocator + pool.Init(mockReaderIteratorAllocate) + + // Get a reader iterator from the pool + iter := pool.Get() + assert.NotNil(t, iter) + + // Return the iterator to the pool + pool.Put(iter) +} + +func TestMultiReaderIteratorPool(t *testing.T) { + opts := pool.NewObjectPoolOptions() + pool := NewMultiReaderIteratorPool(opts) + + // Initialize pool with mock allocator + pool.Init(mockReaderIteratorAllocate) + + // Get a multi-reader iterator from the pool + iter := pool.Get() + assert.NotNil(t, iter) + + // Return the iterator to the pool + pool.Put(iter) +} diff --git a/src/dbnode/encoding/multi_reader_iterator_array_pool_test.go b/src/dbnode/encoding/multi_reader_iterator_array_pool_test.go new file mode 100644 index 0000000000..560f1a094d --- /dev/null +++ b/src/dbnode/encoding/multi_reader_iterator_array_pool_test.go @@ -0,0 +1,48 @@ +package encoding + +import ( + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + + "github.com/m3db/m3/src/x/pool" +) + +func TestMultiReaderIteratorArrayPool(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Define pool bucket sizes + buckets := []pool.Bucket{ + {Capacity: 2, Count: pool.Size(-1)}, + {Capacity: 4, Count: pool.Size(2)}, + {Capacity: 8, Count: pool.Size(3)}, + } + + // Create the pool + pool := NewMultiReaderIteratorArrayPool(buckets) + pool.Init() + + // Test Get() - requesting a capacity within bucket limits + arr := pool.Get(4) + assert.Equal(t, 0, len(arr)) + assert.Equal(t, 4, cap(arr)) // Should match bucket capacity + + // Test Put() - returning an array to the pool + arr = append(arr, nil) // Simulate use + pool.Put(arr) + + // Test Get() - retrieving the same array + reusedArr := pool.Get(4) + assert.Equal(t, 0, len(reusedArr)) + assert.Equal(t, 4, cap(reusedArr)) // Should be the same bucket + + // Test Get() with an oversized request + largeArr := pool.Get(16) + assert.Equal(t, 0, len(largeArr)) + assert.Equal(t, 16, cap(largeArr)) // Should allocate new since it's out of range + + // Test Put() with an oversized array (should not be stored) + pool.Put(largeArr) +} diff --git a/src/dbnode/encoding/null_test.go b/src/dbnode/encoding/null_test.go new file mode 100644 index 0000000000..40acc70ee5 --- /dev/null +++ b/src/dbnode/encoding/null_test.go @@ -0,0 +1,64 @@ +package encoding + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/m3db/m3/src/dbnode/ts" + "github.com/m3db/m3/src/x/context" + xtime "github.com/m3db/m3/src/x/time" +) + +func TestNullEncoder(t *testing.T) { + encoder := NewNullEncoder() + + // Test Encode (should return nil) + err := encoder.Encode(ts.Datapoint{}, xtime.Unit(0), nil) + assert.NoError(t, err) + + // Test Stream (should return nil, false) + stream, ok := encoder.Stream(context.NewBackground()) + assert.Nil(t, stream) + assert.False(t, ok) + + // Test NumEncoded (should be 0) + assert.Equal(t, 0, encoder.NumEncoded()) + + // Test LastEncoded (should return an error) + _, err = encoder.LastEncoded() + assert.Error(t, err) + + // Test LastAnnotationChecksum (should return an error) + _, err = encoder.LastAnnotationChecksum() + assert.Error(t, err) + + // Test Empty (should return true) + assert.True(t, encoder.Empty()) + + // Test Len (should return 0) + assert.Equal(t, 0, encoder.Len()) + + // Test Discard (should return an empty segment) + segment := encoder.Discard() + assert.Equal(t, ts.Segment{}, segment) +} + +func TestNullReaderIterator(t *testing.T) { + iterator := NewNullReaderIterator() + + // Test Current (should return default values) + dp, unit, annotation := iterator.Current() + assert.Equal(t, ts.Datapoint{}, dp) + assert.Equal(t, xtime.Unit(0), unit) + assert.Nil(t, annotation) + + // Test Next (should return false) + assert.False(t, iterator.Next()) + + // Test Err (should return an error) + assert.Error(t, iterator.Err()) + + // Test Close (should not panic) + iterator.Close() +} diff --git a/src/dbnode/encoding/options_test.go b/src/dbnode/encoding/options_test.go new file mode 100644 index 0000000000..c171dc70a4 --- /dev/null +++ b/src/dbnode/encoding/options_test.go @@ -0,0 +1,65 @@ +package encoding + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/m3db/m3/src/x/instrument" + "github.com/m3db/m3/src/x/pool" + xtime "github.com/m3db/m3/src/x/time" +) + +func TestOptionsSettersAndGetters(t *testing.T) { + opts := NewOptions() + + // Prepare dummy values + newTimeUnit := xtime.Minute + newLRUSize := 10 + newM3TSZSize := 64 + newProtoSize := 256 + newMetrics := NewMetrics(instrument.NewOptions().MetricsScope()) + + // Create and init a dummy bytes pool + bytesPool := pool.NewCheckedBytesPool( + []pool.Bucket{{ + Capacity: 1024, + Count: 10, + }}, nil, func(s []pool.Bucket) pool.BytesPool { + return pool.NewBytesPool(s, nil) + }) + bytesPool.Init() + + // Apply all setters + opts2 := opts. + SetDefaultTimeUnit(newTimeUnit). + SetByteFieldDictionaryLRUSize(newLRUSize). + SetIStreamReaderSizeM3TSZ(newM3TSZSize). + SetIStreamReaderSizeProto(newProtoSize). + SetMetrics(newMetrics). + SetBytesPool(bytesPool) + + // Validate getters return the new values + require.Equal(t, newTimeUnit, opts2.DefaultTimeUnit()) + require.Equal(t, newLRUSize, opts2.ByteFieldDictionaryLRUSize()) + require.Equal(t, newM3TSZSize, opts2.IStreamReaderSizeM3TSZ()) + require.Equal(t, newProtoSize, opts2.IStreamReaderSizeProto()) + require.Equal(t, newMetrics, opts2.Metrics()) + require.Equal(t, bytesPool, opts2.BytesPool()) + + // Original should remain unchanged (immutability check) + require.Equal(t, defaultDefaultTimeUnit, opts.DefaultTimeUnit()) + require.Equal(t, defaultByteFieldDictLRUSize, opts.ByteFieldDictionaryLRUSize()) +} + +func TestOptionsDefaults(t *testing.T) { + opts := NewOptions() + + require.Equal(t, defaultDefaultTimeUnit, opts.DefaultTimeUnit()) + require.Equal(t, defaultByteFieldDictLRUSize, opts.ByteFieldDictionaryLRUSize()) + require.Equal(t, defaultIStreamReaderSizeM3TSZ, opts.IStreamReaderSizeM3TSZ()) + require.Equal(t, defaultIStreamReaderSizeProto, opts.IStreamReaderSizeProto()) + require.NotNil(t, opts.TimeEncodingSchemes()) + require.Equal(t, defaultMarkerEncodingScheme, opts.MarkerEncodingScheme()) + require.NotNil(t, opts.Metrics()) +} diff --git a/src/dbnode/encoding/proto/parse_schema_test.go b/src/dbnode/encoding/proto/parse_schema_test.go new file mode 100644 index 0000000000..7e9441f1ae --- /dev/null +++ b/src/dbnode/encoding/proto/parse_schema_test.go @@ -0,0 +1,67 @@ +package proto + +import ( + "os" + "testing" + + "github.com/jhump/protoreflect/desc" + "github.com/stretchr/testify/assert" +) + +func TestParseProtoSchema(t *testing.T) { + // Create a temporary proto file for testing + protoContent := `syntax = "proto3"; + + message TestMessage { + string name = 1; + int32 age = 2; + }` + + protoFile := "test.proto" + err := os.WriteFile(protoFile, []byte(protoContent), 0644) + assert.NoError(t, err) + defer func(name string) { + _ = os.Remove(name) + }(protoFile) // Clean up after the test + + tests := []struct { + name string + filePath string + messageName string + expectErr bool + expectedType *desc.MessageDescriptor + }{ + { + name: "Valid proto file and message", + filePath: protoFile, + messageName: "TestMessage", + expectErr: false, + }, + { + name: "Invalid proto file path", + filePath: "non_existent.proto", + messageName: "TestMessage", + expectErr: true, + }, + { + name: "Message not found", + filePath: protoFile, + messageName: "UnknownMessage", + expectErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result, err := ParseProtoSchema(tt.filePath, tt.messageName) + if tt.expectErr { + assert.Error(t, err, "Expected an error but got none") + assert.Nil(t, result) + } else { + assert.NoError(t, err, "Expected no error but got one") + assert.NotNil(t, result, "Expected a valid MessageDescriptor but got nil") + assert.Equal(t, tt.messageName, result.GetName()) + } + }) + } +} diff --git a/src/dbnode/encoding/series_iterator_pool_test.go b/src/dbnode/encoding/series_iterator_pool_test.go new file mode 100644 index 0000000000..d229161993 --- /dev/null +++ b/src/dbnode/encoding/series_iterator_pool_test.go @@ -0,0 +1,24 @@ +package encoding + +import ( + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" +) + +func TestSeriesIteratorPool(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Create mock object pool + pool := NewSeriesIteratorPool(nil) + pool.Init() + + // Test Get() + iter := pool.Get() + assert.NotNil(t, iter) + + // Test Put() + pool.Put(iter) +} diff --git a/src/dbnode/encoding/series_iterators_test.go b/src/dbnode/encoding/series_iterators_test.go new file mode 100644 index 0000000000..3b704bc21b --- /dev/null +++ b/src/dbnode/encoding/series_iterators_test.go @@ -0,0 +1,50 @@ +package encoding + +import ( + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" +) + +func TestSeriesIterators(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Create mock iterators using GoMock + iter1 := NewMockSeriesIterator(ctrl) + iter2 := NewMockSeriesIterator(ctrl) + + iter1.EXPECT().Close().Times(1) + iter2.EXPECT().Close().Times(1) + + // Test NewSeriesIterators + iters := NewSeriesIterators([]SeriesIterator{iter1, iter2}) + assert.Equal(t, 2, iters.Len()) + assert.Equal(t, []SeriesIterator{iter1, iter2}, iters.Iters()) + + // Test SetAt + mockIter := NewMockSeriesIterator(ctrl) + iters.SetAt(1, mockIter) + assert.Equal(t, mockIter, iters.Iters()[1]) + + // Test Reset + iters.Reset(1) + assert.Equal(t, 1, iters.Len()) + assert.Nil(t, iters.Iters()[0]) // Reset should nil out values + + // Test NewSizedSeriesIterators + sizedIters := NewSizedSeriesIterators(2) + assert.Equal(t, 2, sizedIters.Len()) + sizedIters.SetAt(0, iter1) + sizedIters.SetAt(1, iter2) + + // Test Close + sizedIters.Close() + assert.Nil(t, sizedIters.Iters()[0]) + + // Test EmptySeriesIterators + assert.Equal(t, 0, EmptySeriesIterators.Len()) + assert.Nil(t, EmptySeriesIterators.Iters()) + EmptySeriesIterators.Close() // Should do nothing +} diff --git a/src/dbnode/generated/mocks/generate.go b/src/dbnode/generated/mocks/generate.go index 9f6e3ead64..ba1e97f1b9 100644 --- a/src/dbnode/generated/mocks/generate.go +++ b/src/dbnode/generated/mocks/generate.go @@ -45,5 +45,8 @@ //go:generate sh -c "mockgen -package=index -destination=../../storage/index/index_mock.go -source=../../storage/index/types.go" //go:generate sh -c "mockgen -package=permits -destination=../../storage/limits/permits/permits_mock.go -source=../../storage/limits/permits/types.go" //go:generate sh -c "mockgen -package=xpool -destination=../../x/xpool/xpool_mock.go -source=../../x/xpool/types.go" +//go:generate sh -c "mockgen -package=m3db -destination=../../x/m3em/node/node_mock.go -source=../../x/m3em/node/types.go" +//go:generate sh -c "mockgen -package=sharding -destination=../../sharding/shardset_mock.go -source=../../sharding/types.go" +//go:generate sh -c "mockgen -package=limits -destination=../../storage/limits/limits_mock.go -source=../../storage/limits/types.go" package mocks diff --git a/src/dbnode/ratelimit/options_test.go b/src/dbnode/ratelimit/options_test.go new file mode 100644 index 0000000000..bf0e49e0f4 --- /dev/null +++ b/src/dbnode/ratelimit/options_test.go @@ -0,0 +1,22 @@ +package ratelimit + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOptionsAssignment(t *testing.T) { + var ( + limitCheckEvery = 64 + limitEnabled = true + limitMbps = 128.0 + rOpts = NewOptions() + ) + rOpts = rOpts.SetLimitCheckEvery(limitCheckEvery). + SetLimitEnabled(limitEnabled).SetLimitMbps(limitMbps) + + require.Equal(t, rOpts.LimitCheckEvery(), limitCheckEvery) + require.Equal(t, rOpts.LimitEnabled(), limitEnabled) + require.Equal(t, rOpts.LimitMbps(), limitMbps) +} diff --git a/src/dbnode/sharding/shardset_mock.go b/src/dbnode/sharding/shardset_mock.go new file mode 100644 index 0000000000..b8d963adf6 --- /dev/null +++ b/src/dbnode/sharding/shardset_mock.go @@ -0,0 +1,171 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ../../sharding/types.go + +// Copyright (c) 2025 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Package sharding is a generated GoMock package. +package sharding + +import ( + "reflect" + + "github.com/m3db/m3/src/cluster/shard" + "github.com/m3db/m3/src/x/ident" + + "github.com/golang/mock/gomock" +) + +// MockShardSet is a mock of ShardSet interface. +type MockShardSet struct { + ctrl *gomock.Controller + recorder *MockShardSetMockRecorder +} + +// MockShardSetMockRecorder is the mock recorder for MockShardSet. +type MockShardSetMockRecorder struct { + mock *MockShardSet +} + +// NewMockShardSet creates a new mock instance. +func NewMockShardSet(ctrl *gomock.Controller) *MockShardSet { + mock := &MockShardSet{ctrl: ctrl} + mock.recorder = &MockShardSetMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockShardSet) EXPECT() *MockShardSetMockRecorder { + return m.recorder +} + +// All mocks base method. +func (m *MockShardSet) All() []shard.Shard { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "All") + ret0, _ := ret[0].([]shard.Shard) + return ret0 +} + +// All indicates an expected call of All. +func (mr *MockShardSetMockRecorder) All() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "All", reflect.TypeOf((*MockShardSet)(nil).All)) +} + +// AllIDs mocks base method. +func (m *MockShardSet) AllIDs() []uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AllIDs") + ret0, _ := ret[0].([]uint32) + return ret0 +} + +// AllIDs indicates an expected call of AllIDs. +func (mr *MockShardSetMockRecorder) AllIDs() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllIDs", reflect.TypeOf((*MockShardSet)(nil).AllIDs)) +} + +// HashFn mocks base method. +func (m *MockShardSet) HashFn() HashFn { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HashFn") + ret0, _ := ret[0].(HashFn) + return ret0 +} + +// HashFn indicates an expected call of HashFn. +func (mr *MockShardSetMockRecorder) HashFn() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HashFn", reflect.TypeOf((*MockShardSet)(nil).HashFn)) +} + +// Lookup mocks base method. +func (m *MockShardSet) Lookup(id ident.ID) uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Lookup", id) + ret0, _ := ret[0].(uint32) + return ret0 +} + +// Lookup indicates an expected call of Lookup. +func (mr *MockShardSetMockRecorder) Lookup(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lookup", reflect.TypeOf((*MockShardSet)(nil).Lookup), id) +} + +// LookupShard mocks base method. +func (m *MockShardSet) LookupShard(id uint32) (shard.Shard, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LookupShard", id) + ret0, _ := ret[0].(shard.Shard) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LookupShard indicates an expected call of LookupShard. +func (mr *MockShardSetMockRecorder) LookupShard(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LookupShard", reflect.TypeOf((*MockShardSet)(nil).LookupShard), id) +} + +// LookupStateByID mocks base method. +func (m *MockShardSet) LookupStateByID(shardID uint32) (shard.State, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LookupStateByID", shardID) + ret0, _ := ret[0].(shard.State) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LookupStateByID indicates an expected call of LookupStateByID. +func (mr *MockShardSetMockRecorder) LookupStateByID(shardID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LookupStateByID", reflect.TypeOf((*MockShardSet)(nil).LookupStateByID), shardID) +} + +// Max mocks base method. +func (m *MockShardSet) Max() uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Max") + ret0, _ := ret[0].(uint32) + return ret0 +} + +// Max indicates an expected call of Max. +func (mr *MockShardSetMockRecorder) Max() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Max", reflect.TypeOf((*MockShardSet)(nil).Max)) +} + +// Min mocks base method. +func (m *MockShardSet) Min() uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Min") + ret0, _ := ret[0].(uint32) + return ret0 +} + +// Min indicates an expected call of Min. +func (mr *MockShardSetMockRecorder) Min() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Min", reflect.TypeOf((*MockShardSet)(nil).Min)) +} diff --git a/src/dbnode/storage/limits/limits_mock.go b/src/dbnode/storage/limits/limits_mock.go new file mode 100644 index 0000000000..905a33d6c9 --- /dev/null +++ b/src/dbnode/storage/limits/limits_mock.go @@ -0,0 +1,502 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ../../storage/limits/types.go + +// Copyright (c) 2025 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Package limits is a generated GoMock package. +package limits + +import ( + "reflect" + + "github.com/m3db/m3/src/x/instrument" + + "github.com/golang/mock/gomock" +) + +// MockQueryLimits is a mock of QueryLimits interface. +type MockQueryLimits struct { + ctrl *gomock.Controller + recorder *MockQueryLimitsMockRecorder +} + +// MockQueryLimitsMockRecorder is the mock recorder for MockQueryLimits. +type MockQueryLimitsMockRecorder struct { + mock *MockQueryLimits +} + +// NewMockQueryLimits creates a new mock instance. +func NewMockQueryLimits(ctrl *gomock.Controller) *MockQueryLimits { + mock := &MockQueryLimits{ctrl: ctrl} + mock.recorder = &MockQueryLimitsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockQueryLimits) EXPECT() *MockQueryLimitsMockRecorder { + return m.recorder +} + +// AggregateDocsLimit mocks base method. +func (m *MockQueryLimits) AggregateDocsLimit() LookbackLimit { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AggregateDocsLimit") + ret0, _ := ret[0].(LookbackLimit) + return ret0 +} + +// AggregateDocsLimit indicates an expected call of AggregateDocsLimit. +func (mr *MockQueryLimitsMockRecorder) AggregateDocsLimit() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AggregateDocsLimit", reflect.TypeOf((*MockQueryLimits)(nil).AggregateDocsLimit)) +} + +// AnyFetchExceeded mocks base method. +func (m *MockQueryLimits) AnyFetchExceeded() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AnyFetchExceeded") + ret0, _ := ret[0].(error) + return ret0 +} + +// AnyFetchExceeded indicates an expected call of AnyFetchExceeded. +func (mr *MockQueryLimitsMockRecorder) AnyFetchExceeded() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AnyFetchExceeded", reflect.TypeOf((*MockQueryLimits)(nil).AnyFetchExceeded)) +} + +// BytesReadLimit mocks base method. +func (m *MockQueryLimits) BytesReadLimit() LookbackLimit { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BytesReadLimit") + ret0, _ := ret[0].(LookbackLimit) + return ret0 +} + +// BytesReadLimit indicates an expected call of BytesReadLimit. +func (mr *MockQueryLimitsMockRecorder) BytesReadLimit() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesReadLimit", reflect.TypeOf((*MockQueryLimits)(nil).BytesReadLimit)) +} + +// FetchDocsLimit mocks base method. +func (m *MockQueryLimits) FetchDocsLimit() LookbackLimit { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FetchDocsLimit") + ret0, _ := ret[0].(LookbackLimit) + return ret0 +} + +// FetchDocsLimit indicates an expected call of FetchDocsLimit. +func (mr *MockQueryLimitsMockRecorder) FetchDocsLimit() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchDocsLimit", reflect.TypeOf((*MockQueryLimits)(nil).FetchDocsLimit)) +} + +// Start mocks base method. +func (m *MockQueryLimits) Start() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Start") +} + +// Start indicates an expected call of Start. +func (mr *MockQueryLimitsMockRecorder) Start() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockQueryLimits)(nil).Start)) +} + +// Stop mocks base method. +func (m *MockQueryLimits) Stop() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Stop") +} + +// Stop indicates an expected call of Stop. +func (mr *MockQueryLimitsMockRecorder) Stop() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockQueryLimits)(nil).Stop)) +} + +// MockLookbackLimit is a mock of LookbackLimit interface. +type MockLookbackLimit struct { + ctrl *gomock.Controller + recorder *MockLookbackLimitMockRecorder +} + +// MockLookbackLimitMockRecorder is the mock recorder for MockLookbackLimit. +type MockLookbackLimitMockRecorder struct { + mock *MockLookbackLimit +} + +// NewMockLookbackLimit creates a new mock instance. +func NewMockLookbackLimit(ctrl *gomock.Controller) *MockLookbackLimit { + mock := &MockLookbackLimit{ctrl: ctrl} + mock.recorder = &MockLookbackLimitMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockLookbackLimit) EXPECT() *MockLookbackLimitMockRecorder { + return m.recorder +} + +// Inc mocks base method. +func (m *MockLookbackLimit) Inc(new int, source []byte) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Inc", new, source) + ret0, _ := ret[0].(error) + return ret0 +} + +// Inc indicates an expected call of Inc. +func (mr *MockLookbackLimitMockRecorder) Inc(new, source interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Inc", reflect.TypeOf((*MockLookbackLimit)(nil).Inc), new, source) +} + +// Options mocks base method. +func (m *MockLookbackLimit) Options() LookbackLimitOptions { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Options") + ret0, _ := ret[0].(LookbackLimitOptions) + return ret0 +} + +// Options indicates an expected call of Options. +func (mr *MockLookbackLimitMockRecorder) Options() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Options", reflect.TypeOf((*MockLookbackLimit)(nil).Options)) +} + +// Start mocks base method. +func (m *MockLookbackLimit) Start() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Start") +} + +// Start indicates an expected call of Start. +func (mr *MockLookbackLimitMockRecorder) Start() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockLookbackLimit)(nil).Start)) +} + +// Stop mocks base method. +func (m *MockLookbackLimit) Stop() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Stop") +} + +// Stop indicates an expected call of Stop. +func (mr *MockLookbackLimitMockRecorder) Stop() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockLookbackLimit)(nil).Stop)) +} + +// Update mocks base method. +func (m *MockLookbackLimit) Update(opts LookbackLimitOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Update", opts) + ret0, _ := ret[0].(error) + return ret0 +} + +// Update indicates an expected call of Update. +func (mr *MockLookbackLimitMockRecorder) Update(opts interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockLookbackLimit)(nil).Update), opts) +} + +// MockSourceLoggerBuilder is a mock of SourceLoggerBuilder interface. +type MockSourceLoggerBuilder struct { + ctrl *gomock.Controller + recorder *MockSourceLoggerBuilderMockRecorder +} + +// MockSourceLoggerBuilderMockRecorder is the mock recorder for MockSourceLoggerBuilder. +type MockSourceLoggerBuilderMockRecorder struct { + mock *MockSourceLoggerBuilder +} + +// NewMockSourceLoggerBuilder creates a new mock instance. +func NewMockSourceLoggerBuilder(ctrl *gomock.Controller) *MockSourceLoggerBuilder { + mock := &MockSourceLoggerBuilder{ctrl: ctrl} + mock.recorder = &MockSourceLoggerBuilderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSourceLoggerBuilder) EXPECT() *MockSourceLoggerBuilderMockRecorder { + return m.recorder +} + +// NewSourceLogger mocks base method. +func (m *MockSourceLoggerBuilder) NewSourceLogger(name string, opts instrument.Options) SourceLogger { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewSourceLogger", name, opts) + ret0, _ := ret[0].(SourceLogger) + return ret0 +} + +// NewSourceLogger indicates an expected call of NewSourceLogger. +func (mr *MockSourceLoggerBuilderMockRecorder) NewSourceLogger(name, opts interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewSourceLogger", reflect.TypeOf((*MockSourceLoggerBuilder)(nil).NewSourceLogger), name, opts) +} + +// MockSourceLogger is a mock of SourceLogger interface. +type MockSourceLogger struct { + ctrl *gomock.Controller + recorder *MockSourceLoggerMockRecorder +} + +// MockSourceLoggerMockRecorder is the mock recorder for MockSourceLogger. +type MockSourceLoggerMockRecorder struct { + mock *MockSourceLogger +} + +// NewMockSourceLogger creates a new mock instance. +func NewMockSourceLogger(ctrl *gomock.Controller) *MockSourceLogger { + mock := &MockSourceLogger{ctrl: ctrl} + mock.recorder = &MockSourceLoggerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSourceLogger) EXPECT() *MockSourceLoggerMockRecorder { + return m.recorder +} + +// LogSourceValue mocks base method. +func (m *MockSourceLogger) LogSourceValue(val int64, source []byte) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "LogSourceValue", val, source) +} + +// LogSourceValue indicates an expected call of LogSourceValue. +func (mr *MockSourceLoggerMockRecorder) LogSourceValue(val, source interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LogSourceValue", reflect.TypeOf((*MockSourceLogger)(nil).LogSourceValue), val, source) +} + +// MockOptions is a mock of Options interface. +type MockOptions struct { + ctrl *gomock.Controller + recorder *MockOptionsMockRecorder +} + +// MockOptionsMockRecorder is the mock recorder for MockOptions. +type MockOptionsMockRecorder struct { + mock *MockOptions +} + +// NewMockOptions creates a new mock instance. +func NewMockOptions(ctrl *gomock.Controller) *MockOptions { + mock := &MockOptions{ctrl: ctrl} + mock.recorder = &MockOptionsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockOptions) EXPECT() *MockOptionsMockRecorder { + return m.recorder +} + +// AggregateDocsLimitOpts mocks base method. +func (m *MockOptions) AggregateDocsLimitOpts() LookbackLimitOptions { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AggregateDocsLimitOpts") + ret0, _ := ret[0].(LookbackLimitOptions) + return ret0 +} + +// AggregateDocsLimitOpts indicates an expected call of AggregateDocsLimitOpts. +func (mr *MockOptionsMockRecorder) AggregateDocsLimitOpts() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AggregateDocsLimitOpts", reflect.TypeOf((*MockOptions)(nil).AggregateDocsLimitOpts)) +} + +// BytesReadLimitOpts mocks base method. +func (m *MockOptions) BytesReadLimitOpts() LookbackLimitOptions { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BytesReadLimitOpts") + ret0, _ := ret[0].(LookbackLimitOptions) + return ret0 +} + +// BytesReadLimitOpts indicates an expected call of BytesReadLimitOpts. +func (mr *MockOptionsMockRecorder) BytesReadLimitOpts() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesReadLimitOpts", reflect.TypeOf((*MockOptions)(nil).BytesReadLimitOpts)) +} + +// DiskSeriesReadLimitOpts mocks base method. +func (m *MockOptions) DiskSeriesReadLimitOpts() LookbackLimitOptions { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DiskSeriesReadLimitOpts") + ret0, _ := ret[0].(LookbackLimitOptions) + return ret0 +} + +// DiskSeriesReadLimitOpts indicates an expected call of DiskSeriesReadLimitOpts. +func (mr *MockOptionsMockRecorder) DiskSeriesReadLimitOpts() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DiskSeriesReadLimitOpts", reflect.TypeOf((*MockOptions)(nil).DiskSeriesReadLimitOpts)) +} + +// DocsLimitOpts mocks base method. +func (m *MockOptions) DocsLimitOpts() LookbackLimitOptions { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DocsLimitOpts") + ret0, _ := ret[0].(LookbackLimitOptions) + return ret0 +} + +// DocsLimitOpts indicates an expected call of DocsLimitOpts. +func (mr *MockOptionsMockRecorder) DocsLimitOpts() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DocsLimitOpts", reflect.TypeOf((*MockOptions)(nil).DocsLimitOpts)) +} + +// InstrumentOptions mocks base method. +func (m *MockOptions) InstrumentOptions() instrument.Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InstrumentOptions") + ret0, _ := ret[0].(instrument.Options) + return ret0 +} + +// InstrumentOptions indicates an expected call of InstrumentOptions. +func (mr *MockOptionsMockRecorder) InstrumentOptions() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstrumentOptions", reflect.TypeOf((*MockOptions)(nil).InstrumentOptions)) +} + +// SetAggregateDocsLimitOpts mocks base method. +func (m *MockOptions) SetAggregateDocsLimitOpts(arg0 LookbackLimitOptions) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetAggregateDocsLimitOpts", arg0) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetAggregateDocsLimitOpts indicates an expected call of SetAggregateDocsLimitOpts. +func (mr *MockOptionsMockRecorder) SetAggregateDocsLimitOpts(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAggregateDocsLimitOpts", reflect.TypeOf((*MockOptions)(nil).SetAggregateDocsLimitOpts), arg0) +} + +// SetBytesReadLimitOpts mocks base method. +func (m *MockOptions) SetBytesReadLimitOpts(value LookbackLimitOptions) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetBytesReadLimitOpts", value) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetBytesReadLimitOpts indicates an expected call of SetBytesReadLimitOpts. +func (mr *MockOptionsMockRecorder) SetBytesReadLimitOpts(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetBytesReadLimitOpts", reflect.TypeOf((*MockOptions)(nil).SetBytesReadLimitOpts), value) +} + +// SetDiskSeriesReadLimitOpts mocks base method. +func (m *MockOptions) SetDiskSeriesReadLimitOpts(value LookbackLimitOptions) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetDiskSeriesReadLimitOpts", value) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetDiskSeriesReadLimitOpts indicates an expected call of SetDiskSeriesReadLimitOpts. +func (mr *MockOptionsMockRecorder) SetDiskSeriesReadLimitOpts(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDiskSeriesReadLimitOpts", reflect.TypeOf((*MockOptions)(nil).SetDiskSeriesReadLimitOpts), value) +} + +// SetDocsLimitOpts mocks base method. +func (m *MockOptions) SetDocsLimitOpts(value LookbackLimitOptions) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetDocsLimitOpts", value) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetDocsLimitOpts indicates an expected call of SetDocsLimitOpts. +func (mr *MockOptionsMockRecorder) SetDocsLimitOpts(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDocsLimitOpts", reflect.TypeOf((*MockOptions)(nil).SetDocsLimitOpts), value) +} + +// SetInstrumentOptions mocks base method. +func (m *MockOptions) SetInstrumentOptions(value instrument.Options) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetInstrumentOptions", value) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetInstrumentOptions indicates an expected call of SetInstrumentOptions. +func (mr *MockOptionsMockRecorder) SetInstrumentOptions(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInstrumentOptions", reflect.TypeOf((*MockOptions)(nil).SetInstrumentOptions), value) +} + +// SetSourceLoggerBuilder mocks base method. +func (m *MockOptions) SetSourceLoggerBuilder(value SourceLoggerBuilder) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetSourceLoggerBuilder", value) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetSourceLoggerBuilder indicates an expected call of SetSourceLoggerBuilder. +func (mr *MockOptionsMockRecorder) SetSourceLoggerBuilder(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSourceLoggerBuilder", reflect.TypeOf((*MockOptions)(nil).SetSourceLoggerBuilder), value) +} + +// SourceLoggerBuilder mocks base method. +func (m *MockOptions) SourceLoggerBuilder() SourceLoggerBuilder { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SourceLoggerBuilder") + ret0, _ := ret[0].(SourceLoggerBuilder) + return ret0 +} + +// SourceLoggerBuilder indicates an expected call of SourceLoggerBuilder. +func (mr *MockOptionsMockRecorder) SourceLoggerBuilder() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SourceLoggerBuilder", reflect.TypeOf((*MockOptions)(nil).SourceLoggerBuilder)) +} + +// Validate mocks base method. +func (m *MockOptions) Validate() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Validate") + ret0, _ := ret[0].(error) + return ret0 +} + +// Validate indicates an expected call of Validate. +func (mr *MockOptionsMockRecorder) Validate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockOptions)(nil).Validate)) +} diff --git a/src/dbnode/x/m3em/node/node_mock.go b/src/dbnode/x/m3em/node/node_mock.go new file mode 100644 index 0000000000..4f6d0ed846 --- /dev/null +++ b/src/dbnode/x/m3em/node/node_mock.go @@ -0,0 +1,687 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ../../x/m3em/node/types.go + +// Copyright (c) 2025 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Package m3db is a generated GoMock package. +package m3db + +import ( + "reflect" + + "github.com/m3db/m3/src/cluster/generated/proto/placementpb" + "github.com/m3db/m3/src/cluster/placement" + "github.com/m3db/m3/src/cluster/shard" + "github.com/m3db/m3/src/m3em/build" + "github.com/m3db/m3/src/m3em/node" + "github.com/m3db/m3/src/x/instrument" + + "github.com/golang/mock/gomock" +) + +// MockNode is a mock of Node interface. +type MockNode struct { + ctrl *gomock.Controller + recorder *MockNodeMockRecorder +} + +// MockNodeMockRecorder is the mock recorder for MockNode. +type MockNodeMockRecorder struct { + mock *MockNode +} + +// NewMockNode creates a new mock instance. +func NewMockNode(ctrl *gomock.Controller) *MockNode { + mock := &MockNode{ctrl: ctrl} + mock.recorder = &MockNodeMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockNode) EXPECT() *MockNodeMockRecorder { + return m.recorder +} + +// Bootstrapped mocks base method. +func (m *MockNode) Bootstrapped() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Bootstrapped") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Bootstrapped indicates an expected call of Bootstrapped. +func (mr *MockNodeMockRecorder) Bootstrapped() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bootstrapped", reflect.TypeOf((*MockNode)(nil).Bootstrapped)) +} + +// Clone mocks base method. +func (m *MockNode) Clone() placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Clone") + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// Clone indicates an expected call of Clone. +func (mr *MockNodeMockRecorder) Clone() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clone", reflect.TypeOf((*MockNode)(nil).Clone)) +} + +// Close mocks base method. +func (m *MockNode) Close() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close") + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockNodeMockRecorder) Close() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockNode)(nil).Close)) +} + +// DeregisterListener mocks base method. +func (m *MockNode) DeregisterListener(arg0 node.ListenerID) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "DeregisterListener", arg0) +} + +// DeregisterListener indicates an expected call of DeregisterListener. +func (mr *MockNodeMockRecorder) DeregisterListener(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeregisterListener", reflect.TypeOf((*MockNode)(nil).DeregisterListener), arg0) +} + +// Endpoint mocks base method. +func (m *MockNode) Endpoint() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Endpoint") + ret0, _ := ret[0].(string) + return ret0 +} + +// Endpoint indicates an expected call of Endpoint. +func (mr *MockNodeMockRecorder) Endpoint() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Endpoint", reflect.TypeOf((*MockNode)(nil).Endpoint)) +} + +// GetRemoteOutput mocks base method. +func (m *MockNode) GetRemoteOutput(t node.RemoteOutputType, localDest string) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRemoteOutput", t, localDest) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRemoteOutput indicates an expected call of GetRemoteOutput. +func (mr *MockNodeMockRecorder) GetRemoteOutput(t, localDest interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRemoteOutput", reflect.TypeOf((*MockNode)(nil).GetRemoteOutput), t, localDest) +} + +// Health mocks base method. +func (m *MockNode) Health() (NodeHealth, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Health") + ret0, _ := ret[0].(NodeHealth) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Health indicates an expected call of Health. +func (mr *MockNodeMockRecorder) Health() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Health", reflect.TypeOf((*MockNode)(nil).Health)) +} + +// Hostname mocks base method. +func (m *MockNode) Hostname() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Hostname") + ret0, _ := ret[0].(string) + return ret0 +} + +// Hostname indicates an expected call of Hostname. +func (mr *MockNodeMockRecorder) Hostname() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Hostname", reflect.TypeOf((*MockNode)(nil).Hostname)) +} + +// ID mocks base method. +func (m *MockNode) ID() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ID") + ret0, _ := ret[0].(string) + return ret0 +} + +// ID indicates an expected call of ID. +func (mr *MockNodeMockRecorder) ID() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ID", reflect.TypeOf((*MockNode)(nil).ID)) +} + +// IsAvailable mocks base method. +func (m *MockNode) IsAvailable() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsAvailable") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsAvailable indicates an expected call of IsAvailable. +func (mr *MockNodeMockRecorder) IsAvailable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAvailable", reflect.TypeOf((*MockNode)(nil).IsAvailable)) +} + +// IsInitializing mocks base method. +func (m *MockNode) IsInitializing() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsInitializing") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsInitializing indicates an expected call of IsInitializing. +func (mr *MockNodeMockRecorder) IsInitializing() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsInitializing", reflect.TypeOf((*MockNode)(nil).IsInitializing)) +} + +// IsLeaving mocks base method. +func (m *MockNode) IsLeaving() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsLeaving") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsLeaving indicates an expected call of IsLeaving. +func (mr *MockNodeMockRecorder) IsLeaving() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsLeaving", reflect.TypeOf((*MockNode)(nil).IsLeaving)) +} + +// IsolationGroup mocks base method. +func (m *MockNode) IsolationGroup() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsolationGroup") + ret0, _ := ret[0].(string) + return ret0 +} + +// IsolationGroup indicates an expected call of IsolationGroup. +func (mr *MockNodeMockRecorder) IsolationGroup() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsolationGroup", reflect.TypeOf((*MockNode)(nil).IsolationGroup)) +} + +// Metadata mocks base method. +func (m *MockNode) Metadata() placement.InstanceMetadata { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Metadata") + ret0, _ := ret[0].(placement.InstanceMetadata) + return ret0 +} + +// Metadata indicates an expected call of Metadata. +func (mr *MockNodeMockRecorder) Metadata() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Metadata", reflect.TypeOf((*MockNode)(nil).Metadata)) +} + +// Port mocks base method. +func (m *MockNode) Port() uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Port") + ret0, _ := ret[0].(uint32) + return ret0 +} + +// Port indicates an expected call of Port. +func (mr *MockNodeMockRecorder) Port() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Port", reflect.TypeOf((*MockNode)(nil).Port)) +} + +// Proto mocks base method. +func (m *MockNode) Proto() (*placementpb.Instance, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Proto") + ret0, _ := ret[0].(*placementpb.Instance) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Proto indicates an expected call of Proto. +func (mr *MockNodeMockRecorder) Proto() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Proto", reflect.TypeOf((*MockNode)(nil).Proto)) +} + +// RegisterListener mocks base method. +func (m *MockNode) RegisterListener(arg0 node.Listener) node.ListenerID { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RegisterListener", arg0) + ret0, _ := ret[0].(node.ListenerID) + return ret0 +} + +// RegisterListener indicates an expected call of RegisterListener. +func (mr *MockNodeMockRecorder) RegisterListener(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterListener", reflect.TypeOf((*MockNode)(nil).RegisterListener), arg0) +} + +// SetEndpoint mocks base method. +func (m *MockNode) SetEndpoint(ip string) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetEndpoint", ip) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetEndpoint indicates an expected call of SetEndpoint. +func (mr *MockNodeMockRecorder) SetEndpoint(ip interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetEndpoint", reflect.TypeOf((*MockNode)(nil).SetEndpoint), ip) +} + +// SetHostname mocks base method. +func (m *MockNode) SetHostname(value string) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetHostname", value) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetHostname indicates an expected call of SetHostname. +func (mr *MockNodeMockRecorder) SetHostname(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHostname", reflect.TypeOf((*MockNode)(nil).SetHostname), value) +} + +// SetID mocks base method. +func (m *MockNode) SetID(id string) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetID", id) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetID indicates an expected call of SetID. +func (mr *MockNodeMockRecorder) SetID(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetID", reflect.TypeOf((*MockNode)(nil).SetID), id) +} + +// SetIsolationGroup mocks base method. +func (m *MockNode) SetIsolationGroup(r string) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetIsolationGroup", r) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetIsolationGroup indicates an expected call of SetIsolationGroup. +func (mr *MockNodeMockRecorder) SetIsolationGroup(r interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetIsolationGroup", reflect.TypeOf((*MockNode)(nil).SetIsolationGroup), r) +} + +// SetMetadata mocks base method. +func (m *MockNode) SetMetadata(value placement.InstanceMetadata) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetMetadata", value) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetMetadata indicates an expected call of SetMetadata. +func (mr *MockNodeMockRecorder) SetMetadata(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetMetadata", reflect.TypeOf((*MockNode)(nil).SetMetadata), value) +} + +// SetPort mocks base method. +func (m *MockNode) SetPort(value uint32) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetPort", value) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetPort indicates an expected call of SetPort. +func (mr *MockNodeMockRecorder) SetPort(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetPort", reflect.TypeOf((*MockNode)(nil).SetPort), value) +} + +// SetShardSetID mocks base method. +func (m *MockNode) SetShardSetID(value uint32) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetShardSetID", value) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetShardSetID indicates an expected call of SetShardSetID. +func (mr *MockNodeMockRecorder) SetShardSetID(value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetShardSetID", reflect.TypeOf((*MockNode)(nil).SetShardSetID), value) +} + +// SetShards mocks base method. +func (m *MockNode) SetShards(s shard.Shards) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetShards", s) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetShards indicates an expected call of SetShards. +func (mr *MockNodeMockRecorder) SetShards(s interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetShards", reflect.TypeOf((*MockNode)(nil).SetShards), s) +} + +// SetWeight mocks base method. +func (m *MockNode) SetWeight(w uint32) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetWeight", w) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetWeight indicates an expected call of SetWeight. +func (mr *MockNodeMockRecorder) SetWeight(w interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWeight", reflect.TypeOf((*MockNode)(nil).SetWeight), w) +} + +// SetZone mocks base method. +func (m *MockNode) SetZone(z string) placement.Instance { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetZone", z) + ret0, _ := ret[0].(placement.Instance) + return ret0 +} + +// SetZone indicates an expected call of SetZone. +func (mr *MockNodeMockRecorder) SetZone(z interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetZone", reflect.TypeOf((*MockNode)(nil).SetZone), z) +} + +// Setup mocks base method. +func (m *MockNode) Setup(build build.ServiceBuild, config build.ServiceConfiguration, token string, force bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Setup", build, config, token, force) + ret0, _ := ret[0].(error) + return ret0 +} + +// Setup indicates an expected call of Setup. +func (mr *MockNodeMockRecorder) Setup(build, config, token, force interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Setup", reflect.TypeOf((*MockNode)(nil).Setup), build, config, token, force) +} + +// ShardSetID mocks base method. +func (m *MockNode) ShardSetID() uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ShardSetID") + ret0, _ := ret[0].(uint32) + return ret0 +} + +// ShardSetID indicates an expected call of ShardSetID. +func (mr *MockNodeMockRecorder) ShardSetID() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShardSetID", reflect.TypeOf((*MockNode)(nil).ShardSetID)) +} + +// Shards mocks base method. +func (m *MockNode) Shards() shard.Shards { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Shards") + ret0, _ := ret[0].(shard.Shards) + return ret0 +} + +// Shards indicates an expected call of Shards. +func (mr *MockNodeMockRecorder) Shards() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shards", reflect.TypeOf((*MockNode)(nil).Shards)) +} + +// Start mocks base method. +func (m *MockNode) Start() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Start") + ret0, _ := ret[0].(error) + return ret0 +} + +// Start indicates an expected call of Start. +func (mr *MockNodeMockRecorder) Start() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockNode)(nil).Start)) +} + +// Status mocks base method. +func (m *MockNode) Status() node.Status { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Status") + ret0, _ := ret[0].(node.Status) + return ret0 +} + +// Status indicates an expected call of Status. +func (mr *MockNodeMockRecorder) Status() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Status", reflect.TypeOf((*MockNode)(nil).Status)) +} + +// Stop mocks base method. +func (m *MockNode) Stop() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Stop") + ret0, _ := ret[0].(error) + return ret0 +} + +// Stop indicates an expected call of Stop. +func (mr *MockNodeMockRecorder) Stop() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockNode)(nil).Stop)) +} + +// String mocks base method. +func (m *MockNode) String() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "String") + ret0, _ := ret[0].(string) + return ret0 +} + +// String indicates an expected call of String. +func (mr *MockNodeMockRecorder) String() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "String", reflect.TypeOf((*MockNode)(nil).String)) +} + +// Teardown mocks base method. +func (m *MockNode) Teardown() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Teardown") + ret0, _ := ret[0].(error) + return ret0 +} + +// Teardown indicates an expected call of Teardown. +func (mr *MockNodeMockRecorder) Teardown() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Teardown", reflect.TypeOf((*MockNode)(nil).Teardown)) +} + +// TransferLocalFile mocks base method. +func (m *MockNode) TransferLocalFile(localSrc string, destPaths []string, overwrite bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TransferLocalFile", localSrc, destPaths, overwrite) + ret0, _ := ret[0].(error) + return ret0 +} + +// TransferLocalFile indicates an expected call of TransferLocalFile. +func (mr *MockNodeMockRecorder) TransferLocalFile(localSrc, destPaths, overwrite interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransferLocalFile", reflect.TypeOf((*MockNode)(nil).TransferLocalFile), localSrc, destPaths, overwrite) +} + +// Weight mocks base method. +func (m *MockNode) Weight() uint32 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Weight") + ret0, _ := ret[0].(uint32) + return ret0 +} + +// Weight indicates an expected call of Weight. +func (mr *MockNodeMockRecorder) Weight() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Weight", reflect.TypeOf((*MockNode)(nil).Weight)) +} + +// Zone mocks base method. +func (m *MockNode) Zone() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Zone") + ret0, _ := ret[0].(string) + return ret0 +} + +// Zone indicates an expected call of Zone. +func (mr *MockNodeMockRecorder) Zone() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Zone", reflect.TypeOf((*MockNode)(nil).Zone)) +} + +// MockOptions is a mock of Options interface. +type MockOptions struct { + ctrl *gomock.Controller + recorder *MockOptionsMockRecorder +} + +// MockOptionsMockRecorder is the mock recorder for MockOptions. +type MockOptionsMockRecorder struct { + mock *MockOptions +} + +// NewMockOptions creates a new mock instance. +func NewMockOptions(ctrl *gomock.Controller) *MockOptions { + mock := &MockOptions{ctrl: ctrl} + mock.recorder = &MockOptionsMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockOptions) EXPECT() *MockOptionsMockRecorder { + return m.recorder +} + +// InstrumentOptions mocks base method. +func (m *MockOptions) InstrumentOptions() instrument.Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InstrumentOptions") + ret0, _ := ret[0].(instrument.Options) + return ret0 +} + +// InstrumentOptions indicates an expected call of InstrumentOptions. +func (mr *MockOptionsMockRecorder) InstrumentOptions() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstrumentOptions", reflect.TypeOf((*MockOptions)(nil).InstrumentOptions)) +} + +// NodeOptions mocks base method. +func (m *MockOptions) NodeOptions() node.Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NodeOptions") + ret0, _ := ret[0].(node.Options) + return ret0 +} + +// NodeOptions indicates an expected call of NodeOptions. +func (mr *MockOptionsMockRecorder) NodeOptions() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeOptions", reflect.TypeOf((*MockOptions)(nil).NodeOptions)) +} + +// SetInstrumentOptions mocks base method. +func (m *MockOptions) SetInstrumentOptions(arg0 instrument.Options) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetInstrumentOptions", arg0) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetInstrumentOptions indicates an expected call of SetInstrumentOptions. +func (mr *MockOptionsMockRecorder) SetInstrumentOptions(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetInstrumentOptions", reflect.TypeOf((*MockOptions)(nil).SetInstrumentOptions), arg0) +} + +// SetNodeOptions mocks base method. +func (m *MockOptions) SetNodeOptions(arg0 node.Options) Options { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetNodeOptions", arg0) + ret0, _ := ret[0].(Options) + return ret0 +} + +// SetNodeOptions indicates an expected call of SetNodeOptions. +func (mr *MockOptionsMockRecorder) SetNodeOptions(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetNodeOptions", reflect.TypeOf((*MockOptions)(nil).SetNodeOptions), arg0) +} + +// Validate mocks base method. +func (m *MockOptions) Validate() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Validate") + ret0, _ := ret[0].(error) + return ret0 +} + +// Validate indicates an expected call of Validate. +func (mr *MockOptionsMockRecorder) Validate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockOptions)(nil).Validate)) +} diff --git a/src/msg/producer/writer/keep_alivable_mock_test.go b/src/msg/producer/writer/keep_alivable_mock_test.go index 52b16977eb..03e3f47241 100644 --- a/src/msg/producer/writer/keep_alivable_mock_test.go +++ b/src/msg/producer/writer/keep_alivable_mock_test.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: src/msg/producer/writer/consumer_writer.go +// Source: src/msg/producer/writer/consumer_go // Copyright (c) 2025 Uber Technologies, Inc. // @@ -25,10 +25,10 @@ package writer import ( - reflect "reflect" - time "time" + "reflect" + "time" - gomock "github.com/golang/mock/gomock" + "github.com/golang/mock/gomock" ) // MockconsumerWriter is a mock of consumerWriter interface. From 6f2fc4a6e2ce3629e42dd4bf7b1c5a8973bb71b6 Mon Sep 17 00:00:00 2001 From: Riya Tyagi Date: Wed, 23 Apr 2025 12:21:02 +0530 Subject: [PATCH 2/4] Added tests for dbnode/encoding/proto package --- .../encoding/proto/buffer_decode_test.go | 516 ++++++++++++++++++ .../encoding/proto/buffer_encode_test.go | 320 +++++++++++ .../encoding/proto/custom_marshal_test.go | 493 ++++++++++++++++- .../encoding/proto/custom_unmarshal_test.go | 165 +++++- src/dbnode/encoding/proto/round_trip_test.go | 2 + src/dbnode/encoding/proto/testdata/test.proto | 10 + 6 files changed, 1504 insertions(+), 2 deletions(-) create mode 100644 src/dbnode/encoding/proto/buffer_decode_test.go create mode 100644 src/dbnode/encoding/proto/buffer_encode_test.go create mode 100644 src/dbnode/encoding/proto/testdata/test.proto diff --git a/src/dbnode/encoding/proto/buffer_decode_test.go b/src/dbnode/encoding/proto/buffer_decode_test.go new file mode 100644 index 0000000000..e4fcf4221c --- /dev/null +++ b/src/dbnode/encoding/proto/buffer_decode_test.go @@ -0,0 +1,516 @@ +// Copyright (c) 2024 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package proto + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBuffer(t *testing.T) { + tests := []struct { + name string + buf []byte + index int + expected *buffer + }{ + { + name: "empty buffer", + buf: []byte{}, + index: 0, + expected: &buffer{buf: []byte{}, index: 0}, + }, + { + name: "non-empty buffer", + buf: []byte{1, 2, 3}, + index: 0, + expected: &buffer{buf: []byte{1, 2, 3}, index: 0}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.buf) + assert.Equal(t, tt.expected, cb) + }) + } +} + +func TestBufferReset(t *testing.T) { + tests := []struct { + name string + initial []byte + new []byte + expected *buffer + }{ + { + name: "reset empty buffer", + initial: []byte{1, 2, 3}, + new: []byte{}, + expected: &buffer{buf: []byte{}, index: 0}, + }, + { + name: "reset non-empty buffer", + initial: []byte{1, 2, 3}, + new: []byte{4, 5, 6}, + expected: &buffer{buf: []byte{4, 5, 6}, index: 0}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.initial) + cb.reset(tt.new) + assert.Equal(t, tt.expected, cb) + }) + } +} + +func TestBufferEOF(t *testing.T) { + tests := []struct { + name string + buf []byte + index int + expected bool + }{ + { + name: "empty buffer", + buf: []byte{}, + index: 0, + expected: true, + }, + { + name: "non-empty buffer at start", + buf: []byte{1, 2, 3}, + index: 0, + expected: false, + }, + { + name: "non-empty buffer at end", + buf: []byte{1, 2, 3}, + index: 3, + expected: true, + }, + { + name: "non-empty buffer past end", + buf: []byte{1, 2, 3}, + index: 4, + expected: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := &buffer{buf: tt.buf, index: tt.index} + assert.Equal(t, tt.expected, cb.eof()) + }) + } +} + +func TestBufferSkip(t *testing.T) { + tests := []struct { + name string + buf []byte + index int + count int + expected int + success bool + }{ + { + name: "skip within bounds", + buf: []byte{1, 2, 3}, + index: 0, + count: 2, + expected: 0, + success: true, + }, + { + name: "skip to end", + buf: []byte{1, 2, 3}, + index: 0, + count: 3, + expected: 0, + success: true, + }, + { + name: "skip past end", + buf: []byte{1, 2, 3}, + index: 0, + count: 4, + expected: 0, + success: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := &buffer{buf: tt.buf, index: tt.index} + result, success := cb.skip(tt.count) + assert.Equal(t, tt.expected, result) + assert.Equal(t, tt.success, success) + if success { + assert.Equal(t, tt.index+tt.count, cb.index) + } + }) + } +} + +func TestBufferDecodeVarint(t *testing.T) { + tests := []struct { + name string + buf []byte + expected uint64 + err bool + }{ + { + name: "single byte", + buf: []byte{0x01}, + expected: 1, + err: false, + }, + { + name: "two bytes", + buf: []byte{0x81, 0x01}, + expected: 129, + err: false, + }, + { + name: "three bytes", + buf: []byte{0x81, 0x81, 0x01}, + expected: 16513, + err: false, + }, + { + name: "empty buffer", + buf: []byte{}, + expected: 0, + err: true, + }, + { + name: "overflow", + buf: []byte{0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81}, + expected: 0, + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.buf) + result, err := cb.decodeVarint() + if tt.err { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.expected, result) + } + }) + } +} + +func TestBufferDecodeTagAndWireType(t *testing.T) { + tests := []struct { + name string + buf []byte + expected int32 + wireType int8 + err bool + }{ + { + name: "valid tag and wire type", + buf: []byte{0x08}, // tag 1, wire type 0 + expected: 1, + wireType: 0, + err: false, + }, + { + name: "valid tag and wire type with multiple bytes", + buf: []byte{0x88, 0x01}, // tag 17, wire type 0 + expected: 17, + wireType: 0, + err: false, + }, + { + name: "empty buffer", + buf: []byte{}, + expected: 0, + wireType: 0, + err: true, + }, + { + name: "tag too large", + buf: []byte{0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88}, + expected: 0, + wireType: 0, + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.buf) + tag, wireType, err := cb.decodeTagAndWireType() + if tt.err { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.expected, tag) + assert.Equal(t, tt.wireType, wireType) + } + }) + } +} + +func TestBufferDecodeFixed64(t *testing.T) { + tests := []struct { + name string + buf []byte + expected uint64 + err bool + }{ + { + name: "valid fixed64", + buf: []byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + expected: 1, + err: false, + }, + { + name: "valid fixed64 with high bits set", + buf: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + expected: 0xFFFFFFFFFFFFFFFF, + err: false, + }, + { + name: "buffer too short", + buf: []byte{0x01, 0x00, 0x00, 0x00}, + expected: 0, + err: true, + }, + { + name: "empty buffer", + buf: []byte{}, + expected: 0, + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.buf) + result, err := cb.decodeFixed64() + if tt.err { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.expected, result) + } + }) + } +} + +func TestBufferDecodeFixed32(t *testing.T) { + tests := []struct { + name string + buf []byte + expected uint64 + err bool + }{ + { + name: "valid fixed32", + buf: []byte{0x01, 0x00, 0x00, 0x00}, + expected: 1, + err: false, + }, + { + name: "valid fixed32 with high bits set", + buf: []byte{0xFF, 0xFF, 0xFF, 0xFF}, + expected: 0xFFFFFFFF, + err: false, + }, + { + name: "buffer too short", + buf: []byte{0x01, 0x00}, + expected: 0, + err: true, + }, + { + name: "empty buffer", + buf: []byte{}, + expected: 0, + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.buf) + result, err := cb.decodeFixed32() + if tt.err { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.expected, result) + } + }) + } +} + +func TestDecodeZigZag32(t *testing.T) { + tests := []struct { + name string + input uint64 + expected int32 + }{ + { + name: "zero", + input: 0, + expected: 0, + }, + { + name: "positive number", + input: 2, + expected: 1, + }, + { + name: "negative number", + input: 1, + expected: -1, + }, + { + name: "large positive number", + input: 0xFFFFFFFE, + expected: 0x7FFFFFFF, + }, + { + name: "large negative number", + input: 0xFFFFFFFF, + expected: -0x80000000, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := decodeZigZag32(tt.input) + assert.Equal(t, tt.expected, result) + }) + } +} + +func TestDecodeZigZag64(t *testing.T) { + tests := []struct { + name string + input uint64 + expected int64 + }{ + { + name: "zero", + input: 0, + expected: 0, + }, + { + name: "positive number", + input: 2, + expected: 1, + }, + { + name: "negative number", + input: 1, + expected: -1, + }, + { + name: "large positive number", + input: 0xFFFFFFFFFFFFFFFE, + expected: 0x7FFFFFFFFFFFFFFF, + }, + { + name: "large negative number", + input: 0xFFFFFFFFFFFFFFFF, + expected: -0x8000000000000000, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := decodeZigZag64(tt.input) + assert.Equal(t, tt.expected, result) + }) + } +} + +func TestBufferDecodeRawBytes(t *testing.T) { + tests := []struct { + name string + buf []byte + alloc bool + expected []byte + err bool + }{ + { + name: "valid bytes with allocation", + buf: []byte{0x03, 0x01, 0x02, 0x03}, + alloc: true, + expected: []byte{0x01, 0x02, 0x03}, + err: false, + }, + { + name: "valid bytes without allocation", + buf: []byte{0x03, 0x01, 0x02, 0x03}, + alloc: false, + expected: []byte{0x01, 0x02, 0x03}, + err: false, + }, + { + name: "empty bytes", + buf: []byte{0x00}, + alloc: true, + expected: []byte{}, + err: false, + }, + { + name: "buffer too short", + buf: []byte{0x03, 0x01}, + alloc: true, + expected: nil, + err: true, + }, + { + name: "empty buffer", + buf: []byte{}, + alloc: true, + expected: nil, + err: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.buf) + result, err := cb.decodeRawBytes(tt.alloc) + if tt.err { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.expected, result) + } + }) + } +} diff --git a/src/dbnode/encoding/proto/buffer_encode_test.go b/src/dbnode/encoding/proto/buffer_encode_test.go new file mode 100644 index 0000000000..12ab7e6db5 --- /dev/null +++ b/src/dbnode/encoding/proto/buffer_encode_test.go @@ -0,0 +1,320 @@ +// Copyright (c) 2024 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package proto + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBufferEncodeTagAndWireType(t *testing.T) { + tests := []struct { + name string + tag int32 + wireType int8 + expected []byte + }{ + { + name: "tag 1 wire type 0", + tag: 1, + wireType: 0, + expected: []byte{0x08}, + }, + { + name: "tag 17 wire type 0", + tag: 17, + wireType: 0, + expected: []byte{0x88, 0x01}, + }, + { + name: "tag 1 wire type 1", + tag: 1, + wireType: 1, + expected: []byte{0x09}, + }, + { + name: "tag 1 wire type 2", + tag: 1, + wireType: 2, + expected: []byte{0x0A}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(nil) + cb.encodeTagAndWireType(tt.tag, tt.wireType) + assert.Equal(t, tt.expected, cb.buf) + }) + } +} + +func TestBufferEncodeVarint(t *testing.T) { + tests := []struct { + name string + input uint64 + expected []byte + }{ + { + name: "single byte", + input: 1, + expected: []byte{0x01}, + }, + { + name: "two bytes", + input: 129, + expected: []byte{0x81, 0x01}, + }, + { + name: "three bytes", + input: 16513, + expected: []byte{0x81, 0x81, 0x01}, + }, + { + name: "max uint64", + input: 0xFFFFFFFFFFFFFFFF, + expected: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(nil) + cb.encodeVarint(tt.input) + assert.Equal(t, tt.expected, cb.buf) + }) + } +} + +func TestBufferEncodeFixed64(t *testing.T) { + tests := []struct { + name string + input uint64 + expected []byte + }{ + { + name: "zero", + input: 0, + expected: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + }, + { + name: "one", + input: 1, + expected: []byte{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + }, + { + name: "max uint64", + input: 0xFFFFFFFFFFFFFFFF, + expected: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(nil) + cb.encodeFixed64(tt.input) + assert.Equal(t, tt.expected, cb.buf) + }) + } +} + +func TestBufferEncodeFixed32(t *testing.T) { + tests := []struct { + name string + input uint32 + expected []byte + }{ + { + name: "zero", + input: 0, + expected: []byte{0x00, 0x00, 0x00, 0x00}, + }, + { + name: "one", + input: 1, + expected: []byte{0x01, 0x00, 0x00, 0x00}, + }, + { + name: "max uint32", + input: 0xFFFFFFFF, + expected: []byte{0xFF, 0xFF, 0xFF, 0xFF}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(nil) + cb.encodeFixed32(tt.input) + assert.Equal(t, tt.expected, cb.buf) + }) + } +} + +func TestBufferEncodeRawBytes(t *testing.T) { + tests := []struct { + name string + input []byte + expected []byte + }{ + { + name: "empty bytes", + input: []byte{}, + expected: []byte{0x00}, + }, + { + name: "single byte", + input: []byte{0x01}, + expected: []byte{0x01, 0x01}, + }, + { + name: "multiple bytes", + input: []byte{0x01, 0x02, 0x03}, + expected: []byte{0x03, 0x01, 0x02, 0x03}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(nil) + cb.encodeRawBytes(tt.input) + assert.Equal(t, tt.expected, cb.buf) + }) + } +} + +func TestBufferAppend(t *testing.T) { + tests := []struct { + name string + initial []byte + append []byte + expected []byte + }{ + { + name: "append to empty buffer", + initial: []byte{}, + append: []byte{1, 2, 3}, + expected: []byte{1, 2, 3}, + }, + { + name: "append to non-empty buffer", + initial: []byte{1, 2, 3}, + append: []byte{4, 5, 6}, + expected: []byte{1, 2, 3, 4, 5, 6}, + }, + { + name: "append empty bytes", + initial: []byte{1, 2, 3}, + append: []byte{}, + expected: []byte{1, 2, 3}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cb := newCodedBuffer(tt.initial) + cb.append(tt.append) + assert.Equal(t, tt.expected, cb.buf) + }) + } +} + +func TestEncodeZigZag32(t *testing.T) { + tests := []struct { + name string + input int32 + expected uint64 + }{ + { + name: "zero", + input: 0, + expected: 0, + }, + { + name: "positive number", + input: 1, + expected: 2, + }, + { + name: "negative number", + input: -1, + expected: 1, + }, + { + name: "large positive number", + input: 0x7FFFFFFF, + expected: 0xFFFFFFFE, + }, + { + name: "large negative number", + input: -0x80000000, + expected: 0xFFFFFFFF, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := encodeZigZag32(tt.input) + assert.Equal(t, tt.expected, result) + }) + } +} + +func TestEncodeZigZag64(t *testing.T) { + tests := []struct { + name string + input int64 + expected uint64 + }{ + { + name: "zero", + input: 0, + expected: 0, + }, + { + name: "positive number", + input: 1, + expected: 2, + }, + { + name: "negative number", + input: -1, + expected: 1, + }, + { + name: "large positive number", + input: 0x7FFFFFFFFFFFFFFF, + expected: 0xFFFFFFFFFFFFFFFE, + }, + { + name: "large negative number", + input: -0x8000000000000000, + expected: 0xFFFFFFFFFFFFFFFF, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := encodeZigZag64(tt.input) + assert.Equal(t, tt.expected, result) + }) + } +} \ No newline at end of file diff --git a/src/dbnode/encoding/proto/custom_marshal_test.go b/src/dbnode/encoding/proto/custom_marshal_test.go index bfeaf54a97..ab5be5945c 100644 --- a/src/dbnode/encoding/proto/custom_marshal_test.go +++ b/src/dbnode/encoding/proto/custom_marshal_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,6 +22,7 @@ package proto import ( "fmt" + "math" "testing" "github.com/jhump/protoreflect/dynamic" @@ -84,3 +85,493 @@ func mapInterfaceToMapString(ifaceMap map[interface{}]interface{}) map[string]st } return stringMap } + +func TestCustomMarshallerFloat64(t *testing.T) { + tests := []struct { + name string + tag int32 + value float64 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0.0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 1.5, + expected: []byte{0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x3F}, + }, + { + name: "negative value", + tag: 1, + value: -1.5, + expected: []byte{0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xBF}, + }, + { + name: "max float64", + tag: 1, + value: math.MaxFloat64, + expected: []byte{0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0x7F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encFloat64(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerFloat32(t *testing.T) { + tests := []struct { + name string + tag int32 + value float32 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0.0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 1.5, + expected: []byte{0x0D, 0x00, 0x00, 0xC0, 0x3F}, + }, + { + name: "negative value", + tag: 1, + value: -1.5, + expected: []byte{0x0D, 0x00, 0x00, 0xC0, 0xBF}, + }, + { + name: "max float32", + tag: 1, + value: math.MaxFloat32, + expected: []byte{0x0D, 0xFF, 0xFF, 0x7F, 0x7F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encFloat32(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerBool(t *testing.T) { + tests := []struct { + name string + tag int32 + value bool + expected []byte + }{ + { + name: "false value", + tag: 1, + value: false, + expected: nil, + }, + { + name: "true value", + tag: 1, + value: true, + expected: []byte{0x08, 0x01}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encBool(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerInt32(t *testing.T) { + tests := []struct { + name string + tag int32 + value int32 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x08, 0x2A}, + }, + { + name: "negative value", + tag: 1, + value: -42, + expected: []byte{0x08, 0xD6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}, + }, + { + name: "max int32", + tag: 1, + value: math.MaxInt32, + expected: []byte{0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0x07}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encInt32(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerSInt32(t *testing.T) { + tests := []struct { + name string + tag int32 + value int32 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x08, 0x54}, + }, + { + name: "negative value", + tag: 1, + value: -42, + expected: []byte{0x08, 0x53}, + }, + { + name: "max int32", + tag: 1, + value: math.MaxInt32, + expected: []byte{0x08, 0xFE, 0xFF, 0xFF, 0xFF, 0x0F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encSInt32(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerSFixedInt32(t *testing.T) { + tests := []struct { + name string + tag int32 + value int32 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: []byte{0x0D, 0x00, 0x00, 0x00, 0x00}, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x0D, 0x2A, 0x00, 0x00, 0x00}, + }, + { + name: "negative value", + tag: 1, + value: -42, + expected: []byte{0x0D, 0xD6, 0xFF, 0xFF, 0xFF}, + }, + { + name: "max int32", + tag: 1, + value: math.MaxInt32, + expected: []byte{0x0D, 0xFF, 0xFF, 0xFF, 0x7F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encSFixedInt32(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerUInt32(t *testing.T) { + tests := []struct { + name string + tag int32 + value uint32 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x08, 0x2A}, + }, + { + name: "max uint32", + tag: 1, + value: math.MaxUint32, + expected: []byte{0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encUInt32(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerInt64(t *testing.T) { + tests := []struct { + name string + tag int32 + value int64 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x08, 0x2A}, + }, + { + name: "negative value", + tag: 1, + value: -42, + expected: []byte{0x08, 0xD6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}, + }, + { + name: "max int64", + tag: 1, + value: math.MaxInt64, + expected: []byte{0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encInt64(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerSInt64(t *testing.T) { + tests := []struct { + name string + tag int32 + value int64 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x08, 0x54}, + }, + { + name: "negative value", + tag: 1, + value: -42, + expected: []byte{0x08, 0x53}, + }, + { + name: "max int64", + tag: 1, + value: math.MaxInt64, + expected: []byte{0x08, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encSInt64(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerSFixedInt64(t *testing.T) { + tests := []struct { + name string + tag int32 + value int64 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: []byte{0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x09, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + }, + { + name: "negative value", + tag: 1, + value: -42, + expected: []byte{0x09, 0xD6, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + }, + { + name: "max int64", + tag: 1, + value: math.MaxInt64, + expected: []byte{0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encSFixedInt64(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerUInt64(t *testing.T) { + tests := []struct { + name string + tag int32 + value uint64 + expected []byte + }{ + { + name: "zero value", + tag: 1, + value: 0, + expected: nil, + }, + { + name: "positive value", + tag: 1, + value: 42, + expected: []byte{0x08, 0x2A}, + }, + { + name: "max uint64", + tag: 1, + value: math.MaxUint64, + expected: []byte{0x08, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encUInt64(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerBytes(t *testing.T) { + tests := []struct { + name string + tag int32 + value []byte + expected []byte + }{ + { + name: "empty bytes", + tag: 1, + value: []byte{}, + expected: nil, + }, + { + name: "single byte", + tag: 1, + value: []byte{0x01}, + expected: []byte{0x0A, 0x01, 0x01}, + }, + { + name: "multiple bytes", + tag: 1, + value: []byte{0x01, 0x02, 0x03}, + expected: []byte{0x0A, 0x03, 0x01, 0x02, 0x03}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := newCustomMarshaller() + m.encBytes(tt.tag, tt.value) + require.Equal(t, tt.expected, m.bytes()) + }) + } +} + +func TestCustomMarshallerReset(t *testing.T) { + m := newCustomMarshaller() + + // Add some data + m.encInt32(1, 42) + require.NotEmpty(t, m.bytes()) + + // Reset + m.reset() + require.Empty(t, m.bytes()) + + // Verify we can still use it after reset + m.encInt32(1, 42) + require.Equal(t, []byte{0x08, 0x2A}, m.bytes()) +} diff --git a/src/dbnode/encoding/proto/custom_unmarshal_test.go b/src/dbnode/encoding/proto/custom_unmarshal_test.go index 5bcd21e375..ea7436f969 100644 --- a/src/dbnode/encoding/proto/custom_unmarshal_test.go +++ b/src/dbnode/encoding/proto/custom_unmarshal_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2019 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -22,10 +22,14 @@ package proto import ( "bytes" + "fmt" "math" "testing" "time" + "github.com/golang/protobuf/proto" + dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" + "github.com/jhump/protoreflect/desc" "github.com/jhump/protoreflect/dynamic" "github.com/stretchr/testify/require" ) @@ -178,3 +182,162 @@ func assertAttributesEqualMarshalledBytes( require.NoError(t, err) require.Equal(t, expectedMarshalled, actualMarshalled) } + +func TestCustomUnmarshaller(t *testing.T) { + tests := []struct { + name string + fields []*dpb.FieldDescriptorProto + input []byte + expectedCustom []unmarshalValue + expectedNonCustom []marshalledField + skipUnknown bool + expectError bool + }{ + { + name: "empty message", + fields: []*dpb.FieldDescriptorProto{ + {Name: proto.String("field1"), Number: proto.Int32(1), Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum()}, + }, + input: []byte{}, + expectedCustom: []unmarshalValue{}, + expectedNonCustom: []marshalledField{}, + }, + { + name: "single int32 field", + fields: []*dpb.FieldDescriptorProto{ + {Name: proto.String("field1"), Number: proto.Int32(1), Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum()}, + }, + input: []byte{0x08, 0x2A}, // field 1, value 42 + expectedCustom: []unmarshalValue{ + {fieldNumber: 1, v: 42}, + }, + expectedNonCustom: []marshalledField{}, + }, + { + name: "unknown field with skip", + fields: []*dpb.FieldDescriptorProto{ + {Name: proto.String("field1"), Number: proto.Int32(1), Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum()}, + }, + input: []byte{0x08, 0x2A, 0x10, 0x01}, // field 1=42, unknown field 2=1 + expectedCustom: []unmarshalValue{ + {fieldNumber: 1, v: 42}, + }, + expectedNonCustom: []marshalledField{}, + skipUnknown: true, + }, + { + name: "unknown field without skip", + fields: []*dpb.FieldDescriptorProto{ + {Name: proto.String("field1"), Number: proto.Int32(1), Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum()}, + }, + input: []byte{0x08, 0x2A, 0x10, 0x01}, // field 1=42, unknown field 2=1 + expectError: true, + }, + { + name: "repeated field", + fields: []*dpb.FieldDescriptorProto{ + {Name: proto.String("field1"), Number: proto.Int32(1), Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum(), Label: dpb.FieldDescriptorProto_LABEL_REPEATED.Enum()}, + }, + input: []byte{0x08, 0x2A, 0x08, 0x2B}, // field 1=[42, 43] + expectedCustom: []unmarshalValue{}, + expectedNonCustom: []marshalledField{ + {fieldNum: 1, marshalled: []byte{0x08, 0x2A, 0x08, 0x2B}}, + }, + }, + } + + for i, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Convert field descriptors to proto format + schema := createTestSchema(tt.fields, i) + fields := make([]*dpb.FieldDescriptorProto, 0, len(schema.GetFields())) + for _, f := range schema.GetFields() { + fields = append(fields, f.AsFieldDescriptorProto()) + } + + unmarshaller := newCustomFieldUnmarshaller(customUnmarshallerOptions{ + skipUnknownFields: tt.skipUnknown, + }) + + err := unmarshaller.resetAndUnmarshal(schema, tt.input) + if tt.expectError { + require.Error(t, err) + return + } + require.NoError(t, err) + + // Verify custom values + customValues := unmarshaller.sortedCustomFieldValues() + require.Equal(t, len(tt.expectedCustom), len(customValues)) + for i, expected := range tt.expectedCustom { + require.Equal(t, expected.fieldNumber, customValues[i].fieldNumber) + require.Equal(t, expected.v, customValues[i].v) + } + + // Verify non-custom values + nonCustomValues := unmarshaller.sortedNonCustomFieldValues() + require.Equal(t, len(tt.expectedNonCustom), len(nonCustomValues)) + for i, expected := range tt.expectedNonCustom { + require.Equal(t, expected.fieldNum, nonCustomValues[i].fieldNum) + require.Equal(t, expected.marshalled, nonCustomValues[i].marshalled) + } + }) + } +} + +func TestUnmarshalValue(t *testing.T) { + tests := []struct { + name string + value unmarshalValue + asBool bool + asUint64 uint64 + asInt64 int64 + asFloat64 float64 + asBytes []byte + }{ + { + name: "bool false", + value: unmarshalValue{v: 0}, + asBool: false, + asUint64: 0, + asInt64: 0, + asFloat64: 0.0, + }, + { + name: "bytes", + value: unmarshalValue{bytes: []byte{0x01, 0x02, 0x03}}, + asBytes: []byte{0x01, 0x02, 0x03}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.asBool, tt.value.asBool()) + require.Equal(t, tt.asUint64, tt.value.asUint64()) + require.Equal(t, tt.asInt64, tt.value.asInt64()) + require.Equal(t, tt.asFloat64, tt.value.asFloat64()) + require.Equal(t, tt.asBytes, tt.value.asBytes()) + }) + } +} + +func createTestSchema(fields []*dpb.FieldDescriptorProto, i int) *desc.MessageDescriptor { + // Generate a unique name for each schema + uniqueName := fmt.Sprintf("test_%d.proto", i) + + msg := &dpb.DescriptorProto{ + Name: proto.String("TestMessage"), + Field: fields, + } + file := &dpb.FileDescriptorProto{ + Name: proto.String(uniqueName), + Package: proto.String("test"), + MessageType: []*dpb.DescriptorProto{msg}, + Syntax: proto.String("proto3"), + } + fd, err := desc.CreateFileDescriptor(file) + if err != nil { + panic(err) + } + return fd.GetMessageTypes()[0] +} diff --git a/src/dbnode/encoding/proto/round_trip_test.go b/src/dbnode/encoding/proto/round_trip_test.go index e1846d98bb..b735c04082 100644 --- a/src/dbnode/encoding/proto/round_trip_test.go +++ b/src/dbnode/encoding/proto/round_trip_test.go @@ -192,6 +192,8 @@ func TestRoundTrip(t *testing.T) { } require.NoError(t, iter.Err()) require.Equal(t, len(testCases), i) + iter.Close() + iter.Reset(r, namespace.GetTestSchemaDescr(testVLSchema)) } func TestRoundTripMidStreamSchemaChanges(t *testing.T) { diff --git a/src/dbnode/encoding/proto/testdata/test.proto b/src/dbnode/encoding/proto/testdata/test.proto new file mode 100644 index 0000000000..4e4df07de1 --- /dev/null +++ b/src/dbnode/encoding/proto/testdata/test.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package test; + +message TestMessage { + map map_field = 1; + repeated int32 repeated_field = 2; + TestMessage message_field = 3; + int32 scalar_field = 4; +} \ No newline at end of file From 17363a2369afc1eb5ee1911c2bb4c9b1e6b2b921 Mon Sep 17 00:00:00 2001 From: Riya Tyagi Date: Wed, 23 Apr 2025 18:03:11 +0530 Subject: [PATCH 3/4] fix lint errors --- src/dbnode/encoding/proto/buffer_decode_test.go | 6 ++++-- src/dbnode/encoding/proto/buffer_encode_test.go | 4 +++- src/dbnode/encoding/proto/custom_unmarshal_test.go | 12 +++++++----- src/dbnode/storage/namespace_readers.go | 3 ++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/dbnode/encoding/proto/buffer_decode_test.go b/src/dbnode/encoding/proto/buffer_decode_test.go index e4fcf4221c..c847433b52 100644 --- a/src/dbnode/encoding/proto/buffer_decode_test.go +++ b/src/dbnode/encoding/proto/buffer_decode_test.go @@ -374,6 +374,7 @@ func TestBufferDecodeFixed32(t *testing.T) { } } +// nolint:dupl func TestDecodeZigZag32(t *testing.T) { tests := []struct { name string @@ -415,6 +416,7 @@ func TestDecodeZigZag32(t *testing.T) { } } +// nolint:dupl func TestDecodeZigZag64(t *testing.T) { tests := []struct { name string @@ -458,10 +460,10 @@ func TestDecodeZigZag64(t *testing.T) { func TestBufferDecodeRawBytes(t *testing.T) { tests := []struct { - name string buf []byte - alloc bool expected []byte + name string + alloc bool err bool }{ { diff --git a/src/dbnode/encoding/proto/buffer_encode_test.go b/src/dbnode/encoding/proto/buffer_encode_test.go index 12ab7e6db5..572a77e304 100644 --- a/src/dbnode/encoding/proto/buffer_encode_test.go +++ b/src/dbnode/encoding/proto/buffer_encode_test.go @@ -237,6 +237,7 @@ func TestBufferAppend(t *testing.T) { } } +// nolint:dupl func TestEncodeZigZag32(t *testing.T) { tests := []struct { name string @@ -278,6 +279,7 @@ func TestEncodeZigZag32(t *testing.T) { } } +// nolint:dupl func TestEncodeZigZag64(t *testing.T) { tests := []struct { name string @@ -317,4 +319,4 @@ func TestEncodeZigZag64(t *testing.T) { assert.Equal(t, tt.expected, result) }) } -} \ No newline at end of file +} diff --git a/src/dbnode/encoding/proto/custom_unmarshal_test.go b/src/dbnode/encoding/proto/custom_unmarshal_test.go index ea7436f969..0d2fbf9e83 100644 --- a/src/dbnode/encoding/proto/custom_unmarshal_test.go +++ b/src/dbnode/encoding/proto/custom_unmarshal_test.go @@ -236,7 +236,9 @@ func TestCustomUnmarshaller(t *testing.T) { { name: "repeated field", fields: []*dpb.FieldDescriptorProto{ - {Name: proto.String("field1"), Number: proto.Int32(1), Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum(), Label: dpb.FieldDescriptorProto_LABEL_REPEATED.Enum()}, + {Name: proto.String("field1"), Number: proto.Int32(1), + Type: dpb.FieldDescriptorProto_TYPE_INT32.Enum(), + Label: dpb.FieldDescriptorProto_LABEL_REPEATED.Enum()}, }, input: []byte{0x08, 0x2A, 0x08, 0x2B}, // field 1=[42, 43] expectedCustom: []unmarshalValue{}, @@ -250,10 +252,10 @@ func TestCustomUnmarshaller(t *testing.T) { t.Run(tt.name, func(t *testing.T) { // Convert field descriptors to proto format schema := createTestSchema(tt.fields, i) - fields := make([]*dpb.FieldDescriptorProto, 0, len(schema.GetFields())) - for _, f := range schema.GetFields() { - fields = append(fields, f.AsFieldDescriptorProto()) - } + //fields := make([]*dpb.FieldDescriptorProto, 0, len(schema.GetFields())) + //for _, f := range schema.GetFields() { + // fields = append(fields, f.AsFieldDescriptorProto()) + //} unmarshaller := newCustomFieldUnmarshaller(customUnmarshallerOptions{ skipUnknownFields: tt.skipUnknown, diff --git a/src/dbnode/storage/namespace_readers.go b/src/dbnode/storage/namespace_readers.go index d688810631..83922b7052 100644 --- a/src/dbnode/storage/namespace_readers.go +++ b/src/dbnode/storage/namespace_readers.go @@ -21,9 +21,10 @@ package storage import ( + "sync" + "github.com/uber-go/tally" "go.uber.org/zap" - "sync" "github.com/m3db/m3/src/dbnode/namespace" "github.com/m3db/m3/src/dbnode/persist/fs" From 4b10e8294c00cc3cecb37cdd496ef8afa730c98f Mon Sep 17 00:00:00 2001 From: Riya Tyagi Date: Tue, 29 Apr 2025 16:44:04 +0530 Subject: [PATCH 4/4] fix lint errors --- src/dbnode/encoding/proto/custom_unmarshal_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dbnode/encoding/proto/custom_unmarshal_test.go b/src/dbnode/encoding/proto/custom_unmarshal_test.go index 0d2fbf9e83..374f42e46b 100644 --- a/src/dbnode/encoding/proto/custom_unmarshal_test.go +++ b/src/dbnode/encoding/proto/custom_unmarshal_test.go @@ -243,6 +243,7 @@ func TestCustomUnmarshaller(t *testing.T) { input: []byte{0x08, 0x2A, 0x08, 0x2B}, // field 1=[42, 43] expectedCustom: []unmarshalValue{}, expectedNonCustom: []marshalledField{ + // nolint: misspell {fieldNum: 1, marshalled: []byte{0x08, 0x2A, 0x08, 0x2B}}, }, }, @@ -252,10 +253,6 @@ func TestCustomUnmarshaller(t *testing.T) { t.Run(tt.name, func(t *testing.T) { // Convert field descriptors to proto format schema := createTestSchema(tt.fields, i) - //fields := make([]*dpb.FieldDescriptorProto, 0, len(schema.GetFields())) - //for _, f := range schema.GetFields() { - // fields = append(fields, f.AsFieldDescriptorProto()) - //} unmarshaller := newCustomFieldUnmarshaller(customUnmarshallerOptions{ skipUnknownFields: tt.skipUnknown, @@ -281,6 +278,7 @@ func TestCustomUnmarshaller(t *testing.T) { require.Equal(t, len(tt.expectedNonCustom), len(nonCustomValues)) for i, expected := range tt.expectedNonCustom { require.Equal(t, expected.fieldNum, nonCustomValues[i].fieldNum) + // nolint: misspell require.Equal(t, expected.marshalled, nonCustomValues[i].marshalled) } })