Skip to content

Commit 1bfb763

Browse files
authored
feat(bigtable): populate alts field in channel entry (#2702)
* feat(bigtable): populate alts field in channel entry * WIP
1 parent 64029c9 commit 1bfb763

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

google-cloud-bigtable/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@
204204
<groupId>io.grpc</groupId>
205205
<artifactId>grpc-netty-shaded</artifactId>
206206
</dependency>
207+
<dependency>
208+
<groupId>io.grpc</groupId>
209+
<artifactId>grpc-alts</artifactId>
210+
</dependency>
207211
<dependency>
208212
<groupId>io.grpc</groupId>
209213
<artifactId>grpc-protobuf</artifactId>

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.grpc.Metadata;
3131
import io.grpc.MethodDescriptor;
3232
import io.grpc.Status;
33+
import io.grpc.alts.AltsContextUtil;
3334
import java.io.IOException;
3435
import java.time.Clock;
3536
import java.util.ArrayList;
@@ -565,9 +566,8 @@ static class Entry implements BigtableChannelObserver {
565566
}
566567

567568
void checkAndSetIsAlts(ClientCall<?, ?> call) {
568-
// TODO(populate ALTS holder)
569-
boolean result = false;
570-
isAltsHolder.compareAndSet(null, result);
569+
boolean currentIsAlts = AltsContextUtil.check(call);
570+
isAltsHolder.set(currentIsAlts);
571571
}
572572

573573
ManagedChannel getManagedChannel() {

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/gaxx/grpc/BigtableChannelPoolTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.api.gax.grpc.ChannelFactory;
2323
import com.google.common.collect.Iterables;
24+
import io.grpc.Attributes;
2425
import io.grpc.CallOptions;
2526
import io.grpc.ClientCall;
2627
import io.grpc.ManagedChannel;
@@ -112,6 +113,8 @@ public void setUp() throws IOException {
112113
// Capture the listener when start is called
113114
// Configure mockClientCall.start to capture the listener
114115
doNothing().when(mockClientCall).start(listenerCaptor.capture(), any(Metadata.class));
116+
// Default to no ALTS context
117+
when(mockClientCall.getAttributes()).thenReturn(Attributes.EMPTY);
115118
}
116119

117120
private BigtableChannelPool.Entry getSingleEntry() {
@@ -233,4 +236,16 @@ public void testMixedRpcs() {
233236
assertThat(entry.getAndResetErrorCount()).isEqualTo(1); // The last failure
234237
assertThat(entry.totalOutstandingRpcs()).isEqualTo(0);
235238
}
239+
240+
@Test
241+
public void testNonAltsChannelReturnsFalse() {
242+
// empty attributes
243+
// cannot test true value as logic is complicated.
244+
// alts check looks at attributes.get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY);
245+
when(mockClientCall.getAttributes()).thenReturn(Attributes.EMPTY);
246+
BigtableChannelPool.Entry entry = getSingleEntry();
247+
assertThat(entry.isAltsHolder.get()).isNull();
248+
startCall(unaryMethodDescriptor);
249+
assertThat(entry.isAltsChannel()).isFalse();
250+
}
236251
}

0 commit comments

Comments
 (0)