Skip to content

populate resultAvailableAfter during transaction#run #248

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 14, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ node_modules
.idea
docs/build
.npmrc
*.iml
16 changes: 15 additions & 1 deletion src/v1/internal/stream-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import Record from "../record";

/**
Expand Down Expand Up @@ -44,6 +43,7 @@ class StreamObserver {
this._errorTransformer = errorTransformer;
this._observer = null;
this._conn = null;
this._meta = {};
}

/**
Expand Down Expand Up @@ -83,6 +83,20 @@ class StreamObserver {
this._tail = meta;
}
}
this._copyMetadataOnCompletion( meta );
}

_copyMetadataOnCompletion(meta) {
for (var key in meta) {
if (meta.hasOwnProperty(key)) {
this._meta[key] = meta[key];
}
}
}

serverMetadata() {
const serverMeta = {server: this._conn.server};
return Object.assign({}, this._meta, serverMeta);
}

resolveConnection(conn) {
Expand Down
26 changes: 2 additions & 24 deletions src/v1/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Session {
}

_run(statement, parameters, statementRunner) {
const streamObserver = new _RunObserver(this._onRunFailure());
const streamObserver = new StreamObserver(this._onRunFailure());
const connectionHolder = this._connectionHolderWithMode(this._mode);
if (!this._hasTx) {
connectionHolder.initializeConnection();
Expand All @@ -86,7 +86,7 @@ class Session {
'session with an open transaction; either run from within the ' +
'transaction or use a different session.'));
}
return new Result(streamObserver, statement, parameters, () => streamObserver.meta(), connectionHolder);
return new Result(streamObserver, statement, parameters, () => streamObserver.serverMetadata(), connectionHolder);
}

/**
Expand Down Expand Up @@ -217,28 +217,6 @@ class Session {
}
}

/** Internal stream observer used for transactional results*/
class _RunObserver extends StreamObserver {
constructor(onError) {
super(onError);
this._meta = {};
}

onCompleted(meta) {
super.onCompleted(meta);
for(var key in meta){
if(meta.hasOwnProperty(key)){
this._meta[key]=meta[key];
}
}
}

meta() {
const serverMeta = {server: this._conn.server};
return Object.assign({}, this._meta, serverMeta);
}
}

function _createTransactionExecutor(config) {
const maxRetryTimeMs = (config && config.maxTransactionRetryTime) ? config.maxTransactionRetryTime : null;
return new TransactionExecutor(maxRetryTimeMs);
Expand Down
7 changes: 1 addition & 6 deletions src/v1/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ class _TransactionStreamObserver extends StreamObserver {
const bookmark = meta.bookmark;
this._tx._onBookmark(bookmark);
}

serverMeta() {
const serverMeta = {server: this._conn.server};
return serverMeta;
}
}

/** internal state machine of the transaction*/
Expand All @@ -179,7 +174,7 @@ let _states = {
conn.sync();
}).catch(error => observer.onError(error));

return _newRunResult(observer, statement, parameters, () => observer.serverMeta());
return _newRunResult(observer, statement, parameters, () => observer.serverMetadata());
}
},

Expand Down
16 changes: 15 additions & 1 deletion test/v1/transaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,21 @@ describe('transaction', () => {
}).catch(console.log);
});

it('should handle interactive session', done => {
it('should populate resultAvailableAfter for transaction#run when using 3.1 and onwards', done => {
if (neo4jVersionOlderThan31(done)) {
return;
}
const tx = session.beginTransaction();
tx.run("CREATE (:TXNode1)").then(result => {
tx.commit().then(() => {
expect(result.summary.resultAvailableAfter).toBeDefined();
expect(result.summary.resultAvailableAfter.toInt()).not.toBeLessThan(0);
done();
}).catch(console.log);
}).catch(console.log);
});

it('should handle interactive session', done => {
const tx = session.beginTransaction();
tx.run("RETURN 'foo' AS res").then(result => {
tx.run("CREATE ({name: {param}})", {param: result.records[0].get('res')}).then(() => {
Expand Down