Add support for disabling feature datasets (#6666)
This change adds support for disabling datasets, such that specific files are not loaded into memory when running OSRM. This enables users to not pay the memory cost for features they do not intend to use. Initially, there are two options: - ROUTE_GEOMETRY, for disabling overview, steps, annotations and waypoints. - ROUTE_STEPS, for disabling steps only. Attempts to query features for which the datasets are disabled will lead to a DisabledDatasetException being returned.
This commit is contained in:
@@ -163,6 +163,43 @@ test('constructor: throws on invalid custom limits', function(assert) {
|
||||
})
|
||||
});
|
||||
});
|
||||
test('constructor: throws on invalid disable_feature_dataset option', function(assert) {
|
||||
assert.plan(1);
|
||||
assert.throws(function() {
|
||||
var osrm = new OSRM({
|
||||
path: monaco_path,
|
||||
disable_feature_dataset: ['NOT_EXIST'],
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
test('constructor: throws on non-array disable_feature_dataset', function(assert) {
|
||||
assert.plan(1);
|
||||
assert.throws(function() {
|
||||
var osrm = new OSRM({
|
||||
path: monaco_path,
|
||||
disable_feature_dataset: 'ROUTE_GEOMETRY',
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
test('constructor: ok on valid disable_feature_dataset option', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({
|
||||
path: monaco_path,
|
||||
disable_feature_dataset: ['ROUTE_GEOMETRY'],
|
||||
});
|
||||
assert.ok(osrm);
|
||||
});
|
||||
|
||||
test('constructor: ok on multiple overlapping disable_feature_dataset options', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({
|
||||
path: monaco_path,
|
||||
disable_feature_dataset: ['ROUTE_GEOMETRY', 'ROUTE_STEPS'],
|
||||
});
|
||||
assert.ok(osrm);
|
||||
});
|
||||
|
||||
require('./route.js');
|
||||
require('./trip.js');
|
||||
|
||||
@@ -398,3 +398,65 @@ test('match: match in Monaco with waypoints', function(assert) {
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
test('match: throws on disabled geometry', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.match(options, function(err, route) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('match: ok on disabled geometry', function (assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
steps: false,
|
||||
overview: 'false',
|
||||
annotations: false,
|
||||
skip_waypoints: true,
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.match(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.matchings.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test('match: throws on disabled steps', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
steps: true,
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.match(options, function(err, route) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('match: ok on disabled steps', function (assert) {
|
||||
assert.plan(8);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
steps: false,
|
||||
overview: 'simplified',
|
||||
annotations: true,
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.match(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.ok(response.tracepoints);
|
||||
assert.ok(response.matchings);
|
||||
assert.equal(response.matchings.length, 1);
|
||||
assert.ok(response.matchings[0].geometry, "the match has geometry");
|
||||
assert.ok(response.matchings[0].legs, "the match has legs");
|
||||
assert.notok(response.matchings[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
|
||||
assert.ok(response.matchings[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -103,3 +103,40 @@ test('nearest: nearest in Monaco without motorways', function(assert) {
|
||||
assert.equal(response.waypoints.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test('nearest: throws on disabled geometry', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: [two_test_coordinates[0]],
|
||||
};
|
||||
osrm.nearest(options, function(err, response) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
test('nearest: ok on disabled geometry', function(assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: [two_test_coordinates[0]],
|
||||
skip_waypoints: true,
|
||||
};
|
||||
osrm.nearest(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.notok(response.waypoints);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
test('nearest: ok on disabled steps', function(assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
coordinates: [two_test_coordinates[0]],
|
||||
};
|
||||
osrm.nearest(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.waypoints.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
+63
-1
@@ -761,4 +761,66 @@ test('route: snapping parameter passed through OK', function(assert) {
|
||||
assert.ifError(err);
|
||||
assert.equal(Math.round(route.routes[0].distance * 10), 1315); // Round it to nearest 0.1m to eliminate floating point comparison error
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('route: throws on disabled geometry', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: three_test_coordinates,
|
||||
};
|
||||
osrm.route(options, function(err, route) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('route: ok on disabled geometry', function (assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
steps: false,
|
||||
overview: 'false',
|
||||
annotations: false,
|
||||
skip_waypoints: true,
|
||||
coordinates: three_test_coordinates,
|
||||
};
|
||||
osrm.route(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.routes.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test('route: throws on disabled steps', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
steps: true,
|
||||
coordinates: three_test_coordinates,
|
||||
};
|
||||
osrm.route(options, function(err, route) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('route: ok on disabled steps', function (assert) {
|
||||
assert.plan(8);
|
||||
var osrm = new OSRM({'path': monaco_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
steps: false,
|
||||
overview: 'simplified',
|
||||
annotations: true,
|
||||
coordinates: three_test_coordinates,
|
||||
};
|
||||
osrm.route(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.ok(response.waypoints);
|
||||
assert.ok(response.routes);
|
||||
assert.equal(response.routes.length, 1);
|
||||
assert.ok(response.routes[0].geometry, "the route has geometry");
|
||||
assert.ok(response.routes[0].legs, "the route has legs");
|
||||
assert.notok(response.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
|
||||
assert.ok(response.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
|
||||
});
|
||||
});
|
||||
|
||||
+41
-1
@@ -19,7 +19,7 @@ test('table: flatbuffer format', function(assert) {
|
||||
assert.ok(table instanceof Buffer);
|
||||
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(table));
|
||||
assert.ok(fb.table());
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -369,3 +369,43 @@ tables.forEach(function(annotation) {
|
||||
});
|
||||
});
|
||||
|
||||
test('table: throws on disabled geometry', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: [three_test_coordinates[0], three_test_coordinates[1]],
|
||||
};
|
||||
osrm.table(options, function(err, table) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('table: ok on disabled geometry', function (assert) {
|
||||
assert.plan(4);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: [three_test_coordinates[0], three_test_coordinates[1]],
|
||||
skip_waypoints: true
|
||||
};
|
||||
osrm.table(options, function(err, table) {
|
||||
assert.ifError(err);
|
||||
assert.ok(table.durations, 'distances table result should exist');
|
||||
assert.notok(table.sources)
|
||||
assert.notok(table.destinations)
|
||||
});
|
||||
});
|
||||
|
||||
test('table: ok on disabled steps', function (assert) {
|
||||
assert.plan(4);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
coordinates: [three_test_coordinates[0], three_test_coordinates[1]],
|
||||
};
|
||||
osrm.table(options, function(err, table) {
|
||||
assert.ifError(err);
|
||||
assert.ok(table.durations, 'distances table result should exist');
|
||||
assert.ok(table.sources.length, 2)
|
||||
assert.ok(table.destinations.length, 2)
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,3 +23,20 @@ test.test('tile interface pre-conditions', function(assert) {
|
||||
assert.throws(function() { osrm.tile(17059, 11948, 15, function(err, result) {}) }, /must be an array \[x, y, z\]/);
|
||||
assert.throws(function() { osrm.tile([17059, 11948, -15], function(err, result) {}) }, /must be unsigned/);
|
||||
});
|
||||
|
||||
test.test('tile fails to load with geometry disabled', function(assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
osrm.tile(tile.at, function(err, result) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
test.test('tile ok with steps disabled', function(assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
osrm.tile(tile.at, function(err, result) {
|
||||
assert.ifError(err);
|
||||
assert.equal(result.length, tile.size);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -368,3 +368,65 @@ test('trip: trip in Monaco without motorways', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('trip: throws on disabled geometry', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.trip(options, function(err, route) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('trip: ok on disabled geometry', function (assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
||||
var options = {
|
||||
steps: false,
|
||||
overview: 'false',
|
||||
annotations: false,
|
||||
skip_waypoints: true,
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.trip(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.trips.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test('trip: throws on disabled steps', function (assert) {
|
||||
assert.plan(1);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
steps: true,
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.trip(options, function(err, route) {
|
||||
console.log(err)
|
||||
assert.match(err.message, /DisabledDatasetException/);
|
||||
});
|
||||
});
|
||||
|
||||
test('trip: ok on disabled steps', function (assert) {
|
||||
assert.plan(8);
|
||||
var osrm = new OSRM({'path': data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
||||
var options = {
|
||||
steps: false,
|
||||
overview: 'simplified',
|
||||
annotations: true,
|
||||
coordinates: three_test_coordinates.concat(three_test_coordinates),
|
||||
};
|
||||
osrm.trip(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.ok(response.waypoints);
|
||||
assert.ok(response.trips);
|
||||
assert.equal(response.trips.length, 1);
|
||||
assert.ok(response.trips[0].geometry, "trip has geometry");
|
||||
assert.ok(response.trips[0].legs, "trip has legs");
|
||||
assert.notok(response.trips[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
|
||||
assert.ok(response.trips[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user