github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logtail/service/response_test.go (about) 1 // Copyright 2021 Matrix Origin 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package service 15 16 import ( 17 "math" 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestResponseSize(t *testing.T) { 24 maxMessageSize := 1024 25 pool := NewSegmentPool(maxMessageSize) 26 27 /* --- Fetch a segment --- */ 28 prev := pool.Acquire() 29 t.Log("segment size:", prev.ProtoSize()) 30 require.True(t, prev.ProtoSize() > maxMessageSize) 31 32 /* --- Release it --- */ 33 pool.Release(prev) 34 35 /* --- Fetch again --- */ 36 curr := pool.Acquire() 37 t.Log("segment size:", curr.ProtoSize()) 38 require.Equal(t, prev.ProtoSize(), curr.ProtoSize()) 39 40 curr.StreamID = math.MaxUint64 41 curr.Sequence = math.MaxInt32 42 curr.MaxSequence = math.MaxInt32 43 curr.MessageSize = math.MaxInt32 44 t.Log("max proto size:", curr.ProtoSize()) 45 46 limit := 2*maxMessageSize - curr.ProtoSize() 47 t.Log("limited size:", limit) 48 curr.Payload = curr.Payload[:limit] 49 t.Log("final segment size:", curr.ProtoSize()) 50 require.Equal(t, curr.ProtoSize(), maxMessageSize) 51 }