Skip to content

Commit e942e35

Browse files
committed
chore(spanner): unit test for selecting random mutation
1 parent 3f87f79 commit e942e35

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutationTest.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.testing.SerializableTester.reserializeAndAssert;
2020
import static com.google.common.truth.Truth.assertThat;
2121
import static org.junit.Assert.assertThrows;
22+
import static org.junit.Assert.assertTrue;
2223

2324
import com.google.cloud.ByteArray;
2425
import com.google.cloud.Date;
@@ -359,7 +360,14 @@ public void toProtoCoalescingChangeOfTable() {
359360
Mutation.newInsertBuilder("T2").set("C").to("V5").build());
360361

361362
List<com.google.spanner.v1.Mutation> proto = new ArrayList<>();
362-
Mutation.toProtoGetRandomMutation(mutations, proto);
363+
com.google.spanner.v1.Mutation mutation = Mutation.toProtoGetRandomMutation(mutations, proto);
364+
// Random mutation returned should be INSERT with large number of values
365+
MatcherAssert.assertThat(
366+
mutation,
367+
matchesProto(
368+
"insert { table: 'T1' columns: 'C' values { values { string_value: 'V1' } }"
369+
+ " values { values { string_value: 'V2' } }"
370+
+ " values { values { string_value: 'V3' } } }"));
363371

364372
assertThat(proto.size()).isEqualTo(2);
365373
MatcherAssert.assertThat(
@@ -386,7 +394,13 @@ public void toProtoCoalescingChangeOfOperation() {
386394
Mutation.newUpdateBuilder("T").set("C").to("V5").build());
387395

388396
List<com.google.spanner.v1.Mutation> proto = new ArrayList<>();
389-
Mutation.toProtoGetRandomMutation(mutations, proto);
397+
com.google.spanner.v1.Mutation mutation = Mutation.toProtoGetRandomMutation(mutations, proto);
398+
// Random mutation returned should be of UPDATE operation
399+
MatcherAssert.assertThat(
400+
mutation,
401+
matchesProto(
402+
"update { table: 'T' columns: 'C' values { values { string_value: 'V4' } }"
403+
+ " values { values { string_value: 'V5' } } }"));
390404

391405
assertThat(proto.size()).isEqualTo(2);
392406
MatcherAssert.assertThat(
@@ -413,7 +427,13 @@ public void toProtoCoalescingChangeOfColumn() {
413427
Mutation.newInsertBuilder("T").set("C2").to("V5").build());
414428

415429
List<com.google.spanner.v1.Mutation> proto = new ArrayList<>();
416-
Mutation.toProtoGetRandomMutation(mutations, proto);
430+
com.google.spanner.v1.Mutation mutation = Mutation.toProtoGetRandomMutation(mutations, proto);
431+
MatcherAssert.assertThat(
432+
mutation,
433+
matchesProto(
434+
"insert { table: 'T' columns: 'C1' values { values { string_value: 'V1' } }"
435+
+ " values { values { string_value: 'V2' } }"
436+
+ " values { values { string_value: 'V3' } } }"));
417437

418438
assertThat(proto.size()).isEqualTo(2);
419439
MatcherAssert.assertThat(
@@ -439,7 +459,9 @@ public void toProtoCoalescingDelete() {
439459
Mutation.delete("T", KeySet.range(KeyRange.closedClosed(Key.of("kc"), Key.of("kd")))));
440460

441461
List<com.google.spanner.v1.Mutation> proto = new ArrayList<>();
442-
Mutation.toProtoGetRandomMutation(mutations, proto);
462+
com.google.spanner.v1.Mutation mutation = Mutation.toProtoGetRandomMutation(mutations, proto);
463+
// Random mutation returned should be of DELETE operation
464+
assertTrue(mutation.hasDelete());
443465

444466
assertThat(proto.size()).isEqualTo(1);
445467
MatcherAssert.assertThat(
@@ -470,7 +492,8 @@ public void toProtoCoalescingDeleteChanges() {
470492
Mutation.newInsertBuilder("T2").set("C").to("V1").build());
471493

472494
List<com.google.spanner.v1.Mutation> proto = new ArrayList<>();
473-
Mutation.toProtoGetRandomMutation(mutations, proto);
495+
com.google.spanner.v1.Mutation mutation = Mutation.toProtoGetRandomMutation(mutations, proto);
496+
assertTrue(mutation.hasDelete());
474497

475498
assertThat(proto.size()).isEqualTo(4);
476499
MatcherAssert.assertThat(

0 commit comments

Comments
 (0)