Skip to content

Commit d9e7311

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

File tree

6 files changed

+257
-249
lines changed

6 files changed

+257
-249
lines changed

src/v1/publisher_client.ts

Lines changed: 8 additions & 8 deletions
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
/**
@@ -304,7 +303,8 @@ export class PublisherClient {
304303
const apiCall = this._gaxModule.createApiCall(
305304
callPromise,
306305
this._defaults[methodName],
307-
descriptor
306+
descriptor,
307+
this._opts.fallback
308308
);
309309

310310
this.innerApiCalls[methodName] = apiCall;
@@ -1044,7 +1044,7 @@ export class PublisherClient {
10441044
const callSettings = defaultCallSettings.merge(options);
10451045
this.initialize();
10461046
return this.descriptors.page.listTopics.createStream(
1047-
this.innerApiCalls.listTopics as gax.GaxCall,
1047+
this.innerApiCalls.listTopics as GaxCall,
10481048
request,
10491049
callSettings
10501050
);
@@ -1093,7 +1093,7 @@ export class PublisherClient {
10931093
this.initialize();
10941094
return this.descriptors.page.listTopics.asyncIterate(
10951095
this.innerApiCalls['listTopics'] as GaxCall,
1096-
request as unknown as RequestType,
1096+
request as {},
10971097
callSettings
10981098
) as AsyncIterable<protos.google.pubsub.v1.ITopic>;
10991099
}
@@ -1244,7 +1244,7 @@ export class PublisherClient {
12441244
const callSettings = defaultCallSettings.merge(options);
12451245
this.initialize();
12461246
return this.descriptors.page.listTopicSubscriptions.createStream(
1247-
this.innerApiCalls.listTopicSubscriptions as gax.GaxCall,
1247+
this.innerApiCalls.listTopicSubscriptions as GaxCall,
12481248
request,
12491249
callSettings
12501250
);
@@ -1293,7 +1293,7 @@ export class PublisherClient {
12931293
this.initialize();
12941294
return this.descriptors.page.listTopicSubscriptions.asyncIterate(
12951295
this.innerApiCalls['listTopicSubscriptions'] as GaxCall,
1296-
request as unknown as RequestType,
1296+
request as {},
12971297
callSettings
12981298
) as AsyncIterable<string>;
12991299
}
@@ -1438,7 +1438,7 @@ export class PublisherClient {
14381438
const callSettings = defaultCallSettings.merge(options);
14391439
this.initialize();
14401440
return this.descriptors.page.listTopicSnapshots.createStream(
1441-
this.innerApiCalls.listTopicSnapshots as gax.GaxCall,
1441+
this.innerApiCalls.listTopicSnapshots as GaxCall,
14421442
request,
14431443
callSettings
14441444
);
@@ -1487,7 +1487,7 @@ export class PublisherClient {
14871487
this.initialize();
14881488
return this.descriptors.page.listTopicSnapshots.asyncIterate(
14891489
this.innerApiCalls['listTopicSnapshots'] as GaxCall,
1490-
request as unknown as RequestType,
1490+
request as {},
14911491
callSettings
14921492
) as AsyncIterable<string>;
14931493
}

src/v1/schema_service_client.ts

Lines changed: 4 additions & 4 deletions
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
/**
@@ -271,7 +270,8 @@ export class SchemaServiceClient {
271270
const apiCall = this._gaxModule.createApiCall(
272271
callPromise,
273272
this._defaults[methodName],
274-
descriptor
273+
descriptor,
274+
this._opts.fallback
275275
);
276276

277277
this.innerApiCalls[methodName] = apiCall;
@@ -918,7 +918,7 @@ export class SchemaServiceClient {
918918
const callSettings = defaultCallSettings.merge(options);
919919
this.initialize();
920920
return this.descriptors.page.listSchemas.createStream(
921-
this.innerApiCalls.listSchemas as gax.GaxCall,
921+
this.innerApiCalls.listSchemas as GaxCall,
922922
request,
923923
callSettings
924924
);
@@ -971,7 +971,7 @@ export class SchemaServiceClient {
971971
this.initialize();
972972
return this.descriptors.page.listSchemas.asyncIterate(
973973
this.innerApiCalls['listSchemas'] as GaxCall,
974-
request as unknown as RequestType,
974+
request as {},
975975
callSettings
976976
) as AsyncIterable<protos.google.pubsub.v1.ISchema>;
977977
}

src/v1/subscriber_client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
} from 'google-gax';
3232

3333
import {Transform} from 'stream';
34-
import {RequestType} from 'google-gax/build/src/apitypes';
3534
import {PassThrough} from 'stream';
3635
import * as protos from '../../protos/protos';
3736
import jsonProtos = require('../../protos/protos.json');
@@ -312,7 +311,8 @@ export class SubscriberClient {
312311
const apiCall = this._gaxModule.createApiCall(
313312
callPromise,
314313
this._defaults[methodName],
315-
descriptor
314+
descriptor,
315+
this._opts.fallback
316316
);
317317

318318
this.innerApiCalls[methodName] = apiCall;
@@ -1862,7 +1862,7 @@ export class SubscriberClient {
18621862
const callSettings = defaultCallSettings.merge(options);
18631863
this.initialize();
18641864
return this.descriptors.page.listSubscriptions.createStream(
1865-
this.innerApiCalls.listSubscriptions as gax.GaxCall,
1865+
this.innerApiCalls.listSubscriptions as GaxCall,
18661866
request,
18671867
callSettings
18681868
);
@@ -1911,7 +1911,7 @@ export class SubscriberClient {
19111911
this.initialize();
19121912
return this.descriptors.page.listSubscriptions.asyncIterate(
19131913
this.innerApiCalls['listSubscriptions'] as GaxCall,
1914-
request as unknown as RequestType,
1914+
request as {},
19151915
callSettings
19161916
) as AsyncIterable<protos.google.pubsub.v1.ISubscription>;
19171917
}
@@ -2054,7 +2054,7 @@ export class SubscriberClient {
20542054
const callSettings = defaultCallSettings.merge(options);
20552055
this.initialize();
20562056
return this.descriptors.page.listSnapshots.createStream(
2057-
this.innerApiCalls.listSnapshots as gax.GaxCall,
2057+
this.innerApiCalls.listSnapshots as GaxCall,
20582058
request,
20592059
callSettings
20602060
);
@@ -2103,7 +2103,7 @@ export class SubscriberClient {
21032103
this.initialize();
21042104
return this.descriptors.page.listSnapshots.asyncIterate(
21052105
this.innerApiCalls['listSnapshots'] as GaxCall,
2106-
request as unknown as RequestType,
2106+
request as {},
21072107
callSettings
21082108
) as AsyncIterable<protos.google.pubsub.v1.ISnapshot>;
21092109
}

test/gapic_publisher_v1.ts

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -113,99 +113,101 @@ function stubAsyncIterationCall<ResponseType>(
113113
}
114114

115115
describe('v1.PublisherClient', () => {
116-
it('has servicePath', () => {
117-
const servicePath = publisherModule.v1.PublisherClient.servicePath;
118-
assert(servicePath);
119-
});
120-
121-
it('has apiEndpoint', () => {
122-
const apiEndpoint = publisherModule.v1.PublisherClient.apiEndpoint;
123-
assert(apiEndpoint);
124-
});
125-
126-
it('has port', () => {
127-
const port = publisherModule.v1.PublisherClient.port;
128-
assert(port);
129-
assert(typeof port === 'number');
130-
});
116+
describe('Common methods', () => {
117+
it('has servicePath', () => {
118+
const servicePath = publisherModule.v1.PublisherClient.servicePath;
119+
assert(servicePath);
120+
});
131121

132-
it('should create a client with no option', () => {
133-
const client = new publisherModule.v1.PublisherClient();
134-
assert(client);
135-
});
122+
it('has apiEndpoint', () => {
123+
const apiEndpoint = publisherModule.v1.PublisherClient.apiEndpoint;
124+
assert(apiEndpoint);
125+
});
136126

137-
it('should create a client with gRPC fallback', () => {
138-
const client = new publisherModule.v1.PublisherClient({
139-
fallback: true,
127+
it('has port', () => {
128+
const port = publisherModule.v1.PublisherClient.port;
129+
assert(port);
130+
assert(typeof port === 'number');
140131
});
141-
assert(client);
142-
});
143132

144-
it('has initialize method and supports deferred initialization', async () => {
145-
const client = new publisherModule.v1.PublisherClient({
146-
credentials: {client_email: 'bogus', private_key: 'bogus'},
147-
projectId: 'bogus',
133+
it('should create a client with no option', () => {
134+
const client = new publisherModule.v1.PublisherClient();
135+
assert(client);
148136
});
149-
assert.strictEqual(client.publisherStub, undefined);
150-
await client.initialize();
151-
assert(client.publisherStub);
152-
});
153137

154-
it('has close method for the initialized client', done => {
155-
const client = new publisherModule.v1.PublisherClient({
156-
credentials: {client_email: 'bogus', private_key: 'bogus'},
157-
projectId: 'bogus',
138+
it('should create a client with gRPC fallback', () => {
139+
const client = new publisherModule.v1.PublisherClient({
140+
fallback: true,
141+
});
142+
assert(client);
158143
});
159-
client.initialize();
160-
assert(client.publisherStub);
161-
client.close().then(() => {
162-
done();
144+
145+
it('has initialize method and supports deferred initialization', async () => {
146+
const client = new publisherModule.v1.PublisherClient({
147+
credentials: {client_email: 'bogus', private_key: 'bogus'},
148+
projectId: 'bogus',
149+
});
150+
assert.strictEqual(client.publisherStub, undefined);
151+
await client.initialize();
152+
assert(client.publisherStub);
163153
});
164-
});
165154

166-
it('has close method for the non-initialized client', done => {
167-
const client = new publisherModule.v1.PublisherClient({
168-
credentials: {client_email: 'bogus', private_key: 'bogus'},
169-
projectId: 'bogus',
155+
it('has close method for the initialized client', done => {
156+
const client = new publisherModule.v1.PublisherClient({
157+
credentials: {client_email: 'bogus', private_key: 'bogus'},
158+
projectId: 'bogus',
159+
});
160+
client.initialize();
161+
assert(client.publisherStub);
162+
client.close().then(() => {
163+
done();
164+
});
170165
});
171-
assert.strictEqual(client.publisherStub, undefined);
172-
client.close().then(() => {
173-
done();
166+
167+
it('has close method for the non-initialized client', done => {
168+
const client = new publisherModule.v1.PublisherClient({
169+
credentials: {client_email: 'bogus', private_key: 'bogus'},
170+
projectId: 'bogus',
171+
});
172+
assert.strictEqual(client.publisherStub, undefined);
173+
client.close().then(() => {
174+
done();
175+
});
174176
});
175-
});
176177

177-
it('has getProjectId method', async () => {
178-
const fakeProjectId = 'fake-project-id';
179-
const client = new publisherModule.v1.PublisherClient({
180-
credentials: {client_email: 'bogus', private_key: 'bogus'},
181-
projectId: 'bogus',
178+
it('has getProjectId method', async () => {
179+
const fakeProjectId = 'fake-project-id';
180+
const client = new publisherModule.v1.PublisherClient({
181+
credentials: {client_email: 'bogus', private_key: 'bogus'},
182+
projectId: 'bogus',
183+
});
184+
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
185+
const result = await client.getProjectId();
186+
assert.strictEqual(result, fakeProjectId);
187+
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
182188
});
183-
client.auth.getProjectId = sinon.stub().resolves(fakeProjectId);
184-
const result = await client.getProjectId();
185-
assert.strictEqual(result, fakeProjectId);
186-
assert((client.auth.getProjectId as SinonStub).calledWithExactly());
187-
});
188189

189-
it('has getProjectId method with callback', async () => {
190-
const fakeProjectId = 'fake-project-id';
191-
const client = new publisherModule.v1.PublisherClient({
192-
credentials: {client_email: 'bogus', private_key: 'bogus'},
193-
projectId: 'bogus',
194-
});
195-
client.auth.getProjectId = sinon
196-
.stub()
197-
.callsArgWith(0, null, fakeProjectId);
198-
const promise = new Promise((resolve, reject) => {
199-
client.getProjectId((err?: Error | null, projectId?: string | null) => {
200-
if (err) {
201-
reject(err);
202-
} else {
203-
resolve(projectId);
204-
}
190+
it('has getProjectId method with callback', async () => {
191+
const fakeProjectId = 'fake-project-id';
192+
const client = new publisherModule.v1.PublisherClient({
193+
credentials: {client_email: 'bogus', private_key: 'bogus'},
194+
projectId: 'bogus',
195+
});
196+
client.auth.getProjectId = sinon
197+
.stub()
198+
.callsArgWith(0, null, fakeProjectId);
199+
const promise = new Promise((resolve, reject) => {
200+
client.getProjectId((err?: Error | null, projectId?: string | null) => {
201+
if (err) {
202+
reject(err);
203+
} else {
204+
resolve(projectId);
205+
}
206+
});
205207
});
208+
const result = await promise;
209+
assert.strictEqual(result, fakeProjectId);
206210
});
207-
const result = await promise;
208-
assert.strictEqual(result, fakeProjectId);
209211
});
210212

211213
describe('createTopic', () => {

0 commit comments

Comments
 (0)