Skip to content

Commit

Permalink
fix: row.exists out of memory errors (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
laljikanjareeya committed Mar 30, 2020
1 parent 21f585b commit 191aa0f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/row.ts
Expand Up @@ -555,7 +555,24 @@ export class Row {
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
this.getMetadata(gaxOptions as GetRowOptions, err => {
const options = Object.assign(
{
filter: [
{
row: {
cellLimit: 1,
},
},
{
value: {
strip: true,
},
},
],
},
gaxOptions
);
this.getMetadata(options as GetRowOptions, err => {
if (err) {
if (err instanceof RowError) {
callback(null, false);
Expand Down
51 changes: 48 additions & 3 deletions test/row.ts
Expand Up @@ -21,6 +21,7 @@ import {Mutation} from '../src/mutation.js';
import * as rw from '../src/row';
import {Table, Entry} from '../src/table.js';
import {Chunk} from '../src/chunktransformer.js';
import {CallOptions} from 'google-gax';

const sandbox = sinon.createSandbox();

Expand Down Expand Up @@ -766,18 +767,62 @@ describe('Bigtable/Row', () => {
describe('exists', () => {
it('should not require gaxOptions', done => {
sandbox.stub(row, 'getMetadata').callsFake(gaxOptions => {
assert.deepStrictEqual(gaxOptions, {});
assert.deepStrictEqual(gaxOptions, {
filter: [
{
row: {
cellLimit: 1,
},
},
{
value: {
strip: true,
},
},
],
});
done();
});
row.exists(assert.ifError);
});

it('should pass gaxOptions to getMetadata', done => {
it('should add filter to the read row options', done => {
const gaxOptions = {};
sandbox.stub(row, 'getMetadata').callsFake(gaxOptions_ => {
assert.strictEqual(gaxOptions_, gaxOptions);
assert.deepStrictEqual(gaxOptions_, {
filter: [
{
row: {
cellLimit: 1,
},
},
{
value: {
strip: true,
},
},
],
});
done();
});
row.exists(gaxOptions, assert.ifError);
});

it('should pass gaxOptions to getMetadata', done => {
const gaxOptions = {
testProperty: true,
} as CallOptions;

sandbox.stub(row, 'getMetadata').callsFake(gaxOptions_ => {
assert.strictEqual(
// tslint:disable-next-line no-any
(gaxOptions_ as any).testProperty,
// tslint:disable-next-line no-any
(gaxOptions as any).testProperty
);
done();
});

row.exists(gaxOptions, assert.ifError);
});

Expand Down

0 comments on commit 191aa0f

Please sign in to comment.