...

Source file src/go.etcd.io/etcd/raft/v3/raftpb/raft_test.go

Documentation: go.etcd.io/etcd/raft/v3/raftpb

     1  // Copyright 2021 The etcd Authors
     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 raftpb
    16  
    17  import (
    18  	"math/bits"
    19  	"testing"
    20  	"unsafe"
    21  )
    22  
    23  func TestProtoMemorySizes(t *testing.T) {
    24  	assert := func(size, exp uintptr, name string) {
    25  		t.Helper()
    26  		if size != exp {
    27  			t.Errorf("expected size of %s proto to be %d bytes, found %d bytes", name, exp, size)
    28  		}
    29  	}
    30  
    31  	if64Bit := func(yes, no uintptr) uintptr {
    32  		if bits.UintSize == 64 {
    33  			return yes
    34  		}
    35  		return no
    36  	}
    37  
    38  	var e Entry
    39  	assert(unsafe.Sizeof(e), if64Bit(48, 32), "Entry")
    40  
    41  	var sm SnapshotMetadata
    42  	assert(unsafe.Sizeof(sm), if64Bit(120, 68), "SnapshotMetadata")
    43  
    44  	var s Snapshot
    45  	assert(unsafe.Sizeof(s), if64Bit(144, 80), "Snapshot")
    46  
    47  	var m Message
    48  	assert(unsafe.Sizeof(m), if64Bit(264, 168), "Message")
    49  
    50  	var hs HardState
    51  	assert(unsafe.Sizeof(hs), 24, "HardState")
    52  
    53  	var cs ConfState
    54  	assert(unsafe.Sizeof(cs), if64Bit(104, 52), "ConfState")
    55  
    56  	var cc ConfChange
    57  	assert(unsafe.Sizeof(cc), if64Bit(48, 32), "ConfChange")
    58  
    59  	var ccs ConfChangeSingle
    60  	assert(unsafe.Sizeof(ccs), if64Bit(16, 12), "ConfChangeSingle")
    61  
    62  	var ccv2 ConfChangeV2
    63  	assert(unsafe.Sizeof(ccv2), if64Bit(56, 28), "ConfChangeV2")
    64  }
    65  

View as plain text