From a04ad492d01c73fbb4561a5cffdb888b06aa865d Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 2 Dec 2024 14:10:48 -0800 Subject: [PATCH 1/3] s2a: Don't allow S2AStub to be set S2AStub is an internal API and shouldn't be used outside of s2a. It is still available for tests. --- s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java b/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java index 2cbdf7e4c5f..a9901f7303b 100644 --- a/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java +++ b/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java @@ -110,7 +110,7 @@ public Builder setLocalUid(String localUid) { * Sets the stub to use to communicate with S2A. This is only used for testing that the * stream to S2A gets closed. */ - public Builder setStub(S2AStub stub) { + Builder setStub(S2AStub stub) { checkNotNull(stub); this.stub = stub; return this; @@ -130,4 +130,4 @@ InternalProtocolNegotiator.ClientFactory buildProtocolNegotiatorFactory() { } private S2AChannelCredentials() {} -} \ No newline at end of file +} From 28516396556ee62653095d6ee15639e3da4ec2ad Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 3 Dec 2024 09:09:58 -0800 Subject: [PATCH 2/3] Add `@VisibleForTesting` --- s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java b/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java index a9901f7303b..4be32475205 100644 --- a/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java +++ b/s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.isNullOrEmpty; +import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.grpc.Channel; import io.grpc.ChannelCredentials; @@ -110,6 +111,7 @@ public Builder setLocalUid(String localUid) { * Sets the stub to use to communicate with S2A. This is only used for testing that the * stream to S2A gets closed. */ + @VisibleForTesting Builder setStub(S2AStub stub) { checkNotNull(stub); this.stub = stub; From 3522cc85cc27c7b8d510ef491be95dd149f0d5bf Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 4 Dec 2024 07:47:25 -0800 Subject: [PATCH 3/3] s2a: Move IntegrationTest to io.grpc.s2a It uses a io.grpc.s2a class, so shouldn't be in internal.handler --- .../main/java/io/grpc/s2a/internal/handshaker/S2AStub.java | 5 +++-- .../grpc/s2a/{internal/handshaker => }/IntegrationTest.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) rename s2a/src/test/java/io/grpc/s2a/{internal/handshaker => }/IntegrationTest.java (98%) diff --git a/s2a/src/main/java/io/grpc/s2a/internal/handshaker/S2AStub.java b/s2a/src/main/java/io/grpc/s2a/internal/handshaker/S2AStub.java index c5ac8f96d96..956ec485229 100644 --- a/s2a/src/main/java/io/grpc/s2a/internal/handshaker/S2AStub.java +++ b/s2a/src/main/java/io/grpc/s2a/internal/handshaker/S2AStub.java @@ -44,7 +44,8 @@ public class S2AStub implements AutoCloseable { private boolean doneWriting = false; private boolean isClosed = false; - static S2AStub newInstance(S2AServiceGrpc.S2AServiceStub serviceStub) { + @VisibleForTesting + public static S2AStub newInstance(S2AServiceGrpc.S2AServiceStub serviceStub) { checkNotNull(serviceStub); return new S2AStub(serviceStub); } @@ -224,4 +225,4 @@ SessionResp getResultOrThrow() throws IOException { return response.get(); } } -} \ No newline at end of file +} diff --git a/s2a/src/test/java/io/grpc/s2a/internal/handshaker/IntegrationTest.java b/s2a/src/test/java/io/grpc/s2a/IntegrationTest.java similarity index 98% rename from s2a/src/test/java/io/grpc/s2a/internal/handshaker/IntegrationTest.java rename to s2a/src/test/java/io/grpc/s2a/IntegrationTest.java index 613983d9b39..d8d2fdd4d03 100644 --- a/s2a/src/test/java/io/grpc/s2a/internal/handshaker/IntegrationTest.java +++ b/s2a/src/test/java/io/grpc/s2a/IntegrationTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.grpc.s2a.internal.handshaker; +package io.grpc.s2a; import static com.google.common.truth.Truth.assertThat; import static java.util.concurrent.TimeUnit.SECONDS; @@ -37,6 +37,8 @@ import io.grpc.s2a.S2AChannelCredentials; import io.grpc.s2a.internal.channel.S2AHandshakerServiceChannel; import io.grpc.s2a.internal.handshaker.FakeS2AServer; +import io.grpc.s2a.internal.handshaker.S2AServiceGrpc; +import io.grpc.s2a.internal.handshaker.S2AStub; import io.grpc.stub.StreamObserver; import io.grpc.testing.protobuf.SimpleRequest; import io.grpc.testing.protobuf.SimpleResponse;