Skip to content

Commit

Permalink
fix: better support for fallback mode (#967)
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: googleapis/googleapis-gen@cb6f37a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
  • Loading branch information
gcf-owl-bot[bot] authored Aug 23, 2022
1 parent df16a99 commit 0447d87
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 167 deletions.
16 changes: 8 additions & 8 deletions src/v1/datastore_admin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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');
/**
Expand Down Expand Up @@ -391,7 +390,8 @@ export class DatastoreAdminClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down Expand Up @@ -703,7 +703,7 @@ export class DatastoreAdminClient {
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.exportEntities,
gax.createDefaultBackoffSettings()
this._gaxModule.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.datastore.admin.v1.ExportEntitiesResponse,
Expand Down Expand Up @@ -865,7 +865,7 @@ export class DatastoreAdminClient {
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.importEntities,
gax.createDefaultBackoffSettings()
this._gaxModule.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.protobuf.Empty,
Expand Down Expand Up @@ -1018,7 +1018,7 @@ export class DatastoreAdminClient {
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.createIndex,
gax.createDefaultBackoffSettings()
this._gaxModule.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.datastore.admin.v1.Index,
Expand Down Expand Up @@ -1167,7 +1167,7 @@ export class DatastoreAdminClient {
const decodeOperation = new gax.Operation(
operation,
this.descriptors.longrunning.deleteIndex,
gax.createDefaultBackoffSettings()
this._gaxModule.createDefaultBackoffSettings()
);
return decodeOperation as LROperation<
protos.google.datastore.admin.v1.Index,
Expand Down Expand Up @@ -1311,7 +1311,7 @@ export class DatastoreAdminClient {
const callSettings = defaultCallSettings.merge(options);
this.initialize();
return this.descriptors.page.listIndexes.createStream(
this.innerApiCalls.listIndexes as gax.GaxCall,
this.innerApiCalls.listIndexes as GaxCall,
request,
callSettings
);
Expand Down Expand Up @@ -1361,7 +1361,7 @@ export class DatastoreAdminClient {
this.initialize();
return this.descriptors.page.listIndexes.asyncIterate(
this.innerApiCalls['listIndexes'] as GaxCall,
request as unknown as RequestType,
request as {},
callSettings
) as AsyncIterable<protos.google.datastore.admin.v1.IIndex>;
}
Expand Down
5 changes: 3 additions & 2 deletions src/v1/datastore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import jsonProtos = require('../../protos/protos.json');
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './datastore_client_config.json';
import {operationsProtos} from 'google-gax';

const version = require('../../../package.json').version;

/**
Expand Down Expand Up @@ -274,7 +274,8 @@ export class DatastoreClient {
const apiCall = this._gaxModule.createApiCall(
callPromise,
this._defaults[methodName],
descriptor
descriptor,
this._opts.fallback
);

this.innerApiCalls[methodName] = apiCall;
Expand Down
160 changes: 81 additions & 79 deletions test/gapic_datastore_admin_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,101 +145,103 @@ function stubAsyncIterationCall<ResponseType>(
}

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

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

it('has port', () => {
const port = datastoreadminModule.v1.DatastoreAdminClient.port;
assert(port);
assert(typeof port === 'number');
});

it('should create a client with no option', () => {
const client = new datastoreadminModule.v1.DatastoreAdminClient();
assert(client);
});
describe('Common methods', () => {
it('has servicePath', () => {
const servicePath =
datastoreadminModule.v1.DatastoreAdminClient.servicePath;
assert(servicePath);
});

it('should create a client with gRPC fallback', () => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
fallback: true,
it('has apiEndpoint', () => {
const apiEndpoint =
datastoreadminModule.v1.DatastoreAdminClient.apiEndpoint;
assert(apiEndpoint);
});
assert(client);
});

it('has initialize method and supports deferred initialization', async () => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has port', () => {
const port = datastoreadminModule.v1.DatastoreAdminClient.port;
assert(port);
assert(typeof port === 'number');
});
assert.strictEqual(client.datastoreAdminStub, undefined);
await client.initialize();
assert(client.datastoreAdminStub);
});

it('has close method for the initialized client', done => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('should create a client with no option', () => {
const client = new datastoreadminModule.v1.DatastoreAdminClient();
assert(client);
});
client.initialize();
assert(client.datastoreAdminStub);
client.close().then(() => {
done();

it('should create a client with gRPC fallback', () => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
fallback: true,
});
assert(client);
});
});

it('has close method for the non-initialized client', done => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has initialize method and supports deferred initialization', async () => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.datastoreAdminStub, undefined);
await client.initialize();
assert(client.datastoreAdminStub);
});
assert.strictEqual(client.datastoreAdminStub, undefined);
client.close().then(() => {
done();

it('has close method for the initialized client', done => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
assert(client.datastoreAdminStub);
client.close().then(() => {
done();
});
});
});

it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has close method for the non-initialized client', done => {
const client = new datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
assert.strictEqual(client.datastoreAdminStub, undefined);
client.close().then(() => {
done();
});
});
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 datastoreadminModule.v1.DatastoreAdminClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
it('has getProjectId method', async () => {
const fakeProjectId = 'fake-project-id';
const client = new datastoreadminModule.v1.DatastoreAdminClient({
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()
.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 datastoreadminModule.v1.DatastoreAdminClient({
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('getIndex', () => {
Expand Down
Loading

0 comments on commit 0447d87

Please sign in to comment.