Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 0b3d996

Browse files
committed
chore: add test proxy
Added a server proxy that is going to be used by the Test Framework for Cloud Bigtable Client Libraries. Refs: https://github.com/googleapis/cloud-bigtable-clients-test
1 parent 88c0a0e commit 0b3d996

19 files changed

Lines changed: 952 additions & 1 deletion

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"pretest": "npm run compile",
4343
"test": "c8 mocha build/test",
4444
"test:snap": "SNAPSHOT_UPDATE=1 npm test",
45+
"testproxy": "node testproxy/index.js",
4546
"clean": "gts clean",
4647
"precompile": "gts clean"
4748
},
@@ -64,6 +65,8 @@
6465
"stream-events": "^1.0.2"
6566
},
6667
"devDependencies": {
68+
"@grpc/grpc-js": "^1.7.1",
69+
"@grpc/proto-loader": "^0.7.3",
6770
"@types/escape-string-regexp": "^1.0.0",
6871
"@types/extend": "^3.0.1",
6972
"@types/is": "0.0.21",
@@ -87,8 +90,8 @@
8790
"pack-n-play": "^1.0.0-2",
8891
"proxyquire": "^2.0.0",
8992
"sinon": "^14.0.0",
90-
"tcp-port-used": "^1.0.2",
9193
"snap-shot-it": "^7.9.1",
94+
"tcp-port-used": "^1.0.2",
9295
"ts-loader": "^9.0.0",
9396
"typescript": "^4.6.4",
9497
"uuid": "^9.0.0",

protos/v2_test_proxy.proto

Lines changed: 189 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testproxy/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Test Proxy
2+
3+
This is a **Test Proxy** implementation meant to be used in conjuction with the
4+
[Test Framework for Cloud Bigtable Client Libraries](https://github.com/googleapis/cloud-bigtable-clients-test).
5+
6+
## Setup
7+
8+
Dependencies are installed as part of the main project using **npm**:
9+
10+
```console
11+
$ npm install
12+
```
13+
14+
## Running
15+
16+
In order to start the **Test Proxy** server, run:
17+
18+
```console
19+
$ npm run testproxy
20+
```
21+
22+
This will start the proxy server that will listen to port `9999` by default
23+
and enable [running tests from the main go mock test implementation](https://github.com/googleapis/cloud-bigtable-clients-test#test-execution)
24+
against the JavaScript library implementation.
25+
26+
## Options
27+
28+
### Using a different port
29+
30+
By default the **Test Proxy** will listen to port `9999`, in order to change
31+
the value use the `PORT` environment variable, e.g:
32+
33+
```console
34+
$ PORT=1337 npm run testproxy
35+
```
36+

testproxy/index.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
const {dirname, resolve} = require('node:path');
17+
18+
const grpc = require('@grpc/grpc-js');
19+
const protoLoader = require('@grpc/proto-loader');
20+
21+
const services = require('./services/index.js');
22+
23+
const GAX_PROTOS_DIR = resolve(
24+
dirname(require.resolve('google-gax')),
25+
'../protos'
26+
);
27+
const PROTOS_DIR = resolve(__dirname, '../protos');
28+
const PROTO_PATH = resolve(PROTOS_DIR, 'v2_test_proxy.proto');
29+
const port = parseInt(process.env.PORT, 10) || 9999;
30+
31+
async function loadDescriptor() {
32+
const packageDefinition = await protoLoader.load(PROTO_PATH, {
33+
keepCase: false,
34+
longs: String,
35+
enums: String,
36+
defaults: true,
37+
oneofs: true,
38+
includeDirs: [PROTOS_DIR, GAX_PROTOS_DIR],
39+
});
40+
return grpc.loadPackageDefinition(packageDefinition);
41+
}
42+
43+
function startServer(service) {
44+
const server = new grpc.Server();
45+
server.addService(service, services.getServicesImplementation());
46+
47+
return server.bindAsync(
48+
`0.0.0.0:${port}`,
49+
grpc.ServerCredentials.createInsecure(),
50+
() => {
51+
console.log(`grpc server started on port: ${port}`);
52+
server.start();
53+
}
54+
);
55+
}
56+
57+
async function main() {
58+
const descriptor = await loadDescriptor();
59+
const {service} = descriptor.bigtable.client.test.CloudBigtableV2TestProxy;
60+
await startServer(service);
61+
}
62+
63+
main();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
const grpc = require('@grpc/grpc-js');
17+
const {BigtableClient} = require('../../build/src/index.js').v2;
18+
19+
const normalizeCallback = require('./utils/normalize-callback.js');
20+
21+
const bulkMutateRows = ({clientMap}) =>
22+
normalizeCallback(async rawRequest => {
23+
const {request} = rawRequest;
24+
const {request: mutateRequest} = request;
25+
const {appProfileId, entries, tableName} = mutateRequest;
26+
27+
const {clientId} = request;
28+
const bigtable = clientMap.get(clientId);
29+
const client = new BigtableClient(bigtable.options.BigtableClient);
30+
const result = await new Promise((res, rej) => {
31+
const response = {entries: []};
32+
client
33+
.mutateRows({
34+
appProfileId,
35+
entries,
36+
tableName,
37+
})
38+
.on('data', data => {
39+
response.entries = [...data.entries];
40+
})
41+
.on('error', rej)
42+
.on('end', () => res(response));
43+
});
44+
45+
return {
46+
status: {code: grpc.status.OK, details: []},
47+
entry: result.entries,
48+
};
49+
});
50+
51+
module.exports = bulkMutateRows;

0 commit comments

Comments
 (0)