memgraph/tests/drivers/javascript/max_query_length.js
Marko Budiselic d14a4b69ab Max Query Size
Summary: Query Size Limit in Python, Java, JavaScript

Reviewers: mferencevic, mislav.bradac, teon.banek

Reviewed By: mferencevic, teon.banek

Subscribers: pullbot, buda

Differential Revision: https://phabricator.memgraph.io/D508
2017-07-13 14:09:27 +02:00

52 lines
1.7 KiB
JavaScript

// Determines how long could be a query executed
// from JavaScript driver.
//
// Performs binary search until the maximum possible
// query size has found.
// init driver
var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost:7687",
neo4j.auth.basic("", ""),
{ encrypted: 'ENCRYPTION_OFF' });
// init state
var property_size = 0;
var min_len = 1;
var max_len = 1000000;
// hacking with JS and callbacks concept
function serial_execution() {
var next_size = [Math.floor((min_len + max_len) / 2)];
setInterval(function() {
if (next_size.length > 0) {
property_size = next_size.pop();
var query = "CREATE (n {name:\"" +
(new Array(property_size)).join("a")+ "\"})";
var session = driver.session();
session.run(query, {}).then(function (result) {
console.log("Success with the query length " + query.length);
if (min_len == max_len || property_size + 1 > max_len) {
console.log("\nThe max length of a query from JS driver is: " +
query.length + "\n");
session.close();
driver.close();
process.exit(0);
}
min_len = property_size + 1;
next_size.push(Math.floor((min_len + max_len) / 2));
}).catch(function (error) {
console.log("Failure with the query length " + query.length);
max_len = property_size - 1;
next_size.push(Math.floor((min_len + max_len) / 2));
}).then(function(){
session.close();
});
}
}, 100);
}
// execution
console.log("\nDetermine how long can be a query sent from JavaScript driver.");
serial_execution(); // I don't like JavaScript