2022-03-18 10:25:05 +00:00
|
|
|
package eacltest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-09-08 14:15:08 +00:00
|
|
|
"crypto/rand"
|
2022-03-18 10:25:05 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
|
|
|
|
versiontest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version/test"
|
2022-03-18 10:25:05 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func baseBenchmarkTableBinaryComparison(b *testing.B, factor int) {
|
|
|
|
t := TableN(factor)
|
|
|
|
exp, err := t.Marshal()
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
b.StopTimer()
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
2024-09-03 10:20:30 +00:00
|
|
|
for range b.N {
|
2022-03-18 10:25:05 +00:00
|
|
|
got, _ := t.Marshal()
|
|
|
|
if !bytes.Equal(exp, got) {
|
|
|
|
b.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:15:52 +00:00
|
|
|
func baseBenchmarkTableEqualsComparison(b *testing.B, factor int) {
|
2022-03-18 10:25:05 +00:00
|
|
|
t := TableN(factor)
|
|
|
|
data, err := t.Marshal()
|
|
|
|
require.NoError(b, err)
|
|
|
|
t2 := eacl.NewTable()
|
|
|
|
err = t2.Unmarshal(data)
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
b.StopTimer()
|
|
|
|
b.ResetTimer()
|
|
|
|
b.StartTimer()
|
2024-09-03 10:20:30 +00:00
|
|
|
for range b.N {
|
2022-03-28 08:15:52 +00:00
|
|
|
if !eacl.EqualTables(*t, *t2) {
|
2022-03-18 10:25:05 +00:00
|
|
|
b.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTableBinaryComparison(b *testing.B) {
|
|
|
|
baseBenchmarkTableBinaryComparison(b, 1)
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:15:52 +00:00
|
|
|
func BenchmarkTableEqualsComparison(b *testing.B) {
|
|
|
|
baseBenchmarkTableEqualsComparison(b, 1)
|
2022-03-18 10:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTableBinaryComparison10(b *testing.B) {
|
|
|
|
baseBenchmarkTableBinaryComparison(b, 10)
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:15:52 +00:00
|
|
|
func BenchmarkTableEqualsComparison10(b *testing.B) {
|
|
|
|
baseBenchmarkTableEqualsComparison(b, 10)
|
2022-03-18 10:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTableBinaryComparison100(b *testing.B) {
|
|
|
|
baseBenchmarkTableBinaryComparison(b, 100)
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:15:52 +00:00
|
|
|
func BenchmarkTableEqualsComparison100(b *testing.B) {
|
|
|
|
baseBenchmarkTableEqualsComparison(b, 100)
|
2022-03-18 10:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Target returns random eacl.Target.
|
|
|
|
func TargetN(n int) *eacl.Target {
|
|
|
|
x := eacl.NewTarget()
|
|
|
|
|
|
|
|
x.SetRole(eacl.RoleSystem)
|
|
|
|
keys := make([][]byte, n)
|
|
|
|
|
2024-09-03 10:20:30 +00:00
|
|
|
for i := range n {
|
2022-03-18 10:25:05 +00:00
|
|
|
keys[i] = make([]byte, 32)
|
|
|
|
rand.Read(keys[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
x.SetBinaryKeys(keys)
|
|
|
|
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record returns random eacl.Record.
|
|
|
|
func RecordN(n int) *eacl.Record {
|
|
|
|
x := eacl.NewRecord()
|
|
|
|
|
|
|
|
x.SetAction(eacl.ActionAllow)
|
|
|
|
x.SetOperation(eacl.OperationRangeHash)
|
|
|
|
x.SetTargets(*TargetN(n))
|
|
|
|
|
2024-09-03 10:20:30 +00:00
|
|
|
for range n {
|
2022-05-31 06:55:08 +00:00
|
|
|
x.AddFilter(eacl.HeaderFromObject, eacl.MatchStringEqual, "", cidtest.ID().EncodeToString())
|
2022-03-18 10:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
func TableN(n int) *eacl.Table {
|
|
|
|
x := eacl.NewTable()
|
|
|
|
|
|
|
|
x.SetCID(cidtest.ID())
|
|
|
|
|
2024-09-03 10:20:30 +00:00
|
|
|
for range n {
|
2022-03-18 10:25:05 +00:00
|
|
|
x.AddRecord(RecordN(n))
|
|
|
|
}
|
|
|
|
|
2022-03-23 15:35:44 +00:00
|
|
|
x.SetVersion(versiontest.Version())
|
2022-03-18 10:25:05 +00:00
|
|
|
|
|
|
|
return x
|
|
|
|
}
|