Skip to content

Commit 4b127f2

Browse files
authored
core: Fix CallOptions 'wait for ready' and toString()
- CallOptions 'wait for ready' was not passed between with*() calls and therefore it was not possible to enable it via a stub. - Properly format custom call options in toString() output.
1 parent 7da48ae commit 4b127f2

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

core/src/main/java/io/grpc/CallOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ private CallOptions(CallOptions other) {
359359
executor = other.executor;
360360
compressorName = other.compressorName;
361361
customOptions = other.customOptions;
362+
waitForReady = other.waitForReady;
362363
}
363364

364365
@Override
@@ -370,7 +371,7 @@ public String toString() {
370371
toStringHelper.add("affinity", affinity);
371372
toStringHelper.add("executor", executor != null ? executor.getClass() : null);
372373
toStringHelper.add("compressorName", compressorName);
373-
toStringHelper.add("customOptions", Arrays.toString(customOptions));
374+
toStringHelper.add("customOptions", Arrays.deepToString(customOptions));
374375
toStringHelper.add("waitForReady", isWaitForReady());
375376

376377
return toStringHelper.toString();

core/src/test/java/io/grpc/CallOptionsTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,24 @@
5656
@RunWith(JUnit4.class)
5757
public class CallOptionsTest {
5858
private String sampleAuthority = "authority";
59+
private String sampleCompressor = "compressor";
5960
private Deadline.Ticker ticker = new DeadlineTest.FakeTicker();
6061
private Deadline sampleDeadline = Deadline.after(1, NANOSECONDS, ticker);
6162
private Key<String> sampleKey = Attributes.Key.of("sample");
6263
private Attributes sampleAffinity = Attributes.newBuilder().set(sampleKey, "blah").build();
6364
private CallCredentials sampleCreds = mock(CallCredentials.class);
65+
private CallOptions.Key<String> option1 = CallOptions.Key.of("option1", "default");
66+
private CallOptions.Key<String> option2 = CallOptions.Key.of("option2", "default");
6467
private CallOptions allSet = CallOptions.DEFAULT
6568
.withAuthority(sampleAuthority)
6669
.withDeadline(sampleDeadline)
6770
.withAffinity(sampleAffinity)
6871
.withCredentials(sampleCreds)
69-
.withWaitForReady();
70-
private CallOptions.Key<String> option1 = CallOptions.Key.of("option1", "default");
71-
private CallOptions.Key<String> option2 = CallOptions.Key.of("option2", "default");
72+
.withCompression(sampleCompressor)
73+
.withWaitForReady()
74+
.withExecutor(directExecutor())
75+
.withOption(option1, "value1")
76+
.withOption(option2, "value2");
7277

7378
@Test
7479
public void defaultsAreAllNull() {
@@ -77,6 +82,7 @@ public void defaultsAreAllNull() {
7782
assertThat(CallOptions.DEFAULT.getAffinity()).isEqualTo(Attributes.EMPTY);
7883
assertThat(CallOptions.DEFAULT.getExecutor()).isNull();
7984
assertThat(CallOptions.DEFAULT.getCredentials()).isNull();
85+
assertThat(CallOptions.DEFAULT.getCompressor()).isNull();
8086
assertThat(CallOptions.DEFAULT.isWaitForReady()).isFalse();
8187
}
8288

@@ -93,6 +99,10 @@ public void allWiths() {
9399
assertThat(allSet.getDeadline()).isSameAs(sampleDeadline);
94100
assertThat(allSet.getAffinity()).isSameAs(sampleAffinity);
95101
assertThat(allSet.getCredentials()).isSameAs(sampleCreds);
102+
assertThat(allSet.getCompressor()).isSameAs(sampleCompressor);
103+
assertThat(allSet.getExecutor()).isSameAs(directExecutor());
104+
assertThat(allSet.getOption(option1)).isSameAs("value1");
105+
assertThat(allSet.getOption(option2)).isSameAs("value2");
96106
assertThat(allSet.isWaitForReady()).isTrue();
97107
}
98108

@@ -150,8 +160,8 @@ public void withDeadlineAfter() {
150160
public void toStringMatches_noDeadline_default() {
151161
String expected = "CallOptions{deadline=null, authority=authority, callCredentials=null, "
152162
+ "affinity={sample=blah}, "
153-
+ "executor=class io.grpc.internal.SerializingExecutor, compressorName=null, "
154-
+ "customOptions=[], waitForReady=false}";
163+
+ "executor=class io.grpc.internal.SerializingExecutor, compressorName=compressor, "
164+
+ "customOptions=[[option2, value2], [option1, value1]], waitForReady=true}";
155165
String actual = allSet
156166
.withDeadline(null)
157167
.withExecutor(new SerializingExecutor(directExecutor()))

0 commit comments

Comments
 (0)