Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 303bb22

Browse files
committed
feat(bigtable): populate alts field in channel entry
1 parent 140a1ad commit 303bb22

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121

2222
import com.google.api.gax.grpc.ChannelFactory;
2323
import com.google.common.collect.Iterables;
24-
import io.grpc.CallOptions;
25-
import io.grpc.ClientCall;
26-
import io.grpc.ManagedChannel;
27-
import io.grpc.Metadata;
28-
import io.grpc.MethodDescriptor;
29-
import io.grpc.Status;
24+
import io.grpc.*;
3025
import java.io.IOException;
3126
import java.io.InputStream;
3227
import java.util.List;
@@ -112,6 +107,8 @@ public void setUp() throws IOException {
112107
// Capture the listener when start is called
113108
// Configure mockClientCall.start to capture the listener
114109
doNothing().when(mockClientCall).start(listenerCaptor.capture(), any(Metadata.class));
110+
// Default to no ALTS context
111+
when(mockClientCall.getAttributes()).thenReturn(Attributes.EMPTY);
115112
}
116113

117114
private BigtableChannelPool.Entry getSingleEntry() {
@@ -233,4 +230,16 @@ public void testMixedRpcs() {
233230
assertThat(entry.getAndResetErrorCount()).isEqualTo(1); // The last failure
234231
assertThat(entry.totalOutstandingRpcs()).isEqualTo(0);
235232
}
233+
234+
@Test
235+
public void testNonAltsChannelReturnsFalse() {
236+
// empty attributes
237+
// cannot test true value as logic is complicated.
238+
// alts check looks at attributes.get(AltsProtocolNegotiator.AUTH_CONTEXT_KEY);
239+
when(mockClientCall.getAttributes()).thenReturn(Attributes.EMPTY);
240+
BigtableChannelPool.Entry entry = getSingleEntry();
241+
assertThat(entry.isAltsHolder.get()).isNull();
242+
startCall(unaryMethodDescriptor);
243+
assertThat(entry.isAltsChannel()).isFalse();
244+
}
236245
}

0 commit comments

Comments
 (0)