Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue#354 #355

Merged
merged 1 commit into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/chunktransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class ChunkTransformer extends Transform {
* @private
*/
reset() {
this.prevRowKey = null;
this.family = {};
this.qualifiers = [];
this.qualifier = {};
Expand All @@ -140,13 +139,13 @@ class ChunkTransformer extends Transform {
}

/**
* sets prevRowkey and calls reset when row is committed.
* sets lastRowkey and calls reset when row is committed.
* @private
*/
commit() {
const row = this.row;
this.reset();
this.prevRowKey = row.key;
this.lastRowKey = row.key;
}

/**
Expand Down Expand Up @@ -195,7 +194,7 @@ class ChunkTransformer extends Transform {
*/
validateNewRow(chunk, newRowKey) {
const row = this.row;
const prevRowKey = this.prevRowKey;
const lastRowKey = this.lastRowKey;
let errorMessage;

if (typeof row.key !== 'undefined') {
Expand All @@ -208,7 +207,7 @@ class ChunkTransformer extends Transform {
errorMessage = 'A row key must be set';
} else if (chunk.resetRow) {
errorMessage = 'A new row cannot be reset';
} else if (prevRowKey === newRowKey) {
} else if (lastRowKey === newRowKey) {
errorMessage = 'A commit happened but the same key followed';
} else if (!chunk.familyName) {
errorMessage = 'A family must be set';
Expand Down
26 changes: 13 additions & 13 deletions test/chunktransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ describe('Bigtable/ChunkTransformer', function() {
describe('instantiation', function() {
it('should have initial state', function() {
assert(chunkTransformer instanceof ChunkTransformer);
this.prevRowKey = '';
this.lastRowKey = '';
this.family = {};
this.qualifiers = [];
this.qualifier = {};
this.row = {};
this.state = RowStateEnum.NEW_ROW;
assert.deepStrictEqual(chunkTransformer.row, {}, 'invalid initial state');
assert.deepStrictEqual(
chunkTransformer.prevRowKey,
null,
chunkTransformer.lastRowKey,
undefined,
'invalid initial state'
);
assert.deepStrictEqual(
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Bigtable/ChunkTransformer', function() {
assert(destroySpy.called);
done();
});
chunkTransformer.prevRowKey = 'key';
chunkTransformer.lastRowKey = 'key';

processNewRowSpy.call(chunkTransformer, {
rowKey: 'key',
Expand Down Expand Up @@ -194,9 +194,9 @@ describe('Bigtable/ChunkTransformer', function() {
assert(resetSpy.called, 'reset state failed');
assert(commitSpy.called, 'commit row failed');
assert.strictEqual(
chunkTransformer.prevRowKey,
chunkTransformer.lastRowKey,
chunk.rowKey,
'wrong state prevrowkey'
'wrong state lastRowKey'
);
const expectedRow = {
key: chunk.rowKey,
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('Bigtable/ChunkTransformer', function() {
timestampMicros: 10,
});
});
it('should destroy when rowKey not equal to prevRowKey', function(done) {
it('should destroy when rowKey not equal to lastRowKey', function(done) {
chunkTransformer.on('error', function() {
assert(destroySpy.called);
done();
Expand Down Expand Up @@ -963,7 +963,7 @@ describe('Bigtable/ChunkTransformer', function() {
});
describe('reset', function() {
it('should reset initial state', function() {
chunkTransformer.prevRowKey = 'prevkey';
chunkTransformer.lastRowKey = 'prevkey';
chunkTransformer.qualifier = {
value: 'value',
size: 0,
Expand All @@ -984,8 +984,8 @@ describe('Bigtable/ChunkTransformer', function() {
chunkTransformer.reset();
assert.deepStrictEqual(chunkTransformer.row, {}, 'invalid initial state');
assert.deepStrictEqual(
chunkTransformer.prevRowKey,
null,
chunkTransformer.lastRowKey,
'prevkey',
'invalid initial state'
);
assert.deepStrictEqual(
Expand Down Expand Up @@ -1015,8 +1015,8 @@ describe('Bigtable/ChunkTransformer', function() {
beforeEach(function() {
resetSpy = sinon.spy(chunkTransformer, 'reset');
});
it('should reset to initial state and set prevRowKey', function() {
chunkTransformer.prevRowKey = '';
it('should reset to initial state and set lastRowKey', function() {
chunkTransformer.lastRowKey = '';
chunkTransformer.qualifier = {
value: 'value',
size: 0,
Expand All @@ -1038,7 +1038,7 @@ describe('Bigtable/ChunkTransformer', function() {
assert(resetSpy.called, 'did not call reset');
assert.deepStrictEqual(chunkTransformer.row, {}, 'invalid initial state');
assert.deepStrictEqual(
chunkTransformer.prevRowKey,
chunkTransformer.lastRowKey,
'key',
'invalid initial state'
);
Expand Down