Skip to content

Commit 9f32137

Browse files
test: Add integration test to check that requests with large message sizes that are under the limit succeed (#4037)
* Add integration test to check that requests with large message sizes (but still under limit) succeed * formatting fixes --------- Co-authored-by: Knut Olav Løite <[email protected]>
1 parent 4c88eb9 commit 9f32137

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITTransactionTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.Arrays;
5757
import java.util.Collections;
5858
import java.util.List;
59+
import java.util.Random;
5960
import java.util.Vector;
6061
import java.util.concurrent.CountDownLatch;
6162
import java.util.concurrent.TimeUnit;
@@ -74,6 +75,8 @@ public class ITTransactionTest {
7475
@ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv();
7576
private static Database db;
7677
private static DatabaseClient client;
78+
private static Database largeMessageDb;
79+
private static DatabaseClient largeMessageClient;
7780

7881
/** Sequence for assigning unique keys to test cases. */
7982
private static int seq;
@@ -88,11 +91,31 @@ public static void setUpDatabase() {
8891
+ " V INT64,"
8992
+ ") PRIMARY KEY (K)");
9093
client = env.getTestHelper().getDatabaseClient(db);
94+
95+
largeMessageDb =
96+
env.getTestHelper()
97+
.createTestDatabase(
98+
"CREATE TABLE T ("
99+
+ " K STRING(MAX) NOT NULL,"
100+
+ " col0 BYTES(MAX),"
101+
+ " col1 BYTES(MAX),"
102+
+ " col2 BYTES(MAX),"
103+
+ " col3 BYTES(MAX),"
104+
+ " col4 BYTES(MAX),"
105+
+ " col5 BYTES(MAX),"
106+
+ " col6 BYTES(MAX),"
107+
+ " col7 BYTES(MAX),"
108+
+ " col8 BYTES(MAX),"
109+
+ " col9 BYTES(MAX),"
110+
+ ") PRIMARY KEY (K)");
111+
largeMessageClient = env.getTestHelper().getDatabaseClient(largeMessageDb);
91112
}
92113

93114
@Before
94115
public void removeTestData() {
95116
client.writeAtLeastOnce(Collections.singletonList(Mutation.delete("T", KeySet.all())));
117+
largeMessageClient.writeAtLeastOnce(
118+
Collections.singletonList(Mutation.delete("T", KeySet.all())));
96119
}
97120

98121
private static String uniqueKey() {
@@ -561,6 +584,25 @@ public void testTxWithUncaughtError() {
561584
}
562585
}
563586

587+
@Test
588+
public void testTxWithLargeMessageSize() {
589+
int bytesPerColumn = 10000000; // 10MB
590+
String key = uniqueKey();
591+
Random random = new Random();
592+
List<Mutation> mutations = new ArrayList();
593+
Mutation.WriteBuilder builder = Mutation.newInsertOrUpdateBuilder("T").set("K").to(key);
594+
for (int j = 0; j < 7; j++) {
595+
byte[] data = new byte[bytesPerColumn];
596+
random.nextBytes(data);
597+
builder
598+
.set("col" + j)
599+
.to(com.google.cloud.spanner.Value.bytes(com.google.cloud.ByteArray.copyFrom(data)));
600+
}
601+
mutations.add(builder.build());
602+
// This large message is under the 100MB limit.
603+
largeMessageClient.write(mutations);
604+
}
605+
564606
@Test
565607
public void testTxWithUncaughtErrorAfterSuccessfulBegin() {
566608
try {

0 commit comments

Comments
 (0)