Skip to content

Commit a4dd421

Browse files
committed
Tests for Options.RequestId
1 parent 23074ea commit a4dd421

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Options.java

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ public static UpdateTransactionOption excludeTxnFromChangeStreams() {
177177
return EXCLUDE_TXN_FROM_CHANGE_STREAMS_OPTION;
178178
}
179179

180+
public static RequestIdOption requestId(XGoogSpannerRequestId reqId) {
181+
return new RequestIdOption(reqId);
182+
}
183+
180184
/**
181185
* Specifying this will cause the read to yield at most this many rows. This should be greater
182186
* than 0.

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java

-4
Original file line numberDiff line numberDiff line change
@@ -1568,10 +1568,6 @@ PooledSession get(final boolean eligibleForLongRunning) {
15681568
throw SpannerExceptionFactory.propagateInterrupt(e);
15691569
}
15701570
}
1571-
1572-
public int getChannel() {
1573-
return get().getChannel();
1574-
}
15751571
}
15761572

15771573
interface CachedSession extends Session {

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

+35
Original file line numberDiff line numberDiff line change
@@ -873,4 +873,39 @@ public void testOptions_WithMultipleDifferentIsolationLevels() {
873873
Options options = Options.fromTransactionOptions(transactionOptions);
874874
assertEquals(options.isolationLevel(), IsolationLevel.SERIALIZABLE);
875875
}
876+
877+
@Test
878+
public void testRequestId() {
879+
XGoogSpannerRequestId reqId1 = XGoogSpannerRequestId.of(1, 2, 3, 4);
880+
XGoogSpannerRequestId reqId2 = XGoogSpannerRequestId.of(2, 3, 4, 5);
881+
Options option1 = Options.fromUpdateOptions(Options.requestId(reqId1));
882+
Options option1Prime = Options.fromUpdateOptions(Options.requestId(reqId1));
883+
Options option2 = Options.fromUpdateOptions(Options.requestId(reqId2));
884+
Options option3 = Options.fromUpdateOptions();
885+
886+
assertEquals(option1, option1Prime);
887+
assertNotEquals(option1, option2);
888+
assertEquals(option1.hashCode(), option1Prime.hashCode());
889+
assertNotEquals(option1, option2);
890+
assertNotEquals(option1, option3);
891+
assertNotEquals(option1.hashCode(), option3.hashCode());
892+
893+
assertTrue(option1.hasReqId());
894+
assertThat(option1.toString()).contains("requestId: " + reqId1.toString());
895+
896+
assertFalse(option3.hasReqId());
897+
assertThat(option3.toString()).doesNotContain("requestId");
898+
}
899+
900+
@Test
901+
public void testOptions_WithMultipleDifferentRequestIds() {
902+
XGoogSpannerRequestId reqId1 = XGoogSpannerRequestId.of(1, 1, 1, 1);
903+
XGoogSpannerRequestId reqId2 = XGoogSpannerRequestId.of(1, 1, 1, 2);
904+
TransactionOption[] transactionOptions = {
905+
Options.requestId(reqId1), Options.requestId(reqId2),
906+
};
907+
Options options = Options.fromTransactionOptions(transactionOptions);
908+
assertNotEquals(options.reqId(), reqId1);
909+
assertEquals(options.reqId(), reqId2);
910+
}
876911
}

0 commit comments

Comments
 (0)