2022-03-01 13:22:10 +00:00
|
|
|
package acl_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 10:38:56 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl"
|
|
|
|
aclGrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc"
|
|
|
|
acltest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/test"
|
2022-03-01 13:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkTable_ToGRPCMessage(b *testing.B) {
|
|
|
|
const size = 4
|
|
|
|
|
|
|
|
tb := new(acl.Table)
|
2022-03-01 13:32:54 +00:00
|
|
|
rs := make([]acl.Record, size)
|
2022-03-01 13:22:10 +00:00
|
|
|
for i := range rs {
|
2022-03-01 13:32:54 +00:00
|
|
|
fs := make([]acl.HeaderFilter, size)
|
2022-03-01 13:22:10 +00:00
|
|
|
for j := range fs {
|
2022-03-01 13:32:54 +00:00
|
|
|
fs[j] = *acltest.GenerateFilter(false)
|
2022-03-01 13:22:10 +00:00
|
|
|
}
|
2022-03-01 13:32:54 +00:00
|
|
|
ts := make([]acl.Target, size)
|
2022-03-01 13:22:10 +00:00
|
|
|
for j := range ts {
|
2022-03-01 13:32:54 +00:00
|
|
|
ts[j] = *acltest.GenerateTarget(false)
|
2022-03-01 13:22:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rs[i].SetFilters(fs)
|
|
|
|
rs[i].SetTargets(ts)
|
|
|
|
}
|
|
|
|
tb.SetRecords(rs)
|
|
|
|
|
|
|
|
raw := tb.ToGRPCMessage()
|
|
|
|
|
|
|
|
b.Run("to grpc message", func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
2024-09-04 12:44:59 +00:00
|
|
|
for range b.N {
|
2022-03-01 13:22:10 +00:00
|
|
|
raw := tb.ToGRPCMessage()
|
|
|
|
if len(tb.GetRecords()) != len(raw.(*aclGrpc.EACLTable).Records) {
|
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
b.Run("from grpc message", func(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
2024-09-04 12:44:59 +00:00
|
|
|
for range b.N {
|
2022-03-01 13:22:10 +00:00
|
|
|
tb := new(acl.Table)
|
|
|
|
if tb.FromGRPCMessage(raw) != nil {
|
|
|
|
b.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|