5656import java .util .Arrays ;
5757import java .util .Collections ;
5858import java .util .List ;
59+ import java .util .Random ;
5960import java .util .Vector ;
6061import java .util .concurrent .CountDownLatch ;
6162import 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