File tree Expand file tree Collapse file tree
main/java/com/google/cloud/spanner
test/java/com/google/cloud/spanner Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121
2222import com .google .cloud .spanner .ReadContext .QueryAnalyzeMode ;
2323import com .google .common .collect .ImmutableMap ;
24+
25+ import java .io .Serializable ;
2426import java .util .HashMap ;
2527import java .util .Map ;
2628import java .util .Objects ;
5052 *
5153 * <p>{@code Statement} instances are immutable.
5254 */
53- public final class Statement {
55+ public final class Statement implements Serializable {
56+ private static final long serialVersionUID = -1967958247625065259L ;
57+
5458 private final ImmutableMap <String , Value > parameters ;
5559 private final String sql ;
5660
Original file line number Diff line number Diff line change 2424import com .google .protobuf .Duration ;
2525import com .google .protobuf .util .Durations ;
2626import com .google .spanner .v1 .TransactionOptions ;
27+
28+ import java .io .Serializable ;
2729import java .util .Objects ;
2830import java .util .concurrent .TimeUnit ;
2931
115117 * @see Session#singleUseReadOnlyTransaction(TimestampBound)
116118 * @see Session#readOnlyTransaction(TimestampBound)
117119 */
118- public final class TimestampBound {
120+ public final class TimestampBound implements Serializable {
119121 private static final TimestampBound STRONG_BOUND = new TimestampBound (Mode .STRONG , null , null );
120122 private static final TransactionOptions .ReadOnly STRONG_PROTO =
121123 TransactionOptions .ReadOnly .newBuilder ().setStrong (true ).build ();
124+ private static final long serialVersionUID = 9194565742651275731L ;
122125
123126 private final Mode mode ;
124127 private final Timestamp timestamp ;
Original file line number Diff line number Diff line change 1616
1717package com .google .cloud .spanner ;
1818
19+ import static com .google .common .testing .SerializableTester .reserializeAndAssert ;
1920import static com .google .common .truth .Truth .assertThat ;
2021
2122import com .google .common .collect .ImmutableMap ;
@@ -38,6 +39,7 @@ public void basic() {
3839 assertThat (stmt .getSql ()).isEqualTo (sql );
3940 assertThat (stmt .getParameters ()).isEmpty ();
4041 assertThat (stmt .toString ()).isEqualTo (sql );
42+ reserializeAndAssert (stmt );
4143 }
4244
4345 @ Test
Original file line number Diff line number Diff line change 1717package com .google .cloud .spanner ;
1818
1919import static com .google .cloud .spanner .TimestampBound .Mode ;
20+ import static com .google .common .testing .SerializableTester .reserializeAndAssert ;
2021import static com .google .common .truth .Truth .assertThat ;
2122
2223import com .google .cloud .Timestamp ;
@@ -37,6 +38,15 @@ public class TimestampBoundTest {
3738 private static final String TEST_TIME_ISO = "2015-10-12T15:14:54Z" ;
3839 @ Rule public ExpectedException expectedException = ExpectedException .none ();
3940
41+ @ Test
42+ public void serialization () throws Exception {
43+ reserializeAndAssert (TimestampBound .strong ());
44+ reserializeAndAssert (TimestampBound .ofExactStaleness (10 , TimeUnit .NANOSECONDS ));
45+ reserializeAndAssert (TimestampBound .ofMaxStaleness (100 , TimeUnit .DAYS ));
46+ reserializeAndAssert (TimestampBound .ofMinReadTimestamp (Timestamp .now ()));
47+ reserializeAndAssert (TimestampBound .ofReadTimestamp (Timestamp .now ()));
48+ }
49+
4050 @ Test
4151 public void strong () {
4252 TimestampBound bound = TimestampBound .strong ();
You can’t perform that action at this time.
0 commit comments