Skip to content

Commit

Permalink
chore: add spanner_grpc_config.json and enable grpc-gcp support for s…
Browse files Browse the repository at this point in the history
…panner (#503)
  • Loading branch information
WeiranFang authored and JustinBeckwith committed Feb 15, 2019
1 parent e770252 commit 7cfe40f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const gapic = Object.freeze({
v1: require('./v1'),
});

const gcpApiConfig = require('./spanner_grpc_config.json');

/*!
* DO NOT DELETE THE FOLLOWING NAMESPACE DEFINITIONS
*/
Expand Down Expand Up @@ -206,6 +208,9 @@ class Spanner extends Service {
},
options || {});

// Enable grpc-gcp support
options = Object.assign({'grpc_gcp.apiConfig': gcpApiConfig}, options);

const config = {
baseUrl: options.servicePath || gapic.v1.SpannerClient.servicePath,
protosDir: path.resolve(__dirname, '../protos'),
Expand Down
92 changes: 92 additions & 0 deletions src/spanner_grpc_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"channelPool": {
"maxSize": 10,
"maxConcurrentStreamsLowWatermark": 100
},
"method": [
{
"name": [ "/google.spanner.v1.Spanner/CreateSession" ],
"affinity": {
"command": "BIND",
"affinityKey": "name"
}
},
{
"name": [ "/google.spanner.v1.Spanner/GetSession" ],
"affinity": {
"command": "BOUND",
"affinityKey": "name"
}
},
{
"name": [ "/google.spanner.v1.Spanner/DeleteSession" ],
"affinity": {
"command": "UNBIND",
"affinityKey": "name"
}
},
{
"name": [ "/google.spanner.v1.Spanner/ExecuteSql" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/ExecuteStreamingSql" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/Read" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/StreamingRead" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/BeginTransaction" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/Commit" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/Rollback" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/PartitionQuery" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
},
{
"name": [ "/google.spanner.v1.Spanner/PartitionRead" ],
"affinity": {
"command": "BOUND",
"affinityKey": "session"
}
}
]
}
5 changes: 5 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import * as pfy from '@google-cloud/promisify';
import * as sinon from 'sinon';
import * as spnr from '../src';

const apiConfig = require('../src/spanner_grpc_config.json');

function getFake(obj: {}) {
return obj as {
calledWith_: IArguments;
Expand Down Expand Up @@ -187,6 +189,7 @@ describe('Spanner', () => {
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes: [],
'grpc_gcp.apiConfig': apiConfig,
});

assert.deepStrictEqual(
Expand All @@ -205,6 +208,7 @@ describe('Spanner', () => {
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes: expectedScopes,
'grpc_gcp.apiConfig': apiConfig,
});

assert.deepStrictEqual(
Expand Down Expand Up @@ -235,6 +239,7 @@ describe('Spanner', () => {
libName: 'gccl',
libVersion: require('../../package.json').version,
scopes: [],
'grpc_gcp.apiConfig': apiConfig,
}));
});

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"noImplicitAny": false
"noImplicitAny": false,
"resolveJsonModule": true
},
"include": [
"src/*.ts",
"src/v1/*.d.ts",
"src/**/*.js",
"src/**/*.json",
"test/*.ts",
"system-test/*.ts",
]
Expand Down

0 comments on commit 7cfe40f

Please sign in to comment.