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