Skip to content

Commit bef56cb

Browse files
feat: update Nodejs generator to send API versions in headers for GAPICs (#459)
* feat: update Nodejs generator to send API versions in headers for GAPICs PiperOrigin-RevId: 634109303 Source-Link: googleapis/googleapis@998ade8 Source-Link: googleapis/googleapis-gen@000ca6f Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDAwY2E2ZjAwODAxZjY1Yjg0N2U2MDI5Y2IwNTExMTQwNGRmMjFlYyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent d11283c commit bef56cb

5 files changed

Lines changed: 105 additions & 3 deletions

File tree

handwritten/bigquery-storage/src/v1/big_query_read_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class BigQueryReadClient {
219219
readRows: new this._gaxModule.StreamDescriptor(
220220
this._gaxModule.StreamType.SERVER_STREAMING,
221221
!!opts.fallback,
222-
/* gaxStreamingRetries: */ false
222+
!!opts.gaxServerStreamingRetries
223223
),
224224
};
225225

handwritten/bigquery-storage/src/v1/big_query_write_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class BigQueryWriteClient {
222222
appendRows: new this._gaxModule.StreamDescriptor(
223223
this._gaxModule.StreamType.BIDI_STREAMING,
224224
!!opts.fallback,
225-
/* gaxStreamingRetries: */ false
225+
!!opts.gaxServerStreamingRetries
226226
),
227227
};
228228

handwritten/bigquery-storage/src/v1beta1/big_query_storage_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class BigQueryStorageClient {
218218
readRows: new this._gaxModule.StreamDescriptor(
219219
this._gaxModule.StreamType.SERVER_STREAMING,
220220
!!opts.fallback,
221-
/* gaxStreamingRetries: */ false
221+
!!opts.gaxServerStreamingRetries
222222
),
223223
};
224224

handwritten/bigquery-storage/test/gapic_big_query_read_v1.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,50 @@ describe('v1.BigQueryReadClient', () => {
578578
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
579579
});
580580

581+
it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => {
582+
const client = new bigqueryreadModule.v1.BigQueryReadClient({
583+
gaxServerStreamingRetries: true,
584+
});
585+
client.initialize();
586+
const request = generateSampleMessage(
587+
new protos.google.cloud.bigquery.storage.v1.ReadRowsRequest()
588+
);
589+
const defaultValue1 = getTypeDefaultValue(
590+
'.google.cloud.bigquery.storage.v1.ReadRowsRequest',
591+
['readStream']
592+
);
593+
request.readStream = defaultValue1;
594+
const expectedHeaderRequestParams = `read_stream=${defaultValue1}`;
595+
const expectedResponse = generateSampleMessage(
596+
new protos.google.cloud.bigquery.storage.v1.ReadRowsResponse()
597+
);
598+
client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse);
599+
const stream = client.readRows(request);
600+
const promise = new Promise((resolve, reject) => {
601+
stream.on(
602+
'data',
603+
(
604+
response: protos.google.cloud.bigquery.storage.v1.ReadRowsResponse
605+
) => {
606+
resolve(response);
607+
}
608+
);
609+
stream.on('error', (err: Error) => {
610+
reject(err);
611+
});
612+
});
613+
const response = await promise;
614+
assert.deepStrictEqual(response, expectedResponse);
615+
const actualRequest = (
616+
client.innerApiCalls.readRows as SinonStub
617+
).getCall(0).args[0];
618+
assert.deepStrictEqual(actualRequest, request);
619+
const actualHeaderRequestParams = (
620+
client.innerApiCalls.readRows as SinonStub
621+
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
622+
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
623+
});
624+
581625
it('invokes readRows with error', async () => {
582626
const client = new bigqueryreadModule.v1.BigQueryReadClient({
583627
credentials: {client_email: 'bogus', private_key: 'bogus'},
@@ -657,6 +701,12 @@ describe('v1.BigQueryReadClient', () => {
657701
});
658702
await assert.rejects(promise, expectedError);
659703
});
704+
it('should create a client with gaxServerStreamingRetries enabled', () => {
705+
const client = new bigqueryreadModule.v1.BigQueryReadClient({
706+
gaxServerStreamingRetries: true,
707+
});
708+
assert(client);
709+
});
660710
});
661711

662712
describe('Path templates', () => {

handwritten/bigquery-storage/test/gapic_big_query_storage_v1beta1.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,52 @@ describe('v1beta1.BigQueryStorageClient', () => {
885885
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
886886
});
887887

888+
it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => {
889+
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
890+
gaxServerStreamingRetries: true,
891+
});
892+
client.initialize();
893+
const request = generateSampleMessage(
894+
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest()
895+
);
896+
request.readPosition ??= {};
897+
request.readPosition.stream ??= {};
898+
const defaultValue1 = getTypeDefaultValue(
899+
'.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest',
900+
['readPosition', 'stream', 'name']
901+
);
902+
request.readPosition.stream.name = defaultValue1;
903+
const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1}`;
904+
const expectedResponse = generateSampleMessage(
905+
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse()
906+
);
907+
client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse);
908+
const stream = client.readRows(request);
909+
const promise = new Promise((resolve, reject) => {
910+
stream.on(
911+
'data',
912+
(
913+
response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse
914+
) => {
915+
resolve(response);
916+
}
917+
);
918+
stream.on('error', (err: Error) => {
919+
reject(err);
920+
});
921+
});
922+
const response = await promise;
923+
assert.deepStrictEqual(response, expectedResponse);
924+
const actualRequest = (
925+
client.innerApiCalls.readRows as SinonStub
926+
).getCall(0).args[0];
927+
assert.deepStrictEqual(actualRequest, request);
928+
const actualHeaderRequestParams = (
929+
client.innerApiCalls.readRows as SinonStub
930+
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
931+
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
932+
});
933+
888934
it('invokes readRows with error', async () => {
889935
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
890936
credentials: {client_email: 'bogus', private_key: 'bogus'},
@@ -968,6 +1014,12 @@ describe('v1beta1.BigQueryStorageClient', () => {
9681014
});
9691015
await assert.rejects(promise, expectedError);
9701016
});
1017+
it('should create a client with gaxServerStreamingRetries enabled', () => {
1018+
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
1019+
gaxServerStreamingRetries: true,
1020+
});
1021+
assert(client);
1022+
});
9711023
});
9721024

9731025
describe('Path templates', () => {

0 commit comments

Comments
 (0)