Skip to content

Commit

Permalink
feat: update Nodejs generator to send API versions in headers for GAP…
Browse files Browse the repository at this point in the history
…ICs (#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>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored May 22, 2024
1 parent ae9d0dc commit 9dca0d3
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/v1/big_query_read_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class BigQueryReadClient {
readRows: new this._gaxModule.StreamDescriptor(
this._gaxModule.StreamType.SERVER_STREAMING,
!!opts.fallback,
/* gaxStreamingRetries: */ false
!!opts.gaxServerStreamingRetries
),
};

Expand Down
2 changes: 1 addition & 1 deletion src/v1/big_query_write_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class BigQueryWriteClient {
appendRows: new this._gaxModule.StreamDescriptor(
this._gaxModule.StreamType.BIDI_STREAMING,
!!opts.fallback,
/* gaxStreamingRetries: */ false
!!opts.gaxServerStreamingRetries
),
};

Expand Down
2 changes: 1 addition & 1 deletion src/v1beta1/big_query_storage_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class BigQueryStorageClient {
readRows: new this._gaxModule.StreamDescriptor(
this._gaxModule.StreamType.SERVER_STREAMING,
!!opts.fallback,
/* gaxStreamingRetries: */ false
!!opts.gaxServerStreamingRetries
),
};

Expand Down
50 changes: 50 additions & 0 deletions test/gapic_big_query_read_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,50 @@ describe('v1.BigQueryReadClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => {
const client = new bigqueryreadModule.v1.BigQueryReadClient({
gaxServerStreamingRetries: true,
});
client.initialize();
const request = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1.ReadRowsRequest()
);
const defaultValue1 = getTypeDefaultValue(
'.google.cloud.bigquery.storage.v1.ReadRowsRequest',
['readStream']
);
request.readStream = defaultValue1;
const expectedHeaderRequestParams = `read_stream=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1.ReadRowsResponse()
);
client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse);
const stream = client.readRows(request);
const promise = new Promise((resolve, reject) => {
stream.on(
'data',
(
response: protos.google.cloud.bigquery.storage.v1.ReadRowsResponse
) => {
resolve(response);
}
);
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (
client.innerApiCalls.readRows as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.readRows as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows with error', async () => {
const client = new bigqueryreadModule.v1.BigQueryReadClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -657,6 +701,12 @@ describe('v1.BigQueryReadClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new bigqueryreadModule.v1.BigQueryReadClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('Path templates', () => {
Expand Down
52 changes: 52 additions & 0 deletions test/gapic_big_query_storage_v1beta1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,52 @@ describe('v1beta1.BigQueryStorageClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
gaxServerStreamingRetries: true,
});
client.initialize();
const request = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest()
);
request.readPosition ??= {};
request.readPosition.stream ??= {};
const defaultValue1 = getTypeDefaultValue(
'.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest',
['readPosition', 'stream', 'name']
);
request.readPosition.stream.name = defaultValue1;
const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse()
);
client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse);
const stream = client.readRows(request);
const promise = new Promise((resolve, reject) => {
stream.on(
'data',
(
response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse
) => {
resolve(response);
}
);
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (
client.innerApiCalls.readRows as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.readRows as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows with error', async () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -968,6 +1014,12 @@ describe('v1beta1.BigQueryStorageClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('Path templates', () => {
Expand Down

0 comments on commit 9dca0d3

Please sign in to comment.