Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
fix: better support for fallback mode (#558)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 468790263

Source-Link: googleapis/googleapis@873ab45

Source-Link: https://github.com/googleapis/googleapis-gen/commit/cb6f37aeff2a3472e40a7bbace8c67d75e24bee5
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
gcf-owl-bot[bot] authored Aug 23, 2022
1 parent 61ecf9a commit 14faf3b
Showing 18 changed files with 163 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(name) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_CheckValidCreds_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(parent, transferConfig) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_CreateTransferConfig_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(name) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_DeleteTransferConfig_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(name) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_DeleteTransferRun_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main() {
// [START bigquerydatatransfer_v1_generated_DataTransferService_EnrollDataSources_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
3 changes: 3 additions & 0 deletions samples/generated/v1/data_transfer_service.get_data_source.js
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(name) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_GetDataSource_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(name) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_GetTransferConfig_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(name) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_GetTransferRun_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(parent) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_ListDataSources_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(parent) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_ListTransferConfigs_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(parent) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_ListTransferLogs_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(parent) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_ListTransferRuns_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(parent, startTime, endTime) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_ScheduleTransferRuns_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main() {
// [START bigquerydatatransfer_v1_generated_DataTransferService_StartManualTransferRuns_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@
function main(transferConfig, updateMask) {
// [START bigquerydatatransfer_v1_generated_DataTransferService_UpdateTransferConfig_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
"segments": [
{
"start": 25,
"end": 52,
"end": 55,
"type": "FULL"
}
],
@@ -62,7 +62,7 @@
"segments": [
{
"start": 25,
"end": 66,
"end": 69,
"type": "FULL"
}
],
@@ -110,7 +110,7 @@
"segments": [
{
"start": 25,
"end": 92,
"end": 95,
"type": "FULL"
}
],
@@ -166,7 +166,7 @@
"segments": [
{
"start": 25,
"end": 90,
"end": 93,
"type": "FULL"
}
],
@@ -222,7 +222,7 @@
"segments": [
{
"start": 25,
"end": 52,
"end": 55,
"type": "FULL"
}
],
@@ -262,7 +262,7 @@
"segments": [
{
"start": 25,
"end": 52,
"end": 55,
"type": "FULL"
}
],
@@ -302,7 +302,7 @@
"segments": [
{
"start": 25,
"end": 70,
"end": 73,
"type": "FULL"
}
],
@@ -354,7 +354,7 @@
"segments": [
{
"start": 25,
"end": 64,
"end": 67,
"type": "FULL"
}
],
@@ -402,7 +402,7 @@
"segments": [
{
"start": 25,
"end": 60,
"end": 63,
"type": "FULL"
}
],
@@ -450,7 +450,7 @@
"segments": [
{
"start": 25,
"end": 52,
"end": 55,
"type": "FULL"
}
],
@@ -490,7 +490,7 @@
"segments": [
{
"start": 25,
"end": 52,
"end": 55,
"type": "FULL"
}
],
@@ -530,7 +530,7 @@
"segments": [
{
"start": 25,
"end": 75,
"end": 78,
"type": "FULL"
}
],
@@ -586,7 +586,7 @@
"segments": [
{
"start": 25,
"end": 71,
"end": 74,
"type": "FULL"
}
],
@@ -638,7 +638,7 @@
"segments": [
{
"start": 25,
"end": 52,
"end": 55,
"type": "FULL"
}
],
@@ -678,7 +678,7 @@
"segments": [
{
"start": 25,
"end": 55,
"end": 58,
"type": "FULL"
}
],
20 changes: 10 additions & 10 deletions src/v1/data_transfer_service_client.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ import {
} from 'google-gax';

import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
/**
@@ -300,7 +299,8 @@ export class DataTransferServiceClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
@@ -1701,7 +1701,7 @@ export class DataTransferServiceClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listDataSources.createStream(
this.innerApiCalls.listDataSources as gax.GaxCall,
this.innerApiCalls.listDataSources as GaxCall,
request,
callSettings
);
@@ -1755,7 +1755,7 @@ export class DataTransferServiceClient {
this.initialize();
return this.descriptors.page.listDataSources.asyncIterate(
this.innerApiCalls['listDataSources'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.bigquery.datatransfer.v1.IDataSource>;
}
@@ -1913,7 +1913,7 @@ export class DataTransferServiceClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listTransferConfigs.createStream(
this.innerApiCalls.listTransferConfigs as gax.GaxCall,
this.innerApiCalls.listTransferConfigs as GaxCall,
request,
callSettings
);
@@ -1969,7 +1969,7 @@ export class DataTransferServiceClient {
this.initialize();
return this.descriptors.page.listTransferConfigs.asyncIterate(
this.innerApiCalls['listTransferConfigs'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.bigquery.datatransfer.v1.ITransferConfig>;
}
@@ -2132,7 +2132,7 @@ export class DataTransferServiceClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listTransferRuns.createStream(
this.innerApiCalls.listTransferRuns as gax.GaxCall,
this.innerApiCalls.listTransferRuns as GaxCall,
request,
callSettings
);
@@ -2191,7 +2191,7 @@ export class DataTransferServiceClient {
this.initialize();
return this.descriptors.page.listTransferRuns.asyncIterate(
this.innerApiCalls['listTransferRuns'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.bigquery.datatransfer.v1.ITransferRun>;
}
@@ -2350,7 +2350,7 @@ export class DataTransferServiceClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listTransferLogs.createStream(
this.innerApiCalls.listTransferLogs as gax.GaxCall,
this.innerApiCalls.listTransferLogs as GaxCall,
request,
callSettings
);
@@ -2407,7 +2407,7 @@ export class DataTransferServiceClient {
this.initialize();
return this.descriptors.page.listTransferLogs.asyncIterate(
this.innerApiCalls['listTransferLogs'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.cloud.bigquery.datatransfer.v1.ITransferMessage>;
}
171 changes: 93 additions & 78 deletions test/gapic_data_transfer_service_v1.ts
Original file line number Diff line number Diff line change
@@ -113,101 +113,116 @@ function stubAsyncIterationCall<ResponseType>(
}

describe('v1.DataTransferServiceClient', () => {
it('has servicePath', () => {
const servicePath =
datatransferserviceModule.v1.DataTransferServiceClient.servicePath;
assert(servicePath);
});

it('has apiEndpoint', () => {
const apiEndpoint =
datatransferserviceModule.v1.DataTransferServiceClient.apiEndpoint;
assert(apiEndpoint);
});

it('has port', () => {
const port = datatransferserviceModule.v1.DataTransferServiceClient.port;
assert(port);
assert(typeof port === 'number');
});
describe('Common methods', () => {
it('has servicePath', () => {
const servicePath =
datatransferserviceModule.v1.DataTransferServiceClient.servicePath;
assert(servicePath);
});

it('should create a client with no option', () => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient();
assert(client);
});
it('has apiEndpoint', () => {
const apiEndpoint =
datatransferserviceModule.v1.DataTransferServiceClient.apiEndpoint;
assert(apiEndpoint);
});

it('should create a client with gRPC fallback', () => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient({
fallback: true,
it('has port', () => {
const port = datatransferserviceModule.v1.DataTransferServiceClient.port;
assert(port);
assert(typeof port === 'number');
});
assert(client);
});

it('has initialize method and supports deferred initialization', async () => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('should create a client with no option', () => {
const client =
new datatransferserviceModule.v1.DataTransferServiceClient();
assert(client);
});
assert.strictEqual(client.dataTransferServiceStub, undefined);
await client.initialize();
assert(client.dataTransferServiceStub);
});

it('has close method for the initialized client', done => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('should create a client with gRPC fallback', () => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient(
{
fallback: true,
}
);
assert(client);
});
client.initialize();
assert(client.dataTransferServiceStub);
client.close().then(() => {
done();

it('has initialize method and supports deferred initialization', async () => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient(
{
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
}
);
assert.strictEqual(client.dataTransferServiceStub, undefined);
await client.initialize();
assert(client.dataTransferServiceStub);
});
});

it('has close method for the non-initialized client', done => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the initialized client', done => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient(
{
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
}
);
client.initialize();
assert(client.dataTransferServiceStub);
client.close().then(() => {
done();
});
});
assert.strictEqual(client.dataTransferServiceStub, undefined);
client.close().then(() => {
done();

it('has close method for the non-initialized client', done => {
const client = new datatransferserviceModule.v1.DataTransferServiceClient(
{
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
}
);
assert.strictEqual(client.dataTransferServiceStub, undefined);
client.close().then(() => {
done();
});
});
});

it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new datatransferserviceModule.v1.DataTransferServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new datatransferserviceModule.v1.DataTransferServiceClient(
{
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
}
);
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
const result = await client.getProjectId();
assert.strictEqual(result, fakeProjectId);
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
});
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
const result = await client.getProjectId();
assert.strictEqual(result, fakeProjectId);
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
});

it('has getProjectId method with callback', async () => {
const fakeProjectId = 'fake-project-id';
const client = new datatransferserviceModule.v1.DataTransferServiceClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.auth.getProjectId = sinon
.stub()
.callsArgWith(0, null, fakeProjectId);
const promise = new Promise((resolve, reject) => {
client.getProjectId((err?: Error | null, projectId?: string | null) => {
if (err) {
reject(err);
} else {
resolve(projectId);
it('has getProjectId method with callback', async () => {
const fakeProjectId = 'fake-project-id';
const client = new datatransferserviceModule.v1.DataTransferServiceClient(
{
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
}
);
client.auth.getProjectId = sinon
.stub()
.callsArgWith(0, null, fakeProjectId);
const promise = new Promise((resolve, reject) => {
client.getProjectId((err?: Error | null, projectId?: string | null) => {
if (err) {
reject(err);
} else {
resolve(projectId);
}
});
});
const result = await promise;
assert.strictEqual(result, fakeProjectId);
});
const result = await promise;
assert.strictEqual(result, fakeProjectId);
});

describe('getDataSource', () => {

0 comments on commit 14faf3b

Please sign in to comment.