From bbfe93bb64ab97355f825ac60a9046de417d3833 Mon Sep 17 00:00:00 2001 From: Riya Mehta Date: Thu, 19 Sep 2024 13:12:11 -0700 Subject: [PATCH] Remove global SHARED_RESOURCE_CHANNELS. --- .../s2a/channel/S2AHandshakerServiceChannel.java | 13 ++++--------- .../channel/S2AHandshakerServiceChannelTest.java | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/s2a/src/main/java/io/grpc/s2a/channel/S2AHandshakerServiceChannel.java b/s2a/src/main/java/io/grpc/s2a/channel/S2AHandshakerServiceChannel.java index 75ec7347bb55..9968d9cbdf7f 100644 --- a/s2a/src/main/java/io/grpc/s2a/channel/S2AHandshakerServiceChannel.java +++ b/s2a/src/main/java/io/grpc/s2a/channel/S2AHandshakerServiceChannel.java @@ -20,7 +20,6 @@ import static java.util.concurrent.TimeUnit.SECONDS; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Maps; import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.ChannelCredentials; @@ -35,14 +34,13 @@ import io.netty.util.concurrent.DefaultThreadFactory; import java.time.Duration; import java.util.Optional; -import java.util.concurrent.ConcurrentMap; import javax.annotation.concurrent.ThreadSafe; /** - * Provides APIs for managing gRPC channels to S2A servers. Each channel is local and plaintext. If - * credentials are provided, they are used to secure the channel. + * Provides APIs for managing gRPC channels to an S2A server. Each channel is local and plaintext. + * If credentials are provided, they are used to secure the channel. * - *

This is done as follows: for each S2A server, provides an implementation of gRPC's {@link + *

This is done as follows: for an S2A server, provides an implementation of gRPC's {@link * SharedResourceHolder.Resource} interface called a {@code Resource}. A {@code * Resource} is a factory for creating gRPC channels to the S2A server at a given address, * and a channel must be returned to the {@code Resource} when it is no longer needed. @@ -59,8 +57,6 @@ */ @ThreadSafe public final class S2AHandshakerServiceChannel { - private static final ConcurrentMap> SHARED_RESOURCE_CHANNELS = - Maps.newConcurrentMap(); private static final Duration DELEGATE_TERMINATION_TIMEOUT = Duration.ofSeconds(2); private static final Duration CHANNEL_SHUTDOWN_TIMEOUT = Duration.ofSeconds(10); @@ -76,8 +72,7 @@ public final class S2AHandshakerServiceChannel { public static Resource getChannelResource( String s2aAddress, Optional s2aChannelCredentials) { checkNotNull(s2aAddress); - return SHARED_RESOURCE_CHANNELS.computeIfAbsent( - s2aAddress, channelResource -> new ChannelResource(s2aAddress, s2aChannelCredentials)); + return new ChannelResource(s2aAddress, s2aChannelCredentials); } /** diff --git a/s2a/src/test/java/io/grpc/s2a/channel/S2AHandshakerServiceChannelTest.java b/s2a/src/test/java/io/grpc/s2a/channel/S2AHandshakerServiceChannelTest.java index 57288be1b6fa..70b33e20e453 100644 --- a/s2a/src/test/java/io/grpc/s2a/channel/S2AHandshakerServiceChannelTest.java +++ b/s2a/src/test/java/io/grpc/s2a/channel/S2AHandshakerServiceChannelTest.java @@ -109,7 +109,7 @@ public void getChannelResource_twoEqualChannels() { S2AHandshakerServiceChannel.getChannelResource( "localhost:" + plaintextServer.getPort(), /* s2aChannelCredentials= */ Optional.empty()); - assertThat(resource).isEqualTo(resourceTwo); + assertThat(resource).isNotEqualTo(resourceTwo); } /** Same as getChannelResource_twoEqualChannels, but use mTLS. */ @@ -121,7 +121,7 @@ public void getChannelResource_mtlsTwoEqualChannels() throws Exception { Resource resourceTwo = S2AHandshakerServiceChannel.getChannelResource( "localhost:" + mtlsServer.getPort(), getTlsChannelCredentials()); - assertThat(resource).isEqualTo(resourceTwo); + assertThat(resource).isNotEqualTo(resourceTwo); } /**