Skip to content

Commit 0447d87

Browse files
fix: better support for fallback mode (#967)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 468790263 Source-Link: googleapis/googleapis@873ab45 Source-Link: googleapis/googleapis-gen@cb6f37a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9
1 parent df16a99 commit 0447d87

File tree

4 files changed

+172
-167
lines changed

4 files changed

+172
-167
lines changed

src/v1/datastore_admin_client.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
} from 'google-gax';
3131

3232
import {Transform} from 'stream';
33-
import {RequestType} from 'google-gax/build/src/apitypes';
3433
import * as protos from '../../protos/protos';
3534
import jsonProtos = require('../../protos/protos.json');
3635
/**
@@ -391,7 +390,8 @@ export class DatastoreAdminClient {
391390
const apiCall = this._gaxModule.createApiCall(
392391
callPromise,
393392
this._defaults[methodName],
394-
descriptor
393+
descriptor,
394+
this._opts.fallback
395395
);
396396

397397
this.innerApiCalls[methodName] = apiCall;
@@ -703,7 +703,7 @@ export class DatastoreAdminClient {
703703
const decodeOperation = new gax.Operation(
704704
operation,
705705
this.descriptors.longrunning.exportEntities,
706-
gax.createDefaultBackoffSettings()
706+
this._gaxModule.createDefaultBackoffSettings()
707707
);
708708
return decodeOperation as LROperation<
709709
protos.google.datastore.admin.v1.ExportEntitiesResponse,
@@ -865,7 +865,7 @@ export class DatastoreAdminClient {
865865
const decodeOperation = new gax.Operation(
866866
operation,
867867
this.descriptors.longrunning.importEntities,
868-
gax.createDefaultBackoffSettings()
868+
this._gaxModule.createDefaultBackoffSettings()
869869
);
870870
return decodeOperation as LROperation<
871871
protos.google.protobuf.Empty,
@@ -1018,7 +1018,7 @@ export class DatastoreAdminClient {
10181018
const decodeOperation = new gax.Operation(
10191019
operation,
10201020
this.descriptors.longrunning.createIndex,
1021-
gax.createDefaultBackoffSettings()
1021+
this._gaxModule.createDefaultBackoffSettings()
10221022
);
10231023
return decodeOperation as LROperation<
10241024
protos.google.datastore.admin.v1.Index,
@@ -1167,7 +1167,7 @@ export class DatastoreAdminClient {
11671167
const decodeOperation = new gax.Operation(
11681168
operation,
11691169
this.descriptors.longrunning.deleteIndex,
1170-
gax.createDefaultBackoffSettings()
1170+
this._gaxModule.createDefaultBackoffSettings()
11711171
);
11721172
return decodeOperation as LROperation<
11731173
protos.google.datastore.admin.v1.Index,
@@ -1311,7 +1311,7 @@ export class DatastoreAdminClient {
13111311
const callSettings = defaultCallSettings.merge(options);
13121312
this.initialize();
13131313
return this.descriptors.page.listIndexes.createStream(
1314-
this.innerApiCalls.listIndexes as gax.GaxCall,
1314+
this.innerApiCalls.listIndexes as GaxCall,
13151315
request,
13161316
callSettings
13171317
);
@@ -1361,7 +1361,7 @@ export class DatastoreAdminClient {
13611361
this.initialize();
13621362
return this.descriptors.page.listIndexes.asyncIterate(
13631363
this.innerApiCalls['listIndexes'] as GaxCall,
1364-
request as unknown as RequestType,
1364+
request as {},
13651365
callSettings
13661366
) as AsyncIterable<protos.google.datastore.admin.v1.IIndex>;
13671367
}

src/v1/datastore_client.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import jsonProtos = require('../../protos/protos.json');
3434
* This file defines retry strategy and timeouts for all API methods in this library.
3535
*/
3636
import * as gapicConfig from './datastore_client_config.json';
37-
import {operationsProtos} from 'google-gax';
37+
3838
const version = require('../../../package.json').version;
3939

4040
/**
@@ -274,7 +274,8 @@ export class DatastoreClient {
274274
const apiCall = this._gaxModule.createApiCall(
275275
callPromise,
276276
this._defaults[methodName],
277-
descriptor
277+
descriptor,
278+
this._opts.fallback
278279
);
279280

280281
this.innerApiCalls[methodName] = apiCall;

test/gapic_datastore_admin_v1.ts

+81-79
Original file line numberDiff line numberDiff line change
@@ -145,101 +145,103 @@ function stubAsyncIterationCall<ResponseType>(
145145
}
146146

147147
describe('v1.DatastoreAdminClient', () => {
148-
it('has servicePath', () => {
149-
const servicePath =
150-
datastoreadminModule.v1.DatastoreAdminClient.servicePath;
151-
assert(servicePath);
152-
});
153-
154-
it('has apiEndpoint', () => {
155-
const apiEndpoint =
156-
datastoreadminModule.v1.DatastoreAdminClient.apiEndpoint;
157-
assert(apiEndpoint);
158-
});
159-
160-
it('has port', () => {
161-
const port = datastoreadminModule.v1.DatastoreAdminClient.port;
162-
assert(port);
163-
assert(typeof port === 'number');
164-
});
165-
166-
it('should create a client with no option', () => {
167-
const client = new datastoreadminModule.v1.DatastoreAdminClient();
168-
assert(client);
169-
});
148+
describe('Common methods', () => {
149+
it('has servicePath', () => {
150+
const servicePath =
151+
datastoreadminModule.v1.DatastoreAdminClient.servicePath;
152+
assert(servicePath);
153+
});
170154

171-
it('should create a client with gRPC fallback', () => {
172-
const client = new datastoreadminModule.v1.DatastoreAdminClient({
173-
fallback: true,
155+
it('has apiEndpoint', () => {
156+
const apiEndpoint =
157+
datastoreadminModule.v1.DatastoreAdminClient.apiEndpoint;
158+
assert(apiEndpoint);
174159
});
175-
assert(client);
176-
});
177160

178-
it('has initialize method and supports deferred initialization', async () => {
179-
const client = new datastoreadminModule.v1.DatastoreAdminClient({
180-
credentials: {client_email: 'bogus', private_key: 'bogus'},
181-
projectId: 'bogus',
161+
it('has port', () => {
162+
const port = datastoreadminModule.v1.DatastoreAdminClient.port;
163+
assert(port);
164+
assert(typeof port === 'number');
182165
});
183-
assert.strictEqual(client.datastoreAdminStub, undefined);
184-
await client.initialize();
185-
assert(client.datastoreAdminStub);
186-
});
187166

188-
it('has close method for the initialized client', done => {
189-
const client = new datastoreadminModule.v1.DatastoreAdminClient({
190-
credentials: {client_email: 'bogus', private_key: 'bogus'},
191-
projectId: 'bogus',
167+
it('should create a client with no option', () => {
168+
const client = new datastoreadminModule.v1.DatastoreAdminClient();
169+
assert(client);
192170
});
193-
client.initialize();
194-
assert(client.datastoreAdminStub);
195-
client.close().then(() => {
196-
done();
171+
172+
it('should create a client with gRPC fallback', () => {
173+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
174+
fallback: true,
175+
});
176+
assert(client);
197177
});
198-
});
199178

200-
it('has close method for the non-initialized client', done => {
201-
const client = new datastoreadminModule.v1.DatastoreAdminClient({
202-
credentials: {client_email: 'bogus', private_key: 'bogus'},
203-
projectId: 'bogus',
179+
it('has initialize method and supports deferred initialization', async () => {
180+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
181+
credentials: {client_email: 'bogus', private_key: 'bogus'},
182+
projectId: 'bogus',
183+
});
184+
assert.strictEqual(client.datastoreAdminStub, undefined);
185+
await client.initialize();
186+
assert(client.datastoreAdminStub);
204187
});
205-
assert.strictEqual(client.datastoreAdminStub, undefined);
206-
client.close().then(() => {
207-
done();
188+
189+
it('has close method for the initialized client', done => {
190+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
191+
credentials: {client_email: 'bogus', private_key: 'bogus'},
192+
projectId: 'bogus',
193+
});
194+
client.initialize();
195+
assert(client.datastoreAdminStub);
196+
client.close().then(() => {
197+
done();
198+
});
208199
});
209-
});
210200

211-
it('has getProjectId method', async () => {
212-
const fakeProjectId = 'fake-project-id';
213-
const client = new datastoreadminModule.v1.DatastoreAdminClient({
214-
credentials: {client_email: 'bogus', private_key: 'bogus'},
215-
projectId: 'bogus',
201+
it('has close method for the non-initialized client', done => {
202+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
203+
credentials: {client_email: 'bogus', private_key: 'bogus'},
204+
projectId: 'bogus',
205+
});
206+
assert.strictEqual(client.datastoreAdminStub, undefined);
207+
client.close().then(() => {
208+
done();
209+
});
216210
});
217-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
218-
const result = await client.getProjectId();
219-
assert.strictEqual(result, fakeProjectId);
220-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
221-
});
222211

223-
it('has getProjectId method with callback', async () => {
224-
const fakeProjectId = 'fake-project-id';
225-
const client = new datastoreadminModule.v1.DatastoreAdminClient({
226-
credentials: {client_email: 'bogus', private_key: 'bogus'},
227-
projectId: 'bogus',
212+
it('has getProjectId method', async () => {
213+
const fakeProjectId = 'fake-project-id';
214+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
215+
credentials: {client_email: 'bogus', private_key: 'bogus'},
216+
projectId: 'bogus',
217+
});
218+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
219+
const result = await client.getProjectId();
220+
assert.strictEqual(result, fakeProjectId);
221+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
228222
});
229-
client.auth.getProjectId = sinon
230-
.stub()
231-
.callsArgWith(0, null, fakeProjectId);
232-
const promise = new Promise((resolve, reject) => {
233-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
234-
if (err) {
235-
reject(err);
236-
} else {
237-
resolve(projectId);
238-
}
223+
224+
it('has getProjectId method with callback', async () => {
225+
const fakeProjectId = 'fake-project-id';
226+
const client = new datastoreadminModule.v1.DatastoreAdminClient({
227+
credentials: {client_email: 'bogus', private_key: 'bogus'},
228+
projectId: 'bogus',
229+
});
230+
client.auth.getProjectId = sinon
231+
.stub()
232+
.callsArgWith(0, null, fakeProjectId);
233+
const promise = new Promise((resolve, reject) => {
234+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
235+
if (err) {
236+
reject(err);
237+
} else {
238+
resolve(projectId);
239+
}
240+
});
239241
});
242+
const result = await promise;
243+
assert.strictEqual(result, fakeProjectId);
240244
});
241-
const result = await promise;
242-
assert.strictEqual(result, fakeProjectId);
243245
});
244246

245247
describe('getIndex', () => {

0 commit comments

Comments
 (0)