Skip to content

Commit 9b4c97a

Browse files
auto commit
1 parent cb738d7 commit 9b4c97a

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

db-esdk-performance-testing/benchmarks/go/benchmark/benchmark_tests.go

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package benchmark
55

66
import (
7+
"bytes"
78
"context"
89
"fmt"
910
"log"
1011
"runtime"
1112
"runtime/metrics"
12-
"slices"
1313
"sort"
1414
"strconv"
1515
"sync"
@@ -29,15 +29,23 @@ func (b *DBESDKBenchmark) runBatchPutGetCycle(data []byte) (float64, float64, er
2929
tableName := b.Config.TableName
3030

3131
// Create 25 write requests with same data, different sort_key
32-
var writeRequests []types.WriteRequest
32+
var items []map[string]types.AttributeValue
33+
3334
for i := 0; i < 25; i++ {
3435
item := map[string]types.AttributeValue{
3536
"partition_key": &types.AttributeValueMemberS{Value: "benchmark-test"},
3637
"sort_key": &types.AttributeValueMemberN{Value: strconv.Itoa(i)},
37-
"attribute1": &types.AttributeValueMemberB{Value: data},
38-
"attribute2": &types.AttributeValueMemberS{Value: "sign me!"},
39-
":attribute3": &types.AttributeValueMemberS{Value: "ignore me!"},
38+
"attribute1": &types.AttributeValueMemberM{Value: map[string]types.AttributeValue{
39+
"data": &types.AttributeValueMemberB{Value: data},
40+
}},
41+
"attribute2": &types.AttributeValueMemberS{Value: "sign me!"},
42+
":attribute3": &types.AttributeValueMemberS{Value: "ignore me!"},
4043
}
44+
items = append(items, item)
45+
}
46+
47+
var writeRequests []types.WriteRequest
48+
for _, item := range items {
4149
writeRequests = append(writeRequests, types.WriteRequest{
4250
PutRequest: &types.PutRequest{Item: item},
4351
})
@@ -75,15 +83,42 @@ func (b *DBESDKBenchmark) runBatchPutGetCycle(data []byte) (float64, float64, er
7583
batchGetDuration := time.Since(batchGetStart).Seconds() * 1000
7684

7785
// Verify 25 items retrieved with correct data size
78-
items := result.Responses[tableName]
79-
if len(items) != 25 {
80-
return 0, 0, fmt.Errorf("expected 25 items, got %d", len(items))
86+
returnedItems := result.Responses[tableName]
87+
if len(returnedItems) != 25 {
88+
return 0, 0, fmt.Errorf("expected 25 items, got %d", len(returnedItems))
8189
}
8290

83-
for _, item := range items {
84-
retrievedData, ok := item["attribute1"].(*types.AttributeValueMemberB)
85-
if !ok || !slices.Equal(retrievedData.Value, data) {
86-
return 0, 0, fmt.Errorf("data verification failed")
91+
// Verify each returned item
92+
for i, item := range returnedItems {
93+
if _, ok := item["attribute1"]; !ok {
94+
return 0, 0, fmt.Errorf("item %d missing attribute1", i)
95+
}
96+
97+
// Verify attribute1
98+
if attr1, ok := item["attribute1"].(*types.AttributeValueMemberM); ok {
99+
if dataAttr, ok := attr1.Value["data"].(*types.AttributeValueMemberB); ok {
100+
if !bytes.Equal(dataAttr.Value, data) {
101+
return 0, 0, fmt.Errorf("item %d data mismatch", i)
102+
}
103+
}
104+
}
105+
106+
// Verify attribute2 value
107+
if attr2, ok := item["attribute2"].(*types.AttributeValueMemberS); ok {
108+
if attr2.Value != "sign me!" {
109+
return 0, 0, fmt.Errorf("item %d attribute2 mismatch: got %s", i, attr2.Value)
110+
}
111+
} else {
112+
return 0, 0, fmt.Errorf("item %d attribute2 wrong type", i)
113+
}
114+
115+
// Verify :attribute3 value
116+
if attr3, ok := item[":attribute3"].(*types.AttributeValueMemberS); ok {
117+
if attr3.Value != "ignore me!" {
118+
return 0, 0, fmt.Errorf("item %d :attribute3 mismatch: got %s", i, attr3.Value)
119+
}
120+
} else {
121+
return 0, 0, fmt.Errorf("item %d :attribute3 wrong type", i)
87122
}
88123
}
89124

0 commit comments

Comments
 (0)