Skip to content

Commit cd1af14

Browse files
committed
More view updates
1 parent c21aeb1 commit cd1af14

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import io.grpc.Metadata;
2323
import java.math.BigInteger;
2424
import java.security.SecureRandom;
25-
import java.util.ArrayList;
2625
import java.util.HashMap;
27-
import java.util.List;
2826
import java.util.Map;
2927
import java.util.Objects;
3028
import java.util.regex.MatchResult;
@@ -108,7 +106,8 @@ public String toString() {
108106
this.attempt);
109107
}
110108

111-
private boolean isGreaterThan(XGoogSpannerRequestId other) {
109+
@VisibleForTesting
110+
boolean isGreaterThan(XGoogSpannerRequestId other) {
112111
return this.nthClientId > other.nthClientId
113112
&& this.nthChannelId > other.nthChannelId
114113
&& this.nthRequest > other.nthRequest
@@ -160,26 +159,4 @@ public XGoogSpannerRequestId nextRequestId(long channelId, int attempt) {
160159
return XGoogSpannerRequestId.of(1, 1, 1, 0);
161160
}
162161
}
163-
164-
static void assertMonotonicityOfIds(String prefix, List<XGoogSpannerRequestId> reqIds) {
165-
int size = reqIds.size();
166-
167-
List<String> violations = new ArrayList<>();
168-
for (int i = 1; i < size; i++) {
169-
XGoogSpannerRequestId prev = reqIds.get(i - 1);
170-
XGoogSpannerRequestId curr = reqIds.get(i);
171-
if (prev.isGreaterThan(curr)) {
172-
violations.add(String.format("#%d(%s) > #%d(%s)", i - 1, prev, i, curr));
173-
}
174-
}
175-
176-
if (violations.isEmpty()) {
177-
return;
178-
}
179-
180-
throw new IllegalStateException(
181-
prefix
182-
+ " monotonicity violation:"
183-
+ String.join("\n\t", violations.toArray(new String[0])));
184-
}
185162
}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,36 @@ public String[] accumulatedValues() {
127127
public void assertIntegrity() {
128128
this.unaryResults.forEach(
129129
(String method, CopyOnWriteArrayList<XGoogSpannerRequestId> values) -> {
130-
XGoogSpannerRequestId.assertMonotonicityOfIds(method, values);
130+
assertMonotonicityOfIds(method, values);
131131
});
132132
this.streamingResults.forEach(
133133
(String method, CopyOnWriteArrayList<XGoogSpannerRequestId> values) -> {
134-
XGoogSpannerRequestId.assertMonotonicityOfIds(method, values);
134+
assertMonotonicityOfIds(method, values);
135135
});
136136
}
137137

138+
private void assertMonotonicityOfIds(String prefix, List<XGoogSpannerRequestId> reqIds) {
139+
int size = reqIds.size();
140+
141+
List<String> violations = new ArrayList<>();
142+
for (int i = 1; i < size; i++) {
143+
XGoogSpannerRequestId prev = reqIds.get(i - 1);
144+
XGoogSpannerRequestId curr = reqIds.get(i);
145+
if (prev.isGreaterThan(curr)) {
146+
violations.add(String.format("#%d(%s) > #%d(%s)", i - 1, prev, i, curr));
147+
}
148+
}
149+
150+
if (violations.isEmpty()) {
151+
return;
152+
}
153+
154+
throw new IllegalStateException(
155+
prefix
156+
+ " monotonicity violation:"
157+
+ String.join("\n\t", violations.toArray(new String[0])));
158+
}
159+
138160
public static class methodAndRequestId {
139161
String method;
140162
String requestId;

0 commit comments

Comments
 (0)