github.com/m3db/m3@v1.5.0/src/dbnode/storage/bootstrap/bootstrapper/commitlog/source_data_proto_test.go (about) 1 // Copyright (c) 2019 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package commitlog 22 23 import ( 24 "testing" 25 26 "github.com/m3db/m3/src/dbnode/namespace" 27 "github.com/m3db/m3/src/dbnode/testdata/prototest" 28 "github.com/m3db/m3/src/x/ident" 29 30 "github.com/stretchr/testify/require" 31 ) 32 33 var ( 34 testNamespace = ident.StringID("commitlog_prototest_ns") 35 testSchemaHistory = prototest.NewSchemaHistory() 36 testSchema = prototest.NewMessageDescriptor(testSchemaHistory) 37 testSchemaDesc = namespace.GetTestSchemaDescr(testSchema) 38 testProtoMessages = prototest.NewProtoTestMessages(testSchema) 39 testProtoEqual = func(expect, actual []byte) bool { 40 return prototest.ProtoEqual(testSchema, expect, actual) 41 } 42 ) 43 44 func testProtoOptions() Options { 45 resultOpts := testDefaultOpts.ResultOptions() 46 bOpts := resultOpts.DatabaseBlockOptions(). 47 SetEncoderPool(prototest.ProtoPools.EncoderPool). 48 SetReaderIteratorPool(prototest.ProtoPools.ReaderIterPool). 49 SetMultiReaderIteratorPool(prototest.ProtoPools.MultiReaderIterPool) 50 return testDefaultOpts.SetResultOptions(resultOpts.SetDatabaseBlockOptions(bOpts)) 51 } 52 53 func testProtoNsMetadata(t *testing.T) namespace.Metadata { 54 nOpts := namespace.NewOptions().SetSchemaHistory(testSchemaHistory) 55 md, err := namespace.NewMetadata(testNamespace, nOpts) 56 require.NoError(t, err) 57 return md 58 } 59 60 func setProtoAnnotation(value testValues) testValues { 61 protoIter := prototest.NewProtoMessageIterator(testProtoMessages) 62 for i := 0; i < len(value); i++ { 63 value[i].v = 0 64 value[i].a = protoIter.Next() 65 } 66 return value 67 } 68 69 func TestProtoReadOrderedValues(t *testing.T) { 70 opts := testProtoOptions() 71 md := testProtoNsMetadata(t) 72 testReadOrderedValues(t, opts, md, setProtoAnnotation) 73 } 74 75 func TestProtoReadUnorderedValues(t *testing.T) { 76 opts := testProtoOptions() 77 md := testProtoNsMetadata(t) 78 testReadUnorderedValues(t, opts, md, setProtoAnnotation) 79 } 80 81 func TestProtoItMergesSnapshotsAndCommitLogs(t *testing.T) { 82 opts := testProtoOptions() 83 md := testProtoNsMetadata(t) 84 testItMergesSnapshotsAndCommitLogs(t, opts, md, setProtoAnnotation) 85 }