github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/storage/series/buffer_proto_test.go (about) 1 // Copyright (c) 2016 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 series 22 23 import ( 24 "testing" 25 "time" 26 27 m3dbruntime "github.com/m3db/m3/src/dbnode/runtime" 28 "github.com/m3db/m3/src/dbnode/testdata/prototest" 29 "github.com/m3db/m3/src/x/ident" 30 31 "github.com/m3db/m3/src/dbnode/namespace" 32 ) 33 34 var ( 35 testNamespace = ident.StringID("buffer_test_ns") 36 testSchemaHistory = prototest.NewSchemaHistory() 37 testSchema = prototest.NewMessageDescriptor(testSchemaHistory) 38 testSchemaDesc = namespace.GetTestSchemaDescr(testSchema) 39 testProtoMessages = prototest.NewProtoTestMessages(testSchema) 40 testProtoEqual = func(t *testing.T, expect, actual []byte) { 41 prototest.RequireEqual(t, testSchema, expect, actual) 42 } 43 ) 44 45 func newBufferTestProtoOptions(t *testing.T) Options { 46 bufferBucketPool := NewBufferBucketPool(nil) 47 bufferBucketVersionsPool := NewBufferBucketVersionsPool(nil) 48 49 opts := NewOptions(). 50 SetEncoderPool(prototest.ProtoPools.EncoderPool). 51 SetMultiReaderIteratorPool(prototest.ProtoPools.MultiReaderIterPool). 52 SetBufferBucketPool(bufferBucketPool). 53 SetBufferBucketVersionsPool(bufferBucketVersionsPool). 54 SetRuntimeOptionsManager(m3dbruntime.NewOptionsManager()) 55 opts = opts. 56 SetRetentionOptions(opts.RetentionOptions(). 57 SetBlockSize(2 * time.Minute). 58 SetBufferFuture(10 * time.Second). 59 SetBufferPast(10 * time.Second)). 60 SetDatabaseBlockOptions(opts.DatabaseBlockOptions(). 61 SetContextPool(opts.ContextPool()). 62 SetEncoderPool(opts.EncoderPool()). 63 SetMultiReaderIteratorPool(opts.MultiReaderIteratorPool())) 64 65 return opts 66 } 67 68 func testSetProtoAnnotation(data []DecodedTestValue) []DecodedTestValue { 69 protoIter := prototest.NewProtoMessageIterator(testProtoMessages) 70 for i := 0; i < len(data); i++ { 71 data[i].Value = 0 72 data[i].Annotation = protoIter.Next() 73 } 74 return data 75 } 76 77 func TestProtoBufferWriteRead(t *testing.T) { 78 opts := newBufferTestProtoOptions(t) 79 testBufferWriteRead(t, opts, testSetProtoAnnotation) 80 } 81 82 func TestProtoBufferToStream(t *testing.T) { 83 opts := newBufferTestProtoOptions(t) 84 testBuffertoStream(t, opts, testSetProtoAnnotation) 85 } 86 87 func TestProtoBufferBucketMerge(t *testing.T) { 88 opts := newBufferTestProtoOptions(t) 89 testBufferBucketMerge(t, opts, testSetProtoAnnotation) 90 } 91 92 func TestProtoBufferSnapshot(t *testing.T) { 93 opts := newBufferTestProtoOptions(t) 94 testBufferSnapshot(t, opts, testSetProtoAnnotation) 95 } 96 97 func TestProtoBufferFetchBlocks(t *testing.T) { 98 opts := newBufferTestProtoOptions(t) 99 testBufferFetchBlocks(t, opts, testSetProtoAnnotation) 100 }