Skip to content

Commit 182f7c0

Browse files
test(spanner): Add integration test to check that requests with large message sizes that are under the limit succeed (#5392)
* Add integration test to check that requests with large message sizes that are under the limit succeed * Remove debugging log * Apply gemini suggested code review * Remove redunant ctx initialization * Fix comment typo * Replace "math/rand" with "crypto/rand" * formatting fixes --------- Co-authored-by: rahul2393 <[email protected]>
1 parent 3be783f commit 182f7c0

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

spanner/spanner_snippets/spanner/integration_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,17 @@ func TestAddSplitPointsSample(t *testing.T) {
13321332
assertContains(t, out, "Added split points")
13331333
}
13341334

1335+
func TestTxWithLargeMessageSize(t *testing.T) {
1336+
_ = testutil.SystemTest(t)
1337+
t.Parallel()
1338+
1339+
_, dbName, cleanup := initTest(t, randomID())
1340+
defer cleanup()
1341+
1342+
mustRunSample(t, createDatabase, dbName, "failed to create a database")
1343+
runSample(t, writeLargeData, dbName, "failed to write large data")
1344+
}
1345+
13351346
func maybeCreateKey(projectId, locationId, keyRingId, keyId string) error {
13361347
client, err := kms.NewKeyManagementClient(context.Background())
13371348
if err != nil {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2025 Google LLC
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+
// https://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 spanner
16+
17+
// [START spanner_insert_large_data]
18+
19+
import (
20+
"context"
21+
"crypto/rand"
22+
"io"
23+
"time"
24+
25+
"cloud.google.com/go/spanner"
26+
)
27+
28+
func writeLargeData(w io.Writer, db string) error {
29+
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
30+
defer cancel()
31+
client, err := spanner.NewClient(ctx, db)
32+
if err != nil {
33+
return err
34+
}
35+
defer client.Close()
36+
37+
singerColumns := []string{"SingerId", "FirstName", "LastName", "SingerInfo"}
38+
token := make([]byte, 10000000)
39+
if _, err := rand.Read(token); err != nil {
40+
return err
41+
}
42+
// Mutation is under the 100MB limit
43+
m := []*spanner.Mutation{
44+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{1, "Marc", "Richards", token}),
45+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{2, "Catalina", "Smith", token}),
46+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{3, "Alice", "Trentor", token}),
47+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{4, "Lea", "Martin", token}),
48+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{5, "David", "Lomond", token}),
49+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{6, "Marc", "Richards", token}),
50+
spanner.InsertOrUpdate("Singers", singerColumns, []interface{}{7, "Catalina", "Smith", token}),
51+
}
52+
_, err = client.Apply(ctx, m)
53+
return err
54+
}
55+
56+
// [END spanner_insert_large_data]

0 commit comments

Comments
 (0)