-
Notifications
You must be signed in to change notification settings - Fork 66
feat(gax): add protobuf version tracking to headers #3199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 22 commits
31ebd95
e6aea43
a64e14b
3a7b27d
0037a0a
ea7e7ec
4e18aa6
b1a8960
8d6065c
2dbc3a4
b69684b
02051b3
31da0e5
5a918f4
94d3f45
822ac0c
390c922
01eb41a
92e901b
a202b8b
f9fac2d
9849efd
604f00d
9c51ec7
a99c4b1
c7b3d2b
8bddad1
82c88eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.google.api.gax.httpjson.*; | ||
import com.google.api.gax.rpc.ApiClientHeaderProvider; | ||
|
@@ -31,6 +32,7 @@ | |
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.regex.Pattern; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -39,13 +41,19 @@ | |
// https://github.com/googleapis/gapic-showcase/pull/1456 | ||
// TODO: watch for showcase gRPC trailer changes suggested in | ||
// https://github.com/googleapis/gapic-showcase/pull/1509#issuecomment-2089147103 | ||
class ITApiVersionHeaders { | ||
class ITVersionHeaders { | ||
private static final String HTTP_RESPONSE_HEADER_STRING = | ||
"x-showcase-request-" + ApiClientHeaderProvider.API_VERSION_HEADER_KEY; | ||
private static final String HTTP_CLIENT_API_HEADER_KEY = | ||
"x-showcase-request-" + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(); | ||
private static final Metadata.Key<String> API_VERSION_HEADER_KEY = | ||
Metadata.Key.of( | ||
ApiClientHeaderProvider.API_VERSION_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
private static final Metadata.Key<String> API_CLIENT_HEADER_KEY = | ||
Metadata.Key.of( | ||
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
private static final String EXPECTED_ECHO_API_VERSION = "v1_20240408"; | ||
private static final String CUSTOM_API_VERSION = "user-supplied-version"; | ||
private static final String EXPECTED_EXCEPTION_MESSAGE = | ||
|
@@ -323,4 +331,26 @@ void testHttpJsonCompliance_userApiVersionSetSuccess() throws IOException { | |
assertThat(headerValue).isEqualTo(CUSTOM_API_VERSION); | ||
} | ||
} | ||
|
||
@Test | ||
void testGrpc_matchesClientLibVersion() { | ||
Pattern defautlGrpcHeaderPattern = | ||
Pattern.compile("gl-java/.+ gapic/.+--protobuf-.+ gax/.+ grpc/.+ protobuf/.*"); | ||
grpcClient.echo(EchoRequest.newBuilder().build()); | ||
String headerValue = grpcInterceptor.metadata.get(API_CLIENT_HEADER_KEY); | ||
|
||
assertTrue(defautlGrpcHeaderPattern.matcher(headerValue).matches()); | ||
} | ||
|
||
@Test | ||
void testHttpJson_matchesClientLibVersion() { | ||
Pattern defautlHttpHeaderPattern = | ||
Pattern.compile("gl-java/.+ gapic/.+--protobuf-.+ gax/.+ rest/ protobuf/.*"); | ||
httpJsonClient.echo(EchoRequest.newBuilder().build()); | ||
ArrayList headerValues = | ||
(ArrayList) httpJsonInterceptor.metadata.getHeaders().get(HTTP_CLIENT_API_HEADER_KEY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than using raw-types, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
String headerValue = (String) headerValues.get(0); | ||
|
||
assertTrue(defautlHttpHeaderPattern.matcher(headerValue).matches()); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.